diff options
| author | Nikita Popov <npopov@redhat.com> | 2022-06-29 14:27:04 +0200 |
|---|---|---|
| committer | Nikita Popov <npopov@redhat.com> | 2022-07-05 15:54:53 +0200 |
| commit | 935570b2ad808035a1fd9bf6fa894657babc8694 (patch) | |
| tree | a1dfcf114b5aec6398f9cea5811543f1bb78b17d /llvm/lib/IR/Constants.cpp | |
| parent | f10d271ae27f35cd56535ff7e832a358732c8fcd (diff) | |
| download | llvm-935570b2ad808035a1fd9bf6fa894657babc8694.zip llvm-935570b2ad808035a1fd9bf6fa894657babc8694.tar.gz llvm-935570b2ad808035a1fd9bf6fa894657babc8694.tar.bz2 | |
[ConstExpr] Don't create div/rem expressions
This removes creation of udiv/sdiv/urem/srem constant expressions,
in preparation for their removal. I've added a
ConstantExpr::isDesirableBinOp() predicate to determine whether
an expression should be created for a certain operator.
With this patch, div/rem expressions can still be created through
explicit IR/bitcode, forbidding them entirely will be the next step.
Differential Revision: https://reviews.llvm.org/D128820
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
| -rw-r--r-- | llvm/lib/IR/Constants.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 961e528..f6b745d 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2365,6 +2365,33 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2, return pImpl->ExprConstants.getOrCreate(C1->getType(), Key); } +bool ConstantExpr::isDesirableBinOp(unsigned Opcode) { + switch (Opcode) { + case Instruction::UDiv: + case Instruction::SDiv: + case Instruction::URem: + case Instruction::SRem: + return false; + case Instruction::Add: + case Instruction::Sub: + case Instruction::Mul: + case Instruction::Shl: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::And: + case Instruction::Or: + case Instruction::Xor: + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: + return true; + default: + llvm_unreachable("Argument must be binop opcode"); + } +} + Constant *ConstantExpr::getSizeOf(Type* Ty) { // sizeof is implemented as: (i64) gep (Ty*)null, 1 // Note that a non-inbounds gep is used, as null isn't within any object. |
