Adjust LDC to work with the LLVMContext LLVM changes.

This means we now require a fairly new LLVM revision. I use 75234.
This commit is contained in:
Christian Kamm
2009-07-10 21:30:02 +02:00
parent c4c38715ef
commit 756a2cb2a1
18 changed files with 54 additions and 43 deletions

View File

@@ -322,7 +322,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
// for dynamic array we need to make a global with the data, so we have a pointer for the dynamic array
// Important: don't make the gvar constant, since this const initializer might
// be used as an initializer for a static T[] - where modifying contents is allowed.
LLGlobalVariable* gvar = new LLGlobalVariable(constarr->getType(), false, LLGlobalValue::InternalLinkage, constarr, ".constarray", gIR->module);
LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, constarr->getType(), false, LLGlobalValue::InternalLinkage, constarr, ".constarray");
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);

View File

@@ -396,8 +396,8 @@ LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs)
cmpop = llvm::FCmpInst::FCMP_UNE;
// (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im)
LLValue* b1 = new llvm::FCmpInst(cmpop, lhs_re, rhs_re, "tmp", gIR->scopebb());
LLValue* b2 = new llvm::FCmpInst(cmpop, lhs_im, rhs_im, "tmp", gIR->scopebb());
LLValue* b1 = gIR->ir->CreateFCmp(cmpop, lhs_re, rhs_re, "tmp");
LLValue* b2 = gIR->ir->CreateFCmp(cmpop, lhs_im, rhs_im, "tmp");
if (op == TOKequal)
return gIR->ir->CreateAnd(b1,b2,"tmp");

View File

@@ -133,7 +133,7 @@ void VarDeclaration::codegen(Ir* p)
llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this);
std::string _name(mangle());
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,_type,_isconst,_linkage,NULL,_name);
this->ir.irGlobal->value = gvar;
// set the alignment

View File

@@ -22,15 +22,23 @@ TargetABI* gABI = 0;
//////////////////////////////////////////////////////////////////////////////////////////
IRScope::IRScope()
: builder(llvm::getGlobalContext())
{
begin = end = NULL;
}
IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e)
: builder(b)
{
begin = b;
end = e;
builder.SetInsertPoint(b);
}
const IRScope& IRScope::operator=(const IRScope& rhs)
{
begin = rhs.begin;
end = rhs.end;
builder.SetInsertPoint(begin);
}
//////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -48,6 +48,8 @@ struct IRScope
IRScope();
IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e);
const IRScope& operator=(const IRScope& rhs);
};
struct IRBuilderHelper

View File

@@ -355,7 +355,7 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) {
}
bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) {
IRBuilder<> Builder;
IRBuilder<> Builder(llvm::getGlobalContext());
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {

View File

@@ -79,7 +79,7 @@ void RTTIBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* ma
initname.append(".rtti.voidarr.data");
LLGlobalVariable* G = new llvm::GlobalVariable(
CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module);
*gIR->module, CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname);
G->setAlignment(valtype->alignsize());
push_void_array(getTypePaddedSize(CI->getType()), G);
@@ -98,7 +98,7 @@ void RTTIBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, D
initname.append(".data");
LLGlobalVariable* G = new llvm::GlobalVariable(
CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module);
*gIR->module, CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname);
G->setAlignment(valtype->alignsize());
push_array(dim, DtoBitCast(G, DtoType(valtype->pointerTo())));

View File

@@ -116,7 +116,7 @@ llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char*
}
const llvm::PointerType* t = g->getType();
return new llvm::GlobalVariable(t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName(),target);
return new llvm::GlobalVariable(*target, t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName());
}
//////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -818,7 +818,7 @@ void SwitchStatement::toIR(IRState* p)
const LLType* elemTy = DtoType(condition->type);
const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size());
LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits);
llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, ".string_switch_table_data", gIR->module);
llvm::GlobalVariable* arr = new llvm::GlobalVariable(*gIR->module, arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, ".string_switch_table_data");
const LLType* elemPtrTy = getPtrToType(elemTy);
LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
@@ -1380,7 +1380,7 @@ void WithStatement::toIR(IRState* p)
static LLConstant* generate_unique_critical_section()
{
const LLType* Mty = DtoMutexType();
return new llvm::GlobalVariable(Mty, false, llvm::GlobalValue::InternalLinkage, LLConstant::getNullValue(Mty), ".uniqueCS", gIR->module);
return new llvm::GlobalVariable(*gIR->module, Mty, false, llvm::GlobalValue::InternalLinkage, LLConstant::getNullValue(Mty), ".uniqueCS");
}
void SynchronizedStatement::toIR(IRState* p)

View File

