Finish LLVMContext-ing lib/Analysis. This required pushing LLVMContext's through the ValueTracking API.

llvm-svn: 74873
This commit is contained in:
Owen Anderson 2009-07-06 22:37:39 +00:00
parent 83b5ccbecf
commit f1f1743b2e
11 changed files with 152 additions and 102 deletions

View File

@ -59,6 +59,8 @@ namespace llvm {
} }
private: private:
LLVMContext *getContext() const { return SE.getContext(); }
/// InsertBinop - Insert the specified binary operator, doing a small amount /// InsertBinop - Insert the specified binary operator, doing a small amount
/// of work to avoid inserting an obviously redundant operation. /// of work to avoid inserting an obviously redundant operation.
Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS); Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS);

View File

@ -31,6 +31,7 @@ namespace llvm {
class BasicBlock; class BasicBlock;
class Function; class Function;
class SparseSolver; class SparseSolver;
class LLVMContext;
template<typename T> class SmallVectorImpl; template<typename T> class SmallVectorImpl;
@ -113,6 +114,8 @@ class SparseSolver {
/// compute transfer functions. /// compute transfer functions.
AbstractLatticeFunction *LatticeFunc; AbstractLatticeFunction *LatticeFunc;
LLVMContext *Context;
DenseMap<Value*, LatticeVal> ValueState; // The state each value is in. DenseMap<Value*, LatticeVal> ValueState; // The state each value is in.
SmallPtrSet<BasicBlock*, 16> BBExecutable; // The bbs that are executable. SmallPtrSet<BasicBlock*, 16> BBExecutable; // The bbs that are executable.
@ -128,8 +131,8 @@ class SparseSolver {
SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT
void operator=(const SparseSolver&); // DO NOT IMPLEMENT void operator=(const SparseSolver&); // DO NOT IMPLEMENT
public: public:
explicit SparseSolver(AbstractLatticeFunction *Lattice) explicit SparseSolver(AbstractLatticeFunction *Lattice, LLVMContext* C)
: LatticeFunc(Lattice) {} : LatticeFunc(Lattice), Context(C) {}
~SparseSolver() { ~SparseSolver() {
delete LatticeFunc; delete LatticeFunc;
} }

View File

@ -23,6 +23,7 @@ namespace llvm {
class Instruction; class Instruction;
class APInt; class APInt;
class TargetData; class TargetData;
class LLVMContext;
/// ComputeMaskedBits - Determine which of the bits specified in Mask are /// ComputeMaskedBits - Determine which of the bits specified in Mask are
/// known to be either zero or one and return them in the KnownZero/KnownOne /// known to be either zero or one and return them in the KnownZero/KnownOne
@ -64,14 +65,16 @@ namespace llvm {
Value *FindInsertedValue(Value *V, Value *FindInsertedValue(Value *V,
const unsigned *idx_begin, const unsigned *idx_begin,
const unsigned *idx_end, const unsigned *idx_end,
LLVMContext *Context,
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);
/// This is a convenience wrapper for finding values indexed by a single index /// This is a convenience wrapper for finding values indexed by a single index
/// only. /// only.
inline Value *FindInsertedValue(Value *V, const unsigned Idx, inline Value *FindInsertedValue(Value *V, const unsigned Idx,
LLVMContext *Context,
Instruction *InsertBefore = 0) { Instruction *InsertBefore = 0) {
const unsigned Idxs[1] = { Idx }; const unsigned Idxs[1] = { Idx };
return FindInsertedValue(V, &Idxs[0], &Idxs[1], InsertBefore); return FindInsertedValue(V, &Idxs[0], &Idxs[1], Context, InsertBefore);
} }
/// GetConstantStringInfo - This function computes the length of a /// GetConstantStringInfo - This function computes the length of a

View File

@ -18,6 +18,7 @@
#include "llvm/Intrinsics.h" #include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/ValueTracking.h"
#include "llvm/Support/Dwarf.h" #include "llvm/Support/Dwarf.h"
@ -455,14 +456,15 @@ void DIVariable::dump() const {
DIFactory::DIFactory(Module &m) DIFactory::DIFactory(Module &m)
: M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0),
DeclareFn(0) { DeclareFn(0) {
EmptyStructPtr = PointerType::getUnqual(StructType::get()); EmptyStructPtr =
M.getContext().getPointerTypeUnqual(M.getContext().getStructType());
} }
/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
/// This is only valid when the descriptor is non-null. /// This is only valid when the descriptor is non-null.
Constant *DIFactory::getCastToEmpty(DIDescriptor D) { Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); if (D.isNull()) return M.getContext().getNullValue(EmptyStructPtr);
return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); return M.getContext().getConstantExprBitCast(D.getGV(), EmptyStructPtr);
} }
Constant *DIFactory::GetTagConstant(unsigned TAG) { Constant *DIFactory::GetTagConstant(unsigned TAG) {
@ -478,21 +480,21 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
// Return Constant if previously defined. // Return Constant if previously defined.
if (Slot) return Slot; if (Slot) return Slot;
const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); const PointerType *DestTy = M.getContext().getPointerTypeUnqual(Type::Int8Ty);
// If empty string then use a i8* null instead. // If empty string then use a i8* null instead.
if (String.empty()) if (String.empty())
return Slot = ConstantPointerNull::get(DestTy); return Slot = M.getContext().getConstantPointerNull(DestTy);
// Construct string as an llvm constant. // Construct string as an llvm constant.
Constant *ConstStr = ConstantArray::get(String); Constant *ConstStr = M.getContext().getConstantArray(String);
// Otherwise create and return a new string global. // Otherwise create and return a new string global.
GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
ConstStr, ".str", &M); ConstStr, ".str", &M);
StrGV->setSection("llvm.metadata"); StrGV->setSection("llvm.metadata");
return Slot = ConstantExpr::getBitCast(StrGV, DestTy); return Slot = M.getContext().getConstantExprBitCast(StrGV, DestTy);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -504,10 +506,12 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
SmallVector<Constant*, 16> Elts; SmallVector<Constant*, 16> Elts;
LLVMContext& Ctxt = M.getContext();
for (unsigned i = 0; i != NumTys; ++i) for (unsigned i = 0; i != NumTys; ++i)
Elts.push_back(getCastToEmpty(Tys[i])); Elts.push_back(getCastToEmpty(Tys[i]));
Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, Constant *Init = Ctxt.getConstantArray(Ctxt.getArrayType(EmptyStructPtr,
Elts.size()), Elts.size()),
Elts.data(), Elts.size()); Elts.data(), Elts.size());
// If we already have this array, just return the uniqued version. // If we already have this array, just return the uniqued version.
@ -527,11 +531,12 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_subrange_type), GetTagConstant(dwarf::DW_TAG_subrange_type),
ConstantInt::get(Type::Int64Ty, Lo), M.getContext().getConstantInt(Type::Int64Ty, Lo),
ConstantInt::get(Type::Int64Ty, Hi) M.getContext().getConstantInt(Type::Int64Ty, Hi)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
// If we already have this range, just return the uniqued version. // If we already have this range, just return the uniqued version.
DIDescriptor &Entry = SimpleConstantCache[Init]; DIDescriptor &Entry = SimpleConstantCache[Init];
@ -559,20 +564,22 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
bool isOptimized, bool isOptimized,
const char *Flags, const char *Flags,
unsigned RunTimeVer) { unsigned RunTimeVer) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_compile_unit), GetTagConstant(dwarf::DW_TAG_compile_unit),
Constant::getNullValue(EmptyStructPtr), Ctxt.getNullValue(EmptyStructPtr),
ConstantInt::get(Type::Int32Ty, LangID), Ctxt.getConstantInt(Type::Int32Ty, LangID),
GetStringConstant(Filename), GetStringConstant(Filename),
GetStringConstant(Directory), GetStringConstant(Directory),
GetStringConstant(Producer), GetStringConstant(Producer),
ConstantInt::get(Type::Int1Ty, isMain), Ctxt.getConstantInt(Type::Int1Ty, isMain),
ConstantInt::get(Type::Int1Ty, isOptimized), Ctxt.getConstantInt(Type::Int1Ty, isOptimized),
GetStringConstant(Flags), GetStringConstant(Flags),
ConstantInt::get(Type::Int32Ty, RunTimeVer) Ctxt.getConstantInt(Type::Int32Ty, RunTimeVer)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -587,10 +594,11 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_enumerator), GetTagConstant(dwarf::DW_TAG_enumerator),
GetStringConstant(Name), GetStringConstant(Name),
ConstantInt::get(Type::Int64Ty, Val) M.getContext().getConstantInt(Type::Int64Ty, Val)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -610,20 +618,23 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
uint64_t AlignInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags, uint64_t OffsetInBits, unsigned Flags,
unsigned Encoding) { unsigned Encoding) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_base_type), GetTagConstant(dwarf::DW_TAG_base_type),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber), Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits), Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits), Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
ConstantInt::get(Type::Int64Ty, OffsetInBits), Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
ConstantInt::get(Type::Int32Ty, Flags), Ctxt.getConstantInt(Type::Int32Ty, Flags),
ConstantInt::get(Type::Int32Ty, Encoding) Ctxt.getConstantInt(Type::Int32Ty, Encoding)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.basictype.type", Init->getType()); M.addTypeName("llvm.dbg.basictype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -645,20 +656,23 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
uint64_t OffsetInBits, uint64_t OffsetInBits,
unsigned Flags, unsigned Flags,
DIType DerivedFrom) { DIType DerivedFrom) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(Tag), GetTagConstant(Tag),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber), Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits), Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits), Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
ConstantInt::get(Type::Int64Ty, OffsetInBits), Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
ConstantInt::get(Type::Int32Ty, Flags), Ctxt.getConstantInt(Type::Int32Ty, Flags),
getCastToEmpty(DerivedFrom) getCastToEmpty(DerivedFrom)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -681,23 +695,24 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
DIType DerivedFrom, DIType DerivedFrom,
DIArray Elements, DIArray Elements,
unsigned RuntimeLang) { unsigned RuntimeLang) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(Tag), GetTagConstant(Tag),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber), Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits), Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits), Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
ConstantInt::get(Type::Int64Ty, OffsetInBits), Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
ConstantInt::get(Type::Int32Ty, Flags), Ctxt.getConstantInt(Type::Int32Ty, Flags),
getCastToEmpty(DerivedFrom), getCastToEmpty(DerivedFrom),
getCastToEmpty(Elements), getCastToEmpty(Elements),
ConstantInt::get(Type::Int32Ty, RuntimeLang) Ctxt.getConstantInt(Type::Int32Ty, RuntimeLang)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.composite.type", Init->getType()); M.addTypeName("llvm.dbg.composite.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -720,21 +735,23 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
bool isLocalToUnit, bool isLocalToUnit,
bool isDefinition) { bool isDefinition) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_subprogram), GetTagConstant(dwarf::DW_TAG_subprogram),
Constant::getNullValue(EmptyStructPtr), Ctxt.getNullValue(EmptyStructPtr),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
GetStringConstant(DisplayName), GetStringConstant(DisplayName),
GetStringConstant(LinkageName), GetStringConstant(LinkageName),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo), Ctxt.getConstantInt(Type::Int32Ty, LineNo),
getCastToEmpty(Type), getCastToEmpty(Type),
ConstantInt::get(Type::Int1Ty, isLocalToUnit), Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit),
ConstantInt::get(Type::Int1Ty, isDefinition) Ctxt.getConstantInt(Type::Int1Ty, isDefinition)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -752,22 +769,25 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
DICompileUnit CompileUnit, DICompileUnit CompileUnit,
unsigned LineNo, DIType Type,bool isLocalToUnit, unsigned LineNo, DIType Type,bool isLocalToUnit,
bool isDefinition, llvm::GlobalVariable *Val) { bool isDefinition, llvm::GlobalVariable *Val) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_variable), GetTagConstant(dwarf::DW_TAG_variable),
Constant::getNullValue(EmptyStructPtr), Ctxt.getNullValue(EmptyStructPtr),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
GetStringConstant(DisplayName), GetStringConstant(DisplayName),
GetStringConstant(LinkageName), GetStringConstant(LinkageName),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo), Ctxt.getConstantInt(Type::Int32Ty, LineNo),
getCastToEmpty(Type), getCastToEmpty(Type),
ConstantInt::get(Type::Int1Ty, isLocalToUnit), Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit),
ConstantInt::get(Type::Int1Ty, isDefinition), Ctxt.getConstantInt(Type::Int1Ty, isDefinition),
ConstantExpr::getBitCast(Val, EmptyStructPtr) Ctxt.getConstantExprBitCast(Val, EmptyStructPtr)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -783,16 +803,19 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
const std::string &Name, const std::string &Name,
DICompileUnit CompileUnit, unsigned LineNo, DICompileUnit CompileUnit, unsigned LineNo,
DIType Type) { DIType Type) {
LLVMContext& Ctxt = M.getContext();
Constant *Elts[] = { Constant *Elts[] = {
GetTagConstant(Tag), GetTagConstant(Tag),
getCastToEmpty(Context), getCastToEmpty(Context),
GetStringConstant(Name), GetStringConstant(Name),
getCastToEmpty(CompileUnit), getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo), Ctxt.getConstantInt(Type::Int32Ty, LineNo),
getCastToEmpty(Type) getCastToEmpty(Type)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.variable.type", Init->getType()); M.addTypeName("llvm.dbg.variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -811,7 +834,8 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
getCastToEmpty(Context) getCastToEmpty(Context)
}; };
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Constant *Init =
M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.block.type", Init->getType()); M.addTypeName("llvm.dbg.block.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true, GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
@ -838,8 +862,8 @@ void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
// Invoke llvm.dbg.stoppoint // Invoke llvm.dbg.stoppoint
Value *Args[] = { Value *Args[] = {
llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), M.getContext().getConstantInt(llvm::Type::Int32Ty, LineNo),
llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), M.getContext().getConstantInt(llvm::Type::Int32Ty, ColNo),
getCastToEmpty(CU) getCastToEmpty(CU)
}; };
CallInst::Create(StopPointFn, Args, Args+3, "", BB); CallInst::Create(StopPointFn, Args, Args+3, "", BB);
@ -942,7 +966,7 @@ namespace llvm {
const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type");
if (!Ty) return 0; if (!Ty) return 0;
Ty = PointerType::get(Ty, 0); Ty = V->getParent()->getContext().getPointerType(Ty, 0);
Value *Val = V->stripPointerCasts(); Value *Val = V->stripPointerCasts();
for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); for (Value::use_iterator I = Val->use_begin(), E = Val->use_end();

View File

@ -15,6 +15,7 @@
#include "llvm/Analysis/LoopVR.h" #include "llvm/Analysis/LoopVR.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
@ -71,8 +72,8 @@ ConstantRange LoopVR::getRange(const SCEV* S, const SCEV* T, ScalarEvolution &SE
ConstantRange X = getRange(Mul->getOperand(0), T, SE); ConstantRange X = getRange(Mul->getOperand(0), T, SE);
if (X.isFullSet()) return FullSet; if (X.isFullSet()) return FullSet;
const IntegerType *Ty = IntegerType::get(X.getBitWidth()); const IntegerType *Ty = Context->getIntegerType(X.getBitWidth());
const IntegerType *ExTy = IntegerType::get(X.getBitWidth() * const IntegerType *ExTy = Context->getIntegerType(X.getBitWidth() *
Mul->getNumOperands()); Mul->getNumOperands());
ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth()); ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth());

