aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-29 18:55:55 +0000
committerOwen Anderson <resistor@mac.com>2009-07-29 18:55:55 +0000
commitbaf3c404409d5e47b13984a7f95bfbd6d1f2e79e (patch)
treec06618ee06936e7f5a1dc3c30b313ee49d5eb09b /lib/Transforms
parent26ef510d5d20b89c637d13e2d9169c0458de775c (diff)
Move ConstantExpr to 2.5 API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77494 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/ExtractGV.cpp2
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp22
-rw-r--r--lib/Transforms/IPO/MergeFunctions.cpp2
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp4
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp3
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp240
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp2
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp2
-rw-r--r--lib/Transforms/Scalar/MemCpyOptimizer.cpp4
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp4
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp4
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp12
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp7
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp2
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp2
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp8
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp2
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp4
18 files changed, 162 insertions, 164 deletions
diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp
index 2767f43194..9c28fdbe64 100644
--- a/lib/Transforms/IPO/ExtractGV.cpp
+++ b/lib/Transforms/IPO/ExtractGV.cpp
@@ -107,7 +107,7 @@ namespace {
for (std::vector<GlobalValue*>::iterator GI = Named.begin(),
GE = Named.end(); GI != GE; ++GI) {
(*GI)->setLinkage(GlobalValue::ExternalLinkage);
- AUGs.push_back(Context.getConstantExprBitCast(*GI, SBP));
+ AUGs.push_back(ConstantExpr::getBitCast(*GI, SBP));
}
ArrayType *AT = Context.getArrayType(SBP, AUGs.size());
Constant *Init = ConstantArray::get(AT, AUGs);
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index bf01812bd7..5be3239a63 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -576,7 +576,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Idxs.push_back(NullInt);
for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
Idxs.push_back(CE->getOperand(i));
- NewPtr = Context.getConstantExprGetElementPtr(cast<Constant>(NewPtr),
+ NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr),
&Idxs[0], Idxs.size());
} else {
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
@@ -708,7 +708,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
}
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
Changed |= OptimizeAwayTrappingUsesOfValue(CI,
- Context.getConstantExprCast(CI->getOpcode(),
+ ConstantExpr::getCast(CI->getOpcode(),
NewV, CI->getType()), Context);
if (CI->use_empty()) {
Changed = true;
@@ -726,7 +726,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
break;
if (Idxs.size() == GEPI->getNumOperands()-1)
Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
- Context.getConstantExprGetElementPtr(NewV, &Idxs[0],
+ ConstantExpr::getGetElementPtr(NewV, &Idxs[0],
Idxs.size()), Context);
if (GEPI->use_empty()) {
Changed = true;
@@ -858,7 +858,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Constant *RepValue = NewGV;
if (NewGV->getType() != GV->getType()->getElementType())
- RepValue = Context.getConstantExprBitCast(RepValue,
+ RepValue = ConstantExpr::getBitCast(RepValue,
GV->getType()->getElementType());
// If there is a comparison against null, we will insert a global bool to
@@ -1543,7 +1543,7 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
if (Constant *SOVC = dyn_cast<Constant>(StoredOnceVal)) {
if (GV->getInitializer()->getType() != SOVC->getType())
SOVC =
- Context.getConstantExprBitCast(SOVC, GV->getInitializer()->getType());
+ ConstantExpr::getBitCast(SOVC, GV->getInitializer()->getType());
// Optimize away any trapping uses of the loaded value.
if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, Context))
@@ -1989,7 +1989,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
if (!GCL->use_empty()) {
Constant *V = NGV;
if (V->getType() != GCL->getType())
- V = Context.getConstantExprBitCast(V, GCL->getType());
+ V = ConstantExpr::getBitCast(V, GCL->getType());
GCL->replaceAllUsesWith(V);
}
GCL->eraseFromParent();
@@ -2194,20 +2194,20 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
Constant *Val = getVal(Values, SI->getOperand(0));
MutatedMemory[Ptr] = Val;
} else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CurInst)) {
- InstResult = Context.getConstantExpr(BO->getOpcode(),
+ InstResult = ConstantExpr::get(BO->getOpcode(),
getVal(Values, BO->getOperand(0)),
getVal(Values, BO->getOperand(1)));
} else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) {
- InstResult = Context.getConstantExprCompare(CI->getPredicate(),
+ InstResult = ConstantExpr::getCompare(CI->getPredicate(),
getVal(Values, CI->getOperand(0)),
getVal(Values, CI->getOperand(1)));
} else if (CastInst *CI = dyn_cast<CastInst>(CurInst)) {
- InstResult = Context.getConstantExprCast(CI->getOpcode(),
+ InstResult = ConstantExpr::getCast(CI->getOpcode(),
getVal(Values, CI->getOperand(0)),
CI->getType());
} else if (SelectInst *SI = dyn_cast<SelectInst>(CurInst)) {
InstResult =
- Context.getConstantExprSelect(getVal(Values, SI->getOperand(0)),
+ ConstantExpr::getSelect(getVal(Values, SI->getOperand(0)),
getVal(Values, SI->getOperand(1)),
getVal(Values, SI->getOperand(2)));
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
@@ -2217,7 +2217,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
i != e; ++i)
GEPOps.push_back(getVal(Values, *i));
InstResult =
- Context.getConstantExprGetElementPtr(P, &GEPOps[0], GEPOps.size());
+ ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size());
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
if (LI->isVolatile()) return false; // no volatile accesses.
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp
index 3b54462574..db8a817c9f 100644
--- a/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/lib/Transforms/IPO/MergeFunctions.cpp
@@ -521,7 +521,7 @@ static void AliasGToF(Function *F, Function *G) {
GlobalAlias *GA = new GlobalAlias(
G->getType(), G->getLinkage(), "",
- F->getContext().getConstantExprBitCast(F, G->getType()), G->getParent());
+ ConstantExpr::getBitCast(F, G->getType()), G->getParent());
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 5e6b71a3e4..70ce86a2c3 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -46,7 +46,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
std::vector<Constant*> GEPIndices(2, Context.getNullValue(Type::Int32Ty));
unsigned NumElements = 0;
if (Array) {
- Args[2] = Context.getConstantExprGetElementPtr(Array, &GEPIndices[0],
+ Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
GEPIndices.size());
NumElements =
cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
@@ -113,7 +113,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
Indices[0] = Context.getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
Constant *ElementPtr =
- Context.getConstantExprGetElementPtr(CounterArray, &Indices[0],
+ ConstantExpr::getGetElementPtr(CounterArray, &Indices[0],
Indices.size());
// Load, increment and store the value back.
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index 31b255feb0..2afc0cb272 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -352,8 +352,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
std::vector<Constant*> Indices(2);
Indices[0] = BB->getContext().getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
- Constant *ElementPtr =
- BB->getContext().getConstantExprGetElementPtr(CounterArray,
+ Constant *ElementPtr =ConstantExpr::getGetElementPtr(CounterArray,
&Indices[0], 2);
// Load, increment and store the value back.
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 28a226ccc9..63dddaeee1 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -286,7 +286,7 @@ namespace {
if (V->getType() == Ty) return V;
if (Constant *CV = dyn_cast<Constant>(V))
- return Context->getConstantExprCast(opc, CV, Ty);
+ return ConstantExpr::getCast(opc, CV, Ty);
Instruction *C = CastInst::Create(opc, V, Ty, V->getName(), &Pos);
AddToWorkList(C);
@@ -519,7 +519,7 @@ bool InstCombiner::SimplifyCommutative(BinaryOperator &I) {
if (BinaryOperator *Op = dyn_cast<BinaryOperator>(I.getOperand(0)))
if (Op->getOpcode() == Opcode && isa<Constant>(Op->getOperand(1))) {
if (isa<Constant>(I.getOperand(1))) {
- Constant *Folded = Context->getConstantExpr(I.getOpcode(),
+ Constant *Folded = ConstantExpr::get(I.getOpcode(),
cast<Constant>(I.getOperand(1)),
cast<Constant>(Op->getOperand(1)));
I.setOperand(0, Op->getOperand(0));
@@ -532,7 +532,7 @@ bool InstCombiner::SimplifyCommutative(BinaryOperator &I) {
Constant *C2 = cast<Constant>(Op1->getOperand(1));
// Fold (op (op V1, C1), (op V2, C2)) ==> (op (op V1, V2), (op C1,C2))
- Constant *Folded = Context->getConstantExpr(I.getOpcode(), C1, C2);
+ Constant *Folded = ConstantExpr::get(I.getOpcode(), C1, C2);
Instruction *New = BinaryOperator::Create(Opcode, Op->getOperand(0),
Op1->getOperand(0),
Op1->getName(), &I);
@@ -566,11 +566,11 @@ static inline Value *dyn_castNegVal(Value *V, LLVMContext *Context) {
// Constants can be considered to be negated values if they can be folded.
if (ConstantInt *C = dyn_cast<ConstantInt>(V))
- return Context->getConstantExprNeg(C);
+ return ConstantExpr::getNeg(C);
if (ConstantVector *C = dyn_cast<ConstantVector>(V))
if (C->getType()->getElementType()->isInteger())
- return Context->getConstantExprNeg(C);
+ return ConstantExpr::getNeg(C);
return 0;
}
@@ -585,11 +585,11 @@ static inline Value *dyn_castFNegVal(Value *V, LLVMContext *Context) {
// Constants can be considered to be negated values if they can be folded.
if (ConstantFP *C = dyn_cast<ConstantFP>(V))
- return Context->getConstantExprFNeg(C);
+ return ConstantExpr::getFNeg(C);
if (ConstantVector *C = dyn_cast<ConstantVector>(V))
if (C->getType()->getElementType()->isFloatingPoint())
- return Context->getConstantExprFNeg(C);
+ return ConstantExpr::getFNeg(C);
return 0;
}
@@ -630,12 +630,12 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST,
/// AddOne - Add one to a ConstantInt
static Constant *AddOne(Constant *C, LLVMContext *Context) {
- return Context->getConstantExprAdd(C,
+ return ConstantExpr::getAdd(C,
ConstantInt::get(C->getType(), 1));
}
/// SubOne - Subtract one from a ConstantInt
static Constant *SubOne(ConstantInt *C, LLVMContext *Context) {
- return Context->getConstantExprSub(C,
+ return ConstantExpr::getSub(C,
ConstantInt::get(C->getType(), 1));
}
/// MultiplyOverflows - True if the multiply can not be expressed in an int
@@ -1409,7 +1409,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
Constant *C = ConstantInt::get(*Context, RHSKnownOne);
if (isa<PointerType>(V->getType()))
- C = Context->getConstantExprIntToPtr(C, V->getType());
+ C = ConstantExpr::getIntToPtr(C, V->getType());
return C;
}
return false;
@@ -1865,7 +1865,7 @@ struct AddMaskingAnd {
bool shouldApply(Value *LHS) const {
ConstantInt *C1;
return match(LHS, m_And(m_Value(), m_ConstantInt(C1)), *Context) &&
- Context->getConstantExprAnd(C1, C2)->isNullValue();
+ ConstantExpr::getAnd(C1, C2)->isNullValue();
}
Instruction *apply(BinaryOperator &Add) const {
return BinaryOperator::CreateOr(Add.getOperand(0), Add.getOperand(1));
@@ -1888,8 +1888,8 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
if (Constant *SOC = dyn_cast<Constant>(SO)) {
if (ConstIsRHS)
- return Context->getConstantExpr(I.getOpcode(), SOC, ConstOperand);
- return Context->getConstantExpr(I.getOpcode(), ConstOperand, SOC);
+ return ConstantExpr::get(I.getOpcode(), SOC, ConstOperand);
+ return ConstantExpr::get(I.getOpcode(), ConstOperand, SOC);
}
Value *Op0 = SO, *Op1 = ConstOperand;
@@ -1978,9 +1978,9 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
Value *InV = 0;
if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) {
if (CmpInst *CI = dyn_cast<CmpInst>(&I))
- InV = Context->getConstantExprCompare(CI->getPredicate(), InC, C);
+ InV = ConstantExpr::getCompare(CI->getPredicate(), InC, C);
else
- InV = Context->getConstantExpr(I.getOpcode(), InC, C);
+ InV = ConstantExpr::get(I.getOpcode(), InC, C);
} else {
assert(PN->getIncomingBlock(i) == NonConstBB);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(&I))
@@ -2005,7 +2005,7 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
for (unsigned i = 0; i != NumPHIValues; ++i) {
Value *InV;
if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) {
- InV = Context->getConstantExprCast(CI->getOpcode(), InC, RetTy);
+ InV = ConstantExpr::getCast(CI->getOpcode(), InC, RetTy);
} else {
assert(PN->getIncomingBlock(i) == NonConstBB);
InV = CastInst::Create(CI->getOpcode(), PN->getIncomingValue(i),
@@ -2177,7 +2177,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// X*C1 + X*C2 --> X * (C1+C2)
ConstantInt *C1;
if (X == dyn_castFoldableMul(RHS, C1, Context))
- return BinaryOperator::CreateMul(X, Context->getConstantExprAdd(C1, C2));
+ return BinaryOperator::CreateMul(X, ConstantExpr::getAdd(C1, C2));
}
// X + X*C --> X * (C+1)
@@ -2244,7 +2244,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// (X & FF00) + xx00 -> (X+xx00) & FF00
if (LHS->hasOneUse() &&
match(LHS, m_And(m_Value(X), m_ConstantInt(C2)), *Context)) {
- Constant *Anded = Context->getConstantExprAnd(CRHS, C2);
+ Constant *Anded = ConstantExpr::getAnd(CRHS, C2);
if (Anded == CRHS) {
// See if all bits from the first bit set in the Add RHS up are included
// in the mask. First, get the rightmost bit.
@@ -2303,9 +2303,9 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// (add (sext x), cst) --> (sext (add x, cst'))
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
Constant *CI =
- Context->getConstantExprTrunc(RHSC, LHSConv->getOperand(0)->getType());
+ ConstantExpr::getTrunc(RHSC, LHSConv->getOperand(0)->getType());
if (LHSConv->hasOneUse() &&
- Context->getConstantExprSExt(CI, I.getType()) == RHSC &&
+ ConstantExpr::getSExt(CI, I.getType()) == RHSC &&
WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
// Insert the new, smaller add.
Instruction *NewAdd = BinaryOperator::CreateAdd(LHSConv->getOperand(0),
@@ -2379,9 +2379,9 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
// instcombined.
if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHS)) {
Constant *CI =
- Context->getConstantExprFPToSI(CFP, LHSConv->getOperand(0)->getType());
+ ConstantExpr::getFPToSI(CFP, LHSConv->getOperand(0)->getType());
if (LHSConv->hasOneUse() &&
- Context->getConstantExprSIToFP(CI, I.getType()) == CFP &&
+ ConstantExpr::getSIToFP(CI, I.getType()) == CFP &&
WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
// Insert the new integer add.
Instruction *NewAdd = BinaryOperator::CreateAdd(LHSConv->getOperand(0),
@@ -2493,7 +2493,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(Op1I->getOperand(1)))
// C1-(X+C2) --> (C1-C2)-X
return BinaryOperator::CreateSub(
- Context->getConstantExprSub(CI1, CI2), Op1I->getOperand(0));
+ ConstantExpr::getSub(CI1, CI2), Op1I->getOperand(0));
}
}
@@ -2529,13 +2529,13 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (CSI->isZero())
if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1)))
return BinaryOperator::CreateSDiv(Op1I->getOperand(0),
- Context->getConstantExprNeg(DivRHS));
+ ConstantExpr::getNeg(DivRHS));
// X - X*C --> X * (1-C)
ConstantInt *C2 = 0;
if (dyn_castFoldableMul(Op1I, C2, Context) == Op0) {
Constant *CP1 =
- Context->getConstantExprSub(ConstantInt::get(I.getType(), 1),
+ ConstantExpr::getSub(ConstantInt::get(I.getType(), 1),
C2);
return BinaryOperator::CreateMul(Op0, CP1);
}
@@ -2562,7 +2562,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
ConstantInt *C2; // X*C1 - X*C2 -> X * (C1-C2)
if (X == dyn_castFoldableMul(Op1, C2, Context))
- return BinaryOperator::CreateMul(X, Context->getConstantExprSub(C1, C2));
+ return BinaryOperator::CreateMul(X, ConstantExpr::getSub(C1, C2));
}
return 0;
}
@@ -2634,7 +2634,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (SI->getOpcode() == Instruction::Shl)
if (Constant *ShOp = dyn_cast<Constant>(SI->getOperand(1)))
return BinaryOperator::CreateMul(SI->getOperand(0),
- Context->getConstantExprShl(CI, ShOp));
+ ConstantExpr::getShl(CI, ShOp));
if (CI->isZero())
return ReplaceInstUsesWith(I, Op1); // X * 0 == 0
@@ -2672,7 +2672,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
Instruction *Add = BinaryOperator::CreateMul(Op0I->getOperand(0),
Op1, "tmp");
InsertNewInstBefore(Add, I);
- Value *C1C2 = Context->getConstantExprMul(Op1,
+ Value *C1C2 = ConstantExpr::getMul(Op1,
cast<Constant>(Op0I->getOperand(1)));
return BinaryOperator::CreateAdd(Add, C1C2);
@@ -2955,7 +2955,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
else
return BinaryOperator::Create(I.getOpcode(), LHS->getOperand(0),
- Context->getConstantExprMul(RHS, LHSRHS));
+ ConstantExpr::getMul(RHS, LHSRHS));
}
if (!RHS->isZero()) { // avoid X udiv 0
@@ -3253,7 +3253,7 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
for (unsigned i = 0; i != VWidth; ++i) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) {
if (RHS->getValue().isNegative())
- Elts[i] = cast<ConstantInt>(Context->getConstantExprNeg(RHS));
+ Elts[i] = cast<ConstantInt>(ConstantExpr::getNeg(RHS));
else
Elts[i] = RHS;
}
@@ -3503,7 +3503,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
Value *X = Op->getOperand(0);
Constant *Together = 0;
if (!Op->isShift())
- Together = Context->getConstantExprAnd(AndRHS, OpRHS);
+ Together = ConstantExpr::getAnd(AndRHS, OpRHS);
switch (Op->getOpcode()) {
case Instruction::Xor:
@@ -3633,7 +3633,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
bool isSigned, bool Inside,
Instruction &IB) {
- assert(cast<ConstantInt>(Context->getConstantExprICmp((isSigned ?
+ assert(cast<ConstantInt>(ConstantExpr::getICmp((isSigned ?
ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getZExtValue() &&
"Lo is not <= Hi in range emission code!");
@@ -3649,10 +3649,10 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
}
// Emit V-Lo <u Hi-Lo
- Constant *NegLo = Context->getConstantExprNeg(Lo);
+ Constant *NegLo = ConstantExpr::getNeg(Lo);
Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
InsertNewInstBefore(Add, IB);
- Constant *UpperBound = Context->getConstantExprAdd(NegLo, Hi);
+ Constant *UpperBound = ConstantExpr::getAdd(NegLo, Hi);
return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, UpperBound);
}
@@ -3669,10 +3669,10 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
// Emit V-Lo >u Hi-1-Lo
// Note that Hi has already had one subtracted from it, above.
- ConstantInt *NegLo = cast<ConstantInt>(Context->getConstantExprNeg(Lo));
+ ConstantInt *NegLo = cast<ConstantInt>(ConstantExpr::getNeg(Lo));
Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
InsertNewInstBefore(Add, IB);
- Constant *LowerBound = Context->getConstantExprAdd(NegLo, Hi);
+ Constant *LowerBound = ConstantExpr::getAdd(NegLo, Hi);
return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add, LowerBound);
}
@@ -3714,7 +3714,7 @@ Value *InstCombiner::FoldLogicalPlusAnd(Value *LHS, Value *RHS,
switch (LHSI->getOpcode()) {
default: return 0;
case Instruction::And:
- if (Context->getConstantExprAnd(N, Mask) == Mask) {
+ if (ConstantExpr::getAnd(N, Mask) == Mask) {
// If the AndRHS is a power of two minus one (0+1+), this is simple.
if ((Mask->getValue().countLeadingZeros() +
Mask->getValue().countPopulation()) ==
@@ -3738,7 +3738,7 @@ Value *InstCombiner::FoldLogicalPlusAnd(Value *LHS, Value *RHS,
// If the AndRHS is a power of two minus one (0+1+), and N&Mask == 0
if ((Mask->getValue().countLeadingZeros() +
Mask->getValue().countPopulation()) == Mask->getValue().getBitWidth()
- && Context->getConstantExprAnd(N, Mask)->isNullValue())
+ && ConstantExpr::getAnd(N, Mask)->isNullValue())
break;
return 0;
}
@@ -3843,7 +3843,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
return ReplaceInstUsesWith(I, RHS);
case ICmpInst::ICMP_NE:
if (LHSCst == SubOne(RHSCst, Context)){// (X != 13 & X != 14) -> X-13 >u 1
- Constant *AddCST = Context->getConstantExprNeg(LHSCst);
+ Constant *AddCST = ConstantExpr::getNeg(LHSCst);
Instruction *Add = BinaryOperator::CreateAdd(Val, AddCST,
Val->getName()+".off");
InsertNewInstBefore(Add, I);
@@ -4130,15 +4130,15 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
NewCast = InsertNewInstBefore(NewCast, I);
// trunc_or_bitcast(C1)&C2
Constant *C3 =
- Context->getConstantExprTruncOrBitCast(AndCI,I.getType());
- C3 = Context->getConstantExprAnd(C3, AndRHS);
+ ConstantExpr::getTruncOrBitCast(AndCI,I.getType());
+ C3 = ConstantExpr::getAnd(C3, AndRHS);
return BinaryOperator::CreateAnd(NewCast, C3);
} else if (CastOp->getOpcode() == Instruction::Or) {
// Change: and (cast (or X, C1) to T), C2
// into : trunc(C1)&C2 iff trunc(C1)&C2 == C2
Constant *C3 =
- Context->getConstantExprTruncOrBitCast(AndCI,I.getType());
- if (Context->getConstantExprAnd(C3, AndRHS) == AndRHS)
+ ConstantExpr::getTruncOrBitCast(AndCI,I.getType());
+ if (ConstantExpr::getAnd(C3, AndRHS) == AndRHS)
// trunc(C1)&C2
return ReplaceInstUsesWith(I, AndRHS);
}
@@ -4526,11 +4526,11 @@ Instruction *InstCombiner::FoldOrOfICmps(Instruction &I,
case ICmpInst::ICMP_EQ:
if (LHSCst == SubOne(RHSCst, Context)) {
// (X == 13 | X == 14) -> X-13 <u 2
- Constant *AddCST = Context->getConstantExprNeg(LHSCst);
+ Constant *AddCST = ConstantExpr::getNeg(LHSCst);
Instruction *Add = BinaryOperator::CreateAdd(Val, AddCST,
Val->getName()+".off");
InsertNewInstBefore(Add, I);
- AddCST = Context->getConstantExprSub(AddOne(RHSCst, Context), LHSCst);
+ AddCST = ConstantExpr::getSub(AddOne(RHSCst, Context), LHSCst);
return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, AddCST);
}
break; // (X == 13 | X == 15) -> no change
@@ -5078,7 +5078,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (CI->hasOneUse() && Op0C->hasOneUse()) {
Instruction::CastOps Opcode = Op0C->getOpcode();
if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt) {
- if (RHS == Context->getConstantExprCast(Opcode,
+ if (RHS == ConstantExpr::getCast(Opcode,
Context->getTrue(),
Op0C->getDestTy())) {
Instruction *NewCI = InsertNewInstBefore(CmpInst::Create(
@@ -5097,8 +5097,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
// ~(c-X) == X-c-1 == X+(-c-1)
if (Op0I->getOpcode() == Instruction::Sub && RHS->isAllOnesValue())
if (Constant *Op0I0C = dyn_cast<Constant>(Op0I->getOperand(0))) {
- Constant *NegOp0I0C = Context->getConstantExprNeg(Op0I0C);
- Constant *ConstantRHS = Context->getConstantExprSub(NegOp0I0C,
+ Constant *NegOp0I0C = ConstantExpr::getNeg(Op0I0C);
+ Constant *ConstantRHS = ConstantExpr::getSub(NegOp0I0C,
ConstantInt::get(I.getType(), 1));
return BinaryOperator::CreateAdd(Op0I->getOperand(1), ConstantRHS);
}
@@ -5107,9 +5107,9 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (Op0I->getOpcode() == Instruction::Add) {
// ~(X-c) --> (-c-1)-X
if (RHS->isAllOnesValue()) {
- Constant *NegOp0CI = Context->getConstantExprNeg(Op0CI);
+ Constant *NegOp0CI = ConstantExpr::getNeg(Op0CI);
return BinaryOperator::CreateSub(
- Context->getConstantExprSub(NegOp0CI,
+ ConstantExpr::getSub(NegOp0CI,
ConstantInt::get(I.getType(), 1)),
Op0I->getOperand(0));
} else if (RHS->getValue().isSignBit()) {
@@ -5122,12 +5122,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
} else if (Op0I->getOpcode() == Instruction::Or) {
// (X|C1)^C2 -> X^(C1|C2) iff X&~C1 == 0
if (MaskedValueIsZero(Op0I->getOperand(0), Op0CI->getValue())) {
- Constant *NewRHS = Context->getConstantExprOr(Op0CI, RHS);
+ Constant *NewRHS = ConstantExpr::getOr(Op0CI, RHS);
// Anything in both C1 and C2 is known to be zero, remove it from
// NewRHS.
- Constant *CommonBits = Context->getConstantExprAnd(Op0CI, RHS);
- NewRHS = Context->getConstantExprAnd(NewRHS,
- Context->getConstantExprNot(CommonBits));
+ Constant *CommonBits = ConstantExpr::getAnd(Op0CI, RHS);
+ NewRHS = ConstantExpr::getAnd(NewRHS,
+ ConstantExpr::getNot(CommonBits));
AddToWorkList(Op0I);
I.setOperand(0, Op0I->getOperand(0));
I.setOperand(1, NewRHS);
@@ -5295,7 +5295,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
static ConstantInt *ExtractElement(Constant *V, Constant *Idx,
LLVMContext *Context) {
- return cast<ConstantInt>(Context->getConstantExprExtractElement(V, Idx));
+ return cast<ConstantInt>(ConstantExpr::getExtractElement(V, Idx));
}
static bool HasAddOverflow(ConstantInt *Result,
@@ -5315,7 +5315,7 @@ static bool HasAddOverflow(ConstantInt *Result,
static bool AddWithOverflow(Constant *&Result, Constant *In1,
Constant *In2, LLVMContext *Context,
bool IsSigned = false) {
- Result = Context->getConstantExprAdd(In1, In2);
+ Result = ConstantExpr::getAdd(In1, In2);
if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) {
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
@@ -5351,7 +5351,7 @@ static bool HasSubOverflow(ConstantInt *Result,
static bool SubWithOverflow(Constant *&Result, Constant *In1,
Constant *In2, LLVMContext *Context,
bool IsSigned = false) {
- Result = Context->getConstantExprSub(In1, In2);
+ Result = ConstantExpr::getSub(In1, In2);
if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) {
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
@@ -5409,10 +5409,10 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
Constant *Scale = ConstantInt::get(IntPtrTy, Size);
Constant *OC =
- Context->getConstantExprIntegerCast(OpC, IntPtrTy, true /*SExt*/);
- Scale = Context->getConstantExprMul(OC, Scale);
+ ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
+ Scale = ConstantExpr::getMul(OC, Scale);
if (Constant *RC = dyn_cast<Constant>(Result))
- Result = Context->getConstantExprAdd(RC, Scale);
+ Result = ConstantExpr::getAdd(RC, Scale);
else {
// Emit an add instruction.
Result = IC.InsertNewInstBefore(
@@ -5424,7 +5424,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
// Convert to correct type.
if (Op->getType() != IntPtrTy) {
if (Constant *OpC = dyn_cast<Constant>(Op))
- Op = Context->getConstantExprIntegerCast(OpC, IntPtrTy, true);
+ Op = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true);
else
Op = IC.InsertNewInstBefore(CastInst::CreateIntegerCast(Op, IntPtrTy,
true,
@@ -5433,7 +5433,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
if (Size != 1) {
Constant *Scale = ConstantInt::get(IntPtrTy, Size);
if (Constant *OpC = dyn_cast<Constant>(Op))
- Op = Context->getConstantExprMul(OpC, Scale);
+ Op = ConstantExpr::getMul(OpC, Scale);
else // We'll let instcombine(mul) convert this to a shl if possible.
Op = IC.InsertNewInstBefore(BinaryOperator::CreateMul(Op, Scale,
GEP->getName()+".idx"), I);
@@ -5441,7 +5441,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
// Emit an add instruction.
if (isa<Constant>(Op) && isa<Constant>(Result))
- Result = Context->getConstantExprAdd(cast<Constant>(Op),
+ Result = ConstantExpr::getAdd(cast<Constant>(Op),
cast<Constant>(Result));
else
Result = IC.InsertNewInstBefore(BinaryOperator::CreateAdd(Op, Result,
@@ -5788,12 +5788,12 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
// casting the FP value to the integer value and back, checking for equality.
// Don't do this for zero, because -0.0 is not fractional.
Constant *RHSInt = LHSUnsigned
- ? Context->getConstantExprFPToUI(RHSC, IntTy)
- : Context->getConstantExprFPToSI(RHSC, IntTy);
+ ? ConstantExpr::getFPToUI(RHSC, IntTy)
+ : ConstantExpr::getFPToSI(RHSC, IntTy);
if (!RHS.isZero()) {
bool Equal = LHSUnsigned
- ? Context->getConstantExprUIToFP(RHSInt, RHSC->getType()) == RHSC
- : Context->getConstantExprSIToFP(RHSInt, RHSC->getType()) == RHSC;