[midend-SCCP]增加不可达指令,修改跳转指令参数(基本块args已弃用默认为{})
This commit is contained in:
@@ -695,15 +695,13 @@ class Instruction : public User {
|
|||||||
kCondBr = 0x1UL << 30,
|
kCondBr = 0x1UL << 30,
|
||||||
kBr = 0x1UL << 31,
|
kBr = 0x1UL << 31,
|
||||||
kReturn = 0x1UL << 32,
|
kReturn = 0x1UL << 32,
|
||||||
|
kUnreachable = 0x1UL << 32, ///< Unreachable instruction, used for optimization purposes
|
||||||
// mem op
|
// mem op
|
||||||
kAlloca = 0x1UL << 33,
|
kAlloca = 0x1UL << 34,
|
||||||
kLoad = 0x1UL << 34,
|
kLoad = 0x1UL << 35,
|
||||||
kStore = 0x1UL << 35,
|
kStore = 0x1UL << 36,
|
||||||
kGetElementPtr = 0x1UL << 36,
|
kGetElementPtr = 0x1UL << 37,
|
||||||
kMemset = 0x1UL << 37,
|
kMemset = 0x1UL << 38,
|
||||||
// kGetSubArray = 0x1UL << 38,
|
|
||||||
// Constant Kind removed as Constants are now Values, not Instructions.
|
|
||||||
// kConstant = 0x1UL << 37, // Conflicts with kMemset if kept as is
|
|
||||||
// phi
|
// phi
|
||||||
kPhi = 0x1UL << 39,
|
kPhi = 0x1UL << 39,
|
||||||
kBitItoF = 0x1UL << 40,
|
kBitItoF = 0x1UL << 40,
|
||||||
@@ -852,6 +850,7 @@ public:
|
|||||||
}
|
}
|
||||||
bool isUnconditional() const { return kind == kBr; }
|
bool isUnconditional() const { return kind == kBr; }
|
||||||
bool isConditional() const { return kind == kCondBr; }
|
bool isConditional() const { return kind == kCondBr; }
|
||||||
|
bool isCondBr() const { return kind == kCondBr; }
|
||||||
bool isPhi() const { return kind == kPhi; }
|
bool isPhi() const { return kind == kPhi; }
|
||||||
bool isAlloca() const { return kind == kAlloca; }
|
bool isAlloca() const { return kind == kAlloca; }
|
||||||
bool isLoad() const { return kind == kLoad; }
|
bool isLoad() const { return kind == kLoad; }
|
||||||
@@ -894,6 +893,9 @@ class PhiInst : public Instruction {
|
|||||||
public:
|
public:
|
||||||
Value* getValue(unsigned k) const {return getOperand(2 * k);} ///< 获取位置为k的值
|
Value* getValue(unsigned k) const {return getOperand(2 * k);} ///< 获取位置为k的值
|
||||||
BasicBlock* getBlock(unsigned k) const {return dynamic_cast<BasicBlock*>(getOperand(2 * k + 1));}
|
BasicBlock* getBlock(unsigned k) const {return dynamic_cast<BasicBlock*>(getOperand(2 * k + 1));}
|
||||||
|
//增加llvm同名方法实现获取value和block
|
||||||
|
Value* getIncomingValue(unsigned k) const {return getOperand(2 * k);} ///< 获取位置为k的值
|
||||||
|
BasicBlock* getIncomingBlock(unsigned k) const {return dynamic_cast<BasicBlock*>(getOperand(2 * k + 1));}
|
||||||
|
|
||||||
auto& getincomings() const {return blk2val;} ///< 获取所有的基本块和对应的值
|
auto& getincomings() const {return blk2val;} ///< 获取所有的基本块和对应的值
|
||||||
|
|
||||||
@@ -1117,6 +1119,14 @@ public:
|
|||||||
|
|
||||||
}; // class CondBrInst
|
}; // class CondBrInst
|
||||||
|
|
||||||
|
class UnreachableInst : public Instruction {
|
||||||
|
public:
|
||||||
|
// 构造函数:设置指令类型为 kUnreachable
|
||||||
|
explicit UnreachableInst(const std::string& name, BasicBlock *parent = nullptr)
|
||||||
|
: Instruction(kUnreachable, Type::getVoidType(), parent, "") {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
//! Allocate memory for stack variables, used for non-global variable declartion
|
//! Allocate memory for stack variables, used for non-global variable declartion
|
||||||
class AllocaInst : public Instruction {
|
class AllocaInst : public Instruction {
|
||||||
friend class IRBuilder;
|
friend class IRBuilder;
|
||||||
|
|||||||
@@ -239,19 +239,25 @@ class IRBuilder {
|
|||||||
block->getInstructions().emplace(position, inst);
|
block->getInstructions().emplace(position, inst);
|
||||||
return inst;
|
return inst;
|
||||||
} ///< 创建return指令
|
} ///< 创建return指令
|
||||||
UncondBrInst * createUncondBrInst(BasicBlock *thenBlock, const std::vector<Value *> &args) {
|
UncondBrInst * createUncondBrInst(BasicBlock *thenBlock, const std::vector<Value *> &args = {}) {
|
||||||
auto inst = new UncondBrInst(thenBlock, args, block);
|
auto inst = new UncondBrInst(thenBlock, args, block);
|
||||||
assert(inst);
|
assert(inst);
|
||||||
block->getInstructions().emplace(position, inst);
|
block->getInstructions().emplace(position, inst);
|
||||||
return inst;
|
return inst;
|
||||||
} ///< 创建无条件指令
|
} ///< 创建无条件指令
|
||||||
CondBrInst * createCondBrInst(Value *condition, BasicBlock *thenBlock, BasicBlock *elseBlock,
|
CondBrInst * createCondBrInst(Value *condition, BasicBlock *thenBlock, BasicBlock *elseBlock,
|
||||||
const std::vector<Value *> &thenArgs, const std::vector<Value *> &elseArgs) {
|
const std::vector<Value *> &thenArgs = {}, const std::vector<Value *> &elseArgs = {}) {
|
||||||
auto inst = new CondBrInst(condition, thenBlock, elseBlock, thenArgs, elseArgs, block);
|
auto inst = new CondBrInst(condition, thenBlock, elseBlock, thenArgs, elseArgs, block);
|
||||||
assert(inst);
|
assert(inst);
|
||||||
block->getInstructions().emplace(position, inst);
|
block->getInstructions().emplace(position, inst);
|
||||||
return inst;
|
return inst;
|
||||||
} ///< 创建条件跳转指令
|
} ///< 创建条件跳转指令
|
||||||
|
UnreachableInst * createUnreachableInst(const std::string &name = "") {
|
||||||
|
auto inst = new UnreachableInst(name, block);
|
||||||
|
assert(inst);
|
||||||
|
block->getInstructions().emplace(position, inst);
|
||||||
|
return inst;
|
||||||
|
} ///< 创建不可达指令
|
||||||
AllocaInst * createAllocaInst(Type *type, const std::vector<Value *> &dims = {}, const std::string &name = "") {
|
AllocaInst * createAllocaInst(Type *type, const std::vector<Value *> &dims = {}, const std::string &name = "") {
|
||||||
auto inst = new AllocaInst(type, dims, block, name);
|
auto inst = new AllocaInst(type, dims, block, name);
|
||||||
assert(inst);
|
assert(inst);
|
||||||
|
|||||||
Reference in New Issue
Block a user