View File

@ -65,6 +65,7 @@
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
#include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
@ -3839,8 +3840,12 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
return std::make_pair(CNC, CNC); return std::make_pair(CNC, CNC);
} }
ConstantInt *Solution1 = ConstantInt::get((NegB + SqrtVal).sdiv(TwoA)); LLVMContext *Context = SE.getContext();
ConstantInt *Solution2 = ConstantInt::get((NegB - SqrtVal).sdiv(TwoA));
ConstantInt *Solution1 =
Context->getConstantInt((NegB + SqrtVal).sdiv(TwoA));
ConstantInt *Solution2 =
Context->getConstantInt((NegB - SqrtVal).sdiv(TwoA));
return std::make_pair(SE.getConstant(Solution1), return std::make_pair(SE.getConstant(Solution1),
SE.getConstant(Solution2)); SE.getConstant(Solution2));
@ -3908,7 +3913,7 @@ const SCEV* ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) {
#endif #endif
// Pick the smallest positive root value. // Pick the smallest positive root value.
if (ConstantInt *CB = if (ConstantInt *CB =
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, dyn_cast<ConstantInt>(Context->getConstantExprICmp(ICmpInst::ICMP_ULT,
R1->getValue(), R2->getValue()))) { R1->getValue(), R2->getValue()))) {
if (CB->getZExtValue() == false) if (CB->getZExtValue() == false)
std::swap(R1, R2); // R1 is the minimum root now. std::swap(R1, R2); // R1 is the minimum root now.
@ -4157,7 +4162,7 @@ const SCEV* ScalarEvolution::getBECount(const SCEV* Start,
// Check Add for unsigned overflow. // Check Add for unsigned overflow.
// TODO: More sophisticated things could be done here. // TODO: More sophisticated things could be done here.
const Type *WideTy = IntegerType::get(getTypeSizeInBits(Ty) + 1); const Type *WideTy = Context->getIntegerType(getTypeSizeInBits(Ty) + 1);
const SCEV* OperandExtendedAdd = const SCEV* OperandExtendedAdd =
getAddExpr(getZeroExtendExpr(Diff, WideTy), getAddExpr(getZeroExtendExpr(Diff, WideTy),
getZeroExtendExpr(RoundUp, WideTy)); getZeroExtendExpr(RoundUp, WideTy));
@ -4313,7 +4318,7 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// The exit value should be (End+A)/A. // The exit value should be (End+A)/A.
APInt ExitVal = (End + A).udiv(A); APInt ExitVal = (End + A).udiv(A);
ConstantInt *ExitValue = ConstantInt::get(ExitVal); ConstantInt *ExitValue = SE.getContext()->getConstantInt(ExitVal);
// Evaluate at the exit value. If we really did fall out of the valid // Evaluate at the exit value. If we really did fall out of the valid
// range, then we computed our trip count, otherwise wrap around or other // range, then we computed our trip count, otherwise wrap around or other
@ -4325,7 +4330,7 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// Ensure that the previous value is in the range. This is a sanity check. // Ensure that the previous value is in the range. This is a sanity check.
assert(Range.contains( assert(Range.contains(
EvaluateConstantChrecAtConstant(this, EvaluateConstantChrecAtConstant(this,
ConstantInt::get(ExitVal - One), SE)->getValue()) && SE.getContext()->getConstantInt(ExitVal - One), SE)->getValue()) &&
"Linear scev computation is off in a bad way!"); "Linear scev computation is off in a bad way!");
return SE.getConstant(ExitValue); return SE.getConstant(ExitValue);
} else if (isQuadratic()) { } else if (isQuadratic()) {
@ -4345,7 +4350,8 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
if (R1) { if (R1) {
// Pick the smallest positive root value. // Pick the smallest positive root value.
if (ConstantInt *CB = if (ConstantInt *CB =
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, dyn_cast<ConstantInt>(
SE.getContext()->getConstantExprICmp(ICmpInst::ICMP_ULT,
R1->getValue(), R2->getValue()))) { R1->getValue(), R2->getValue()))) {
if (CB->getZExtValue() == false) if (CB->getZExtValue() == false)
std::swap(R1, R2); // R1 is the minimum root now. std::swap(R1, R2); // R1 is the minimum root now.
@ -4358,7 +4364,8 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
SE); SE);
if (Range.contains(R1Val->getValue())) { if (Range.contains(R1Val->getValue())) {
// The next iteration must be out of the range... // The next iteration must be out of the range...
ConstantInt *NextVal = ConstantInt::get(R1->getValue()->getValue()+1); ConstantInt *NextVal =
SE.getContext()->getConstantInt(R1->getValue()->getValue()+1);
R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
if (!Range.contains(R1Val->getValue())) if (!Range.contains(R1Val->getValue()))
@ -4368,7 +4375,8 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// If R1 was not in the range, then it is a good return value. Make // If R1 was not in the range, then it is a good return value. Make
// sure that R1-1 WAS in the range though, just in case. // sure that R1-1 WAS in the range though, just in case.
ConstantInt *NextVal = ConstantInt::get(R1->getValue()->getValue()-1); ConstantInt *NextVal =
SE.getContext()->getConstantInt(R1->getValue()->getValue()-1);
R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
if (Range.contains(R1Val->getValue())) if (Range.contains(R1Val->getValue()))
return R1; return R1;

View File

@ -15,6 +15,7 @@
#include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/LLVMContext.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
using namespace llvm; using namespace llvm;
@ -54,7 +55,7 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, const Type *Ty) {
// FIXME: keep track of the cast instruction. // FIXME: keep track of the cast instruction.
if (Constant *C = dyn_cast<Constant>(V)) if (Constant *C = dyn_cast<Constant>(V))
return ConstantExpr::getCast(Op, C, Ty); return getContext()->getConstantExprCast(Op, C, Ty);
if (Argument *A = dyn_cast<Argument>(V)) { if (Argument *A = dyn_cast<Argument>(V)) {
// Check to see if there is already a cast! // Check to see if there is already a cast!
@ -125,7 +126,7 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
// Fold a binop with constant operands. // Fold a binop with constant operands.
if (Constant *CLHS = dyn_cast<Constant>(LHS)) if (Constant *CLHS = dyn_cast<Constant>(LHS))
if (Constant *CRHS = dyn_cast<Constant>(RHS)) if (Constant *CRHS = dyn_cast<Constant>(RHS))
return ConstantExpr::get(Opcode, CLHS, CRHS); return getContext()->getConstantExpr(Opcode, CLHS, CRHS);
// Do a quick scan to see if we have this binop nearby. If so, reuse it. // Do a quick scan to see if we have this binop nearby. If so, reuse it.
unsigned ScanLimit = 6; unsigned ScanLimit = 6;
@ -166,7 +167,7 @@ static bool FactorOutConstant(const SCEV* &S,
// For a Constant, check for a multiple of the given factor. // For a Constant, check for a multiple of the given factor.
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) { if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) {
ConstantInt *CI = ConstantInt *CI =
ConstantInt::get(C->getValue()->getValue().sdiv(Factor)); SE.getContext()->getConstantInt(C->getValue()->getValue().sdiv(Factor));
// If the quotient is zero and the remainder is non-zero, reject // If the quotient is zero and the remainder is non-zero, reject
// the value at this scale. It will be considered for subsequent // the value at this scale. It will be considered for subsequent
// smaller scales. // smaller scales.
@ -286,7 +287,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin,
Ops = NewOps; Ops = NewOps;
AnyNonZeroIndices |= !ScaledOps.empty(); AnyNonZeroIndices |= !ScaledOps.empty();
Value *Scaled = ScaledOps.empty() ? Value *Scaled = ScaledOps.empty() ?
Constant::getNullValue(Ty) : getContext()->getNullValue(Ty) :
expandCodeFor(SE.getAddExpr(ScaledOps), Ty); expandCodeFor(SE.getAddExpr(ScaledOps), Ty);
GepIndices.push_back(Scaled); GepIndices.push_back(Scaled);
@ -299,7 +300,8 @@ Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin,
uint64_t FullOffset = C->getValue()->getZExtValue(); uint64_t FullOffset = C->getValue()->getZExtValue();
if (FullOffset < SL.getSizeInBytes()) { if (FullOffset < SL.getSizeInBytes()) {
unsigned ElIdx = SL.getElementContainingOffset(FullOffset); unsigned ElIdx = SL.getElementContainingOffset(FullOffset);
GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx)); GepIndices.push_back(
getContext()->getConstantInt(Type::Int32Ty, ElIdx));
ElTy = STy->getTypeAtIndex(ElIdx); ElTy = STy->getTypeAtIndex(ElIdx);
Ops[0] = Ops[0] =
SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx)); SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx));
@ -328,7 +330,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin,
// Fold a GEP with constant operands. // Fold a GEP with constant operands.
if (Constant *CLHS = dyn_cast<Constant>(V)) if (Constant *CLHS = dyn_cast<Constant>(V))
if (Constant *CRHS = dyn_cast<Constant>(Idx)) if (Constant *CRHS = dyn_cast<Constant>(Idx))
return ConstantExpr::getGetElementPtr(CLHS, &CRHS, 1); return getContext()->getConstantExprGetElementPtr(CLHS, &CRHS, 1);
// Do a quick scan to see if we have this GEP nearby. If so, reuse it. // Do a quick scan to see if we have this GEP nearby. If so, reuse it.
unsigned ScanLimit = 6; unsigned ScanLimit = 6;
@ -400,7 +402,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) {
// -1 * ... ---> 0 - ... // -1 * ... ---> 0 - ...
if (FirstOp == 1) if (FirstOp == 1)
V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V); V = InsertBinop(Instruction::Sub, getContext()->getNullValue(Ty), V);
return V; return V;
} }
@ -412,7 +414,7 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) {
const APInt &RHS = SC->getValue()->getValue(); const APInt &RHS = SC->getValue()->getValue();
if (RHS.isPowerOf2()) if (RHS.isPowerOf2())
return InsertBinop(Instruction::LShr, LHS, return InsertBinop(Instruction::LShr, LHS,
ConstantInt::get(Ty, RHS.logBase2())); getContext()->getConstantInt(Ty, RHS.logBase2()));
} }
Value *RHS = expandCodeFor(S->getRHS(), Ty); Value *RHS = expandCodeFor(S->getRHS(), Ty);
@ -522,7 +524,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
BasicBlock *Preheader = L->getLoopPreheader(); BasicBlock *Preheader = L->getLoopPreheader();
PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin()); PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
InsertedValues.insert(PN); InsertedValues.insert(PN);
PN->addIncoming(Constant::getNullValue(Ty), Preheader); PN->addIncoming(getContext()->getNullValue(Ty), Preheader);
pred_iterator HPI = pred_begin(Header); pred_iterator HPI = pred_begin(Header);
assert(HPI != pred_end(Header) && "Loop with zero preds???"); assert(HPI != pred_end(Header) && "Loop with zero preds???");
@ -532,7 +534,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
// Insert a unit add instruction right before the terminator corresponding // Insert a unit add instruction right before the terminator corresponding
// to the back-edge. // to the back-edge.
Constant *One = ConstantInt::get(Ty, 1); Constant *One = getContext()->getConstantInt(Ty, 1);
Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next", Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
(*HPI)->getTerminator()); (*HPI)->getTerminator());
InsertedValues.insert(Add); InsertedValues.insert(Add);

