[midend]增加部分逻辑位移指令

This commit is contained in:
rain2133
2025-08-13 15:28:37 +08:00
parent 60cb8d6e49
commit cd27f5fda9
2 changed files with 17 additions and 4 deletions

View File

@ -727,6 +727,7 @@ class Instruction : public User {
kFCmpGE = 0x1UL << 20, kFCmpGE = 0x1UL << 20,
kAnd = 0x1UL << 21, kAnd = 0x1UL << 21,
kOr = 0x1UL << 22, kOr = 0x1UL << 22,
// kXor = 0x1UL << 46,
// Unary // Unary
kNeg = 0x1UL << 23, kNeg = 0x1UL << 23,
kNot = 0x1UL << 24, kNot = 0x1UL << 24,
@ -751,8 +752,10 @@ class Instruction : public User {
kPhi = 0x1UL << 39, kPhi = 0x1UL << 39,
kBitItoF = 0x1UL << 40, kBitItoF = 0x1UL << 40,
kBitFtoI = 0x1UL << 41, kBitFtoI = 0x1UL << 41,
kSra = 0x1UL << 42, kSrl = 0x1UL << 42, // 逻辑右移
kMulh = 0x1UL << 43 kSll = 0x1UL << 43, // 逻辑左移
kSra = 0x1UL << 44, // 算术右移
kMulh = 0x1UL << 45
}; };
protected: protected:
@ -855,6 +858,10 @@ public:
return "BitItoF"; return "BitItoF";
case kBitFtoI: case kBitFtoI:
return "BitFtoI"; return "BitFtoI";
case kSrl:
return "lshr";
case kSll:
return "shl";
case kSra: case kSra:
return "ashr"; return "ashr";
default: default:
@ -868,7 +875,7 @@ public:
bool isBinary() const { bool isBinary() const {
static constexpr uint64_t BinaryOpMask = static constexpr uint64_t BinaryOpMask =
(kAdd | kSub | kMul | kDiv | kRem | kAnd | kOr | kSra | kMulh) | (kAdd | kSub | kMul | kDiv | kRem | kAnd | kOr | kSra | kSrl | kSll | kMulh) |
(kICmpEQ | kICmpNE | kICmpLT | kICmpGT | kICmpLE | kICmpGE); (kICmpEQ | kICmpNE | kICmpLT | kICmpGT | kICmpLE | kICmpGE);
return kind & BinaryOpMask; return kind & BinaryOpMask;
} }

View File

@ -217,7 +217,13 @@ class IRBuilder {
BinaryInst * createOrInst(Value *lhs, Value *rhs, const std::string &name = "") { BinaryInst * createOrInst(Value *lhs, Value *rhs, const std::string &name = "") {
return createBinaryInst(Instruction::kOr, Type::getIntType(), lhs, rhs, name); return createBinaryInst(Instruction::kOr, Type::getIntType(), lhs, rhs, name);
} ///< 创建按位或指令 } ///< 创建按位或指令
BinaryInst * createSRAInst(Value *lhs, Value *rhs, const std::string &name = "") { BinaryInst * createSllInst(Value *lhs, Value *rhs, const std::string &name = "") {
return createBinaryInst(Instruction::kSll, Type::getIntType(), lhs, rhs, name);
} ///< 创建逻辑左移指令
BinaryInst * createSrlInst(Value *lhs, Value *rhs, const std::string &name = "") {
return createBinaryInst(Instruction::kSrl, Type::getIntType(), lhs, rhs, name);
} ///< 创建逻辑右移指令
BinaryInst * createSraInst(Value *lhs, Value *rhs, const std::string &name = "") {
return createBinaryInst(Instruction::kSra, Type::getIntType(), lhs, rhs, name); return createBinaryInst(Instruction::kSra, Type::getIntType(), lhs, rhs, name);
} ///< 创建算术右移指令 } ///< 创建算术右移指令
BinaryInst * createMulhInst(Value *lhs, Value *rhs, const std::string &name = "") { BinaryInst * createMulhInst(Value *lhs, Value *rhs, const std::string &name = "") {