summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-31 20:28:14 +0000
committerOwen Anderson <resistor@mac.com>2009-07-31 20:28:14 +0000
commita7235ea7245028a0723e8ab7fd011386b3900777 (patch)
tree4d702ea3baaaeaeaeb5cf194e266a0911882c613 /lib/Transforms
parent2a29899d74476e2a14069af7231ab76d8322a157 (diff)
downloadllvm-a7235ea7245028a0723e8ab7fd011386b3900777.tar.gz
llvm-a7235ea7245028a0723e8ab7fd011386b3900777.tar.bz2
llvm-a7235ea7245028a0723e8ab7fd011386b3900777.tar.xz
Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are
metadata related, which I'm waiting on to avoid conflicting with Devang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77721 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp5
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp6
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp30
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp2
-rw-r--r--lib/Transforms/Instrumentation/BlockProfiling.cpp4
-rw-r--r--lib/Transforms/Instrumentation/EdgeProfiling.cpp2
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp11
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp2
-rw-r--r--lib/Transforms/Scalar/CodeGenPrepare.cpp4
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp155
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp4
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp28
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp12
-rw-r--r--lib/Transforms/Scalar/Reg2Mem.cpp2
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp20
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp22
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp14
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp3
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp16
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp4
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp26
21 files changed, 169 insertions, 203 deletions
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index 69df49796a..f3e0b18573 100644
--- a/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -576,7 +576,6 @@ Function *ArgPromotion::DoPromotion(Function *F,
AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
const Type *RetTy = FTy->getReturnType();
- LLVMContext &Context = RetTy->getContext();
// Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
// have zero fixed arguments.
@@ -681,7 +680,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
}
if (ExtraArgHack)
- Args.push_back(Context.getNullValue(Type::Int32Ty));
+ Args.push_back(Constant::getNullValue(Type::Int32Ty));
// Push any varargs arguments on the list
for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
@@ -845,7 +844,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Notify the alias analysis implementation that we inserted a new argument.
if (ExtraArgHack)
- AA.copyValue(Context.getNullValue(Type::Int32Ty), NF->arg_begin());
+ AA.copyValue(Constant::getNullValue(Type::Int32Ty), NF->arg_begin());
// Tell the alias analysis that the old function is about to disappear.
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index fbdca723f6..47f5e65ccd 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -601,8 +601,6 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
const Type *NRetTy = NULL;
unsigned RetCount = NumRetVals(F);
- LLVMContext &Context = RetTy->getContext();
-
// -1 means unused, other numbers are the new index
SmallVector<int, 5> NewRetIdxs(RetCount, -1);
std::vector<const Type*> RetTypes;
@@ -797,7 +795,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else if (New->getType() == Type::VoidTy) {
// Our return value has uses, but they will get removed later on.
// Replace by null for now.
- Call->replaceAllUsesWith(Context.getNullValue(Call->getType()));
+ Call->replaceAllUsesWith(Constant::getNullValue(Call->getType()));
} else {
assert(isa<StructType>(RetTy) &&
"Return type changed, but not into a void. The old return type"
@@ -860,7 +858,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else {
// If this argument is dead, replace any uses of it with null constants
// (these are guaranteed to become unused later on).
- I->replaceAllUsesWith(Context.getNullValue(I->getType()));
+ I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
}
// If we change the return value of the function we must rewrite any return
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index b6eb45d653..35e3fe91f5 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -261,10 +261,10 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
} else if (isa<ConstantAggregateZero>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
if (IdxV < STy->getNumElements())
- return Context.getNullValue(STy->getElementType(IdxV));
+ return Constant::getNullValue(STy->getElementType(IdxV));
} else if (const SequentialType *STy =
dyn_cast<SequentialType>(Agg->getType())) {
- return Context.getNullValue(STy->getElementType());
+ return Constant::getNullValue(STy->getElementType());
}
} else if (isa<UndefValue>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
@@ -550,7 +550,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
DOUT << "PERFORMING GLOBAL SRA ON: " << *GV;
- Constant *NullInt = Context.getNullValue(Type::Int32Ty);
+ Constant *NullInt = Constant::getNullValue(Type::Int32Ty);
// Loop over all of the uses of the global, replacing the constantexpr geps,
// with smaller constantexpr geps or direct references.
@@ -828,10 +828,10 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Type *NewTy = ArrayType::get(MI->getAllocatedType(),
NElements->getZExtValue());
MallocInst *NewMI =
- new MallocInst(NewTy, Context.getNullValue(Type::Int32Ty),
+ new MallocInst(NewTy, Constant::getNullValue(Type::Int32Ty),
MI->getAlignment(), MI->getName(), MI);
Value* Indices[2];
- Indices[0] = Indices[1] = Context.getNullValue(Type::Int32Ty);
+ Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2,
NewMI->getName()+".el0", MI);
MI->replaceAllUsesWith(NewGEP);
@@ -1187,7 +1187,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
Context);
Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr,
- Context.getNullValue(NPtr->getType()),
+ Constant::getNullValue(NPtr->getType()),
SCI->getName());
SCI->replaceAllUsesWith(New);
SCI->eraseFromParent();
@@ -1286,7 +1286,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
GlobalVariable *NGV =
new GlobalVariable(*GV->getParent(),
PFieldTy, false, GlobalValue::InternalLinkage,
- Context.getNullValue(PFieldTy),
+ Constant::getNullValue(PFieldTy),
GV->getName() + ".f" + Twine(FieldNo), GV,
GV->isThreadLocal());
FieldGlobals.push_back(NGV);
@@ -1312,7 +1312,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
Value *RunningOr = 0;
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
Value *Cond = new ICmpInst(MI, ICmpInst::ICMP_EQ, FieldMallocs[i],
- Context.getNullValue(FieldMallocs[i]->getType()),
+ Constant::getNullValue(FieldMallocs[i]->getType()),
"isnull");
if (!RunningOr)
RunningOr = Cond; // First seteq
@@ -1339,7 +1339,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
- Context.getNullValue(GVVal->getType()),
+ Constant::getNullValue(GVVal->getType()),
"tmp");
BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
@@ -1347,7 +1347,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Fill in FreeBlock.
new FreeInst(GVVal, FreeBlock);
- new StoreInst(Context.getNullValue(GVVal->getType()), FieldGlobals[i],
+ new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i],
FreeBlock);
BranchInst::Create(NextBlock, FreeBlock);
@@ -1387,7 +1387,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Insert a store of null into each global.
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
const PointerType *PT = cast<PointerType>(FieldGlobals[i]->getType());
- Constant *Null = Context.getNullValue(PT->getElementType());
+ Constant *Null = Constant::getNullValue(PT->getElementType());
new StoreInst(Null, FieldGlobals[i], SI);
}
// Erase the original store.
@@ -1958,7 +1958,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
} else {
const Type *FTy = FunctionType::get(Type::VoidTy, false);
const PointerType *PFTy = PointerType::getUnqual(FTy);
- CSVals[1] = Context.getNullValue(PFTy);
+ CSVals[1] = Constant::getNullValue(PFTy);
CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
}
CAList.push_back(ConstantStruct::get(CSVals));
@@ -2053,7 +2053,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
- Elts.push_back(Context.getNullValue(STy->getElementType(i)));
+ Elts.push_back(Constant::getNullValue(STy->getElementType(i)));
} else if (isa<UndefValue>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
Elts.push_back(UndefValue::get(STy->getElementType(i)));
@@ -2080,7 +2080,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i)
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
- Constant *Elt = Context.getNullValue(ATy->getElementType());
+ Constant *Elt = Constant::getNullValue(ATy->getElementType());
Elts.assign(ATy->getNumElements(), Elt);
} else if (isa<UndefValue>(Init)) {
Constant *Elt = UndefValue::get(ATy->getElementType());
@@ -2369,7 +2369,7 @@ static bool EvaluateStaticConstructor(Function *F) {
// silly, e.g. storing the address of the alloca somewhere and using it
// later. Since this is undefined, we'll just make it be null.
if (!Tmp->use_empty())
- Tmp->replaceAllUsesWith(F->getContext().getNullValue(Tmp->getType()));
+ Tmp->replaceAllUsesWith(Constant::getNullValue(Tmp->getType()));
delete Tmp;
}
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index 3a65ac7a8f..568798bd3a 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -427,7 +427,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst);
// Coming from a call to setjmp, the return is 0.
- PHI->addIncoming(Inst->getContext().getNullValue(Type::Int32Ty), ABlock);
+ PHI->addIncoming(Constant::getNullValue(Type::Int32Ty), ABlock);
// Add the case for this setjmp's number...
SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));
diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp
index 700260db46..9139c92235 100644
--- a/lib/Transforms/Instrumentation/BlockProfiling.cpp
+++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp
@@ -66,7 +66,7 @@ bool FunctionProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
- M.getContext().getNullValue(ATy), "FuncProfCounters");
+ Constant::getNullValue(ATy), "FuncProfCounters");
// Instrument all of the functions...
unsigned i = 0;
@@ -111,7 +111,7 @@ bool BlockProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
- M.getContext().getNullValue(ATy), "BlockProfCounters");
+ Constant::getNullValue(ATy), "BlockProfCounters");
// Instrument all of the blocks...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
index b900945dac..f291b44547 100644
--- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp
+++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
@@ -67,7 +67,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
- M.getContext().getNullValue(ATy), "EdgeProfCounters");
+ Constant::getNullValue(ATy), "EdgeProfCounters");
// Instrument all of the edges...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 6e5b523d6c..dc34bf70a3 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -23,7 +23,6 @@
void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Array) {
- LLVMContext &Context = MainFn->getContext();
const Type *ArgVTy =
PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty);
@@ -35,15 +34,15 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
// This could force argc and argv into programs that wouldn't otherwise have
// them, but instead we just pass null values in.
std::vector<Value*> Args(4);
- Args[0] = Context.getNullValue(Type::Int32Ty);
- Args[1] = Context.getNullValue(ArgVTy);
+ Args[0] = Constant::getNullValue(Type::Int32Ty);
+ Args[1] = Constant::getNullValue(ArgVTy);
// Skip over any allocas in the entry block.
BasicBlock *Entry = MainFn->begin();
BasicBlock::iterator InsertPos = Entry->begin();
while (isa<AllocaInst>(InsertPos)) ++InsertPos;
- std::vector<Constant*> GEPIndices(2, Context.getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::Int32Ty));
unsigned NumElements = 0;
if (Array) {
Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
@@ -101,8 +100,6 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
GlobalValue *CounterArray) {
- LLVMContext &Context = BB->getContext();
-
// Insert the increment after any alloca or PHI instructions...
BasicBlock::iterator InsertPos = BB->getFirstNonPHI();
while (isa<AllocaInst>(InsertPos))
@@ -110,7 +107,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
- Indices[0] = Context.getNullValue(Type::Int32Ty);
+ Indices[0] = Constant::getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
Constant *ElementPtr =
ConstantExpr::getGetElementPtr(CounterArray, &Indices[0],
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index 2afc0cb272..e2aa10924c 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -350,7 +350,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
- Indices[0] = BB->getContext().getNullValue(Type::Int32Ty);
+ Indices[0] = Constant::getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
Constant *ElementPtr =ConstantExpr::getGetElementPtr(CounterArray,
&Indices[0], 2);
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index 4e8bc4b3bb..cae70cdd46 100644
--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -560,8 +560,6 @@ static bool IsNonLocalValue(Value *V, BasicBlock *BB) {
bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
const Type *AccessTy,
DenseMap<Value*,Value*> &SunkAddrs) {
- LLVMContext &Context = MemoryInst->getContext();
-
// Figure out what addressing mode will be built up for this operation.
SmallVector<Instruction*, 16> AddrModeInsts;
ExtAddrMode AddrMode = AddressingModeMatcher::Match(Addr, AccessTy,MemoryInst,
@@ -658,7 +656,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
}
if (Result == 0)
- SunkAddr = Context.getNullValue(Addr->getType());
+ SunkAddr = Constant::getNullValue(Addr->getType());
else
SunkAddr = new IntToPtrInst(Result, Addr->getType(), "sunkaddr",InsertPt);
}
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 9f7ff59f11..0a6153db81 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -857,7 +857,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If all of the demanded bits in the inputs are known zeros, return zero.
if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
- return Context->getNullValue(VTy);
+ return Constant::getNullValue(VTy);
} else if (I->getOpcode() == Instruction::Or) {
// We can simplify (X|Y) -> X or Y in the user's context if we know that
@@ -926,7 +926,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If all of the demanded bits in the inputs are known zeros, return zero.
if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
- return Context->getNullValue(VTy);
+ return Constant::getNullValue(VTy);
// If the RHS is a constant, see if we can simplify it.
if (ShrinkDemandedConstant(I, 1, DemandedMask & ~LHSKnownZero, Context))
@@ -1470,7 +1470,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
return 0;
const Type *EltTy = cast<VectorType>(V->getType())->getElementType();
- Constant *Zero = Context->getNullValue(EltTy);
+ Constant *Zero = Constant::getNullValue(EltTy);
Constant *Undef = UndefValue::get(EltTy);
std::vector<Constant*> Elts;
for (unsigned i = 0; i != VWidth; ++i) {
@@ -1808,7 +1808,7 @@ static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F,
// Make what used to be the LHS of the root be the user of the root...
Value *ExtraOperand = TmpLHSI->getOperand(1);
if (&Root == TmpLHSI) {
- Root.replaceAllUsesWith(Context->getNullValue(TmpLHSI->getType()));
+ Root.replaceAllUsesWith(Constant::getNullValue(TmpLHSI->getType()));
return 0;
}
Root.replaceAllUsesWith(TmpLHSI); // Users now use TmpLHSI
@@ -2187,7 +2187,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// X + ~X --> -1 since ~X = -X-1
if (dyn_castNotVal(LHS, Context) == RHS ||
dyn_castNotVal(RHS, Context) == LHS)
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0
@@ -2417,7 +2417,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (Op0 == Op1) // sub X, X -> 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// If this is a 'B = x-(-A)', change to B = x+A...
if (Value *V = dyn_castNegVal(Op1, Context))
@@ -2623,7 +2623,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
Value *Op0 = I.getOperand(0);
if (isa<UndefValue>(I.getOperand(1))) // undef * X -> 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// Simplify mul instructions with a constant RHS...
if (Constant *Op1 = dyn_cast<Constant>(I.getOperand(1))) {
@@ -2904,7 +2904,7 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
if (isa<UndefValue>(Op0)) {
if (Op0->getType()->isFPOrFPVector())
return ReplaceInstUsesWith(I, Op0);
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// X / undef -> undef
@@ -2952,7 +2952,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
if (ConstantInt *LHSRHS = dyn_cast<ConstantInt>(LHS->getOperand(1))) {
if (MultiplyOverflows(RHS, LHSRHS,
I.getOpcode()==Instruction::SDiv, Context))
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
else
return BinaryOperator::Create(I.getOpcode(), LHS->getOperand(0),
ConstantExpr::getMul(RHS, LHSRHS));
@@ -2971,7 +2971,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
// 0 / X == 0, we don't need to preserve faults!
if (ConstantInt *LHS = dyn_cast<ConstantInt>(Op0))
if (LHS->equalsInt(0))
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// It can't be division by zero, hence it must be division by one.
if (I.getType() == Type::Int1Ty)
@@ -3007,7 +3007,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
Value *IC = InsertNewInstBefore(new ICmpInst(*Context,
ICmpInst::ICMP_ULT, Op0, C),
I);
- return SelectInst::Create(IC, Context->getNullValue(I.getType()),
+ return SelectInst::Create(IC, Constant::getNullValue(I.getType()),
ConstantInt::get(I.getType(), 1));
}
}
@@ -3108,7 +3108,7 @@ Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
if (isa<UndefValue>(Op0)) { // undef % X -> 0
if (I.getType()->isFPOrFPVector())
return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN)
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
if (isa<UndefValue>(Op1))
return ReplaceInstUsesWith(I, Op1); // X % undef -> undef
@@ -3133,7 +3133,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
// 0 % X == 0 for integer, we don't need to preserve faults!
if (Constant *LHS = dyn_cast<Constant>(Op0))
if (LHS->isNullValue())
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
// X % 0 == undef, we don't need to preserve faults!
@@ -3141,7 +3141,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
return ReplaceInstUsesWith(I, UndefValue::get(I.getType()));
if (RHS->equalsInt(1)) // X % 1 == 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {
@@ -3181,7 +3181,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
if (RHSI->getOpcode() == Instruction::Shl &&
isa<ConstantInt>(RHSI->getOperand(0))) {
if (cast<ConstantInt>(RHSI->getOperand(0))->getValue().isPowerOf2()) {
- Constant *N1 = Context->getAllOnesValue(I.getType());
+ Constant *N1 = Constant::getAllOnesValue(I.getType());
Value *Add = InsertNewInstBefore(BinaryOperator::CreateAdd(RHSI, N1,
"tmp"), I);
return BinaryOperator::CreateAnd(Op0, Add);
@@ -4008,7 +4008,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (isa<UndefValue>(Op1)) // X & undef -> 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// and X, X = X
if (Op0 == Op1)
@@ -4101,7 +4101,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
// (1 >> x) & 1 --> zext(x == 0)
if (AndRHSMask == 1 && Op0LHS == AndRHS) {
Instruction *NewICmp = new ICmpInst(*Context, ICmpInst::ICMP_EQ,
- Op0RHS, Context->getNullValue(I.getType()));
+ Op0RHS, Constant::getNullValue(I.getType()));
InsertNewInstBefore(NewICmp, I);
return new ZExtInst(NewICmp, I.getType());
}
@@ -4159,7 +4159,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Value *Op1NotVal = dyn_castNotVal(Op1, Context);
if (Op0NotVal == Op1 || Op1NotVal == Op0) // A & ~A == ~A & A == 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// (~A & ~B) == (~(A | B)) - De Morgan's Law
if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) {
@@ -4733,7 +4733,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (isa<UndefValue>(Op1)) // X | undef -> -1
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// or X, X = X
if (Op0 == Op1)
@@ -4934,14 +4934,14 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (match(Op0, m_Not(m_Value(A)), *Context)) { // ~A | Op1
if (A == Op1) // ~A | A == -1
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
} else {
A = 0;
}
// Note, A is still live here!
if (match(Op1, m_Not(m_Value(B)), *Context)) { // Op0 | ~B
if (Op0 == B)
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// (~A | ~B) == (~(A & B)) - De Morgan's Law
if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) {
@@ -5019,14 +5019,14 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (isa<UndefValue>(Op0))
// Handle undef ^ undef -> 0 special case. This is a common
// idiom (misuse).
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef
}
// xor X, X = 0, even if X is nested in a sequence of Xor's.
if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1), Context)) {
assert(Result == &I && "AssociativeOpt didn't work?"); Result=Result;
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// See if we can simplify any instructions used by the instruction whose sole
@@ -5148,11 +5148,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (Value *X = dyn_castNotVal(Op0, Context)) // ~A ^ A == -1
if (X == Op1)
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
if (Value *X = dyn_castNotVal(Op1, Context)) // A ^ ~A == -1
if (X == Op0)
- return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1);
@@ -5378,7 +5378,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
gep_type_iterator GTI = gep_type_begin(GEP);
const Type *IntPtrTy = TD.getIntPtrType();
LLVMContext *Context = IC.getContext();
- Value *Result = Context->getNullValue(IntPtrTy);
+ Value *Result = Constant::getNullValue(IntPtrTy);
// Build a mask for high order bits.
unsigned IntPtrWidth = TD.getPointerSizeInBits();
@@ -5578,7 +5578,7 @@ Instruction *InstCombiner::FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
if (Offset == 0)
Offset = EmitGEPOffset(GEPLHS, I, *this);
return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), Offset,
- Context->getNullValue(Offset->getType()));
+ Constant::getNullValue(Offset->getType()));
} else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {
// If the base pointers are different, but the indices are the same, just
// compare the base pointer.
@@ -5892,7 +5892,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_UNE: // True if unordered or not equal
// Canonicalize these to be 'fcmp uno %X, 0.0'.
I.setPredicate(FCmpInst::FCMP_UNO);
- I.setOperand(1, Context->getNullValue(Op0->getType()));
+ I.setOperand(1, Constant::getNullValue(Op0->getType()));
return &I;
case FCmpInst::FCMP_ORD: // True if ordered (no nans)
@@ -5901,7 +5901,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_OLE: // True if ordered and less than or equal
// Canonicalize these to be 'fcmp ord %X, 0.0'.
I.setPredicate(FCmpInst::FCMP_ORD);
- I.setOperand(1, Context->getNullValue(Op0->getType()));
+ I.setOperand(1, Constant::getNullValue(Op0->getType()));
return &I;
}
}
@@ -6165,7 +6165,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// (x <u 2147483648) -> (x >s -1) -> true if sign bit clear
if (CI->isMinValue(true))
return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
- Context->getAllOnesValue(Op0->getType()));
+ Constant::getAllOnesValue(Op0->getType()));
}
break;
case ICmpInst::ICMP_UGT:
@@ -6184,7 +6184,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// (x >u 2147483647) -> (x <s 0) -> true if sign bit set
if (CI->isMaxValue(true))
return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
- Context->getNullValue(Op0->getType()));
+ Constant::getNullValue(Op0->getType()));
}
break;
case ICmpInst::ICMP_SLT:
@@ -6292,7 +6292,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
}
if (isAllZeros)
return new ICmpInst(*Context, I.getPredicate(), LHSI->getOperand(0),
- Context->getNullValue(LHSI->getOperand(0)->getType()));
+ Constant::getNullValue(LHSI->getOperand(0)->getType()));
}
break;
@@ -6472,7 +6472,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (A == Op1 || B == Op1) { // (A^B) == A -> B == 0
Value *OtherVal = A == Op1 ? B : A;
return new ICmpInst(*Context, I.getPredicate(), OtherVal,
- Context->getNullValue(A->getType()));
+ Constant::getNullValue(A->getType()));
}
if (match(Op1, m_Xor(m_Value(C), m_Value(D)), *Context)) {
@@ -6500,18 +6500,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// A == (A^B) -> B == 0
Value *OtherVal = A == Op0 ? B : A;
return new ICmpInst(*Context, I.getPredicate(), OtherVal,
- Context->getNullValue(A->getType()));
+ Constant::getNullValue(A->getType()));
}
// (A-B) == A -> B == 0
if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B)), *Context))
return new ICmpInst(*Context, I.getPredicate(), B,
- Context->getNullValue(B->getType()));
+ Constant::getNullValue(B->getType()));
// A == (A-B) -> B == 0
if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B)), *Context))
return new ICmpInst(*Context, I.getPredicate(), B,
- Context->getNullValue(B->getType()));
+ Constant::getNullValue(B->getType()));
// (X&Z) == (Y&Z) -> (X^Y) & Z == 0
if (Op0->hasOneUse() && Op1->hasOneUse() &&
@@ -6533,7 +6533,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Op1 = InsertNewInstBefore(BinaryOperator::CreateXor(X, Y, "tmp"), I);
Op1 = InsertNewInstBefore(BinaryOperator::CreateAnd(Op1, Z, "tmp"), I);
I.setOperand(0, Op1);
- I.setOperand(1, Context->getNullValue(Op1->getType()));
+ I.setOperand(1, Constant::getNullValue(Op1->getType()));
return &I;
}
}
@@ -6956,7 +6956,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
return new ICmpInst(*Context,
TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
- And, Context->getNullValue(And->getType()));
+ And, Constant::getNullValue(And->getType()));
}
break;
}
@@ -7079,7 +7079,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BO->getName());
InsertNewInstBefore(NewRem, ICI);
return new ICmpInst(*Context, ICI.getPredicate(), NewRem,
- Context->getNullValue(BO->getType()));
+ Constant::getNullValue(BO->getType()));
}
}
break;
@@ -7146,12 +7146,12 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
if (RHS == BOC && RHSV.isPowerOf2())
return new ICmpInst(*Context, isICMP_NE ? ICmpInst::ICMP_EQ :
ICmpInst::ICMP_NE, LHSI,
- Context->getNullValue(RHS->getType()));
+ Constant::getNullValue(RHS->getType()));
// Replace (and X, (1 << size(X)-1) != 0) with x s< 0
if (BOC->getValue().isSignBit()) {
Value *X = BO->getOperand(0);
- Constant *Zero = Context->getNullValue(X->getType());
+ Constant *Zero = Constant::getNullValue(X->getType());
ICmpInst::Predicate pred = isICMP_NE ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
return new ICmpInst(*Context, pred, X, Zero);
@@ -7295,7 +7295,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
if (isSignedExt) {
// We're performing an unsigned comp with a sign extended value.
// This is true if the input is >= 0. [aka >s -1]
- Constant *NegOne = Context->getAllOnesValue(SrcTy);
+ Constant *NegOne = Constant::getAllOnesValue(SrcTy);
Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT,
LHSCIOp, NegOne, ICI.getName()), ICI);
} else {
@@ -7355,21 +7355,21 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) {
// shl X, 0 == X and shr X, 0 == X
// shl 0, X == 0 and shr 0, X == 0
- if (Op1 == Context->getNullValue(Op1->getType()) ||
- Op0 == Context->getNullValue(Op0->getType()))
+ if (Op1 == Constant::getNullValue(Op1->getType()) ||
+ Op0 == Constant::getNullValue(Op0->getType()))
return ReplaceInstUsesWith(I, Op0);
if (isa<UndefValue>(Op0)) {
if (I.getOpcode() == Instruction::AShr) // undef >>s X -> undef
return ReplaceInstUsesWith(I, Op0);
else // undef << X -> 0, undef >>u X -> 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
if (isa<UndefValue>(Op1)) {
if (I.getOpcode() == Instruction::AShr) // X >>s undef -> X
return ReplaceInstUsesWith(I, Op0);
else // X << undef, X >>u undef -> 0
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// See if we can fold away this shift.
@@ -7401,7 +7401,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
//
if (Op1->uge(TypeBits)) {
if (I.getOpcode() != Instruction::AShr)
- return ReplaceInstUsesWith(I, Context->getNullValue(Op0->getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
else {
I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1));
return &I;
@@ -7629,7 +7629,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
// saturates.
if (AmtSum >= TypeBits) {
if (I.getOpcode() != Instruction::AShr)
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr.
}
@@ -7638,7 +7638,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
} else if (ShiftOp->getOpcode() == Instruction::LShr &&
I.getOpcode() == Instruction::AShr) {
if (AmtSum >= TypeBits)
- return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// ((X >>u C1) >>s C2) -> (X >>u (C1+C2)) since C1 != 0.
return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
@@ -8477,7 +8477,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
if (DestBitWidth == 1) {
Constant *One = ConstantInt::get(Src->getType(), 1);
Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI);
- Value *Zero = Context->getNullValue(Src->getType());
+ Value *Zero = Constant::getNullValue(Src->getType());
return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero);
}
@@ -8492,7 +8492,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
APInt Mask(APInt::getLowBitsSet(SrcBitWidth, ShAmt).shl(DestBitWidth));
if (MaskedValueIsZero(ShiftOp, Mask)) {
if (ShAmt >= DestBitWidth) // All zeros.
- return ReplaceInstUsesWith(CI, Context->getNullValue(Ty));
+ return ReplaceInstUsesWith(CI, Constant::getNullValue(Ty));
// Okay, we can shrink this. Truncate the input, then return a new
// shift.
@@ -8699,8 +8699,8 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
// Canonicalize sign-extend from i1 to a select.
if (Src->getType() == Type::Int1Ty)
return SelectInst::Create(Src,
- Context->getAllOnesValue(CI.getType()),
- Context->getNullValue(CI.getType()));
+ Constant::getAllOnesValue(CI.getType()),
+ Constant::getNullValue(CI.getType()));
// See if the value being truncated is already sign extended. If so, just
// eliminate the trunc/sext pair.
@@ -8970,7 +8970,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
// If the source and destination are pointers, and this cast is equivalent
// to a getelementptr X, 0, 0, 0... turn it into the appropriate gep.
// This can enhance SROA and other transforms that want type-safe pointers.
- Constant *ZeroUInt = Context->getNullValue(Type::Int32Ty);
+ Constant *ZeroUInt = Constant::getNullValue(Type::Int32Ty);
unsigned NumZeros = 0;
while (SrcElTy != DstElTy &&
isa<CompositeType>(SrcElTy) && !isa<PointerType>(SrcElTy) &&
@@ -8996,7 +8996,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
Value *Elem = InsertCastBefore(Instruction::BitCast, Src,
DestVTy->getElementType(), CI);
return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
- Context->getNullValue(Type::Int32Ty));
+ Constant::getNullValue(Type::Int32Ty));
}
// FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast)
}
@@ -9006,7 +9006,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
if (SrcVTy->getNumElements() == 1) {
if (!isa<VectorType>(DestTy)) {
Instruction *Elem =
- ExtractElementInst::Create(Src, Context->getNullValue(Type::Int32Ty));
+ ExtractElementInst::Create(Src, Constant::getNullValue(Type::Int32Ty));
InsertNewInstBefore(Elem, CI);
return CastInst::Create(Instruction::BitCast, Elem, DestTy);
}
@@ -9086,9 +9086,9 @@ static Constant *GetSelectFoldableConstant(Instruction *I,
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
- return Context->getNullValue(I->getType());
+ return Constant::getNullValue(I->getType());
case Instruction::And:
- return Context->getAllOnesValue(I->getType());
+ return Constant::getAllOnesValue(I->getType());
case Instruction::Mul:
return ConstantInt::get(I->getType(), 1);
}
@@ -9743,7 +9743,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);
// Set the size of the copy to 0, it will be deleted on the next iteration.
- MI->setOperand(3, Context->getNullValue(MemOpLength->getType()));
+ MI->setOperand(3, Constant::getNullValue(MemOpLength->getType()));
return MI;
}
@@ -9782,7 +9782,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
Dest, false, Alignment), *MI);
// Set the size of the copy to 0, it will be deleted on the next iteration.
- MI->setLength(Context->getNullValue(LenC->getType()));
+ MI->setLength(Constant::getNullValue(LenC->getType()));
return MI;
}
@@ -10259,7 +10259,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
// If the function takes more arguments than the call was taking, add them
// now...
for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i)
- Args.push_back(Context->getNullValue(FT->getParamType(i)));
+ Args.push_back(Constant::getNullValue(FT->getParamType(i)));
// If we are removing arguments to the function, emit an obnoxious warning...
if (FT->getNumParams() < NumActualArgs) {
@@ -11092,9 +11092,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// With: T = long A+B; gep %P, T, ...
//
Value *Sum, *SO1 = SrcGEPOperands.back(), *GO1 = GEP.getOperand(1);
- if (SO1 == Context->getNullValue(SO1->getType())) {
+ if (SO1 == Constant::getNullValue(SO1->getType())) {
Sum = GO1;
- } else if (GO1 == Context->getNullValue(GO1->getType())) {
+ } else if (GO1 == Constant::getNullValue(GO1->getType())) {
Sum = SO1;
} else {
// If they aren't the same type, convert both to an integer of the
@@ -11227,7 +11227,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
TD->getTypeAllocSize(ResElTy)) {
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = GEP.getOperand(1);
GetElementPtrInst *NewGEP =
GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
@@ -11291,7 +11291,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// Insert the new GEP instruction.
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewIdx;
Instruction *NewGEP =
GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
@@ -11388,7 +11388,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Now that I is pointing to the first non-allocation-inst in the block,
// insert our getelementptr instruction...
//
- Value *NullIdx = Context->getNullValue(Type::Int32Ty);
+ Value *NullIdx = Constant::getNullValue(Type::Int32Ty);
Value *Idx[2];
Idx[0] = NullIdx;
Idx[1] = NullIdx;
@@ -11400,7 +11400,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// allocation.
return ReplaceInstUsesWith(AI, V);
} else if (isa<UndefValue>(AI.getArraySize())) {
- return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType()));
+ return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
}
}
@@ -11409,7 +11409,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Note that we only do this for alloca's, because malloc should allocate
// and return a unique pointer, even for a zero byte allocation.
if (TD->getTypeAllocSize(AI.getAllocatedType()) == 0)
- return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType()));
+ return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
// If the alignment is 0 (unspecified), assign it the preferred alignment.
if (AI.getAlignment() == 0)
@@ -11521,7 +11521,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI,
if (Constant *CSrc = dyn_cast<Constant>(CastOp))
if (ASrcTy->getNumElements() != 0) {
Value *Idxs[2];
- Idxs[0] = Idxs[1] = Context->getNullValue(Type::Int32Ty);
+ Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty);
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2);
SrcTy = cast<PointerType>(CastOp->getType());
SrcPTy = SrcTy->getElementType();
@@ -11588,7 +11588,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// an unreachable instruction directly because we cannot modify the
// CFG.
new StoreInst(UndefValue::get(LI.getType()),
- Context->getNullValue(Op->getType()), &LI);
+ Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
}
@@ -11602,7 +11602,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// this code is not reachable. We do this instead of inserting an
// unreachable instruction directly because we cannot modify the CFG.
new StoreInst(UndefValue::get(LI.getType()),
- Context->getNullValue(Op->getType()), &LI);
+ Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@@ -11626,7 +11626,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// an unreachable instruction directly because we cannot modify the
// CFG.
new StoreInst(UndefValue::get(LI.getType()),
- Context->getNullValue(Op->getType()), &LI);
+ Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@@ -11642,7 +11642,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op->getUnderlyingObject())){
if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
if (GV->getInitializer()->isNullValue())
- return ReplaceInstUsesWith(LI, Context->getNullValue(LI.getType()));
+ return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType()));
else if (isa<UndefValue>(GV->getInitializer()))
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@@ -11694,7 +11694,6 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
User *CI = cast<User>(SI.getOperand(1));
Value *CastOp = CI->getOperand(0);
- LLVMContext *Context = IC.getContext();
const Type *DestPTy = cast<PointerType>(CI->getType())->getElementType();
const PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType());
@@ -11716,7 +11715,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
// constants.
if (isa<ArrayType>(SrcPTy) || isa<StructType>(SrcPTy)) {
// Index through pointer.
- Constant *Zero = Context->getNullValue(Type::Int32Ty);
+ Constant *Zero = Constant::getNullValue(Type::Int32Ty);
NewGEPIndices.push_back(Zero);
while (1) {
@@ -12190,7 +12189,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
return ReplaceInstUsesWith(EV, UndefValue::get(EV.getType()));
if (isa<ConstantAggregateZero>(C))
- return ReplaceInstUsesWith(EV, Context->getNullValue(EV.getType()));
+ return ReplaceInstUsesWith(EV, Constant::getNullValue(EV.getType()));
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
// Extract the element indexed by the first index out of the constant
@@ -12337,7 +12336,7 @@ static Value *FindScalarElement(Value *V, unsigned EltNo,
if (isa<UndefValue>(V))
return UndefValue::get(PTy->getElementType());
else if (isa<ConstantAggregateZero>(V))
- return Context->getNullValue(PTy->getElementType());
+ return Constant::getNullValue(PTy->getElementType());
else if (ConstantVector *CP = dyn_cast<ConstantVector>(V))
return CP->getOperand(EltNo);
else if (InsertElementInst *III = dyn_cast<InsertElementInst>(V)) {
@@ -12377,7 +12376,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
// If vector val is constant 0, replace extract with scalar 0.
if (isa<ConstantAggregateZero>(EI.getOperand(0)))
- return ReplaceInstUsesWith(EI, Context->getNullValue(EI.getType()));
+ return ReplaceInstUsesWith(EI, Constant::getNullValue(EI.getType()));
if (ConstantVector *C = dyn_cast<ConstantVector>(EI.getOperand(0))) {
// If vector val is constant with all elements the same, replace EI with
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index df72d41745..6554d6a452 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1577,9 +1577,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride,
BasicBlock *LatchBlock = L->getLoopLatch();
Instruction *IVIncInsertPt = LatchBlock->getTerminator();
- LLVMContext &Context = Preheader->getContext();
-
- Value *CommonBaseV = Context.getNullValue(ReplacedTy);
+ Value *CommonBaseV = Constant::getNullValue(ReplacedTy);
const SCEV *RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy);
IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty),
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 5ec5bf79ae..f9427bb693 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -1761,7 +1761,7 @@ namespace {
switch (BO->getOpcode()) {
case Instruction::And: {
// "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
- ConstantInt *CI = cast<ConstantInt>(Context->getAllOnesValue(Ty));
+ ConstantInt *CI = cast<ConstantInt>(Constant::getAllOnesValue(Ty));
if (Canonical == CI) {
add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
@@ -1769,7 +1769,7 @@ namespace {
} break;
case Instruction::Or: {
// "or i32 %a, %b" EQ 0 then %a EQ 0 and %b EQ 0
- Constant *Zero = Context->getNullValue(Ty);
+ Constant *Zero = Constant::getNullValue(Ty);
if (Canonical == Zero) {
add(Zero, Op0, ICmpInst::ICMP_EQ, NewContext);
add(Zero, Op1, ICmpInst::ICMP_EQ, NewContext);
@@ -1793,10 +1793,10 @@ namespace {
}
if (Canonical == LHS) {
if (isa<ConstantInt>(Canonical))
- add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_EQ,
+ add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ,
NewContext);
} else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) {
- add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_NE,
+ add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_NE,
NewContext);
}
} break;
@@ -1841,10 +1841,10 @@ namespace {
}
// TODO: The GEPI indices are all zero. Copy from definition to operand,
// jumping the type plane as needed.
- if (isRelatedBy(GEPI, Context->getNullValue(GEPI->getType()),
+ if (isRelatedBy(GEPI, Constant::getNullValue(GEPI->getType()),
ICmpInst::ICMP_NE)) {
Value *Ptr = GEPI->getPointerOperand();
- add(Ptr, Context->getNullValue(Ptr->getType()), ICmpInst::ICMP_NE,
+ add(Ptr, Constant::getNullValue(Ptr->getType()), ICmpInst::ICMP_NE,
NewContext);
}
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
@@ -1898,9 +1898,9 @@ namespace {
const Type *Ty = BO->getType();
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
- Constant *Zero = Context->getNullValue(Ty);
+ Constant *Zero = Constant::getNullValue(Ty);
Constant *One = ConstantInt::get(Ty, 1);
- ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
+ ConstantInt *AllOnes = cast<ConstantInt>(Constant::getAllOnesValue(Ty));
switch (Opcode) {
default: break;
@@ -2121,9 +2121,9 @@ namespace {
// TODO: The GEPI indices are all zero. Copy from operand to definition,
// jumping the type plane as needed.
Value *Ptr = GEPI->getPointerOperand();
- if (isRelatedBy(Ptr, Context->getNullValue(Ptr->getType()),
+ if (isRelatedBy(Ptr, Constant::getNullValue(Ptr->getType()),
ICmpInst::ICMP_NE)) {
- add(GEPI, Context->getNullValue(GEPI->getType()), ICmpInst::ICMP_NE,
+ add(GEPI, Constant::getNullValue(GEPI->getType()), ICmpInst::ICMP_NE,
NewContext);
}
}
@@ -2515,7 +2515,7 @@ namespace {
void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) {
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &AI);
- VRP.add(AI.getContext().getNullValue(AI.getType()),
+ VRP.add(Constant::getNullValue(AI.getType()),
&AI, ICmpInst::ICMP_NE);
VRP.solve();
}
@@ -2526,7 +2526,7 @@ namespace {
if (isa<Constant>(Ptr)) return;
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &LI);
- VRP.add(LI.getContext().getNullValue(Ptr->getType()),
+ VRP.add(Constant::getNullValue(Ptr->getType()),
Ptr, ICmpInst::ICMP_NE);
VRP.solve();
}
@@ -2536,7 +2536,7 @@ namespace {
if (isa<Constant>(Ptr)) return;
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
- VRP.add(SI.getContext().getNullValue(Ptr->getType()),
+ VRP.add(Constant::getNullValue(Ptr->getType()),
Ptr, ICmpInst::ICMP_NE);
VRP.solve();
}
@@ -2574,7 +2574,7 @@ namespace {
case Instruction::SDiv: {
Value *Divisor = BO.getOperand(1);
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
- VRP.add(BO.getContext().getNullValue(Divisor->getType()),
+ VRP.add(Constant::getNullValue(Divisor->getType()),
Divisor, ICmpInst::ICMP_NE);
VRP.solve();
break;
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index cade3e6c04..e8bc859517 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -201,7 +201,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
static Instruction *LowerNegateToMultiply(Instruction *Neg,
std::map<AssertingVH<>, unsigned> &ValueRankMap,
LLVMContext &Context) {
- Constant *Cst = Neg->getContext().getAllOnesValue(Neg->getType());
+ Constant *Cst = Constant::getAllOnesValue(Neg->getType());
Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg);
ValueRankMap.erase(Neg);
@@ -563,8 +563,6 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
bool IterateOptimization = false;
if (Ops.size() == 1) return Ops[0].Op;
- LLVMContext &Context = I->getContext();
-
unsigned Opcode = I->getOpcode();
if (Constant *V1 = dyn_cast<Constant>(Ops[Ops.size()-2].Op))
@@ -626,10 +624,10 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
if (FoundX != i) {
if (Opcode == Instruction::And) { // ...&X&~X = 0
++NumAnnihil;
- return Context.getNullValue(X->getType());
+ return Constant::getNullValue(X->getType());
} else if (Opcode == Instruction::Or) { // ...|X|~X = -1
++NumAnnihil;
- return Context.getAllOnesValue(X->getType());
+ return Constant::getAllOnesValue(X->getType());
}
}
}
@@ -648,7 +646,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
assert(Opcode == Instruction::Xor);
if (e == 2) {
++NumAnnihil;
- return Context.getNullValue(Ops[0].Op->getType());
+ return Constant::getNullValue(Ops[0].Op->getType());
}
// ... X^X -> ...
Ops.erase(Ops.begin()+i, Ops.begin()+i+2);
@@ -673,7 +671,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
// Remove X and -X from the operand list.
if (Ops.size() == 2) {
++NumAnnihil;
- return Context.getNullValue(X->getType());
+ return Constant::getNullValue(X->getType());
} else {
Ops.erase(Ops.begin()+i);
if (i < FoundX)
diff --git a/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp
index 2c1569dbda..e1075a650d 100644
--- a/lib/Transforms/Scalar/Reg2Mem.cpp
+++ b/lib/Transforms/Scalar/Reg2Mem.cpp
@@ -69,7 +69,7 @@ namespace {
CastInst *AllocaInsertionPoint =
CastInst::Create(Instruction::BitCast,
- F.getContext().getNullValue(Type::Int32Ty), Type::Int32Ty,
+ Constant::getNullValue(Type::Int32Ty), Type::Int32Ty,
"reg2mem alloca point", I);
// Find the escaped instructions. But don't create stack slots for
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 7db39d5fb8..80629329b2 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -813,12 +813,12 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
if (NonOverdefVal->isUndefined()) {
// Could annihilate value.
if (I.getOpcode() == Instruction::And)
- markConstant(IV, &I, Context->getNullValue(I.getType()));
+ markConstant(IV, &I, Constant::getNullValue(I.getType()));
else if (const VectorType *PT = dyn_cast<VectorType>(I.getType()))
- markConstant(IV, &I, Context->getAllOnesValue(PT));
+ markConstant(IV, &I, Constant::getAllOnesValue(PT));
else
markConstant(IV, &I,
- Context->getAllOnesValue(I.getType()));
+ Constant::getAllOnesValue(I.getType()));
return;
} else {
if (I.getOpcode() == Instruction::And) {
@@ -1134,7 +1134,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
if (isa<ConstantPointerNull>(Ptr) &&
cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
// load null -> null
- markConstant(IV, &I, Context->getNullValue(I.getType()));
+ markConstant(IV, &I, Constant::getNullValue(I.getType()));
return;
}
@@ -1376,22 +1376,22 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// to be handled here, because we don't know whether the top part is 1's
// or 0's.
assert(Op0LV.isUndefined());
- markForcedConstant(LV, I, Context->getNullValue(ITy));
+ markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Mul:
case Instruction::And:
// undef * X -> 0. X could be zero.
// undef & X -> 0. X could be zero.
- markForcedConstant(LV, I, Context->getNullValue(ITy));
+ markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Or:
// undef | X -> -1. X could be -1.
if (const VectorType *PTy = dyn_cast<VectorType>(ITy))
markForcedConstant(LV, I,
- Context->getAllOnesValue(PTy));
+ Constant::getAllOnesValue(PTy));
else
- markForcedConstant(LV, I, Context->getAllOnesValue(ITy));
+ markForcedConstant(LV, I, Constant::getAllOnesValue(ITy));
return true;
case Instruction::SDiv:
@@ -1404,7 +1404,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// undef / X -> 0. X could be maxint.
// undef % X -> 0. X could be 1.
- markForcedConstant(LV, I, Context->getNullValue(ITy));
+ markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::AShr:
@@ -1425,7 +1425,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// X >> undef -> 0. X could be 0.
// X << undef -> 0. X could be 0.
- markForcedConstant(LV, I, Context->getNullValue(ITy));
+ markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Select:
// undef ? X : Y -> X or Y. There could be commonality between X/Y.
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 7877db4e4f..cacf3dbb4b 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -329,7 +329,6 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
std::vector<AllocationInst*> &WorkList) {
DOUT << "Found inst to SROA: " << *AI;
SmallVector<AllocaInst*, 32> ElementAllocas;
- LLVMContext &Context = AI->getContext();
if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
ElementAllocas.reserve(ST->getNumContainedTypes());
for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) {
@@ -418,7 +417,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
// expanded itself once the worklist is rerun.
//
SmallVector<Value*, 8> NewArgs;
- NewArgs.push_back(Context.getNullValue(Type::Int32Ty));
+ NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
NewArgs.append(GEPI->op_begin()+3, GEPI->op_end());
RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(),
NewArgs.end(), "", GEPI);
@@ -512,7 +511,6 @@ static bool AllUsersAreLoads(Value *Ptr) {
///
void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI,
AllocaInfo &Info) {
- LLVMContext &Context = User->getContext();
if (BitCastInst *C = dyn_cast<BitCastInst>(User))
return isSafeUseOfBitCastedAllocation(C, AI, Info);
@@ -532,7 +530,7 @@ void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI,
// The GEP is not safe to transform if not of the form "GEP <ptr>, 0, <cst>".
if (I == E ||
- I.getOperand() != Context.getNullValue(I.getOperand()->getType())) {
+ I.getOperand() != Constant::getNullValue(I.getOperand()->getType())) {
return MarkUnsafe(Info);
}
@@ -766,7 +764,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
const Type *BytePtrTy = MI->getRawDest()->getType();
bool SROADest = MI->getRawDest() == BCInst;
- Constant *Zero = Context.getNullValue(Type::Int32Ty);
+ Constant *Zero = Constant::getNullValue(Type::Int32Ty);
for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
// If this is a memcpy/memmove, emit a GEP of the other element address.
@@ -821,7 +819,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
Constant *StoreVal;
if (ConstantInt *CI = dyn_cast<ConstantInt>(MI->getOperand(2))) {
if (CI->isZero()) {
- StoreVal = Context.getNullValue(EltTy); // 0.0, null, 0, <0,0>
+ StoreVal = Constant::getNullValue(EltTy); // 0.0, null, 0, <0,0>
} else {
// If EltTy is a vector type, get the element type.
const Type *ValTy = EltTy->getScalarType();
@@ -1041,10 +1039,8 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI,
ArrayEltBitOffset = TD->getTypeAllocSizeInBits(ArrayEltTy);
}
- LLVMContext &Context = LI->getContext();
-
Value *ResultVal =
- Context.getNullValue(IntegerType::get(AllocaSizeBits));
+ Constant::getNullValue(IntegerType::get(AllocaSizeBits));
for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
// Load the value from the alloca. If the NewElt is an aggregate, cast
@@ -1189,10 +1185,8 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
if (isa<ConstantInt>(I.getOperand()))
return;
- LLVMContext &Context = GEPI->getContext();
-
if (NumElements == 1) {
- GEPI->setOperand(2, Context.getNullValue(Type::Int32Ty));
+ GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty));
return;
}
@@ -1200,11 +1194,11 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
// All users of the GEP must be loads. At each use of the GEP, insert
// two loads of the appropriate indexed GEP and select between them.
Value *IsOne = new ICmpInst(GEPI, ICmpInst::ICMP_NE, I.getOperand(),
- Context.getNullValue(I.getOperand()->getType()),
+ Constant::getNullValue(I.getOperand()->getType()),
"isone");
// Insert the new GEP instructions, which are properly indexed.
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
- Indices[1] = Context.getNullValue(Type::Int32Ty);
+ Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0),
Indices.begin(),
Indices.end(),
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index 04bc39b4e0..2ac980fbe6 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -679,7 +679,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization {
uint64_t i = 0;
while (1) {
if (i == Str.size()) // Didn't find the char. strchr returns null.
- return Context->getNullValue(CI->getType());
+ return Constant::getNullValue(CI->getType());
// Did we find our match?
if (Str[i] == CharValue)
break;
@@ -918,7 +918,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization {
Value *LHS = CI->getOperand(1), *RHS = CI->getOperand(2);
if (LHS == RHS) // memcmp(s,s,x) -> 0
- return Context->getNullValue(CI->getType());
+ return Constant::getNullValue(CI->getType());
// Make sure we have a constant length.
ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getOperand(3));
@@ -926,7 +926,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization {
uint64_t Len = LenC->getZExtValue();
if (Len == 0) // memcmp(s1,s2,0) -> 0
- return Context->getNullValue(CI->getType());
+ return Constant::getNullValue(CI->getType());
if (Len == 1) { // memcmp(S1,S2,1) -> *LHS - *RHS
Value *LHSV = B.CreateLoad(CastToCStr(LHS, B), "lhsv");
@@ -1163,7 +1163,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
// Constant fold.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
if (CI->getValue() == 0) // ffs(0) -> 0.
- return Context->getNullValue(CI->getType());
+ return Constant::getNullValue(CI->getType());
return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1
CI->getValue().countTrailingZeros()+1);
}
@@ -1176,7 +1176,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp");
V = B.CreateIntCast(V, Type::Int32Ty, false, "tmp");
- Value *Cond = B.CreateICmpNE(Op, Context->getNullValue(ArgType), "tmp");
+ Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType), "tmp");
return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0));
}
};
@@ -1235,7 +1235,7 @@ struct VISIBILITY_HIDDEN AbsOpt : public LibCallOptimization {
// abs(x) -> x >s -1 ? x : -x
Value *Op = CI->getOperand(1);
Value *Pos = B.CreateICmpSGT(Op,
- Context->getAllOnesValue(Op->getType()),
+ Constant::getAllOnesValue(Op->getType()),
"ispos");
Value *Neg = B.CreateNeg(Op, "neg");
return B.CreateSelect(Pos, Op, Neg);
@@ -1371,7 +1371,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization {
Value *Ptr = CastToCStr(CI->getOperand(1), B);
B.CreateStore(V, Ptr);
Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul");
- B.CreateStore(Context->getNullValue(Type::Int8Ty), Ptr);
+ B.CreateStore(Constant::getNullValue(Type::Int8Ty), Ptr);
return ConstantInt::get(CI->getType(), 1);
}
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index e6522749bc..4e1015968d 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -252,8 +252,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
// Create a value to return... if the function doesn't return null...
if (BB->getParent()->getReturnType() != Type::VoidTy)
- RetVal = TI->getContext().getNullValue(
- BB->getParent()->getReturnType());
+ RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
// Create the return...
NewTI = ReturnInst::Create(RetVal);
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index d897c2acd1..80da263df5 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -239,8 +239,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
DOUT << "inputs: " << inputs.size() << "\n";
DOUT << "outputs: " << outputs.size() << "\n";
- LLVMContext &Context = header->getContext();
-
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
case 0:
@@ -304,7 +302,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP =
@@ -352,8 +350,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
void CodeExtractor::
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Values &inputs, Values &outputs) {
- LLVMContext &Context = codeReplacer->getContext();
-
// Emit a call to the new function, passing in: *pointer to struct (if
// aggregating parameters), or plan inputs and allocated memory for outputs
std::vector<Value*> params, StructValues, ReloadOutputs;
@@ -394,7 +390,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
- Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
@@ -420,7 +416,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
@@ -442,7 +438,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
- SwitchInst::Create(Context.getNullValue(Type::Int16Ty),
+ SwitchInst::Create(Constant::getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@@ -521,7 +517,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
@@ -559,7 +555,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
- ReturnInst::Create(Context.getNullValue(OldFnRetTy), TheSwitch);
+ ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index 305897c8ff..ce7b04a497 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -103,8 +103,6 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
bool Changed = false;
assert(MallocFunc && FreeFunc && "Pass not initialized!");
- LLVMContext &Context = BB.getContext();
-
BasicBlock::InstListType &BBIL = BB.getInstList();
const TargetData &TD = getAnalysis<TargetData>();
@@ -156,7 +154,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
if (MCall->getType() != Type::VoidTy)
MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
- MCast = Context.getNullValue(MI->getType());
+ MCast = Constant::getNullValue(MI->getType());
// Replace all uses of the old malloc inst with the cast inst
MI->replaceAllUsesWith(MCast);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index a9d218c5fd..4eac467e07 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -115,8 +115,6 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
// doInitialization - Make sure that there is a prototype for abort in the
// current module.
bool LowerInvoke::doInitialization(Module &M) {
- LLVMContext &Context = M.getContext();
-
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
AbortMessage = 0;
if (ExpensiveEHSupport) {
@@ -143,7 +141,7 @@ bool LowerInvoke::doInitialization(Module &M) {
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
JBListHead = new GlobalVariable(M, PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
- Context.getNullValue(PtrJBList),
+ Constant::getNullValue(PtrJBList),
"llvm.sjljeh.jblist");
}
@@ -177,8 +175,6 @@ bool LowerInvoke::doInitialization(Module &M) {
}
void LowerInvoke::createAbortMessage(Module *M) {
- LLVMContext &Context = M->getContext();
-
if (ExpensiveEHSupport) {
// The abort message for expensive EH support tells the user that the
// program 'unwound' without an 'invoke' instruction.
@@ -189,7 +185,7 @@ void LowerInvoke::createAbortMessage(Module *M) {
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
- std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
// The abort message for cheap EH support tells the user that EH is not
@@ -202,7 +198,7 @@ void LowerInvoke::createAbortMessage(Module *M) {
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
- std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}
}
@@ -223,7 +219,6 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) {
}
bool LowerInvoke::insertCheapEHSupport(Function &F) {
- LLVMContext &Context = F.getContext();
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
@@ -256,7 +251,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
// Insert a return instruction. This really should be a "barrier", as it
// is unreachable.
ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 :
- Context.getNullValue(F.getReturnType()), UI);
+ Constant::getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now.
BB->getInstList().erase(UI);
@@ -271,7 +266,6 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
AllocaInst *InvokeNum,
SwitchInst *CatchSwitch) {
- LLVMContext &Context = II->getContext();
ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo);
// If the unwind edge has phi nodes, split the edge.
@@ -291,7 +285,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI();
// nonvolatile.
- new StoreInst(Context.getNullValue(Type::Int32Ty), InvokeNum, false, NI);
+ new StoreInst(Constant::getNullValue(Type::Int32Ty), InvokeNum, false, NI);
// Add a switch case to our unwind block.
CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
@@ -433,8 +427,6 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<UnwindInst*> Unwinds;
std::vector<InvokeInst*> Invokes;
- LLVMContext &Context = F.getContext();
-
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
// Remember all return instructions in case we insert an invoke into this
@@ -482,7 +474,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"jblink", F.begin()->begin());
std::vector<Value*> Idx;
- Idx.push_back(Context.getNullValue(Type::Int32Ty));
+ Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"OldBuf",
@@ -535,7 +527,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Compare the return value to zero.
Value *IsNormal = new ICmpInst(EntryBB->getTerminator(),
ICmpInst::ICMP_EQ, SJRet,
- Context.getNullValue(SJRet->getType()),
+ Constant::getNullValue(SJRet->getType()),
"notunwind");
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();
@@ -569,14 +561,14 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Load the JBList, if it's null, then there was no catch!
Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr,
- Context.getNullValue(BufPtr->getType()),
+ Constant::getNullValue(BufPtr->getType()),
"notnull");
BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp.
// Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx;
- Idx.push_back(Context.getNullValue(Type::Int32Ty));
+ Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);