diff options
author | Manuel Jacob <me@manueljacob.de> | 2016-03-14 22:34:17 +0000 |
---|---|---|
committer | Manuel Jacob <me@manueljacob.de> | 2016-03-14 22:34:17 +0000 |
commit | 6be355961e8e9aa9f8da76a907c2a1788fd06ba5 (patch) | |
tree | d4ae2b8ed444eb7f499627955463905d8f00de62 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | f9709ee0013e6d936cc2c4822ab148a904444250 (diff) | |
download | llvm-6be355961e8e9aa9f8da76a907c2a1788fd06ba5.zip llvm-6be355961e8e9aa9f8da76a907c2a1788fd06ba5.tar.gz llvm-6be355961e8e9aa9f8da76a907c2a1788fd06ba5.tar.bz2 |
Re-add ConstantFoldInstOperands form taking opcode and return type.
Summary:
This form was replaced by a form taking an instruction instead of opcode and
return type in r258391. After committing this change (and some depending,
follow-up changes) it turned out in the review thread to be controversial. The
discussion didn't come to a conclusion yet. I'm re-adding the old form to fix
the API regression and to provide a better base for discussion, possibly on
llvm-dev.
A difference to the original function is that it can't be called with GEPs
(similarly to how it was already the case for compares). In order to support
opaque pointers in the future, folding GEPs needs to be passed the source
element type, which is not possible with the current API.
Reviewers: dberlin, reames
Subscribers: dblaikie, eddyb
Differential Revision: http://reviews.llvm.org/D17901
llvm-svn: 263501
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 9e21a7e..cf472ae 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -902,12 +902,11 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, /// folding using this function strips this information. /// static Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, + Type *DestTy, unsigned Opcode, ArrayRef<Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI) { - Type *DestTy = InstOrCE->getType(); - // Handle easy binops first. if (Instruction::isBinaryOp(Opcode)) return ConstantFoldBinaryOpOperands(Opcode, Ops[0], Ops[1], DL); @@ -1040,7 +1039,8 @@ ConstantFoldConstantExpressionImpl(const ConstantExpr *CE, const DataLayout &DL, return ConstantFoldCompareInstOperands(CE->getPredicate(), Ops[0], Ops[1], DL, TLI); - return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI); + return ConstantFoldInstOperandsImpl(CE, CE->getType(), CE->getOpcode(), Ops, + DL, TLI); } Constant *llvm::ConstantFoldConstantExpression(const ConstantExpr *CE, @@ -1054,7 +1054,16 @@ Constant *llvm::ConstantFoldInstOperands(Instruction *I, ArrayRef<Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI) { - return ConstantFoldInstOperandsImpl(I, I->getOpcode(), Ops, DL, TLI); + return ConstantFoldInstOperandsImpl(I, I->getType(), I->getOpcode(), Ops, DL, + TLI); +} + +Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, + ArrayRef<Constant *> Ops, + const DataLayout &DL, + const TargetLibraryInfo *TLI) { + assert(Opcode != Instruction::GetElementPtr && "Invalid for GEPs"); + return ConstantFoldInstOperandsImpl(nullptr, DestTy, Opcode, Ops, DL, TLI); } Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, |