• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LIBARK_DEFECT_SCAN_AUX_INCLUDE_GRAPH_H
17 #define LIBARK_DEFECT_SCAN_AUX_INCLUDE_GRAPH_H
18 
19 #include <string>
20 #include <vector>
21 #include "compiler/optimizer/ir/basicblock.h"
22 #include "compiler/optimizer/ir/graph.h"
23 #include "inst_type.h"
24 
25 namespace panda::defect_scan_aux {
26 class BasicBlock;
27 class Graph;
28 
29 // a wrapper class for compiler::Inst
30 class Inst {
31 public:
Inst(const compiler::Inst * inst)32     explicit Inst(const compiler::Inst *inst) : inst_(inst)
33     {
34         type_ = GetInstType(inst_);
35     }
36     ~Inst() = default;
37 
38     bool operator==(const Inst &inst) const;
39     bool operator!=(const Inst &inst) const;
40     InstType GetType() const;
41     bool IsInstStLexVar() const;
42     bool IsInstLdLexVar() const;
43     bool IsInstStGlobal() const;
44     bool IsInstLdGlobal() const;
45     uint16_t GetArgIndex() const;
46     uint32_t GetPc() const;
47     BasicBlock GetBasicBlock() const;
48     Graph GetGraph() const;
49     std::vector<Inst> GetInputInsts() const;
50     std::vector<Inst> GetUserInsts() const;
51     std::vector<uint32_t> GetImms() const;
52 
53 private:
54     InstType GetInstType(const compiler::Inst *inst);
55 
56     const compiler::Inst *inst_ {nullptr};
57     InstType type_ {InstType::INVALID_TYPE};
58 };
59 
60 // a wrapper class for compiler::BasicBlock
61 class BasicBlock {
62 public:
BasicBlock(const compiler::BasicBlock * bb)63     explicit BasicBlock(const compiler::BasicBlock *bb) : bb_(bb) {}
64     ~BasicBlock() = default;
65 
66     bool operator==(const BasicBlock &bb) const;
67     bool operator!=(const BasicBlock &bb) const;
68     Graph GetGraph() const;
69     std::vector<BasicBlock> GetPredBlocks() const;
70     std::vector<BasicBlock> GetSuccBlocks() const;
71     std::vector<Inst> GetInstList() const;
72 
73 private:
74     const compiler::BasicBlock *bb_ {nullptr};
75 };
76 
77 // a wrapper class for compiler::Graph
78 class Graph {
79 public:
80     using InstVisitor = std::function<void(const Inst &)>;
Graph(const compiler::Graph * graph)81     explicit Graph(const compiler::Graph *graph) : graph_(graph) {}
82     ~Graph() = default;
83 
84     BasicBlock GetStartBasicBlock() const;
85     BasicBlock GetEndBasicBlock() const;
86     std::vector<BasicBlock> GetBasicBlockList() const;
87     void VisitAllInstructions(const InstVisitor visitor) const;
88 
89 private:
90     const compiler::Graph *graph_ {nullptr};
91 };
92 }  // namespace panda::defect_scan_aux
93 
94 #endif  // LIBARK_DEFECT_SCAN_AUX_INCLUDE_GRAPH_H