[llvm-commits] [llvm] r74807 - in /llvm/trunk: include/llvm/ include/llvm/Transforms/Utils/ lib/CodeGen/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/
Owen Anderson
resistor at mac.com
Sun Jul 5 15:41:44 PDT 2009
Author: resistor
Date: Sun Jul 5 17:41:43 2009
New Revision: 74807
URL: http://llvm.org/viewvc/llvm-project?rev=74807&view=rev
Log:
More LLVMContext-ification.
Modified:
llvm/trunk/include/llvm/BasicBlock.h
llvm/trunk/include/llvm/Function.h
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h
llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h
llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp
llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp
llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
llvm/trunk/lib/VMCore/BasicBlock.cpp
llvm/trunk/lib/VMCore/Function.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
Modified: llvm/trunk/include/llvm/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BasicBlock.h?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/BasicBlock.h Sun Jul 5 17:41:43 2009
@@ -22,6 +22,7 @@
namespace llvm {
class TerminatorInst;
+class LLVMContext;
template<> struct ilist_traits<Instruction>
: public SymbolTableListTraits<Instruction, BasicBlock> {
@@ -85,6 +86,10 @@
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
BasicBlock *InsertBefore = 0);
public:
+ /// getContext - Get the context in which this basic block lives,
+ /// or null if it is not currently attached to a function.
+ LLVMContext* getContext() const;
+
/// Instruction iterators...
typedef InstListType::iterator iterator;
typedef InstListType::const_iterator const_iterator;
Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Sun Jul 5 17:41:43 2009
@@ -129,7 +129,7 @@
/// getContext - Return a pointer to the LLVMContext associated with this
/// function, or NULL if this function is not bound to a context yet.
- LLVMContext* getContext();
+ LLVMContext* getContext() const;
/// isVarArg - Return true if this function takes a variable number of
/// arguments.
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Sun Jul 5 17:41:43 2009
@@ -166,6 +166,7 @@
Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
const unsigned* IdxList,
unsigned NumIdx);
+ Constant* getConstantExprSizeOf(const Type* Ty);
Constant* getZeroValueForNegation(const Type* Ty);
// ConstantFP accessors
@@ -188,6 +189,7 @@
MDString* getMDString(const std::string &Str);
// FunctionType accessors
+ FunctionType* getFunctionType(const Type* Result, bool isVarArg);
FunctionType* getFunctionType(const Type* Result,
const std::vector<const Type*>& Params,
bool isVarArg);
Modified: llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h Sun Jul 5 17:41:43 2009
@@ -23,6 +23,7 @@
class DominatorTree;
class DominanceFrontier;
class AliasSetTracker;
+class LLVMContext;
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
/// This is true if there are only loads and stores to the alloca...
@@ -39,6 +40,7 @@
///
void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
DominatorTree &DT, DominanceFrontier &DF,
+ LLVMContext* Context,
AliasSetTracker *AST = 0);
} // End llvm namespace
Modified: llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h Sun Jul 5 17:41:43 2009
@@ -20,9 +20,10 @@
namespace llvm {
class Value;
class Instruction;
+ class LLVMContext;
typedef DenseMap<const Value *, Value *> ValueMapTy;
- Value *MapValue(const Value *V, ValueMapTy &VM);
+ Value *MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context);
void RemapInstruction(Instruction *I, ValueMapTy &VM);
} // End llvm namespace
Modified: llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp Sun Jul 5 17:41:43 2009
@@ -314,7 +314,7 @@
if (ExceptionValueVar && DT && DF && isAllocaPromotable(ExceptionValueVar)) {
// Turn the exception temporary into registers and phi nodes if possible.
std::vector<AllocaInst*> Allocas(1, ExceptionValueVar);
- PromoteMemToReg(Allocas, *DT, *DF);
+ PromoteMemToReg(Allocas, *DT, *DF, Context);
return true;
}
return false;
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Sun Jul 5 17:41:43 2009
@@ -593,7 +593,7 @@
if (AI) {
std::vector<AllocaInst*> Allocas;
Allocas.push_back(AI);
- PromoteMemToReg(Allocas, *DT, *DF, CurAST);
+ PromoteMemToReg(Allocas, *DT, *DF, Context, CurAST);
}
}
}
@@ -773,7 +773,7 @@
PromotedAllocas.reserve(PromotedValues.size());
for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
PromotedAllocas.push_back(PromotedValues[i].first);
- PromoteMemToReg(PromotedAllocas, *DT, *DF, CurAST);
+ PromoteMemToReg(PromotedAllocas, *DT, *DF, Context, CurAST);
}
/// FindPromotableValuesInLoop - Check the current loop for stores to definite
Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Sun Jul 5 17:41:43 2009
@@ -186,7 +186,7 @@
if (Allocas.empty()) break;
- PromoteMemToReg(Allocas, DT, DF);
+ PromoteMemToReg(Allocas, DT, DF, Context);
NumPromoted += Allocas.size();
Changed = true;
}
Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Sun Jul 5 17:41:43 2009
@@ -16,6 +16,7 @@
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Constant.h"
#include "llvm/Type.h"
#include "llvm/Analysis/AliasAnalysis.h"
@@ -49,7 +50,7 @@
// contained within it must dominate their uses, that all uses will
// eventually be removed (they are themselves dead).
if (!I.use_empty())
- I.replaceAllUsesWith(UndefValue::get(I.getType()));
+ I.replaceAllUsesWith(BB->getContext()->getUndef(I.getType()));
BB->getInstList().pop_back();
}
@@ -69,7 +70,7 @@
if (PN->getIncomingValue(0) != PN)
PN->replaceAllUsesWith(PN->getIncomingValue(0));
else
- PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+ PN->replaceAllUsesWith(BB->getContext()->getUndef(PN->getType()));
PN->eraseFromParent();
}
}
@@ -250,7 +251,8 @@
// Create a value to return... if the function doesn't return null...
if (BB->getParent()->getReturnType() != Type::VoidTy)
- RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
+ RetVal = TI->getParent()->getContext()->getNullValue(
+ BB->getParent()->getReturnType());
// Create the return...
NewTI = ReturnInst::Create(RetVal);
@@ -385,7 +387,8 @@
if (NumPreds == 0) {
// Insert dummy values as the incoming value.
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
- cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
+ cast<PHINode>(I)->addIncoming(BB->getContext()->getUndef(I->getType()),
+ NewBB);
return NewBB;
}
Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Sun Jul 5 17:41:43 2009
@@ -20,6 +20,7 @@
#include "llvm/IntrinsicInst.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
@@ -150,7 +151,8 @@
ArgTypes.push_back(I->getType());
// Create a new function type...
- FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(),
+ FunctionType *FTy =
+ F->getContext()->getFunctionType(F->getFunctionType()->getReturnType(),
ArgTypes, F->getFunctionType()->isVarArg());
// Create the new function...
@@ -323,10 +325,13 @@
/// mapping its operands through ValueMap if they are available.
Constant *PruningFunctionCloner::
ConstantFoldMappedInstruction(const Instruction *I) {
+ LLVMContext* Context = I->getParent()->getContext();
+
SmallVector<Constant*, 8> Ops;
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (Constant *Op = dyn_cast_or_null<Constant>(MapValue(I->getOperand(i),
- ValueMap)))
+ ValueMap,
+ Context)))
Ops.push_back(Op);
else
return 0; // All operands not constant!
@@ -361,6 +366,7 @@
ClonedCodeInfo *CodeInfo,
const TargetData *TD) {
assert(NameSuffix && "NameSuffix cannot be null!");
+ LLVMContext* Context = OldFunc->getContext();
#ifndef NDEBUG
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
@@ -430,7 +436,8 @@
for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {
if (BasicBlock *MappedBlock =
cast_or_null<BasicBlock>(ValueMap[PN->getIncomingBlock(pred)])) {
- Value *InVal = MapValue(PN->getIncomingValue(pred), ValueMap);
+ Value *InVal = MapValue(PN->getIncomingValue(pred),
+ ValueMap, Context);
assert(InVal && "Unknown input value?");
PN->setIncomingValue(pred, InVal);
PN->setIncomingBlock(pred, MappedBlock);
@@ -482,7 +489,7 @@
BasicBlock::iterator I = NewBB->begin();
BasicBlock::const_iterator OldI = OldBB->begin();
while ((PN = dyn_cast<PHINode>(I++))) {
- Value *NV = UndefValue::get(PN->getType());
+ Value *NV = OldFunc->getContext()->getUndef(PN->getType());
PN->replaceAllUsesWith(NV);
assert(ValueMap[OldI] == PN && "ValueMap mismatch");
ValueMap[OldI] = NV;
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Sun Jul 5 17:41:43 2009
@@ -88,7 +88,8 @@
GlobalVariable *GV = cast<GlobalVariable>(ValueMap[I]);
if (I->hasInitializer())
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
- ValueMap)));
+ ValueMap,
+ &M->getContext())));
GV->setLinkage(I->getLinkage());
GV->setThreadLocal(I->isThreadLocal());
GV->setConstant(I->isConstant());
@@ -119,7 +120,7 @@
GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
GA->setLinkage(I->getLinkage());
if (const Constant* C = I->getAliasee())
- GA->setAliasee(cast<Constant>(MapValue(C, ValueMap)));
+ GA->setAliasee(cast<Constant>(MapValue(C, ValueMap, &M->getContext())));
}
return New;
Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Sun Jul 5 17:41:43 2009
@@ -18,6 +18,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/Dominators.h"
@@ -237,6 +238,8 @@
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:
@@ -262,7 +265,8 @@
if (AggregateArgs)
paramTy.push_back((*I)->getType());
else
- paramTy.push_back(PointerType::getUnqual((*I)->getType()));
+ paramTy.push_back(
+ header->getContext()->getPointerTypeUnqual((*I)->getType()));
}
DOUT << "Function type: " << *RetTy << " f(";
@@ -272,11 +276,13 @@
DOUT << ")\n";
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
- PointerType *StructPtr = PointerType::getUnqual(StructType::get(paramTy));
+ PointerType *StructPtr =
+ Context->getPointerTypeUnqual(Context->getStructType(paramTy));
paramTy.clear();
paramTy.push_back(StructPtr);
}
- const FunctionType *funcType = FunctionType::get(RetTy, paramTy, false);
+ const FunctionType *funcType =
+ Context->getFunctionType(RetTy, paramTy, false);
// Create the new function
Function *newFunction = Function::Create(funcType,
@@ -298,8 +304,8 @@
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, i);
+ Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
std::string GEPname = "gep_" + inputs[i]->getName();
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
@@ -346,6 +352,8 @@
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;
@@ -378,7 +386,7 @@
ArgTypes.push_back((*v)->getType());
// Allocate a struct at the beginning of this function
- Type *StructArgTy = StructType::get(ArgTypes);
+ Type *StructArgTy = Context->getStructType(ArgTypes);
Struct =
new AllocaInst(StructArgTy, 0, "structArg",
codeReplacer->getParent()->begin()->begin());
@@ -386,8 +394,8 @@
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, i);
+ Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName());
@@ -412,8 +420,8 @@
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
+ Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName());
@@ -434,7 +442,7 @@
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
- SwitchInst::Create(ConstantInt::getNullValue(Type::Int16Ty),
+ SwitchInst::Create(Context->getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@@ -465,17 +473,17 @@
case 0:
case 1: break; // No value needed.
case 2: // Conditional branch, return a bool
- brVal = ConstantInt::get(Type::Int1Ty, !SuccNum);
+ brVal = Context->getConstantInt(Type::Int1Ty, !SuccNum);
break;
default:
- brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
+ brVal = Context->getConstantInt(Type::Int16Ty, SuccNum);
break;
}
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
// Update the switch instruction.
- TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
+ TheSwitch->addCase(Context->getConstantInt(Type::Int16Ty, SuccNum),
OldTarget);
// Restore values just before we exit
@@ -513,8 +521,8 @@
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
+ Idx[0] = Context->getNullValue(Type::Int32Ty);
+ Idx[1] = Context->getConstantInt(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(),
@@ -551,7 +559,7 @@
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
- ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
+ ReturnInst::Create(Context->getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();
Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Sun Jul 5 17:41:43 2009
@@ -15,6 +15,7 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
@@ -238,6 +239,7 @@
//
bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
Instruction *TheCall = CS.getInstruction();
+ LLVMContext *Context = TheCall->getParent()->getContext();
assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
"Instruction not in function!");
@@ -302,7 +304,7 @@
if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
!CalledFunc->onlyReadsMemory()) {
const Type *AggTy = cast<PointerType>(I->getType())->getElementType();
- const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
// Create the alloca. If we have TargetData, use nice alignment.
unsigned Align = 1;
@@ -319,15 +321,16 @@
Value *Size;
if (TD == 0)
- Size = ConstantExpr::getSizeOf(AggTy);
+ Size = Context->getConstantExprSizeOf(AggTy);
else
- Size = ConstantInt::get(Type::Int64Ty, TD->getTypeStoreSize(AggTy));
+ Size = Context->getConstantInt(Type::Int64Ty,
+ TD->getTypeStoreSize(AggTy));
// Always generate a memcpy of alignment 1 here because we don't know
// the alignment of the src pointer. Other optimizations can infer
// better alignment.
Value *CallArgs[] = {
- DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1)
+ DestCast, SrcCast, Size, Context->getConstantInt(Type::Int32Ty, 1)
};
CallInst *TheMemCpy =
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
@@ -517,7 +520,7 @@
if (!TheCall->use_empty()) {
ReturnInst *R = Returns[0];
if (TheCall == R->getReturnValue())
- TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
else
TheCall->replaceAllUsesWith(R->getReturnValue());
}
@@ -610,7 +613,7 @@
// using the return value of the call with the computed value.
if (!TheCall->use_empty()) {
if (TheCall == Returns[0]->getReturnValue())
- TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
else
TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
}
@@ -630,7 +633,7 @@
} else if (!TheCall->use_empty()) {
// No returns, but something is using the return value of the call. Just
// nuke the result.
- TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
}
// Since we are now done with the Call/Invoke, we can delete it.
Modified: llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LCSSA.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LCSSA.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LCSSA.cpp Sun Jul 5 17:41:43 2009
@@ -33,6 +33,7 @@
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Dominators.h"
@@ -242,7 +243,7 @@
DenseMap<DomTreeNode*, Value*> &Phis) {
// If there is no dominator info for this BB, it is unreachable.
if (BB == 0)
- return UndefValue::get(OrigInst->getType());
+ return Context->getUndef(OrigInst->getType());
// If we have already computed this value, return the previously computed val.
if (Phis.count(BB)) return Phis[BB];
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Sun Jul 5 17:41:43 2009
@@ -20,6 +20,7 @@
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/DebugInfo.h"
@@ -262,7 +263,8 @@
/// too, recursively.
void
llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
-
+ LLVMContext* Context = PN->getParent()->getContext();
+
// We can remove a PHI if it is on a cycle in the def-use graph
// where each node in the cycle has degree one, i.e. only one use,
// and is an instruction with no side effects.
@@ -279,7 +281,7 @@
if (PHINode *JP = dyn_cast<PHINode>(J))
if (!PHIs.insert(cast<PHINode>(JP))) {
// Break the cycle and delete the PHI and its operands.
- JP->replaceAllUsesWith(UndefValue::get(JP->getType()));
+ JP->replaceAllUsesWith(Context->getUndef(JP->getType()));
RecursivelyDeleteTriviallyDeadInstructions(JP);
break;
}
@@ -299,7 +301,7 @@
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
Value *NewVal = PN->getIncomingValue(0);
// Replace self referencing PHI with undef, it must be dead.
- if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
+ if (NewVal == PN) NewVal = DestBB->getContext()->getUndef(PN->getType());
PN->replaceAllUsesWith(NewVal);
PN->eraseFromParent();
}
Modified: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp Sun Jul 5 17:41:43 2009
@@ -37,6 +37,7 @@
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Type.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/Dominators.h"
@@ -165,7 +166,7 @@
// Delete the dead terminator.
if (AA) AA->deleteValue(TI);
if (!TI->use_empty())
- TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
+ TI->replaceAllUsesWith(Context->getUndef(TI->getType()));
TI->eraseFromParent();
Changed |= true;
}
Modified: llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp Sun Jul 5 17:41:43 2009
@@ -19,6 +19,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Constants.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Target/TargetData.h"
@@ -86,10 +87,10 @@
// This function is always successful.
//
bool LowerAllocations::doInitialization(Module &M) {
- const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
+ const Type *BPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
// Prototype malloc as "char* malloc(...)", because we don't know in
// doInitialization whether size_t is int or long.
- FunctionType *FT = FunctionType::get(BPTy, true);
+ FunctionType *FT = Context->getFunctionType(BPTy, true);
MallocFunc = M.getOrInsertFunction("malloc", FT);
FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
return true;
@@ -115,11 +116,12 @@
// malloc(type) becomes i8 *malloc(size)
Value *MallocArg;
if (LowerMallocArgToInteger)
- MallocArg = ConstantInt::get(Type::Int64Ty,
+ MallocArg = Context->getConstantInt(Type::Int64Ty,
TD.getTypeAllocSize(AllocTy));
else
- MallocArg = ConstantExpr::getSizeOf(AllocTy);
- MallocArg = ConstantExpr::getTruncOrBitCast(cast<Constant>(MallocArg),
+ MallocArg = Context->getConstantExprSizeOf(AllocTy);
+ MallocArg =
+ Context->getConstantExprTruncOrBitCast(cast<Constant>(MallocArg),
IntPtrTy);
if (MI->isArrayAllocation()) {
@@ -127,8 +129,10 @@
cast<ConstantInt>(MallocArg)->isOne()) {
MallocArg = MI->getOperand(0); // Operand * 1 = Operand
} else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
- CO = ConstantExpr::getIntegerCast(CO, IntPtrTy, false /*ZExt*/);
- MallocArg = ConstantExpr::getMul(CO, cast<Constant>(MallocArg));
+ CO =
+ Context->getConstantExprIntegerCast(CO, IntPtrTy, false /*ZExt*/);
+ MallocArg = Context->getConstantExprMul(CO,
+ cast<Constant>(MallocArg));
} else {
Value *Scale = MI->getOperand(0);
if (Scale->getType() != IntPtrTy)
@@ -150,7 +154,7 @@
if (MCall->getType() != Type::VoidTy)
MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
- MCast = Constant::getNullValue(MI->getType());
+ MCast = Context->getNullValue(MI->getType());
// Replace all uses of the old malloc inst with the cast inst
MI->replaceAllUsesWith(MCast);
@@ -160,7 +164,7 @@
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
Value *PtrCast =
new BitCastInst(FI->getOperand(0),
- PointerType::getUnqual(Type::Int8Ty), "", I);
+ Context->getPointerTypeUnqual(Type::Int8Ty), "", I);
// Insert a call to the free function...
CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
Modified: llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp Sun Jul 5 17:41:43 2009
@@ -40,6 +40,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -114,33 +115,33 @@
// doInitialization - Make sure that there is a prototype for abort in the
// current module.
bool LowerInvoke::doInitialization(Module &M) {
- const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
AbortMessage = 0;
if (ExpensiveEHSupport) {
// Insert a type for the linked list of jump buffers.
unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
JBSize = JBSize ? JBSize : 200;
- const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
+ const Type *JmpBufTy = Context->getArrayType(VoidPtrTy, JBSize);
{ // The type is recursive, so use a type holder.
std::vector<const Type*> Elements;
Elements.push_back(JmpBufTy);
- OpaqueType *OT = OpaqueType::get();
- Elements.push_back(PointerType::getUnqual(OT));
- PATypeHolder JBLType(StructType::get(Elements));
+ OpaqueType *OT = Context->getOpaqueType();
+ Elements.push_back(Context->getPointerTypeUnqual(OT));
+ PATypeHolder JBLType(Context->getStructType(Elements));
OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle.
JBLinkTy = JBLType.get();
M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
}
- const Type *PtrJBList = PointerType::getUnqual(JBLinkTy);
+ const Type *PtrJBList = Context->getPointerTypeUnqual(JBLinkTy);
// Now that we've done that, insert the jmpbuf list head global, unless it
// already exists.
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
JBListHead = new GlobalVariable(PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
- Constant::getNullValue(PtrJBList),
+ Context->getNullValue(PtrJBList),
"llvm.sjljeh.jblist", &M);
}
@@ -178,26 +179,26 @@
// The abort message for expensive EH support tells the user that the
// program 'unwound' without an 'invoke' instruction.
Constant *Msg =
- ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
+ Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg", M);
- std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
- AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
+ std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
+ AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
// The abort message for cheap EH support tells the user that EH is not
// enabled.
Constant *Msg =
- ConstantArray::get("Exception handler needed, but not enabled. Recompile"
- " program with -enable-correct-eh-support.\n");
+ Context->getConstantArray("Exception handler needed, but not enabled."
+ "Recompile program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg", M);
- std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}
}
Modified: llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp Sun Jul 5 17:41:43 2009
@@ -18,6 +18,7 @@
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
@@ -200,11 +201,11 @@
"SwitchLeaf", NewLeaf);
} else {
// Emit V-Lo <=u Hi-Lo
- Constant* NegLo = ConstantExpr::getNeg(Leaf.Low);
+ Constant* NegLo = Context->getConstantExprNeg(Leaf.Low);
Instruction* Add = BinaryOperator::CreateAdd(Val, NegLo,
Val->getName()+".off",
NewLeaf);
- Constant *UpperBound = ConstantExpr::getAdd(NegLo, Leaf.High);
+ Constant *UpperBound = Context->getConstantExprAdd(NegLo, Leaf.High);
Comp = new ICmpInst(ICmpInst::ICMP_ULE, Add, UpperBound,
"SwitchLeaf", NewLeaf);
}
Modified: llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp Sun Jul 5 17:41:43 2009
@@ -75,7 +75,7 @@
if (Allocas.empty()) break;
- PromoteMemToReg(Allocas, DT, DF);
+ PromoteMemToReg(Allocas, DT, DF, Context);
NumPromoted += Allocas.size();
Changed = true;
}
Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Sun Jul 5 17:41:43 2009
@@ -23,6 +23,7 @@
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/ADT/DenseMap.h"
@@ -181,6 +182,8 @@
/// AST - An AliasSetTracker object to update. If null, don't update it.
///
AliasSetTracker *AST;
+
+ LLVMContext* Context;
/// AllocaLookup - Reverse mapping of Allocas.
///
@@ -212,8 +215,9 @@
DenseMap<const BasicBlock*, unsigned> BBNumPreds;
public:
PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt,
- DominanceFrontier &df, AliasSetTracker *ast)
- : Allocas(A), DT(dt), DF(df), AST(ast) {}
+ DominanceFrontier &df, AliasSetTracker *ast,
+ LLVMContext* C)
+ : Allocas(A), DT(dt), DF(df), AST(ast), Context(C) {}
void run();
@@ -445,7 +449,7 @@
//
RenamePassData::ValVector Values(Allocas.size());
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
- Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());
+ Values[i] = Context->getUndef(Allocas[i]->getAllocatedType());
// Walks all basic blocks in the function performing the SSA rename algorithm
// and inserting the phi nodes we marked as necessary
@@ -472,7 +476,7 @@
// Just delete the users now.
//
if (!A->use_empty())
- A->replaceAllUsesWith(UndefValue::get(A->getType()));
+ A->replaceAllUsesWith(Context->getUndef(A->getType()));
if (AST) AST->deleteValue(A);
A->eraseFromParent();
}
@@ -558,7 +562,7 @@
BasicBlock::iterator BBI = BB->begin();
while ((SomePHI = dyn_cast<PHINode>(BBI++)) &&
SomePHI->getNumIncomingValues() == NumBadPreds) {
- Value *UndefVal = UndefValue::get(SomePHI->getType());
+ Value *UndefVal = Context->getUndef(SomePHI->getType());
for (unsigned pred = 0, e = Preds.size(); pred != e; ++pred)
SomePHI->addIncoming(UndefVal, Preds[pred]);
}
@@ -804,7 +808,7 @@
if (StoresByIndex.empty()) {
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;)
if (LoadInst *LI = dyn_cast<LoadInst>(*UI++)) {
- LI->replaceAllUsesWith(UndefValue::get(LI->getType()));
+ LI->replaceAllUsesWith(Context->getUndef(LI->getType()));
if (AST && isa<PointerType>(LI->getType()))
AST->deleteValue(LI);
LBI.deleteValue(LI);
@@ -995,9 +999,9 @@
///
void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
DominatorTree &DT, DominanceFrontier &DF,
- AliasSetTracker *AST) {
+ LLVMContext* Context, AliasSetTracker *AST) {
// If there is nothing to do, bail out...
if (Allocas.empty()) return;
- PromoteMem2Reg(Allocas, DT, DF, AST).run();
+ PromoteMem2Reg(Allocas, DT, DF, AST, Context).run();
}
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Jul 5 17:41:43 2009
@@ -16,6 +16,7 @@
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Type.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
@@ -1274,6 +1275,8 @@
/// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
/// PHI node, see if we can eliminate it.
static bool FoldTwoEntryPHINode(PHINode *PN) {
+ LLVMContext* Context = PN->getParent()->getContext();
+
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
// statement", which has a very simple dominance structure. Basically, we
// are trying to find the condition that is being branched on, which
@@ -1311,7 +1314,7 @@
if (PN->getIncomingValue(0) != PN)
PN->replaceAllUsesWith(PN->getIncomingValue(0));
else
- PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+ PN->replaceAllUsesWith(Context->getUndef(PN->getType()));
} else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
&AggressiveInsts) ||
!DominatesMergePoint(PN->getIncomingValue(1), BB,
@@ -1605,6 +1608,7 @@
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
assert(PBI->isConditional() && BI->isConditional());
BasicBlock *BB = BI->getParent();
+ LLVMContext* Context = BB->getContext();
// If this block ends with a branch instruction, and if there is a
// predecessor that ends on a branch of the same condition, make
@@ -1616,7 +1620,7 @@
if (BB->getSinglePredecessor()) {
// Turn this into a branch on constant.
bool CondIsTrue = PBI->getSuccessor(0) == BB;
- BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue));
+ BI->setCondition(Context->getConstantInt(Type::Int1Ty, CondIsTrue));
return true; // Nuke the branch on constant.
}
@@ -1636,7 +1640,7 @@
PBI->getCondition() == BI->getCondition() &&
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
bool CondIsTrue = PBI->getSuccessor(0) == BB;
- NewPN->addIncoming(ConstantInt::get(Type::Int1Ty,
+ NewPN->addIncoming(Context->getConstantInt(Type::Int1Ty,
CondIsTrue), *PI);
} else {
NewPN->addIncoming(BI->getCondition(), *PI);
Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Sun Jul 5 17:41:43 2009
@@ -13,14 +13,16 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/ValueMapper.h"
+#include "llvm/BasicBlock.h"
#include "llvm/Constants.h"
#include "llvm/GlobalValue.h"
#include "llvm/Instruction.h"
+#include "llvm/LLVMContext.h"
#include "llvm/MDNode.h"
#include "llvm/ADT/SmallVector.h"
using namespace llvm;
-Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
+Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context) {
Value *&VMSlot = VM[V];
if (VMSlot) return VMSlot; // Does it exist in the map yet?
@@ -40,7 +42,7 @@
else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
i != e; ++i) {
- Value *MV = MapValue(*i, VM);
+ Value *MV = MapValue(*i, VM, Context);
if (MV != *i) {
// This array must contain a reference to a global, make a new array
// and return it.
@@ -51,8 +53,8 @@
Values.push_back(cast<Constant>(*j));
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
- Values.push_back(cast<Constant>(MapValue(*i, VM)));
- return VM[V] = ConstantArray::get(CA->getType(), Values);
+ Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
+ return VM[V] = Context->getConstantArray(CA->getType(), Values);
}
}
return VM[V] = C;
@@ -60,7 +62,7 @@
} else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
for (User::op_iterator b = CS->op_begin(), i = b, e = CS->op_end();
i != e; ++i) {
- Value *MV = MapValue(*i, VM);
+ Value *MV = MapValue(*i, VM, Context);
if (MV != *i) {
// This struct must contain a reference to a global, make a new struct
// and return it.
@@ -71,8 +73,8 @@
Values.push_back(cast<Constant>(*j));
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
- Values.push_back(cast<Constant>(MapValue(*i, VM)));
- return VM[V] = ConstantStruct::get(CS->getType(), Values);
+ Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
+ return VM[V] = Context->getConstantStruct(CS->getType(), Values);
}
}
return VM[V] = C;
@@ -80,12 +82,12 @@
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
std::vector<Constant*> Ops;
for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
- Ops.push_back(cast<Constant>(MapValue(*i, VM)));
+ Ops.push_back(cast<Constant>(MapValue(*i, VM, Context)));
return VM[V] = CE->getWithOperands(Ops);
} else if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
for (User::op_iterator b = CP->op_begin(), i = b, e = CP->op_end();
i != e; ++i) {
- Value *MV = MapValue(*i, VM);
+ Value *MV = MapValue(*i, VM, Context);
if (MV != *i) {
// This vector value must contain a reference to a global, make a new
// vector constant and return it.
@@ -96,8 +98,8 @@
Values.push_back(cast<Constant>(*j));
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
- Values.push_back(cast<Constant>(MapValue(*i, VM)));
- return VM[V] = ConstantVector::get(Values);
+ Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
+ return VM[V] = Context->getConstantVector(Values);
}
}
return VM[V] = C;
@@ -107,7 +109,7 @@
e = N->elem_end(); i != e; ++i) {
if (!*i) continue;
- Value *MV = MapValue(*i, VM);
+ Value *MV = MapValue(*i, VM, Context);
if (MV != *i) {
// This MDNode must contain a reference to a global, make a new MDNode
// and return it.
@@ -117,8 +119,8 @@
Values.push_back(*j);
Values.push_back(MV);
for (++i; i != e; ++i)
- Values.push_back(MapValue(*i, VM));
- return VM[V] = MDNode::get(Values.data(), Values.size());
+ Values.push_back(MapValue(*i, VM, Context));
+ return VM[V] = Context->getMDNode(Values.data(), Values.size());
}
}
return VM[V] = C;
@@ -136,7 +138,7 @@
///
void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) {
for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
- Value *V = MapValue(*op, ValueMap);
+ Value *V = MapValue(*op, ValueMap, I->getParent()->getContext());
assert(V && "Referenced value not in value map!");
*op = V;
}
Modified: llvm/trunk/lib/VMCore/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/BasicBlock.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/BasicBlock.cpp (original)
+++ llvm/trunk/lib/VMCore/BasicBlock.cpp Sun Jul 5 17:41:43 2009
@@ -29,6 +29,10 @@
return 0;
}
+LLVMContext* BasicBlock::getContext() const {
+ return Parent ? Parent->getContext() : 0;
+}
+
// Explicit instantiation of SymbolTableListTraits since some of the methods
// are not in the public header file...
template class SymbolTableListTraits<Instruction, BasicBlock>;
Modified: llvm/trunk/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Function.cpp (original)
+++ llvm/trunk/lib/VMCore/Function.cpp Sun Jul 5 17:41:43 2009
@@ -114,8 +114,8 @@
// Helper Methods in Function
//===----------------------------------------------------------------------===//
-LLVMContext* Function::getContext() {
- Module* M = getParent();
+LLVMContext* Function::getContext() const {
+ const Module* M = getParent();
if (M) return &M->getContext();
return 0;
}
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=74807&r1=74806&r2=74807&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Sun Jul 5 17:41:43 2009
@@ -374,6 +374,10 @@
return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
}
+Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
+ return ConstantExpr::getSizeOf(Ty);
+}
+
Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
return ConstantExpr::getZeroValueForNegationExpr(Ty);
}
@@ -428,6 +432,10 @@
}
// FunctionType accessors
+FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
+ return FunctionType::get(Result, isVarArg);
+}
+
FunctionType* LLVMContext::getFunctionType(const Type* Result,
const std::vector<const Type*>& Params,
bool isVarArg) {
More information about the llvm-commits
mailing list