forked from OSchip/llvm-project
Finish LLVMContext-ing lib/Analysis. This required pushing LLVMContext's through the ValueTracking API.
llvm-svn: 74873
This commit is contained in:
parent
83b5ccbecf
commit
f1f1743b2e
|
@ -59,6 +59,8 @@ namespace llvm {
|
|||
}
|
||||
|
||||
private:
|
||||
LLVMContext *getContext() const { return SE.getContext(); }
|
||||
|
||||
/// InsertBinop - Insert the specified binary operator, doing a small amount
|
||||
/// of work to avoid inserting an obviously redundant operation.
|
||||
Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS);
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace llvm {
|
|||
class BasicBlock;
|
||||
class Function;
|
||||
class SparseSolver;
|
||||
class LLVMContext;
|
||||
|
||||
template<typename T> class SmallVectorImpl;
|
||||
|
||||
|
@ -113,6 +114,8 @@ class SparseSolver {
|
|||
/// compute transfer functions.
|
||||
AbstractLatticeFunction *LatticeFunc;
|
||||
|
||||
LLVMContext *Context;
|
||||
|
||||
DenseMap<Value*, LatticeVal> ValueState; // The state each value is in.
|
||||
SmallPtrSet<BasicBlock*, 16> BBExecutable; // The bbs that are executable.
|
||||
|
||||
|
@ -128,8 +131,8 @@ class SparseSolver {
|
|||
SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT
|
||||
void operator=(const SparseSolver&); // DO NOT IMPLEMENT
|
||||
public:
|
||||
explicit SparseSolver(AbstractLatticeFunction *Lattice)
|
||||
: LatticeFunc(Lattice) {}
|
||||
explicit SparseSolver(AbstractLatticeFunction *Lattice, LLVMContext* C)
|
||||
: LatticeFunc(Lattice), Context(C) {}
|
||||
~SparseSolver() {
|
||||
delete LatticeFunc;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace llvm {
|
|||
class Instruction;
|
||||
class APInt;
|
||||
class TargetData;
|
||||
class LLVMContext;
|
||||
|
||||
/// ComputeMaskedBits - Determine which of the bits specified in Mask are
|
||||
/// known to be either zero or one and return them in the KnownZero/KnownOne
|
||||
|
@ -64,14 +65,16 @@ namespace llvm {
|
|||
Value *FindInsertedValue(Value *V,
|
||||
const unsigned *idx_begin,
|
||||
const unsigned *idx_end,
|
||||
LLVMContext *Context,
|
||||
Instruction *InsertBefore = 0);
|
||||
|
||||
/// This is a convenience wrapper for finding values indexed by a single index
|
||||
/// only.
|
||||
inline Value *FindInsertedValue(Value *V, const unsigned Idx,
|
||||
LLVMContext *Context,
|
||||
Instruction *InsertBefore = 0) {
|
||||
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
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
|
@ -455,14 +456,15 @@ void DIVariable::dump() const {
|
|||
DIFactory::DIFactory(Module &m)
|
||||
: M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0),
|
||||
DeclareFn(0) {
|
||||
EmptyStructPtr = PointerType::getUnqual(StructType::get());
|
||||
EmptyStructPtr =
|
||||
M.getContext().getPointerTypeUnqual(M.getContext().getStructType());
|
||||
}
|
||||
|
||||
/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
|
||||
/// This is only valid when the descriptor is non-null.
|
||||
Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
|
||||
if (D.isNull()) return Constant::getNullValue(EmptyStructPtr);
|
||||
return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
|
||||
if (D.isNull()) return M.getContext().getNullValue(EmptyStructPtr);
|
||||
return M.getContext().getConstantExprBitCast(D.getGV(), EmptyStructPtr);
|
||||
}
|
||||
|
||||
Constant *DIFactory::GetTagConstant(unsigned TAG) {
|
||||
|
@ -478,21 +480,21 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
|
|||
// Return Constant if previously defined.
|
||||
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 (String.empty())
|
||||
return Slot = ConstantPointerNull::get(DestTy);
|
||||
return Slot = M.getContext().getConstantPointerNull(DestTy);
|
||||
|
||||
// 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.
|
||||
GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
|
||||
GlobalVariable::InternalLinkage,
|
||||
ConstStr, ".str", &M);
|
||||
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) {
|
||||
SmallVector<Constant*, 16> Elts;
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
|
||||
for (unsigned i = 0; i != NumTys; ++i)
|
||||
Elts.push_back(getCastToEmpty(Tys[i]));
|
||||
|
||||
Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
|
||||
Constant *Init = Ctxt.getConstantArray(Ctxt.getArrayType(EmptyStructPtr,
|
||||
Elts.size()),
|
||||
Elts.data(), Elts.size());
|
||||
// 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) {
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_subrange_type),
|
||||
ConstantInt::get(Type::Int64Ty, Lo),
|
||||
ConstantInt::get(Type::Int64Ty, Hi)
|
||||
M.getContext().getConstantInt(Type::Int64Ty, Lo),
|
||||
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.
|
||||
DIDescriptor &Entry = SimpleConstantCache[Init];
|
||||
|
@ -559,20 +564,22 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
|
|||
bool isOptimized,
|
||||
const char *Flags,
|
||||
unsigned RunTimeVer) {
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_compile_unit),
|
||||
Constant::getNullValue(EmptyStructPtr),
|
||||
ConstantInt::get(Type::Int32Ty, LangID),
|
||||
Ctxt.getNullValue(EmptyStructPtr),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LangID),
|
||||
GetStringConstant(Filename),
|
||||
GetStringConstant(Directory),
|
||||
GetStringConstant(Producer),
|
||||
ConstantInt::get(Type::Int1Ty, isMain),
|
||||
ConstantInt::get(Type::Int1Ty, isOptimized),
|
||||
Ctxt.getConstantInt(Type::Int1Ty, isMain),
|
||||
Ctxt.getConstantInt(Type::Int1Ty, isOptimized),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -587,10 +594,11 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
|
|||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_enumerator),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -610,20 +618,23 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
|
|||
uint64_t AlignInBits,
|
||||
uint64_t OffsetInBits, unsigned Flags,
|
||||
unsigned Encoding) {
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_base_type),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
ConstantInt::get(Type::Int32Ty, Encoding)
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, Flags),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -645,20 +656,23 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
|
|||
uint64_t OffsetInBits,
|
||||
unsigned Flags,
|
||||
DIType DerivedFrom) {
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(Tag),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, Flags),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -681,23 +695,24 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
|
|||
DIType DerivedFrom,
|
||||
DIArray Elements,
|
||||
unsigned RuntimeLang) {
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(Tag),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, Flags),
|
||||
getCastToEmpty(DerivedFrom),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -720,21 +735,23 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
|
|||
bool isLocalToUnit,
|
||||
bool isDefinition) {
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_subprogram),
|
||||
Constant::getNullValue(EmptyStructPtr),
|
||||
Ctxt.getNullValue(EmptyStructPtr),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
GetStringConstant(DisplayName),
|
||||
GetStringConstant(LinkageName),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNo),
|
||||
getCastToEmpty(Type),
|
||||
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
|
||||
ConstantInt::get(Type::Int1Ty, isDefinition)
|
||||
Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -752,22 +769,25 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
|
|||
DICompileUnit CompileUnit,
|
||||
unsigned LineNo, DIType Type,bool isLocalToUnit,
|
||||
bool isDefinition, llvm::GlobalVariable *Val) {
|
||||
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_variable),
|
||||
Constant::getNullValue(EmptyStructPtr),
|
||||
Ctxt.getNullValue(EmptyStructPtr),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
GetStringConstant(DisplayName),
|
||||
GetStringConstant(LinkageName),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNo),
|
||||
getCastToEmpty(Type),
|
||||
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
|
||||
ConstantInt::get(Type::Int1Ty, isDefinition),
|
||||
ConstantExpr::getBitCast(Val, EmptyStructPtr)
|
||||
Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit),
|
||||
Ctxt.getConstantInt(Type::Int1Ty, isDefinition),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -783,16 +803,19 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
|||
const std::string &Name,
|
||||
DICompileUnit CompileUnit, unsigned LineNo,
|
||||
DIType Type) {
|
||||
LLVMContext& Ctxt = M.getContext();
|
||||
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(Tag),
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
Ctxt.getConstantInt(Type::Int32Ty, LineNo),
|
||||
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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -811,7 +834,8 @@ DIBlock DIFactory::CreateBlock(DIDescriptor 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());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
|
@ -838,8 +862,8 @@ void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
|
|||
|
||||
// Invoke llvm.dbg.stoppoint
|
||||
Value *Args[] = {
|
||||
llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo),
|
||||
llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo),
|
||||
M.getContext().getConstantInt(llvm::Type::Int32Ty, LineNo),
|
||||
M.getContext().getConstantInt(llvm::Type::Int32Ty, ColNo),
|
||||
getCastToEmpty(CU)
|
||||
};
|
||||
CallInst::Create(StopPointFn, Args, Args+3, "", BB);
|
||||
|
@ -942,7 +966,7 @@ namespace llvm {
|
|||
const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type");
|
||||
if (!Ty) return 0;
|
||||
|
||||
Ty = PointerType::get(Ty, 0);
|
||||
Ty = V->getParent()->getContext().getPointerType(Ty, 0);
|
||||
|
||||
Value *Val = V->stripPointerCasts();
|
||||
for (Value::use_iterator I = Val->use_begin(), E = Val->use_end();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "llvm/Analysis/LoopVR.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
||||
#include "llvm/Assembly/Writer.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);
|
||||
if (X.isFullSet()) return FullSet;
|
||||
|
||||
const IntegerType *Ty = IntegerType::get(X.getBitWidth());
|
||||
const IntegerType *ExTy = IntegerType::get(X.getBitWidth() *
|
||||
const IntegerType *Ty = Context->getIntegerType(X.getBitWidth());
|
||||
const IntegerType *ExTy = Context->getIntegerType(X.getBitWidth() *
|
||||
Mul->getNumOperands());
|
||||
ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth());
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/GlobalVariable.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Analysis/ConstantFolding.h"
|
||||
#include "llvm/Analysis/Dominators.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
|
@ -3839,8 +3840,12 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
|
|||
return std::make_pair(CNC, CNC);
|
||||
}
|
||||
|
||||
ConstantInt *Solution1 = ConstantInt::get((NegB + SqrtVal).sdiv(TwoA));
|
||||
ConstantInt *Solution2 = ConstantInt::get((NegB - SqrtVal).sdiv(TwoA));
|
||||
LLVMContext *Context = SE.getContext();
|
||||
|
||||
ConstantInt *Solution1 =
|
||||
Context->getConstantInt((NegB + SqrtVal).sdiv(TwoA));
|
||||
ConstantInt *Solution2 =
|
||||
Context->getConstantInt((NegB - SqrtVal).sdiv(TwoA));
|
||||
|
||||
return std::make_pair(SE.getConstant(Solution1),
|
||||
SE.getConstant(Solution2));
|
||||
|
@ -3908,7 +3913,7 @@ const SCEV* ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) {
|
|||
#endif
|
||||
// Pick the smallest positive root value.
|
||||
if (ConstantInt *CB =
|
||||
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
|
||||
dyn_cast<ConstantInt>(Context->getConstantExprICmp(ICmpInst::ICMP_ULT,
|
||||
R1->getValue(), R2->getValue()))) {
|
||||
if (CB->getZExtValue() == false)
|
||||
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.
|
||||
// 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 =
|
||||
getAddExpr(getZeroExtendExpr(Diff, WideTy),
|
||||
getZeroExtendExpr(RoundUp, WideTy));
|
||||
|
@ -4313,7 +4318,7 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
|||
|
||||
// The exit value should be (End+A)/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
|
||||
// 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.
|
||||
assert(Range.contains(
|
||||
EvaluateConstantChrecAtConstant(this,
|
||||
ConstantInt::get(ExitVal - One), SE)->getValue()) &&
|
||||
SE.getContext()->getConstantInt(ExitVal - One), SE)->getValue()) &&
|
||||
"Linear scev computation is off in a bad way!");
|
||||
return SE.getConstant(ExitValue);
|
||||
} else if (isQuadratic()) {
|
||||
|
@ -4345,8 +4350,9 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
|||
if (R1) {
|
||||
// Pick the smallest positive root value.
|
||||
if (ConstantInt *CB =
|
||||
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
|
||||
R1->getValue(), R2->getValue()))) {
|
||||
dyn_cast<ConstantInt>(
|
||||
SE.getContext()->getConstantExprICmp(ICmpInst::ICMP_ULT,
|
||||
R1->getValue(), R2->getValue()))) {
|
||||
if (CB->getZExtValue() == false)
|
||||
std::swap(R1, R2); // R1 is the minimum root now.
|
||||
|
||||
|
@ -4358,7 +4364,8 @@ const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
|||
SE);
|
||||
if (Range.contains(R1Val->getValue())) {
|
||||
// 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);
|
||||
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
|
||||
// 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);
|
||||
if (Range.contains(R1Val->getValue()))
|
||||
return R1;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "llvm/Analysis/ScalarEvolutionExpander.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
using namespace llvm;
|
||||
|
@ -54,7 +55,7 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, const Type *Ty) {
|
|||
|
||||
// FIXME: keep track of the cast instruction.
|
||||
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)) {
|
||||
// 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.
|
||||
if (Constant *CLHS = dyn_cast<Constant>(LHS))
|
||||
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.
|
||||
unsigned ScanLimit = 6;
|
||||
|
@ -166,7 +167,7 @@ static bool FactorOutConstant(const SCEV* &S,
|
|||
// For a Constant, check for a multiple of the given factor.
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) {
|
||||
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
|
||||
// the value at this scale. It will be considered for subsequent
|
||||
// smaller scales.
|
||||
|
@ -286,7 +287,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin,
|
|||
Ops = NewOps;
|
||||
AnyNonZeroIndices |= !ScaledOps.empty();
|
||||
Value *Scaled = ScaledOps.empty() ?
|
||||
Constant::getNullValue(Ty) :
|
||||
getContext()->getNullValue(Ty) :
|
||||
expandCodeFor(SE.getAddExpr(ScaledOps), Ty);
|
||||
GepIndices.push_back(Scaled);
|
||||
|
||||
|
@ -299,7 +300,8 @@ Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin,
|
|||
uint64_t FullOffset = C->getValue()->getZExtValue();
|
||||
if (FullOffset < SL.getSizeInBytes()) {
|
||||
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);
|
||||
Ops[0] =
|
||||
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.
|
||||
if (Constant *CLHS = dyn_cast<Constant>(V))
|
||||
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.
|
||||
unsigned ScanLimit = 6;
|
||||
|
@ -400,7 +402,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) {
|
|||
|
||||
// -1 * ... ---> 0 - ...
|
||||
if (FirstOp == 1)
|
||||
V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V);
|
||||
V = InsertBinop(Instruction::Sub, getContext()->getNullValue(Ty), V);
|
||||
return V;
|
||||
}
|
||||
|
||||
|
@ -412,7 +414,7 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) {
|
|||
const APInt &RHS = SC->getValue()->getValue();
|
||||
if (RHS.isPowerOf2())
|
||||
return InsertBinop(Instruction::LShr, LHS,
|
||||
ConstantInt::get(Ty, RHS.logBase2()));
|
||||
getContext()->getConstantInt(Ty, RHS.logBase2()));
|
||||
}
|
||||
|
||||
Value *RHS = expandCodeFor(S->getRHS(), Ty);
|
||||
|
@ -522,7 +524,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
|||
BasicBlock *Preheader = L->getLoopPreheader();
|
||||
PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
|
||||
InsertedValues.insert(PN);
|
||||
PN->addIncoming(Constant::getNullValue(Ty), Preheader);
|
||||
PN->addIncoming(getContext()->getNullValue(Ty), Preheader);
|
||||
|
||||
pred_iterator HPI = pred_begin(Header);
|
||||
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
|
||||
// to the back-edge.
|
||||
Constant *One = ConstantInt::get(Ty, 1);
|
||||
Constant *One = getContext()->getConstantInt(Ty, 1);
|
||||
Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
|
||||
(*HPI)->getTerminator());
|
||||
InsertedValues.insert(Add);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "llvm/Constants.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
using namespace llvm;
|
||||
|
||||
|
@ -153,7 +154,7 @@ void SparseSolver::getFeasibleSuccessors(TerminatorInst &TI,
|
|||
}
|
||||
|
||||
// Constant condition variables mean the branch can only go a single way
|
||||
Succs[C == ConstantInt::getFalse()] = true;
|
||||
Succs[C == Context->getConstantIntFalse()] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "llvm/Instructions.h"
|
||||
#include "llvm/GlobalVariable.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Support/GetElementPtrTypeIterator.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,
|
||||
SmallVector<unsigned, 10> &Idxs,
|
||||
unsigned IdxSkip,
|
||||
LLVMContext* Context,
|
||||
Instruction *InsertBefore) {
|
||||
const llvm::StructType *STy = llvm::dyn_cast<llvm::StructType>(IndexedType);
|
||||
if (STy) {
|
||||
|
@ -845,7 +847,7 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
|
|||
Idxs.push_back(i);
|
||||
Value *PrevTo = To;
|
||||
To = BuildSubAggregate(From, To, STy->getElementType(i), Idxs, IdxSkip,
|
||||
InsertBefore);
|
||||
Context, InsertBefore);
|
||||
Idxs.pop_back();
|
||||
if (!To) {
|
||||
// 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.
|
||||
|
||||
// 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)
|
||||
return NULL;
|
||||
|
@ -891,16 +893,18 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType,
|
|||
//
|
||||
// All inserted insertvalue instructions are inserted before InsertBefore
|
||||
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!");
|
||||
const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(),
|
||||
idx_begin,
|
||||
idx_end);
|
||||
Value *To = UndefValue::get(IndexedType);
|
||||
Value *To = Context->getUndef(IndexedType);
|
||||
SmallVector<unsigned, 10> Idxs(idx_begin, idx_end);
|
||||
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
|
||||
|
@ -910,7 +914,8 @@ Value *BuildSubAggregate(Value *From, const unsigned *idx_begin,
|
|||
/// If InsertBefore is not null, this function will duplicate (modified)
|
||||
/// insertvalues when a part of a nested struct is extracted.
|
||||
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
|
||||
// recursion)
|
||||
if (idx_begin == idx_end)
|
||||
|
@ -921,20 +926,20 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
|
|||
assert(ExtractValueInst::getIndexedType(V->getType(), idx_begin, idx_end)
|
||||
&& "Invalid indices for type?");
|
||||
const CompositeType *PTy = cast<CompositeType>(V->getType());
|
||||
|
||||
|
||||
if (isa<UndefValue>(V))
|
||||
return UndefValue::get(ExtractValueInst::getIndexedType(PTy,
|
||||
return Context->getUndef(ExtractValueInst::getIndexedType(PTy,
|
||||
idx_begin,
|
||||
idx_end));
|
||||
else if (isa<ConstantAggregateZero>(V))
|
||||
return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy,
|
||||
idx_begin,
|
||||
idx_end));
|
||||
return Context->getNullValue(ExtractValueInst::getIndexedType(PTy,
|
||||
idx_begin,
|
||||
idx_end));
|
||||
else if (Constant *C = dyn_cast<Constant>(V)) {
|
||||
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C))
|
||||
// Recursively process this constant
|
||||
return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1, idx_end,
|
||||
InsertBefore);
|
||||
return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1,
|
||||
idx_end, Context, InsertBefore);
|
||||
} else if (InsertValueInst *I = dyn_cast<InsertValueInst>(V)) {
|
||||
// Loop the indices for the insertvalue instruction in parallel with the
|
||||
// requested indices
|
||||
|
@ -953,7 +958,8 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
|
|||
// %C = insertvalue {i32, i32 } %A, i32 11, 1
|
||||
// which allows the unused 0,0 element from the nested struct to be
|
||||
// removed.
|
||||
return BuildSubAggregate(V, idx_begin, req_idx, InsertBefore);
|
||||
return BuildSubAggregate(V, idx_begin, req_idx,
|
||||
Context, InsertBefore);
|
||||
else
|
||||
// We can't handle this without inserting insertvalues
|
||||
return 0;
|
||||
|
@ -964,13 +970,13 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
|
|||
// looking for, then.
|
||||
if (*req_idx != *i)
|
||||
return FindInsertedValue(I->getAggregateOperand(), idx_begin, idx_end,
|
||||
InsertBefore);
|
||||
Context, InsertBefore);
|
||||
}
|
||||
// If we end up here, the indices of the insertvalue match with those
|
||||
// requested (though possibly only partially). Now we recursively look at
|
||||
// the inserted value, passing any remaining indices.
|
||||
return FindInsertedValue(I->getInsertedValueOperand(), req_idx, idx_end,
|
||||
InsertBefore);
|
||||
Context, InsertBefore);
|
||||
} else if (ExtractValueInst *I = dyn_cast<ExtractValueInst>(V)) {
|
||||
// If we're extracting a value from an aggregrate that was extracted from
|
||||
// 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?");
|
||||
|
||||
return FindInsertedValue(I->getAggregateOperand(), Idxs.begin(), Idxs.end(),
|
||||
InsertBefore);
|
||||
Context, InsertBefore);
|
||||
}
|
||||
// Otherwise, we don't know (such as, extracting from a function return value
|
||||
// or load instruction)
|
||||
|
|
|
@ -183,7 +183,7 @@ bool IPCP::PropagateConstantReturn(Function &F) {
|
|||
if (!STy)
|
||||
V = RI->getOperand(i);
|
||||
else
|
||||
V = FindInsertedValue(RI->getOperand(0), i);
|
||||
V = FindInsertedValue(RI->getOperand(0), i, Context);
|
||||
|
||||
if (V) {
|
||||
// Ignore undefs, we can change them into anything
|
||||
|
|
|
@ -642,7 +642,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
|
|||
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
||||
It = TrackedMultipleRetVals.find(std::make_pair(F, i));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue