[midend-SCCP]为跳转指令增加getSuccessors方法
This commit is contained in:
@@ -1074,6 +1074,16 @@ public:
|
|||||||
auto getArguments() const {
|
auto getArguments() const {
|
||||||
return make_range(std::next(operand_begin()), operand_end());
|
return make_range(std::next(operand_begin()), operand_end());
|
||||||
}
|
}
|
||||||
|
std::vector<BasicBlock *> getSuccessors() const {
|
||||||
|
std::vector<BasicBlock *> succs;
|
||||||
|
// 假设无条件分支的目标块是它的第一个操作数
|
||||||
|
if (getNumOperands() > 0) {
|
||||||
|
if (auto target_bb = dynamic_cast<BasicBlock *>(getOperand(0))) {
|
||||||
|
succs.push_back(target_bb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return succs;
|
||||||
|
}
|
||||||
|
|
||||||
}; // class UncondBrInst
|
}; // class UncondBrInst
|
||||||
|
|
||||||
@@ -1105,6 +1115,20 @@ public:
|
|||||||
BasicBlock* getElseBlock() const {
|
BasicBlock* getElseBlock() const {
|
||||||
return dynamic_cast<BasicBlock *>(getOperand(2));
|
return dynamic_cast<BasicBlock *>(getOperand(2));
|
||||||
}
|
}
|
||||||
|
std::vector<BasicBlock *> getSuccessors() const {
|
||||||
|
std::vector<BasicBlock *> succs;
|
||||||
|
// 假设条件分支的真实块是第二个操作数,假块是第三个操作数
|
||||||
|
// 操作数通常是:[0] 条件值, [1] TrueTargetBlock, [2] FalseTargetBlock
|
||||||
|
if (getNumOperands() > 2) {
|
||||||
|
if (auto true_bb = getThenBlock()) {
|
||||||
|
succs.push_back(true_bb);
|
||||||
|
}
|
||||||
|
if (auto false_bb = getElseBlock()) {
|
||||||
|
succs.push_back(false_bb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return succs;
|
||||||
|
}
|
||||||
// auto getThenArguments() const {
|
// auto getThenArguments() const {
|
||||||
// auto begin = std::next(operand_begin(), 3);
|
// auto begin = std::next(operand_begin(), 3);
|
||||||
// // auto end = std::next(begin, getThenBlock()->getNumArguments());
|
// // auto end = std::next(begin, getThenBlock()->getNumArguments());
|
||||||
|
|||||||
Reference in New Issue
Block a user