Merge remote-tracking branch 'origin/midend-mem2reg' into midend
This commit is contained in:
@@ -468,7 +468,6 @@ public:
|
||||
|
||||
// --- End of refactored ConstantValue and related classes ---
|
||||
|
||||
|
||||
class Instruction;
|
||||
class Function;
|
||||
class BasicBlock;
|
||||
@@ -487,7 +486,6 @@ public:
|
||||
|
||||
using inst_list = std::list<std::unique_ptr<Instruction>>;
|
||||
using iterator = inst_list::iterator;
|
||||
using arg_list = std::vector<AllocaInst *>;
|
||||
using block_list = std::vector<BasicBlock *>;
|
||||
using block_set = std::unordered_set<BasicBlock *>;
|
||||
|
||||
@@ -495,7 +493,6 @@ protected:
|
||||
|
||||
Function *parent; ///< 从属的函数
|
||||
inst_list instructions; ///< 拥有的指令序列
|
||||
arg_list arguments; ///< 分配空间后的形式参数列表
|
||||
block_list successors; ///< 前驱列表
|
||||
block_list predecessors; ///< 后继列表
|
||||
bool reachable = false;
|
||||
@@ -515,14 +512,12 @@ public:
|
||||
public:
|
||||
|
||||
unsigned getNumInstructions() const { return instructions.size(); }
|
||||
unsigned getNumArguments() const { return arguments.size(); }
|
||||
unsigned getNumPredecessors() const { return predecessors.size(); }
|
||||
unsigned getNumSuccessors() const { return successors.size(); }
|
||||
Function* getParent() const { return parent; }
|
||||
void setParent(Function *func) { parent = func; }
|
||||
inst_list& getInstructions() { return instructions; }
|
||||
auto getInstructions_Range() const { return make_range(instructions); }
|
||||
arg_list& getArguments() { return arguments; }
|
||||
block_list& getPredecessors() { return predecessors; }
|
||||
void clearPredecessors() { predecessors.clear(); }
|
||||
block_list& getSuccessors() { return successors; }
|
||||
@@ -530,7 +525,6 @@ public:
|
||||
iterator begin() { return instructions.begin(); }
|
||||
iterator end() { return instructions.end(); }
|
||||
iterator terminator() { return std::prev(end()); }
|
||||
void insertArgument(AllocaInst *inst) { arguments.push_back(inst); }
|
||||
bool hasSuccessor(BasicBlock *block) const {
|
||||
return std::find(successors.begin(), successors.end(), block) != successors.end();
|
||||
} ///< 判断是否有后继块
|
||||
@@ -1065,6 +1059,8 @@ public:
|
||||
}; // class UncondBrInst
|
||||
|
||||
//! Conditional branch
|
||||
// 这里的args是指向条件分支的两个分支的参数列表但是现在弃用了
|
||||
// 通过mem2reg优化后,数据流分析将不会由arguments来传递
|
||||
class CondBrInst : public Instruction {
|
||||
friend class IRBuilder;
|
||||
friend class Function;
|
||||
@@ -1090,17 +1086,17 @@ public:
|
||||
BasicBlock* getElseBlock() const {
|
||||
return dynamic_cast<BasicBlock *>(getOperand(2));
|
||||
}
|
||||
auto getThenArguments() const {
|
||||
auto begin = std::next(operand_begin(), 3);
|
||||
auto end = std::next(begin, getThenBlock()->getNumArguments());
|
||||
return make_range(begin, end);
|
||||
}
|
||||
auto getElseArguments() const {
|
||||
auto begin =
|
||||
std::next(operand_begin(), 3 + getThenBlock()->getNumArguments());
|
||||
auto end = operand_end();
|
||||
return make_range(begin, end);
|
||||
}
|
||||
// auto getThenArguments() const {
|
||||
// auto begin = std::next(operand_begin(), 3);
|
||||
// // auto end = std::next(begin, getThenBlock()->getNumArguments());
|
||||
// return make_range(begin, end);
|
||||
// }
|
||||
// auto getElseArguments() const {
|
||||
// auto begin =
|
||||
// std::next(operand_begin(), 3 + getThenBlock()->getNumArguments());
|
||||
// auto end = operand_end();
|
||||
// return make_range(begin, end);
|
||||
// }
|
||||
|
||||
}; // class CondBrInst
|
||||
|
||||
@@ -1243,6 +1239,21 @@ public:
|
||||
class GlobalValue;
|
||||
|
||||
|
||||
class Argument : public Value {
|
||||
protected:
|
||||
Function *func;
|
||||
int index;
|
||||
|
||||
public:
|
||||
Argument(Type *type, Function *func, int index, const std::string &name = "")
|
||||
: Value(type, name), func(func), index(index) {}
|
||||
|
||||
public:
|
||||
Function* getParent() const { return func; }
|
||||
int getIndex() const { return index; }
|
||||
};
|
||||
|
||||
|
||||
class Module;
|
||||
//! Function definitionclass
|
||||
class Function : public Value {
|
||||
@@ -1254,6 +1265,7 @@ protected:
|
||||
|
||||
public:
|
||||
using block_list = std::list<std::unique_ptr<BasicBlock>>;
|
||||
using arg_list = std::vector<Argument *>;
|
||||
enum FunctionAttribute : uint64_t {
|
||||
PlaceHolder = 0x0UL,
|
||||
Pure = 0x1UL << 0,
|
||||
@@ -1265,6 +1277,7 @@ public:
|
||||
protected:
|
||||
Module *parent; ///< 函数的父模块
|
||||
block_list blocks; ///< 函数包含的基本块列表
|
||||
arg_list arguments; ///< 函数参数列表
|
||||
FunctionAttribute attribute = PlaceHolder; ///< 函数属性
|
||||
std::set<Function *> callees; ///< 函数调用的函数集合
|
||||
public:
|
||||
@@ -1289,6 +1302,16 @@ protected:
|
||||
auto getBasicBlocks() { return make_range(blocks); }
|
||||
block_list& getBasicBlocks_NoRange() { return blocks; }
|
||||
BasicBlock* getEntryBlock() { return blocks.front().get(); }
|
||||
void insertArgument(Argument *arg) { arguments.push_back(arg); }
|
||||
arg_list& getArguments() { return arguments; }
|
||||
unsigned getNumArguments() const { return arguments.size(); }
|
||||
Argument* getArgument(unsigned index) const {
|
||||
assert(index < arguments.size() && "Argument index out of bounds");
|
||||
return arguments[index];
|
||||
} ///< 获取位置为index的参数
|
||||
auto getArgumentsRange() const {
|
||||
return make_range(arguments.begin(), arguments.end());
|
||||
} ///< 获取参数列表的范围
|
||||
void removeBasicBlock(BasicBlock *blockToRemove) {
|
||||
auto is_same_ptr = [blockToRemove](const std::unique_ptr<BasicBlock> &ptr) { return ptr.get() == blockToRemove; };
|
||||
blocks.remove_if(is_same_ptr);
|
||||
|
||||
Reference in New Issue
Block a user