summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-16 18:04:31 +0000
committerOwen Anderson <resistor@mac.com>2009-07-16 18:04:31 +0000
commit001dbfebcbbded8c8e74b19e838b50da2b6c6fb5 (patch)
tree1dc61249ea3e7ecc74b897c4c6014f9bbbc341ac
parentf96db468fcf62d671cda99b68b6cfd3f2dc0b839 (diff)
downloadllvm-001dbfebcbbded8c8e74b19e838b50da2b6c6fb5.tar.gz
llvm-001dbfebcbbded8c8e74b19e838b50da2b6c6fb5.tar.bz2
llvm-001dbfebcbbded8c8e74b19e838b50da2b6c6fb5.tar.xz
Move the ConstantInt uniquing table into LLVMContextImpl. This exposed a number of issues in
our current context-passing stuff, which is also fixed here git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76089 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--examples/BrainF/BrainFDriver.cpp4
-rw-r--r--include/llvm/Analysis/LoopPass.h1
-rw-r--r--include/llvm/CallGraphSCCPass.h2
-rw-r--r--include/llvm/Constants.h5
-rw-r--r--include/llvm/LLVMContext.h2
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp4
-rw-r--r--lib/Analysis/ScalarEvolution.cpp12
-rw-r--r--lib/CodeGen/SelectionDAG/FastISel.cpp2
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp3
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp2
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp3
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp1
-rw-r--r--lib/Transforms/IPO/DeadTypeElimination.cpp1
-rw-r--r--lib/Transforms/IPO/ExtractGV.cpp2
-rw-r--r--lib/Transforms/IPO/GlobalDCE.cpp2
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp1
-rw-r--r--lib/Transforms/IPO/IPConstantPropagation.cpp2
-rw-r--r--lib/Transforms/IPO/IndMemRemoval.cpp2
-rw-r--r--lib/Transforms/IPO/Internalize.cpp2
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp2
-rw-r--r--lib/Transforms/IPO/MergeFunctions.cpp2
-rw-r--r--lib/Transforms/IPO/PartialInlining.cpp2
-rw-r--r--lib/Transforms/IPO/PartialSpecialization.cpp2
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp1
-rw-r--r--lib/Transforms/IPO/StripDeadPrototypes.cpp1
-rw-r--r--lib/Transforms/IPO/StripSymbols.cpp1
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp28
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp3
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp2
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp2
-rw-r--r--lib/VMCore/Constants.cpp61
-rw-r--r--lib/VMCore/LLVMContext.cpp4
-rw-r--r--lib/VMCore/LLVMContextImpl.cpp48
-rw-r--r--lib/VMCore/LLVMContextImpl.h52
34 files changed, 173 insertions, 91 deletions
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 4eaa4940e7..021b9510ce 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -80,13 +80,13 @@ void addMainFunction(Module *mod) {
}
//ret i32 0
- ReturnInst::Create(ConstantInt::get(APInt(32, 0)), bb);
+ ReturnInst::Create(getGlobalContext().getConstantInt(APInt(32, 0)), bb);
}
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
- LLVMContext Context;
+ LLVMContext &Context = getGlobalContext();
if (InputFilename == "") {
std::cerr<<"Error: You must specify the filename of the program to "
diff --git a/include/llvm/Analysis/LoopPass.h b/include/llvm/Analysis/LoopPass.h
index 7659b5bf45..a6a23c6b61 100644
--- a/include/llvm/Analysis/LoopPass.h
+++ b/include/llvm/Analysis/LoopPass.h
@@ -37,6 +37,7 @@ public:
// Initialization and finalization hooks.
virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
+ Context = L->getHeader()->getContext();
return false;
}
diff --git a/include/llvm/CallGraphSCCPass.h b/include/llvm/CallGraphSCCPass.h
index d5ff17cf24..8d5d7c3edf 100644
--- a/include/llvm/CallGraphSCCPass.h
+++ b/include/llvm/CallGraphSCCPass.h
@@ -22,6 +22,7 @@
#define LLVM_CALL_GRAPH_SCC_PASS_H
#include "llvm/Pass.h"
+#include "llvm/Analysis/CallGraph.h"
namespace llvm {
@@ -37,6 +38,7 @@ struct CallGraphSCCPass : public Pass {
/// doInitialization - This method is called before the SCC's of the program
/// has been processed, allowing the pass to do initialization as necessary.
virtual bool doInitialization(CallGraph &CG) {
+ Context = &CG.getModule().getContext();
return false;
}
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index e06ce1f1b9..df086416a8 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -50,6 +50,7 @@ class ConstantInt : public Constant {
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const IntegerType *Ty, const APInt& V);
APInt Val;
+ friend class LLVMContextImpl;
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
@@ -102,10 +103,6 @@ public:
return CreateTrueFalseVals(false);
}
- /// Return a ConstantInt with the specified value and an implied Type. The
- /// type is the integer type that corresponds to the bit width of the value.
- static ConstantInt *get(const APInt &V);
-
/// getType - Specialize the getType() method to always return an IntegerType,
/// which reduces the amount of casting needed in parts of the compiler.
///
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index 552e7992c6..4aa2c20ec2 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -93,6 +93,8 @@ public:
ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
Constant *getConstantIntSigned(const Type *Ty, int64_t V);
+ /// Return a ConstantInt with the specified value and an implied Type. The
+ /// type is the integer type that corresponds to the bit width of the value.
ConstantInt* getConstantInt(const APInt& V);
/// If Ty is a vector type, return a Constant with a splat of the given
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 59839e8c8b..c10c6f3f27 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -312,6 +312,8 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) {
AliasAnalysis::AliasResult
BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
const Value *V2, unsigned V2Size) {
+ Context = &V1->getType()->getContext();
+
// Strip off any constant expression casts if they exist
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V1))
if (CE->isCast() && isa<PointerType>(CE->getOperand(0)->getType()))
@@ -530,6 +532,8 @@ BasicAliasAnalysis::CheckGEPInstructions(
const PointerType *GEPPointerTy = cast<PointerType>(BasePtr1Ty);
+ Context = &GEPPointerTy->getContext();
+
// Find the (possibly empty) initial sequence of equal values... which are not
// necessarily constants.
unsigned NumGEP1Operands = NumGEP1Ops, NumGEP2Operands = NumGEP2Ops;
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index dcd6558d34..1b0b37ba01 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -191,7 +191,7 @@ const SCEV *ScalarEvolution::getConstant(ConstantInt *V) {
}
const SCEV *ScalarEvolution::getConstant(const APInt& Val) {
- return getConstant(ConstantInt::get(Val));
+ return getConstant(Context->getConstantInt(Val));
}
const SCEV *
@@ -1517,7 +1517,7 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops) {
++Idx;
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
// We found two constants, fold them together!
- ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() *
+ ConstantInt *Fold = Context->getConstantInt(LHSC->getValue()->getValue() *
RHSC->getValue()->getValue());
Ops[0] = getConstant(Fold);
Ops.erase(Ops.begin()+1); // Erase the folded element
@@ -1868,7 +1868,7 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl<const SCEV *> &Ops) {
assert(Idx < Ops.size());
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
// We found two constants, fold them together!
- ConstantInt *Fold = ConstantInt::get(
+ ConstantInt *Fold = Context->getConstantInt(
APIntOps::smax(LHSC->getValue()->getValue(),
RHSC->getValue()->getValue()));
Ops[0] = getConstant(Fold);
@@ -1965,7 +1965,7 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<const SCEV *> &Ops) {
assert(Idx < Ops.size());
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
// We found two constants, fold them together!
- ConstantInt *Fold = ConstantInt::get(
+ ConstantInt *Fold = Context->getConstantInt(
APIntOps::umax(LHSC->getValue()->getValue(),
RHSC->getValue()->getValue()));
Ops[0] = getConstant(Fold);
@@ -2887,7 +2887,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
// Turn shift left of a constant amount into a multiply.
if (ConstantInt *SA = dyn_cast<ConstantInt>(U->getOperand(1))) {
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
- Constant *X = ConstantInt::get(
+ Constant *X = Context->getConstantInt(
APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth)));
return getMulExpr(getSCEV(U->getOperand(0)), getSCEV(X));
}
@@ -2897,7 +2897,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
// Turn logical shift right of a constant into a unsigned divide.
if (ConstantInt *SA = dyn_cast<ConstantInt>(U->getOperand(1))) {
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
- Constant *X = ConstantInt::get(
+ Constant *X = Context->getConstantInt(
APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth)));
return getUDivExpr(getSCEV(U->getOperand(0)), getSCEV(X));
}
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index adb4d729e6..d523e7fce3 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -108,7 +108,7 @@ unsigned FastISel::getRegForValue(Value *V) {
if (isExact) {
APInt IntVal(IntBitWidth, 2, x);
- unsigned IntegerReg = getRegForValue(ConstantInt::get(IntVal));
+ unsigned IntegerReg = getRegForValue(Context->getConstantInt(IntVal));
if (IntegerReg != 0)
Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
}
diff --git a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 600185be97..1412ad9f11 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -2305,7 +2305,8 @@ SDValue DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) {
ISD::SETLT);
// Build a 64 bit pair (0, FF) in the constant pool, with FF in the lo bits.
- SDValue FudgePtr = DAG.getConstantPool(ConstantInt::get(FF.zext(64)),
+ SDValue FudgePtr = DAG.getConstantPool(
+ DAG.getContext()->getConstantInt(FF.zext(64)),
TLI.getPointerTy());
// Get a pointer to FF if the sign bit was set, or to 0 otherwise.
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index caa3ce1857..4491eb262b 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -874,7 +874,7 @@ SDValue SelectionDAG::getConstant(uint64_t Val, MVT VT, bool isT) {
}
SDValue SelectionDAG::getConstant(const APInt &Val, MVT VT, bool isT) {
- return getConstant(*ConstantInt::get(Val), VT, isT);
+ return getConstant(*Context->getConstantInt(Val), VT, isT);
}
SDValue SelectionDAG::getConstant(const ConstantInt &Val, MVT VT, bool isT) {
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index b1589d4c09..4f90bb31fc 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -2406,7 +2406,8 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
// Convert the ConstantVector mask operand into an array of ints, with -1
// representing undef values.
SmallVector<Constant*, 8> MaskElts;
- cast<Constant>(I.getOperand(2))->getVectorElements(*Context, MaskElts);
+ cast<Constant>(I.getOperand(2))->getVectorElements(*DAG.getContext(),
+ MaskElts);
unsigned MaskNumElts = MaskElts.size();
for (unsigned i = 0; i != MaskNumElts; ++i) {
if (isa<UndefValue>(MaskElts[i]))
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 2e913914d6..e86f619dcb 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -908,6 +908,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
bool DAE::runOnModule(Module &M) {
bool Changed = false;
+ Context = &M.getContext();
// First pass: Do a simple check to see if any functions can have their "..."
// removed. We can do this if they never call va_start. This loop cannot be
diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp
index 85aed2b791..f202403d80 100644
--- a/lib/Transforms/IPO/DeadTypeElimination.cpp
+++ b/lib/Transforms/IPO/DeadTypeElimination.cpp
@@ -77,6 +77,7 @@ static inline bool ShouldNukeSymtabEntry(const Type *Ty){
//
bool DTE::runOnModule(Module &M) {
bool Changed = false;
+ Context = &M.getContext();
TypeSymbolTable &ST = M.getTypeSymbolTable();
std::set<const Type *> UsedTypes = getAnalysis<FindUsedTypes>().getTypes();
diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp
index b7c5ca3e6e..fa3a055b20 100644
--- a/lib/Transforms/IPO/ExtractGV.cpp
+++ b/lib/Transforms/IPO/ExtractGV.cpp
@@ -44,6 +44,8 @@ namespace {
return false; // Nothing to extract
}
+ Context = &M.getContext();
+
if (deleteStuff)
return deleteGV();
M.setModuleInlineAsm("");
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp
index 9c652b996a..9ecc494d9b 100644
--- a/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/lib/Transforms/IPO/GlobalDCE.cpp
@@ -58,6 +58,8 @@ ModulePass *llvm::createGlobalDCEPass() { return new GlobalDCE(); }
bool GlobalDCE::runOnModule(Module &M) {
bool Changed = false;
+ Context = &M.getContext();
+
// Loop over the module, adding globals which are obviously necessary.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Changed |= RemoveUnusedGlobalValue(*I);
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 398f78a098..8b3cf48cee 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2476,6 +2476,7 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
bool GlobalOpt::runOnModule(Module &M) {
bool Changed = false;
+ Context = &M.getContext();
// Try to find the llvm.globalctors list.
GlobalVariable *GlobalCtors = FindGlobalCtors(M);
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index e27792a098..30834e2d67 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -56,6 +56,8 @@ bool IPCP::runOnModule(Module &M) {
bool Changed = false;
bool LocalChange = true;
+ Context = &M.getContext();
+
// FIXME: instead of using smart algorithms, we just iterate until we stop
// making changes.
while (LocalChange) {
diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp
index 2086a16683..7b9b0ccb8b 100644
--- a/lib/Transforms/IPO/IndMemRemoval.cpp
+++ b/lib/Transforms/IPO/IndMemRemoval.cpp
@@ -44,6 +44,8 @@ static RegisterPass<IndMemRemPass>
X("indmemrem","Indirect Malloc and Free Removal");
bool IndMemRemPass::runOnModule(Module &M) {
+ Context = &M.getContext();
+
// In theory, all direct calls of malloc and free should be promoted
// to intrinsics. Therefore, this goes through and finds where the
// address of free or malloc are taken and replaces those with bounce
diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp
index 5093ae90b5..9bc9172517 100644
--- a/lib/Transforms/IPO/Internalize.cpp
+++ b/lib/Transforms/IPO/Internalize.cpp
@@ -101,6 +101,8 @@ void InternalizePass::LoadFile(const char *Filename) {
bool InternalizePass::runOnModule(Module &M) {
CallGraph *CG = getAnalysisIfAvailable<CallGraph>();
CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : 0;
+
+ Context = &M.getContext();
if (ExternalNames.empty()) {
// Return if we're not in 'all but main' mode and have no external api
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index dfdf5b6f2d..bfa2bd9bc2 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -134,6 +134,8 @@ static RegisterPass<LowerSetJmp> X("lowersetjmp", "Lower Set Jump");
bool LowerSetJmp::runOnModule(Module& M) {
bool Changed = false;
+ Context = &M.getContext();
+
// These are what the functions are called.
Function* SetJmp = M.getFunction("llvm.setjmp");
Function* LongJmp = M.getFunction("llvm.longjmp");
diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp
index 9cc4daa9d2..e93a08784f 100644
--- a/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/lib/Transforms/IPO/MergeFunctions.cpp
@@ -615,6 +615,8 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
bool MergeFunctions::runOnModule(Module &M) {
bool Changed = false;
+ Context = &M.getContext();
+
std::map<unsigned long, std::vector<Function *> > FnMap;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
diff --git a/lib/Transforms/IPO/PartialInlining.cpp b/lib/Transforms/IPO/PartialInlining.cpp
index 73ec9c1076..a6e090b317 100644
--- a/lib/Transforms/IPO/PartialInlining.cpp
+++ b/lib/Transforms/IPO/PartialInlining.cpp
@@ -141,6 +141,8 @@ Function* PartialInliner::unswitchFunction(Function* F) {
}
bool PartialInliner::runOnModule(Module& M) {
+ Context = &M.getContext();
+
std::vector<Function*> worklist;
worklist.reserve(M.size());
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI)
diff --git a/lib/Transforms/IPO/PartialSpecialization.cpp b/lib/Transforms/IPO/PartialSpecialization.cpp
index 0e1fdb9915..3b2ce14860 100644
--- a/lib/Transforms/IPO/PartialSpecialization.cpp
+++ b/lib/Transforms/IPO/PartialSpecialization.cpp
@@ -108,6 +108,8 @@ SpecializeFunction(Function* F,
bool PartSpec::runOnModule(Module &M) {
+ Context = &M.getContext();
+
bool Changed = false;
for (Module::iterator I = M.begin(); I != M.end(); ++I) {
Function &F = *I;
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 6c32050909..8d2a9cbdd5 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -70,6 +70,7 @@ ModulePass *llvm::createRaiseAllocationsPass() {
// function into the appropriate instruction.
//
void RaiseAllocations::doInitialization(Module &M) {
+ Context = &M.getContext();
// Get Malloc and free prototypes if they exist!
MallocFunc = M.getFunction("malloc");
diff --git a/lib/Transforms/IPO/StripDeadPrototypes.cpp b/lib/Transforms/IPO/StripDeadPrototypes.cpp
index a94d78e276..2a1779107a 100644
--- a/lib/Transforms/IPO/StripDeadPrototypes.cpp
+++ b/lib/Transforms/IPO/StripDeadPrototypes.cpp
@@ -42,6 +42,7 @@ X("strip-dead-prototypes", "Strip Unused Function Prototypes");
bool StripDeadPrototypesPass::runOnModule(Module &M) {
bool MadeChange = false;
+ Context = &M.getContext();
// Erase dead function prototypes.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp
index 323d1800a9..82a0952aa2 100644
--- a/lib/Transforms/IPO/StripSymbols.cpp
+++ b/lib/Transforms/IPO/StripSymbols.cpp
@@ -374,6 +374,7 @@ bool StripDebugInfo(Module &M) {
}
bool StripSymbols::runOnModule(Module &M) {
+ Context = &M.getContext();
bool Changed = false;
Changed |= StripDebugInfo(M);
if (!OnlyDebugInfo)
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 50d606311a..51de4f7c05 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -905,6 +905,7 @@ namespace {
class VISIBILITY_HIDDEN ValueRanges {
ValueNumbering &VN;
TargetData *TD;
+ LLVMContext *Context;
class VISIBILITY_HIDDEN ScopedRange {
typedef std::vector<std::pair<DomTreeDFS::Node *, ConstantRange> >
@@ -1025,7 +1026,8 @@ namespace {
public:
- ValueRanges(ValueNumbering &VN, TargetData *TD) : VN(VN), TD(TD) {}
+ ValueRanges(ValueNumbering &VN, TargetData *TD, LLVMContext *C) :
+ VN(VN), TD(TD), Context(C) {}
#ifndef NDEBUG
virtual ~ValueRanges() {}
@@ -1167,7 +1169,7 @@ namespace {
Value *V = VN.value(n); // XXX: redesign worklist.
const Type *Ty = V->getType();
if (Ty->isInteger()) {
- addToWorklist(V, ConstantInt::get(*I), ICmpInst::ICMP_EQ, VRP);
+ addToWorklist(V, Context->getConstantInt(*I), ICmpInst::ICMP_EQ, VRP);
return;
} else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
assert(*I == 0 && "Pointer is null but not zero?");
@@ -1678,7 +1680,8 @@ namespace {
Top(DTDFS->getNodeForBlock(TopInst->getParent())),
TopBB(TopInst->getParent()),
TopInst(TopInst),
- modified(modified)
+ modified(modified),
+ Context(TopInst->getParent()->getContext())
{
assert(Top && "VRPSolver created for unreachable basic block.");
assert(Top->getBlock() == TopInst->getParent() && "Context mismatch.");
@@ -1779,7 +1782,8 @@ namespace {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) {
if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) {
- add(RHS, ConstantInt::get(CI->getValue() ^ Arg->getValue()),
+ add(RHS,
+ Context->getConstantInt(CI->getValue() ^ Arg->getValue()),
ICmpInst::ICMP_EQ, NewContext);
}
}
@@ -2404,7 +2408,7 @@ namespace {
DomTreeDFS::Node *Root = DTDFS->getRootNode();
VN = new ValueNumbering(DTDFS);
IG = new InequalityGraph(*VN, Root);
- VR = new ValueRanges(*VN, TD);
+ VR = new ValueRanges(*VN, TD, Context);
WorkList.push_back(Root);
do {
@@ -2526,21 +2530,23 @@ namespace {
void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) {
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
+ LLVMContext *Context = SI.getParent()->getContext();
uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
APInt Min(APInt::getHighBitsSet(DstBitWidth, DstBitWidth-SrcBitWidth+1));
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth-1));
- VRP.add(ConstantInt::get(Min), &SI, ICmpInst::ICMP_SLE);
- VRP.add(ConstantInt::get(Max), &SI, ICmpInst::ICMP_SGE);
+ VRP.add(Context->getConstantInt(Min), &SI, ICmpInst::ICMP_SLE);
+ VRP.add(Context->getConstantInt(Max), &SI, ICmpInst::ICMP_SGE);
VRP.solve();
}
void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) {
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &ZI);
+ LLVMContext *Context = ZI.getParent()->getContext();
uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth));
- VRP.add(ConstantInt::get(Max), &ZI, ICmpInst::ICMP_UGE);
+ VRP.add(Context->getConstantInt(Max), &ZI, ICmpInst::ICMP_UGE);
VRP.solve();
}
@@ -2629,6 +2635,8 @@ namespace {
Pred = IC.getPredicate();
+ LLVMContext *Context = IC.getParent()->getContext();
+
if (ConstantInt *Op1 = dyn_cast<ConstantInt>(IC.getOperand(1))) {
ConstantInt *NextVal = 0;
switch (Pred) {
@@ -2636,12 +2644,12 @@ namespace {
case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_ULT:
if (Op1->getValue() != 0)
- NextVal = ConstantInt::get(Op1->getValue()-1);
+ NextVal = Context->getConstantInt(Op1->getValue()-1);
break;
case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_UGT:
if (!Op1->getValue().isAllOnesValue())
- NextVal = ConstantInt::get(Op1->getValue()+1);
+ NextVal = Context->getConstantInt(Op1->getValue()+1);
break;
}
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 6ada2882e3..7fa1a08f8a 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -1662,7 +1662,10 @@ static bool AddressIsTaken(GlobalValue *GV) {
}
bool IPSCCP::runOnModule(Module &M) {
+ Context = &M.getContext();
+
SCCPSolver Solver;
+ Solver.setContext(Context);
// Loop over all functions, marking arguments to those with their addresses
// taken or that are external as overdefined.
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index 8a28ca23b1..f285406b19 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -1730,6 +1730,8 @@ void SimplifyLibCalls::setDoesNotAlias(Function &F, unsigned n) {
/// doInitialization - Add attributes to well-known functions.
///
bool SimplifyLibCalls::doInitialization(Module &M) {
+ Context = &M.getContext();
+
Modified = false;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Function &F = *I;
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index fae3edf0ad..1417f10e64 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -115,6 +115,8 @@ 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) {
+ Context = &M.getContext();
+
const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
AbortMessage = 0;
if (ExpensiveEHSupport) {
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 49dd6a06d8..680aed5902 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -190,67 +190,6 @@ ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) {
return WhichOne ? TheTrueVal : TheFalseVal;
}
-
-namespace {
- struct DenseMapAPIntKeyInfo {
- struct KeyTy {
- APInt val;
- const Type* type;
- KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {}
- KeyTy(const KeyTy& that) : val(that.val), type(that.type) {}
- bool operator==(const KeyTy& that) const {
- return type == that.type && this->val == that.val;
- }
- bool operator!=(const KeyTy& that) const {
- return !this->operator==(that);
- }
- };
- static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); }
- static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); }
- static unsigned getHashValue(const KeyTy &Key) {
- return DenseMapInfo<void*>::getHashValue(Key.type) ^
- Key.val.getHashValue();
- }
- static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
- return LHS == RHS;
- }
- static bool isPod() { return false; }
- };
-}
-
-
-typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
- DenseMapAPIntKeyInfo> IntMapTy;
-static ManagedStatic<IntMapTy> IntConstants;
-
-// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
-// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
-// operator== and operator!= to ensure that the DenseMap doesn't attempt to
-// compare APInt's of different widths, which would violate an APInt class
-// invariant which generates an assertion.
-ConstantInt *ConstantInt::get(const APInt& V) {
- // Get the corresponding integer type for the bit width of the value.
- const IntegerType *ITy = IntegerType::get(V.getBitWidth());
- // get an existing value or the insertion position
- DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
-
- ConstantsLock->reader_acquire();
- ConstantInt *&Slot = (*IntConstants)[Key];
- ConstantsLock->reader_release();
-
- if (!Slot) {
- sys::SmartScopedWriter<true> Writer(*ConstantsLock);
- ConstantInt *&NewSlot = (*IntConstants)[Key];
- if (!Slot) {
- NewSlot = new ConstantInt(ITy, V);
- }
-
- return NewSlot;
- } else {
- return Slot;
- }
-}
-
//===----------------------------------------------------------------------===//
// ConstantFP
//===----------------------------------------------------------------------===//
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 73c93a2d6e..0372f31e67 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -29,7 +29,7 @@ LLVMContext& llvm::getGlobalContext() {
return *GlobalContext;
}
-LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
+LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
LLVMContext::~LLVMContext() { delete pImpl; }
// Constant accessors
@@ -117,7 +117,7 @@ Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) {
}
ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
- return ConstantInt::get(V);
+ return pImpl->getConstantInt(V);
}
Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp
new file mode 100644
index 0000000000..a92c19fe04
--- /dev/null
+++ b/lib/VMCore/LLVMContextImpl.cpp
@@ -0,0 +1,48 @@
+//===--------------- LLVMContextImpl.cpp - Implementation ------*- C++ -*--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements LLVMContextImpl, the opaque implementation
+// of LLVMContext.
+//
+//===----------------------------------------------------------------------===//
+
+#include "LLVMContextImpl.h"
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
+using namespace llvm;
+
+// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
+// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
+// operator== and operator!= to ensure that the DenseMap doesn't attempt to
+// compare APInt's of different widths, which would violate an APInt class
+// invariant which generates an assertion.
+ConstantInt *LLVMContextImpl::getConstantInt(const APInt& V) {
+ // Get the corresponding integer type for the bit width of the value.
+ const IntegerType *ITy = Context.getIntegerType(V.getBitWidth());
+ // get an existing value or the insertion position
+ DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
+
+ ConstantsLock.reader_acquire();
+ ConstantInt *&Slot = IntConstants[Key];
+ ConstantsLock.reader_release();
+
+ if (!Slot) {
+ sys::SmartScopedWriter<true> Writer(ConstantsLock);
+ ConstantInt *&NewSlot = IntConstants[Key];
+ if (!Slot) {
+ NewSlot = new ConstantInt(ITy, V);
+ }
+
+ return NewSlot;
+ } else {
+ return Slot;
+ }
+}
+
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index 4e089fb661..fbf29fdfc4 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -1,4 +1,4 @@
-//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
+//===----------------- LLVMContextImpl.h - Implementation ------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
@@ -15,9 +15,57 @@
#ifndef LLVM_LLVMCONTEXT_IMPL_H
#define LLVM_LLVMCONTEXT_IMPL_H
+#include "llvm/System/RWMutex.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/DenseMap.h"
+
namespace llvm {
-class LLVMContextImpl {
+class ConstantInt;
+class LLVMContext;
+class Type;
+
+struct DenseMapAPIntKeyInfo {
+ struct KeyTy {
+ APInt val;
+ const Type* type;
+ KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {}
+ KeyTy(const KeyTy& that) : val(that.val), type(that.type) {}
+ bool operator==(const KeyTy& that) const {
+ return type == that.type && this->val == that.val;
+ }
+ bool operator!=(const KeyTy& that) const {
+ return !this->operator==(that);
+ }
+ };
+ static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); }
+ static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); }
+ static unsigned getHashValue(const KeyTy &Key) {
+ return DenseMapInfo<void*>::getHashValue(Key.type) ^
+ Key.val.getHashValue();
+ }
+ static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
+ return LHS == RHS;
+ }
+ static bool isPod() { return false; }
+};
+
+class LLVMContextImpl {
+ sys::SmartRWMutex<true> ConstantsLock;
+
+ typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
+ DenseMapAPIntKeyInfo> IntMapTy;
+ IntMapTy IntConstants;
+
+ LLVMContext &Context;
+ LLVMContextImpl();
+ LLVMContextImpl(const LLVMContextImpl&);
+public:
+ LLVMContextImpl(LLVMContext &C) : Context(C) { }
+
+ /// Return a ConstantInt with the specified value and an implied Type. The
+ /// type is the integer type that corresponds to the bit width of the value.
+ ConstantInt* getConstantInt(const APInt &V);
};
}