@@ -187,7 +187,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args, std::vector<llvm::Attribut
const LLArrayType* typeinfoarraytype = LLArrayType::get(typeinfotype,vtype->getNumElements());
llvm::GlobalVariable* typeinfomem =
new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module);
new llvm::GlobalVariable(*gIR->module, typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage");
if (Logger::enabled())
Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
@@ -208,8 +208,8 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args, std::vector<llvm::Attribut
pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype)));
const LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf());
tiinits = llvm::ConstantStruct::get(pinits);
LLValue* typeinfoarrayparam = new llvm::GlobalVariable(tiarrty,
true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array", gIR->module);
LLValue* typeinfoarrayparam = new llvm::GlobalVariable(*gIR->module, tiarrty,
true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array");
llvm::AttributeWithIndex Attr;
// specify arguments

View File

@@ -38,7 +38,7 @@ static LLGlobalVariable* emitDwarfGlobalDecl(const LLStructType* type, const cha
LLGlobalValue::LinkageTypes linkage = linkonce
? DEBUGINFO_LINKONCE_LINKAGE_TYPE
: LLGlobalValue::InternalLinkage;
LLGlobalVariable* gv = new LLGlobalVariable(type, true, linkage, NULL, name, gIR->module);
LLGlobalVariable* gv = new LLGlobalVariable(*gIR->module, type, true, linkage, NULL, name);
gv->setSection("llvm.metadata");
return gv;
}
@@ -256,7 +256,7 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
elems[1] = DBG_CAST(ptr);
LLConstant* ca = LLConstantArray::get(at, elems);
members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module);
members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
members->setSection("llvm.metadata");
name = DtoConstStringPtr(t->toChars(), "llvm.metadata");
@@ -330,7 +330,7 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
const LLArrayType* at = LLArrayType::get(DBG_TYPE, elems.size());
LLConstant* ca = LLConstantArray::get(at, elems);
members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module);
members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
members->setSection("llvm.metadata");
}

View File

@@ -430,7 +430,7 @@ DValue* StringExp::toElem(IRState* p)
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;
if (Logger::enabled())
Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n';
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,".str",gIR->module);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,at,true,_linkage,_init,".str");
llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false);
LLConstant* idxs[2] = { zero, zero };
@@ -506,7 +506,7 @@ LLConstant* StringExp::toConstElem(IRState* p)
}
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_init->getType(),true,_linkage,_init,".str",gIR->module);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,_init->getType(),true,_linkage,_init,".str");
llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false);
LLConstant* idxs[2] = { zero, zero };
@@ -2385,7 +2385,7 @@ LLConstant* ArrayLiteralExp::toConstElem(IRState* p)
// for dynamic arrays we need to put the initializer in a global, and build a constant dynamic array reference with the .ptr field pointing into this global
// Important: don't make the global constant, since this const initializer might
// be used as an initializer for a static T[] - where modifying contents is allowed.
LLConstant* globalstore = new LLGlobalVariable(arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module);
LLConstant* globalstore = new LLGlobalVariable(*gIR->module, arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage");
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2);

View File

@@ -585,7 +585,7 @@ LLConstant* DtoConstString(const char* str)
std::string s(str?str:"");
LLConstant* init = llvm::ConstantArray::get(s, true);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str", gIR->module);
*gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str");
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
return DtoConstSlice(
DtoConstSize_t(s.length()),
@@ -597,7 +597,7 @@ LLConstant* DtoConstStringPtr(const char* str, const char* section)
std::string s(str);
LLConstant* init = llvm::ConstantArray::get(s, true);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str", gIR->module);
*gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str");
if (section) gvar->setSection(section);
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
return llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);

View File

@@ -172,7 +172,7 @@ llvm::Module* Module::genLLVMModule(Ir* sir)
{
const LLArrayType* usedTy = LLArrayType::get(getVoidPtrType(), ir.usedArray.size());
LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray);
LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module);
LLGlobalVariable* usedArray = new LLGlobalVariable(*ir.module, usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used");
usedArray->setSection("llvm.metadata");
}
@@ -578,12 +578,12 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
std::string thismrefname = "_D";
thismrefname += gIR->dmodule->mangle();
thismrefname += "11__moduleRefZ";
LLGlobalVariable* thismref = new LLGlobalVariable(modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname, gIR->module);
LLGlobalVariable* thismref = new LLGlobalVariable(*gIR->module, modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname);
// make sure _Dmodule_ref is declared
LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref");
if (!mref)
mref = new LLGlobalVariable(getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref", gIR->module);
mref = new LLGlobalVariable(*gIR->module, getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref");
// make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list
llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor);
@@ -680,7 +680,7 @@ void Module::genmoduleinfo()
m_name.append(m->mangle());
m_name.append("8__ModuleZ");
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name);
importInits.push_back(m_gvar);
}
// has import array?
@@ -692,7 +692,7 @@ void Module::genmoduleinfo()
m_name.append(mangle());
m_name.append("9__importsZ");
llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
if (!m_gvar) m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name);
c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType()));
c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
}
@@ -743,7 +743,7 @@ void Module::genmoduleinfo()
m_name.append(mangle());
m_name.append("9__classesZ");
assert(gIR->module->getGlobalVariable(m_name) == NULL);
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(*gIR->module, classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name);
c = DtoGEPi(m_gvar, 0, 0);
c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
}
@@ -811,7 +811,7 @@ void Module::genmoduleinfo()
// it makes no sense that the our own module info already exists!
assert(!gIR->module->getGlobalVariable(MIname));
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module, constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname);
// build the modulereference and ctor for registering it
LLFunction* mictor = build_module_reference_and_ctor(gvar);
@@ -834,5 +834,5 @@ void Module::genmoduleinfo()
std::vector<LLConstant*> appendInits(1, magicinit);
LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits);
std::string appendName("llvm.global_ctors");
llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module);
llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(*gIR->module, appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName);
}

