forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
881 B
37 lines
881 B
// IR 基本块:
|
|
// - 保存指令序列
|
|
// - 维护或可计算前驱/后继关系,用于 CFG 分析与优化
|
|
|
|
#include "ir/IR.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace ir {
|
|
|
|
BasicBlock::BasicBlock(std::string name) : name_(std::move(name)) {}
|
|
|
|
const std::string& BasicBlock::GetName() const { return name_; }
|
|
|
|
Function* BasicBlock::GetParent() const { return parent_; }
|
|
|
|
void BasicBlock::SetParent(Function* parent) { parent_ = parent; }
|
|
|
|
bool BasicBlock::HasTerminator() const {
|
|
return !instructions_.empty() && instructions_.back()->IsTerminator();
|
|
}
|
|
|
|
const std::vector<std::unique_ptr<Instruction>>& BasicBlock::GetInstructions()
|
|
const {
|
|
return instructions_;
|
|
}
|
|
|
|
const std::vector<BasicBlock*>& BasicBlock::GetPredecessors() const {
|
|
return predecessors_;
|
|
}
|
|
|
|
const std::vector<BasicBlock*>& BasicBlock::GetSuccessors() const {
|
|
return successors_;
|
|
}
|
|
|
|
} // namespace ir
|