View File

@ -17,6 +17,7 @@
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
using namespace llvm; using namespace llvm;
@ -153,7 +154,7 @@ void SparseSolver::getFeasibleSuccessors(TerminatorInst &TI,
} }
// Constant condition variables mean the branch can only go a single way // Constant condition variables mean the branch can only go a single way
Succs[C == ConstantInt::getFalse()] = true; Succs[C == Context->getConstantIntFalse()] = true;
return; return;
} }

View File

@ -17,6 +17,7 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
@ -834,6 +835,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType, Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
SmallVector<unsigned, 10> &Idxs, SmallVector<unsigned, 10> &Idxs,
unsigned IdxSkip, unsigned IdxSkip,
LLVMContext* Context,
Instruction *InsertBefore) { Instruction *InsertBefore) {
const llvm::StructType *STy = llvm::dyn_cast<llvm::StructType>(IndexedType); const llvm::StructType *STy = llvm::dyn_cast<llvm::StructType>(IndexedType);
if (STy) { if (STy) {
@ -845,7 +847,7 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
Idxs.push_back(i); Idxs.push_back(i);
Value *PrevTo = To; Value *PrevTo = To;
To = BuildSubAggregate(From, To, STy->getElementType(i), Idxs, IdxSkip, To = BuildSubAggregate(From, To, STy->getElementType(i), Idxs, IdxSkip,
InsertBefore); Context, InsertBefore);
Idxs.pop_back(); Idxs.pop_back();
if (!To) { if (!To) {
// Couldn't find any inserted value for this index? Cleanup // Couldn't find any inserted value for this index? Cleanup
@ -868,7 +870,7 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
// we might be able to find the complete struct somewhere. // we might be able to find the complete struct somewhere.
// Find the value that is at that particular spot // Find the value that is at that particular spot
Value *V = FindInsertedValue(From, Idxs.begin(), Idxs.end()); Value *V = FindInsertedValue(From, Idxs.begin(), Idxs.end(), Context);
if (!V) if (!V)
return NULL; return NULL;
@ -891,16 +893,18 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
// //
// All inserted insertvalue instructions are inserted before InsertBefore // All inserted insertvalue instructions are inserted before InsertBefore
Value *BuildSubAggregate(Value *From, const unsigned *idx_begin, Value *BuildSubAggregate(Value *From, const unsigned *idx_begin,
const unsigned *idx_end, Instruction *InsertBefore) { const unsigned *idx_end, LLVMContext *Context,
Instruction *InsertBefore) {
assert(InsertBefore && "Must have someplace to insert!"); assert(InsertBefore && "Must have someplace to insert!");
const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(), const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(),
idx_begin, idx_begin,
idx_end); idx_end);
Value *To = UndefValue::get(IndexedType); Value *To = Context->getUndef(IndexedType);
SmallVector<unsigned, 10> Idxs(idx_begin, idx_end); SmallVector<unsigned, 10> Idxs(idx_begin, idx_end);
unsigned IdxSkip = Idxs.size(); unsigned IdxSkip = Idxs.size();
return BuildSubAggregate(From, To, IndexedType, Idxs, IdxSkip, InsertBefore); return BuildSubAggregate(From, To, IndexedType, Idxs, IdxSkip,
Context, InsertBefore);
} }
/// FindInsertedValue - Given an aggregrate and an sequence of indices, see if /// FindInsertedValue - Given an aggregrate and an sequence of indices, see if
@ -910,7 +914,8 @@ Value *BuildSubAggregate(Value *From, const unsigned *idx_begin,
/// If InsertBefore is not null, this function will duplicate (modified) /// If InsertBefore is not null, this function will duplicate (modified)
/// insertvalues when a part of a nested struct is extracted. /// insertvalues when a part of a nested struct is extracted.
Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
const unsigned *idx_end, Instruction *InsertBefore) { const unsigned *idx_end, LLVMContext* Context,
Instruction *InsertBefore) {
// Nothing to index? Just return V then (this is useful at the end of our // Nothing to index? Just return V then (this is useful at the end of our
// recursion) // recursion)
if (idx_begin == idx_end) if (idx_begin == idx_end)
@ -923,18 +928,18 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
const CompositeType *PTy = cast<CompositeType>(V->getType()); const CompositeType *PTy = cast<CompositeType>(V->getType());
if (isa<UndefValue>(V)) if (isa<UndefValue>(V))
return UndefValue::get(ExtractValueInst::getIndexedType(PTy, return Context->getUndef(ExtractValueInst::getIndexedType(PTy,
idx_begin, idx_begin,
idx_end)); idx_end));
else if (isa<ConstantAggregateZero>(V)) else if (isa<ConstantAggregateZero>(V))
return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy, return Context->getNullValue(ExtractValueInst::getIndexedType(PTy,
idx_begin, idx_begin,
idx_end)); idx_end));
else if (Constant *C = dyn_cast<Constant>(V)) { else if (Constant *C = dyn_cast<Constant>(V)) {
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) if (isa<ConstantArray>(C) || isa<ConstantStruct>(C))
// Recursively process this constant // Recursively process this constant
return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1, idx_end, return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1,
InsertBefore); idx_end, Context, InsertBefore);
} else if (InsertValueInst *I = dyn_cast<InsertValueInst>(V)) { } else if (InsertValueInst *I = dyn_cast<InsertValueInst>(V)) {
// Loop the indices for the insertvalue instruction in parallel with the // Loop the indices for the insertvalue instruction in parallel with the
// requested indices // requested indices
@ -953,7 +958,8 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
// %C = insertvalue {i32, i32 } %A, i32 11, 1 // %C = insertvalue {i32, i32 } %A, i32 11, 1
// which allows the unused 0,0 element from the nested struct to be // which allows the unused 0,0 element from the nested struct to be
// removed. // removed.
return BuildSubAggregate(V, idx_begin, req_idx, InsertBefore); return BuildSubAggregate(V, idx_begin, req_idx,
Context, InsertBefore);
else else
// We can't handle this without inserting insertvalues // We can't handle this without inserting insertvalues
return 0; return 0;
@ -964,13 +970,13 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
// looking for, then. // looking for, then.
if (*req_idx != *i) if (*req_idx != *i)
return FindInsertedValue(I->getAggregateOperand(), idx_begin, idx_end, return FindInsertedValue(I->getAggregateOperand(), idx_begin, idx_end,
InsertBefore); Context, InsertBefore);
} }
// If we end up here, the indices of the insertvalue match with those // If we end up here, the indices of the insertvalue match with those
// requested (though possibly only partially). Now we recursively look at // requested (though possibly only partially). Now we recursively look at
// the inserted value, passing any remaining indices. // the inserted value, passing any remaining indices.
return FindInsertedValue(I->getInsertedValueOperand(), req_idx, idx_end, return FindInsertedValue(I->getInsertedValueOperand(), req_idx, idx_end,
InsertBefore); Context, InsertBefore);
} else if (ExtractValueInst *I = dyn_cast<ExtractValueInst>(V)) { } else if (ExtractValueInst *I = dyn_cast<ExtractValueInst>(V)) {
// If we're extracting a value from an aggregrate that was extracted from // If we're extracting a value from an aggregrate that was extracted from
// something else, we can extract from that something else directly instead. // something else, we can extract from that something else directly instead.
@ -994,7 +1000,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
&& "Number of indices added not correct?"); && "Number of indices added not correct?");
return FindInsertedValue(I->getAggregateOperand(), Idxs.begin(), Idxs.end(), return FindInsertedValue(I->getAggregateOperand(), Idxs.begin(), Idxs.end(),
InsertBefore); Context, InsertBefore);
} }
// Otherwise, we don't know (such as, extracting from a function return value // Otherwise, we don't know (such as, extracting from a function return value
// or load instruction) // or load instruction)

View File

@ -183,7 +183,7 @@ bool IPCP::PropagateConstantReturn(Function &F) {
if (!STy) if (!STy)
V = RI->getOperand(i); V = RI->getOperand(i);
else else
V = FindInsertedValue(RI->getOperand(0), i); V = FindInsertedValue(RI->getOperand(0), i, Context);
if (V) { if (V) {
// Ignore undefs, we can change them into anything // Ignore undefs, we can change them into anything

View File

@ -642,7 +642,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
It = TrackedMultipleRetVals.find(std::make_pair(F, i)); It = TrackedMultipleRetVals.find(std::make_pair(F, i));
if (It == TrackedMultipleRetVals.end()) break; if (It == TrackedMultipleRetVals.end()) break;
if (Value *Val = FindInsertedValue(I.getOperand(0), i)) if (Value *Val = FindInsertedValue(I.getOperand(0), i, Context))
mergeInValue(It->second, F, getValueState(Val)); mergeInValue(It->second, F, getValueState(Val));
} }
} }