mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-20 14:29:27 +00:00
Push LLVMContext through GlobalVariables and IRBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74985 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8b8d31e3ec
commit
3d29df3e8a
@ -128,6 +128,7 @@ void BrainF::header(LLVMContext& C) {
|
||||
get("Error: The head has left the tape.", true);
|
||||
|
||||
GlobalVariable *aberrormsg = new GlobalVariable(
|
||||
module->getContext(),
|
||||
msg_0->getType(),
|
||||
true,
|
||||
GlobalValue::InternalLinkage,
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class LLVMContext;
|
||||
class Module;
|
||||
class Constant;
|
||||
template<typename ValueSubClass, typename ItemParentClass>
|
||||
@ -49,13 +50,15 @@ public:
|
||||
}
|
||||
/// GlobalVariable ctor - If a parent module is specified, the global is
|
||||
/// automatically inserted into the end of the specified modules global list.
|
||||
GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
|
||||
GlobalVariable(LLVMContext &Context, const Type *Ty,
|
||||
bool isConstant, LinkageTypes Linkage,
|
||||
Constant *Initializer = 0, const std::string &Name = "",
|
||||
Module *Parent = 0, bool ThreadLocal = false,
|
||||
unsigned AddressSpace = 0);
|
||||
/// GlobalVariable ctor - This creates a global and inserts it before the
|
||||
/// specified other global.
|
||||
GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
|
||||
GlobalVariable(LLVMContext &Context, const Type *Ty,
|
||||
bool isConstant, LinkageTypes Linkage,
|
||||
Constant *Initializer, const std::string &Name,
|
||||
GlobalVariable *InsertBefore, bool ThreadLocal = false,
|
||||
unsigned AddressSpace = 0);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "llvm/GlobalAlias.h"
|
||||
#include "llvm/GlobalVariable.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Support/ConstantFolder.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -42,12 +43,16 @@ template <bool preserveNames=true, typename T = ConstantFolder> class IRBuilder{
|
||||
BasicBlock *BB;
|
||||
BasicBlock::iterator InsertPt;
|
||||
T Folder;
|
||||
LLVMContext& Context;
|
||||
public:
|
||||
IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
|
||||
explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
|
||||
: Folder(F) { SetInsertPoint(TheBB); }
|
||||
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
|
||||
: Folder(F) { SetInsertPoint(TheBB, IP); }
|
||||
IRBuilder(const T& F = T(), LLVMContext &C = getGlobalContext()) :
|
||||
Folder(F), Context(C) { ClearInsertionPoint(); }
|
||||
explicit IRBuilder(BasicBlock *TheBB, const T& F = T(),
|
||||
LLVMContext &C = getGlobalContext()) :
|
||||
Folder(F), Context(C) { SetInsertPoint(TheBB); }
|
||||
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T(),
|
||||
LLVMContext &C = getGlobalContext())
|
||||
: Folder(F), Context(C) { SetInsertPoint(TheBB, IP); }
|
||||
|
||||
/// getFolder - Get the constant folder being used.
|
||||
const T& getFolder() { return Folder; }
|
||||
@ -125,7 +130,7 @@ public:
|
||||
///
|
||||
ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
|
||||
const Type *RetType = BB->getParent()->getReturnType();
|
||||
Value *V = UndefValue::get(RetType);
|
||||
Value *V = Context.getUndef(RetType);
|
||||
for (unsigned i = 0; i != N; ++i)
|
||||
V = CreateInsertValue(V, retVals[i], i, "mrv");
|
||||
return Insert(ReturnInst::Create(V));
|
||||
@ -349,7 +354,7 @@ public:
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
|
||||
}
|
||||
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
|
||||
Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
|
||||
Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0);
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Folder.CreateGetElementPtr(PC, &Idx, 1);
|
||||
@ -359,8 +364,8 @@ public:
|
||||
Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
|
||||
const char *Name = "") {
|
||||
Value *Idxs[] = {
|
||||
ConstantInt::get(Type::Int32Ty, Idx0),
|
||||
ConstantInt::get(Type::Int32Ty, Idx1)
|
||||
Context.getConstantInt(Type::Int32Ty, Idx0),
|
||||
Context.getConstantInt(Type::Int32Ty, Idx1)
|
||||
};
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
@ -369,7 +374,7 @@ public:
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
|
||||
}
|
||||
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
|
||||
Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
|
||||
Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0);
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Folder.CreateGetElementPtr(PC, &Idx, 1);
|
||||
@ -379,8 +384,8 @@ public:
|
||||
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
|
||||
const char *Name = "") {
|
||||
Value *Idxs[] = {
|
||||
ConstantInt::get(Type::Int64Ty, Idx0),
|
||||
ConstantInt::get(Type::Int64Ty, Idx1)
|
||||
Context.getConstantInt(Type::Int64Ty, Idx0),
|
||||
Context.getConstantInt(Type::Int64Ty, Idx1)
|
||||
};
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
@ -392,8 +397,9 @@ public:
|
||||
return CreateConstGEP2_32(Ptr, 0, Idx, Name);
|
||||
}
|
||||
Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
|
||||
Constant *StrConstant = ConstantArray::get(Str, true);
|
||||
GlobalVariable *gv = new GlobalVariable(StrConstant->getType(),
|
||||
Constant *StrConstant = Context.getConstantArray(Str, true);
|
||||
GlobalVariable *gv = new GlobalVariable(Context,
|
||||
StrConstant->getType(),
|
||||
true,
|
||||
GlobalValue::InternalLinkage,
|
||||
StrConstant,
|
||||
@ -405,7 +411,7 @@ public:
|
||||
}
|
||||
Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
|
||||
Value *gv = CreateGlobalString(Str, Name);
|
||||
Value *zero = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Value *zero = Context.getConstantInt(Type::Int32Ty, 0);
|
||||
Value *Args[] = { zero, zero };
|
||||
return CreateGEP(gv, Args, Args+2, Name);
|
||||
}
|
||||
@ -697,13 +703,13 @@ public:
|
||||
|
||||
/// CreateIsNull - Return an i1 value testing if \arg Arg is null.
|
||||
Value *CreateIsNull(Value *Arg, const char *Name = "") {
|
||||
return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
|
||||
return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()),
|
||||
Name);
|
||||
}
|
||||
|
||||
/// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
|
||||
Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
|
||||
return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
|
||||
return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()),
|
||||
Name);
|
||||
}
|
||||
|
||||
@ -718,7 +724,7 @@ public:
|
||||
Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
|
||||
Value *Difference = CreateSub(LHS_int, RHS_int);
|
||||
return CreateSDiv(Difference,
|
||||
ConstantExpr::getSizeOf(ArgType->getElementType()),
|
||||
Context.getConstantExprSizeOf(ArgType->getElementType()),
|
||||
Name);
|
||||
}
|
||||
};
|
||||
|
@ -490,7 +490,7 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
|
||||
Constant *ConstStr = VMContext.getConstantArray(String);
|
||||
|
||||
// Otherwise create and return a new string global.
|
||||
GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
|
||||
GlobalVariable *StrGV = new GlobalVariable(VMContext,ConstStr->getType(), true,
|
||||
GlobalVariable::InternalLinkage,
|
||||
ConstStr, ".str", &M);
|
||||
StrGV->setSection("llvm.metadata");
|
||||
@ -516,7 +516,7 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
|
||||
DIDescriptor &Entry = SimpleConstantCache[Init];
|
||||
if (!Entry.isNull()) return DIArray(Entry.getGV());
|
||||
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.array", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -542,7 +542,7 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
|
||||
|
||||
M.addTypeName("llvm.dbg.subrange.type", Init->getType());
|
||||
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.subrange", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -579,7 +579,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::LinkOnceAnyLinkage,
|
||||
Init, "llvm.dbg.compile_unit", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -598,7 +598,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.enumerator", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -632,7 +632,7 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.basictype.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.basictype", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -668,7 +668,7 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.derivedtype", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -708,7 +708,7 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.composite.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.composite", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -746,7 +746,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::LinkOnceAnyLinkage,
|
||||
Init, "llvm.dbg.subprogram", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -780,7 +780,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::LinkOnceAnyLinkage,
|
||||
Init, "llvm.dbg.global_variable", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -806,7 +806,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.variable.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.variable", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
@ -826,7 +826,7 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
|
||||
sizeof(Elts)/sizeof(Elts[0]));
|
||||
|
||||
M.addTypeName("llvm.dbg.block.type", Init->getType());
|
||||
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "llvm.dbg.block", &M);
|
||||
GV->setSection("llvm.metadata");
|
||||
|
@ -516,7 +516,8 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
|
||||
}
|
||||
|
||||
if (GV == 0) {
|
||||
GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0, Name,
|
||||
GV = new GlobalVariable(Context, Ty, false,
|
||||
GlobalValue::ExternalLinkage, 0, Name,
|
||||
M, false, AddrSpace);
|
||||
} else {
|
||||
if (GV->getType()->getElementType() != Ty)
|
||||
@ -607,7 +608,7 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty,
|
||||
|
||||
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
|
||||
} else {
|
||||
FwdVal = new GlobalVariable(PTy->getElementType(), false,
|
||||
FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
|
||||
GlobalValue::ExternalWeakLinkage, 0, Name, M);
|
||||
}
|
||||
|
||||
@ -651,7 +652,7 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) {
|
||||
}
|
||||
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
|
||||
} else {
|
||||
FwdVal = new GlobalVariable(PTy->getElementType(), false,
|
||||
FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
|
||||
GlobalValue::ExternalWeakLinkage, 0, "", M);
|
||||
}
|
||||
|
||||
|
@ -1258,7 +1258,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
|
||||
isThreadLocal = Record[7];
|
||||
|
||||
GlobalVariable *NewGV =
|
||||
new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule,
|
||||
new GlobalVariable(Context, Ty, isConstant, Linkage, 0, "", TheModule,
|
||||
isThreadLocal, AddressSpace);
|
||||
NewGV->setAlignment(Alignment);
|
||||
if (!Section.empty())
|
||||
|
@ -229,7 +229,7 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
|
||||
// to be a ModulePass (which means it cannot be in the 'llc' pipeline
|
||||
// (which uses a FunctionPassManager (which segfaults (not asserts) if
|
||||
// provided a ModulePass))).
|
||||
Constant *GV = new GlobalVariable(FrameMap->getType(), true,
|
||||
Constant *GV = new GlobalVariable(*F.getContext(), FrameMap->getType(), true,
|
||||
GlobalVariable::InternalLinkage,
|
||||
FrameMap, "__gc_" + F.getName(),
|
||||
F.getParent());
|
||||
@ -292,7 +292,7 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
|
||||
if (!Head) {
|
||||
// If the root chain does not exist, insert a new one with linkonce
|
||||
// linkage!
|
||||
Head = new GlobalVariable(StackEntryPtrTy, false,
|
||||
Head = new GlobalVariable(M.getContext(), StackEntryPtrTy, false,
|
||||
GlobalValue::LinkOnceAnyLinkage,
|
||||
Constant::getNullValue(StackEntryPtrTy),
|
||||
"llvm_gc_root_chain", &M);
|
||||
|
@ -573,7 +573,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
|
||||
// symbol over in the dest module... the initializer will be filled in
|
||||
// later by LinkGlobalInits.
|
||||
GlobalVariable *NewDGV =
|
||||
new GlobalVariable(SGV->getType()->getElementType(),
|
||||
new GlobalVariable(Context, SGV->getType()->getElementType(),
|
||||
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
|
||||
SGV->getName(), Dest, false,
|
||||
SGV->getType()->getAddressSpace());
|
||||
@ -606,7 +606,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
|
||||
// AppendingVars map. The name is cleared out so that no linkage is
|
||||
// performed.
|
||||
GlobalVariable *NewDGV =
|
||||
new GlobalVariable(SGV->getType()->getElementType(),
|
||||
new GlobalVariable(Context, SGV->getType()->getElementType(),
|
||||
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
|
||||
"", Dest, false,
|
||||
SGV->getType()->getAddressSpace());
|
||||
@ -634,8 +634,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
|
||||
// we are replacing may be a function (if a prototype, weak, etc) or a
|
||||
// global variable.
|
||||
GlobalVariable *NewDGV =
|
||||
new GlobalVariable(SGV->getType()->getElementType(), SGV->isConstant(),
|
||||
NewLinkage, /*init*/0, DGV->getName(), Dest, false,
|
||||
new GlobalVariable(Context, SGV->getType()->getElementType(),
|
||||
SGV->isConstant(), NewLinkage, /*init*/0,
|
||||
DGV->getName(), Dest, false,
|
||||
SGV->getType()->getAddressSpace());
|
||||
|
||||
// Propagate alignment, section, and visibility info.
|
||||
@ -1156,7 +1157,7 @@ static bool LinkAppendingVars(Module *M,
|
||||
|
||||
// Create the new global variable...
|
||||
GlobalVariable *NG =
|
||||
new GlobalVariable(NewType, G1->isConstant(), G1->getLinkage(),
|
||||
new GlobalVariable(Context, NewType, G1->isConstant(), G1->getLinkage(),
|
||||
/*init*/0, First->first, M, G1->isThreadLocal(),
|
||||
G1->getType()->getAddressSpace());
|
||||
|
||||
|
@ -108,7 +108,7 @@ namespace {
|
||||
}
|
||||
ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
|
||||
Constant *Init = Context->getConstantArray(AT, AUGs);
|
||||
GlobalValue *gv = new GlobalVariable(AT, false,
|
||||
GlobalValue *gv = new GlobalVariable(M.getContext(), AT, false,
|
||||
GlobalValue::AppendingLinkage,
|
||||
Init, "llvm.used", &M);
|
||||
gv->setSection("llvm.metadata");
|
||||
|
@ -490,12 +490,13 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
|
||||
Context->getConstantInt(Type::Int32Ty, i),
|
||||
Context);
|
||||
assert(In && "Couldn't get element of initializer?");
|
||||
GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false,
|
||||
GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(i),
|
||||
false,
|
||||
GlobalVariable::InternalLinkage,
|
||||
In, GV->getName()+"."+utostr(i),
|
||||
(Module *)NULL,
|
||||
GV->isThreadLocal(),
|
||||
GV->getType()->getAddressSpace());
|
||||
GV->getType()->getAddressSpace());
|
||||
Globals.insert(GV, NGV);
|
||||
NewGlobals.push_back(NGV);
|
||||
|
||||
@ -526,7 +527,8 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
|
||||
Context);
|
||||
assert(In && "Couldn't get element of initializer?");
|
||||
|
||||
GlobalVariable *NGV = new GlobalVariable(STy->getElementType(), false,
|
||||
GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(),
|
||||
false,
|
||||
GlobalVariable::InternalLinkage,
|
||||
In, GV->getName()+"."+utostr(i),
|
||||
(Module *)NULL,
|
||||
@ -841,7 +843,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
|
||||
// Create the new global variable. The contents of the malloc'd memory is
|
||||
// undefined, so initialize with an undef value.
|
||||
Constant *Init = Context->getUndef(MI->getAllocatedType());
|
||||
GlobalVariable *NewGV = new GlobalVariable(MI->getAllocatedType(), false,
|
||||
GlobalVariable *NewGV = new GlobalVariable(*Context, MI->getAllocatedType(),
|
||||
false,
|
||||
GlobalValue::InternalLinkage, Init,
|
||||
GV->getName()+".body",
|
||||
(Module *)NULL,
|
||||
@ -862,7 +865,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
|
||||
// If there is a comparison against null, we will insert a global bool to
|
||||
// keep track of whether the global was initialized yet or not.
|
||||
GlobalVariable *InitBool =
|
||||
new GlobalVariable(Type::Int1Ty, false, GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(*Context, Type::Int1Ty, false,
|
||||
GlobalValue::InternalLinkage,
|
||||
Context->getConstantIntFalse(), GV->getName()+".init",
|
||||
(Module *)NULL, GV->isThreadLocal());
|
||||
bool InitBoolUsed = false;
|
||||
@ -1282,7 +1286,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
|
||||
const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy);
|
||||
|
||||
GlobalVariable *NGV =
|
||||
new GlobalVariable(PFieldTy, false, GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(*Context, PFieldTy, false,
|
||||
GlobalValue::InternalLinkage,
|
||||
Context->getNullValue(PFieldTy),
|
||||
GV->getName() + ".f" + utostr(FieldNo), GV,
|
||||
GV->isThreadLocal());
|
||||
@ -1579,7 +1584,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
|
||||
DOUT << " *** SHRINKING TO BOOL: " << *GV;
|
||||
|
||||
// Create the new global, initializing it to false.
|
||||
GlobalVariable *NewGV = new GlobalVariable(Type::Int1Ty, false,
|
||||
GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
|
||||
GlobalValue::InternalLinkage, Context->getConstantIntFalse(),
|
||||
GV->getName()+".b",
|
||||
(Module *)NULL,
|
||||
@ -1974,7 +1979,8 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
|
||||
}
|
||||
|
||||
// Create the new global and insert it next to the existing list.
|
||||
GlobalVariable *NGV = new GlobalVariable(CA->getType(), GCL->isConstant(),
|
||||
GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
|
||||
GCL->isConstant(),
|
||||
GCL->getLinkage(), CA, "",
|
||||
(Module *)NULL,
|
||||
GCL->isThreadLocal());
|
||||
@ -2222,7 +2228,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
||||
} else if (AllocaInst *AI = dyn_cast<AllocaInst>(CurInst)) {
|
||||
if (AI->isArrayAllocation()) return false; // Cannot handle array allocs.
|
||||
const Type *Ty = AI->getType()->getElementType();
|
||||
AllocaTmps.push_back(new GlobalVariable(Ty, false,
|
||||
AllocaTmps.push_back(new GlobalVariable(*Context, Ty, false,
|
||||
GlobalValue::InternalLinkage,
|
||||
Context->getUndef(Ty),
|
||||
AI->getName()));
|
||||
|
@ -65,7 +65,7 @@ bool FunctionProfiler::runOnModule(Module &M) {
|
||||
|
||||
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
|
||||
GlobalVariable *Counters =
|
||||
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
|
||||
Context->getNullValue(ATy), "FuncProfCounters", &M);
|
||||
|
||||
// Instrument all of the functions...
|
||||
@ -110,7 +110,7 @@ bool BlockProfiler::runOnModule(Module &M) {
|
||||
|
||||
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
|
||||
GlobalVariable *Counters =
|
||||
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
|
||||
Context->getNullValue(ATy), "BlockProfCounters", &M);
|
||||
|
||||
// Instrument all of the blocks...
|
||||
|
@ -66,7 +66,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
|
||||
|
||||
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
|
||||
GlobalVariable *Counters =
|
||||
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
|
||||
Context->getNullValue(ATy), "EdgeProfCounters", &M);
|
||||
|
||||
// Instrument all of the edges...
|
||||
|
@ -198,7 +198,8 @@ GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
|
||||
uint64_t resetval) : T(t) {
|
||||
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
|
||||
ResetValue = Init;
|
||||
Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
|
||||
Counter = new GlobalVariable(M.getContext(), T, false,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "RandomSteeringCounter", &M);
|
||||
}
|
||||
|
||||
@ -237,7 +238,8 @@ GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
|
||||
: AI(0), T(t) {
|
||||
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
|
||||
ResetValue = Init;
|
||||
Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
|
||||
Counter = new GlobalVariable(M.getContext(), T, false,
|
||||
GlobalValue::InternalLinkage,
|
||||
Init, "RandomSteeringCounter", &M);
|
||||
}
|
||||
|
||||
|
@ -1290,7 +1290,8 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
|
||||
// pass to be run after this pass, to merge duplicate strings.
|
||||
FormatStr.erase(FormatStr.end()-1);
|
||||
Constant *C = Context->getConstantArray(FormatStr, true);
|
||||
C = new GlobalVariable(C->getType(), true,GlobalVariable::InternalLinkage,
|
||||
C = new GlobalVariable(*Context, C->getType(),
|
||||
true, GlobalVariable::InternalLinkage,
|
||||
C, "str", Callee->getParent());
|
||||
EmitPutS(C, B);
|
||||
return CI->use_empty() ? (Value*)CI :
|
||||
|
@ -56,7 +56,8 @@ Module *llvm::CloneModule(const Module *M,
|
||||
//
|
||||
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
|
||||
I != E; ++I) {
|
||||
GlobalVariable *GV = new GlobalVariable(I->getType()->getElementType(),
|
||||
GlobalVariable *GV = new GlobalVariable(M->getContext(),
|
||||
I->getType()->getElementType(),
|
||||
false,
|
||||
GlobalValue::ExternalLinkage, 0,
|
||||
I->getName(), New);
|
||||
|
@ -139,7 +139,8 @@ bool LowerInvoke::doInitialization(Module &M) {
|
||||
// Now that we've done that, insert the jmpbuf list head global, unless it
|
||||
// already exists.
|
||||
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
|
||||
JBListHead = new GlobalVariable(PtrJBList, false,
|
||||
JBListHead = new GlobalVariable(M.getContext(),
|
||||
PtrJBList, false,
|
||||
GlobalValue::LinkOnceAnyLinkage,
|
||||
Context->getNullValue(PtrJBList),
|
||||
"llvm.sjljeh.jblist", &M);
|
||||
@ -182,7 +183,8 @@ void LowerInvoke::createAbortMessage(Module *M) {
|
||||
Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
|
||||
Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", M);
|
||||
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
|
||||
@ -195,7 +197,8 @@ void LowerInvoke::createAbortMessage(Module *M) {
|
||||
"Recompile program with -enable-correct-eh-support.\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
|
||||
Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", M);
|
||||
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
|
||||
|
@ -700,7 +700,8 @@ void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
|
||||
/*--.. Operations on global variables ......................................--*/
|
||||
|
||||
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
|
||||
return wrap(new GlobalVariable(unwrap(Ty), false,
|
||||
LLVMContext &Context = unwrap(M)->getContext();
|
||||
return wrap(new GlobalVariable(Context, unwrap(Ty), false,
|
||||
GlobalValue::ExternalLinkage, 0, Name,
|
||||
unwrap(M)));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "llvm/GlobalVariable.h"
|
||||
#include "llvm/GlobalAlias.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/Support/LeakDetector.h"
|
||||
@ -93,11 +94,13 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
|
||||
// GlobalVariable Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
|
||||
GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
|
||||
bool constant, LinkageTypes Link,
|
||||
Constant *InitVal, const std::string &Name,
|
||||
Module *ParentModule, bool ThreadLocal,
|
||||
unsigned AddressSpace)
|
||||
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
||||
: GlobalValue(Context.getPointerType(Ty, AddressSpace),
|
||||
Value::GlobalVariableVal,
|
||||
OperandTraits<GlobalVariable>::op_begin(this),
|
||||
InitVal != 0, Link, Name),
|
||||
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
|
||||
@ -113,11 +116,13 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
|
||||
ParentModule->getGlobalList().push_back(this);
|
||||
}
|
||||
|
||||
GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
|
||||
GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
|
||||
bool constant, LinkageTypes Link,
|
||||
Constant *InitVal, const std::string &Name,
|
||||
GlobalVariable *Before, bool ThreadLocal,
|
||||
unsigned AddressSpace)
|
||||
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
||||
: GlobalValue(Context.getPointerType(Ty, AddressSpace),
|
||||
Value::GlobalVariableVal,
|
||||
OperandTraits<GlobalVariable>::op_begin(this),
|
||||
InitVal != 0, Link, Name),
|
||||
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
|
||||
|
@ -28,17 +28,20 @@ using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Methods to implement the globals and functions lists.
|
||||
// NOTE: It is ok to allocate the globals used for these methods from the
|
||||
// global context, because all we ever do is use them to compare for equality.
|
||||
//
|
||||
|
||||
GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
|
||||
GlobalVariable *Ret = new GlobalVariable(Type::Int32Ty, false,
|
||||
GlobalVariable *Ret = new GlobalVariable(getGlobalContext(),
|
||||
Type::Int32Ty, false,
|
||||
GlobalValue::ExternalLinkage);
|
||||
// This should not be garbage monitored.
|
||||
LeakDetector::removeGarbageObject(Ret);
|
||||
return Ret;
|
||||
}
|
||||
GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
|
||||
GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
|
||||
GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
|
||||
GlobalValue::ExternalLinkage);
|
||||
// This should not be garbage monitored.
|
||||
LeakDetector::removeGarbageObject(Ret);
|
||||
@ -270,7 +273,8 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
|
||||
if (GV == 0) {
|
||||
// Nope, add it
|
||||
GlobalVariable *New =
|
||||
new GlobalVariable(Ty, false, GlobalVariable::ExternalLinkage, 0, Name);
|
||||
new GlobalVariable(getContext(), Ty, false,
|
||||
GlobalVariable::ExternalLinkage, 0, Name);
|
||||
GlobalList.push_back(New);
|
||||
return New; // Return the new declaration.
|
||||
}
|
||||
|
@ -236,7 +236,8 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
|
||||
GV->eraseFromParent();
|
||||
if (!M1Tors.empty()) {
|
||||
Constant *M1Init = GetTorInit(M1Tors);
|
||||
new GlobalVariable(M1Init->getType(), false, GlobalValue::AppendingLinkage,
|
||||
new GlobalVariable(M1->getContext(), M1Init->getType(), false,
|
||||
GlobalValue::AppendingLinkage,
|
||||
M1Init, GlobalName, M1);
|
||||
}
|
||||
|
||||
@ -247,7 +248,8 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
|
||||
GV->eraseFromParent();
|
||||
if (!M2Tors.empty()) {
|
||||
Constant *M2Init = GetTorInit(M2Tors);
|
||||
new GlobalVariable(M2Init->getType(), false, GlobalValue::AppendingLinkage,
|
||||
new GlobalVariable(M2->getContext(), M2Init->getType(), false,
|
||||
GlobalValue::AppendingLinkage,
|
||||
M2Init, GlobalName, M2);
|
||||
}
|
||||
}
|
||||
|
@ -703,7 +703,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
|
||||
// 1. Add a string constant with its name to the global file
|
||||
Constant *InitArray = ConstantArray::get(F->getName());
|
||||
GlobalVariable *funcName =
|
||||
new GlobalVariable(InitArray->getType(), true /*isConstant*/,
|
||||
new GlobalVariable(Safe->getContext(),
|
||||
InitArray->getType(), true /*isConstant*/,
|
||||
GlobalValue::InternalLinkage, InitArray,
|
||||
F->getName() + "_name", Safe);
|
||||
|
||||
@ -722,7 +723,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
|
||||
// Create a new global to hold the cached function pointer.
|
||||
Constant *NullPtr = ConstantPointerNull::get(F->getType());
|
||||
GlobalVariable *Cache =
|
||||
new GlobalVariable(F->getType(), false,GlobalValue::InternalLinkage,
|
||||
new GlobalVariable(F->getParent()->getContext(),
|
||||
F->getType(), false,GlobalValue::InternalLinkage,
|
||||
NullPtr,F->getName()+".fpcache", F->getParent());
|
||||
|
||||
// Construct a new stub function that will re-route calls to F
|
||||
|
Loading…
x
Reference in New Issue
Block a user