View File

@@ -298,8 +298,8 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
irg->value = gIR->module->getGlobalVariable(mangle);
if (!irg->value)
irg->value = new llvm::GlobalVariable(irg->type.get(), true,
TYPEINFO_LINKAGE_TYPE, NULL, mangle, gIR->module);
irg->value = new llvm::GlobalVariable(*gIR->module, irg->type.get(), true,
TYPEINFO_LINKAGE_TYPE, NULL, mangle);
tid->ir.irGlobal = irg;
@@ -318,8 +318,8 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
// Construct the metadata
llvm::MDNode* metadata = llvm::MDNode::get(mdVals, TD_NumFields);
// Insert it into the module
new llvm::GlobalVariable(metadata->getType(), true,
METADATA_LINKAGE_TYPE, metadata, metaname, gIR->module);
new llvm::GlobalVariable(*gIR->module, metadata->getType(), true,
METADATA_LINKAGE_TYPE, metadata, metaname);
}
#endif

View File

@@ -40,7 +40,7 @@ LLGlobalVariable * IrStruct::getVtblSymbol()
const LLType* vtblTy = type->irtype->isClass()->getVtbl();
vtbl = new llvm::GlobalVariable(
vtblTy, true, _linkage, NULL, initname, gIR->module);
*gIR->module, vtblTy, true, _linkage, NULL, initname);
return vtbl;
}
@@ -69,7 +69,7 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol()
// classinfos cannot be constants since they're used a locks for synchronized
classInfo = new llvm::GlobalVariable(
tc->getPA().get(), false, _linkage, NULL, initname, gIR->module);
*gIR->module, tc->getPA().get(), false, _linkage, NULL, initname);
#ifdef USE_METADATA
// Generate some metadata on this ClassInfo if it's for a class.
@@ -89,8 +89,8 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol()
// Construct the metadata
llvm::MDNode* metadata = llvm::MDNode::get(mdVals, CD_NumFields);
// Insert it into the module
new llvm::GlobalVariable(metadata->getType(), true,
METADATA_LINKAGE_TYPE, metadata, CD_PREFIX + initname, gIR->module);
new llvm::GlobalVariable(*gIR->module, metadata->getType(), true,
METADATA_LINKAGE_TYPE, metadata, CD_PREFIX + initname);
}
#endif
@@ -122,7 +122,8 @@ LLGlobalVariable * IrStruct::getInterfaceArraySymbol()
name.append("16__interfaceInfosZ");
llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl);
classInterfacesArray = new llvm::GlobalVariable(array_type, true, _linkage, NULL, name, classInfo);
classInterfacesArray = new llvm::GlobalVariable(*gIR->module,
array_type, true, _linkage, NULL, name);
return classInterfacesArray;
}
@@ -396,12 +397,12 @@ llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instan
mangle.append("6__vtblZ");
llvm::GlobalVariable* GV = new llvm::GlobalVariable(
*gIR->module,
vtbl_constant->getType(),
true,
_linkage,
vtbl_constant,
mangle,
gIR->module
mangle
);
// insert into the vtbl map

View File

@@ -9,7 +9,7 @@ IrModule::IrModule(Module* module, const char* srcfilename)
LLConstant* slice = DtoConstString(srcfilename);
fileName = new llvm::GlobalVariable(
slice->getType(), true, LLGlobalValue::InternalLinkage, slice, ".modulefilename", gIR->module);
*gIR->module, slice->getType(), true, LLGlobalValue::InternalLinkage, slice, ".modulefilename");
}
IrModule::~IrModule()

View File

@@ -58,7 +58,7 @@ LLGlobalVariable * IrStruct::getInitSymbol()
llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl);
init = new llvm::GlobalVariable(
init_pa.get(), true, _linkage, NULL, initname, gIR->module);
*gIR->module, init_pa.get(), true, _linkage, NULL, initname);
// set alignment
init->setAlignment(type->alignsize());