mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 09:31:03 +03:00
Only allocate the module file name once. Fixes #90.
This commit is contained in:
parent
40f724234d
commit
6cb213badf
7 changed files with 29 additions and 57 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
|
|
||||||
#include "mtype.h"
|
#include "mtype.h"
|
||||||
|
#include "module.h"
|
||||||
#include "dsymbol.h"
|
#include "dsymbol.h"
|
||||||
#include "aggregate.h"
|
#include "aggregate.h"
|
||||||
#include "declaration.h"
|
#include "declaration.h"
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
#include "gen/runtime.h"
|
#include "gen/runtime.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
#include "gen/dvalue.h"
|
#include "gen/dvalue.h"
|
||||||
|
#include "ir/irmodule.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -1072,25 +1074,11 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice)
|
||||||
llvm::AttrListPtr palist;
|
llvm::AttrListPtr palist;
|
||||||
|
|
||||||
// file param
|
// file param
|
||||||
// FIXME: every array bounds check creates a global for the filename !!!
|
args.push_back(gIR->dmodule->ir.irModule->fileName);
|
||||||
LLConstant* c = DtoConstString(loc.filename);
|
|
||||||
|
|
||||||
llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
|
|
||||||
if (!alloc)
|
|
||||||
{
|
|
||||||
alloc = DtoAlloca(c->getType(), ".srcfile");
|
|
||||||
gIR->func()->srcfileArg = alloc;
|
|
||||||
}
|
|
||||||
LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
|
|
||||||
DtoStore(c->getOperand(0), ptr);
|
|
||||||
ptr = DtoGEPi(alloc, 0,1, "tmp");
|
|
||||||
DtoStore(c->getOperand(1), ptr);
|
|
||||||
|
|
||||||
args.push_back(alloc);
|
|
||||||
palist = palist.addAttr(1, llvm::Attribute::ByVal);
|
palist = palist.addAttr(1, llvm::Attribute::ByVal);
|
||||||
|
|
||||||
// line param
|
// line param
|
||||||
c = DtoConstUint(loc.linnum);
|
LLConstant* c = DtoConstUint(loc.linnum);
|
||||||
args.push_back(c);
|
args.push_back(c);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
#include "gen/llvmhelpers.h"
|
#include "gen/llvmhelpers.h"
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
#include "gen/functions.h"
|
#include "gen/functions.h"
|
||||||
#include "gen/typeinf.h"
|
#include "gen/typeinf.h"
|
||||||
#include "gen/todebug.h"
|
#include "gen/todebug.h"
|
||||||
|
#include "ir/irmodule.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
@ -110,7 +112,6 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std:
|
||||||
void DtoAssert(Loc* loc, DValue* msg)
|
void DtoAssert(Loc* loc, DValue* msg)
|
||||||
{
|
{
|
||||||
std::vector<LLValue*> args;
|
std::vector<LLValue*> args;
|
||||||
LLConstant* c;
|
|
||||||
|
|
||||||
// func
|
// func
|
||||||
const char* fname = msg ? "_d_assert_msg" : "_d_assert";
|
const char* fname = msg ? "_d_assert_msg" : "_d_assert";
|
||||||
|
@ -120,9 +121,6 @@ void DtoAssert(Loc* loc, DValue* msg)
|
||||||
llvm::AttrListPtr palist;
|
llvm::AttrListPtr palist;
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
|
|
||||||
// FIXME: every assert creates a global for the filename !!!
|
|
||||||
c = DtoConstString(loc->filename);
|
|
||||||
|
|
||||||
// msg param
|
// msg param
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +129,7 @@ void DtoAssert(Loc* loc, DValue* msg)
|
||||||
llvm::AllocaInst* alloc = gIR->func()->msgArg;
|
llvm::AllocaInst* alloc = gIR->func()->msgArg;
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
{
|
{
|
||||||
alloc = DtoAlloca(c->getType(), ".assertmsg");
|
alloc = DtoAlloca(DtoArrayType(LLType::Int8Ty), ".assertmsg");
|
||||||
DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
|
DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
|
||||||
gIR->func()->msgArg = alloc;
|
gIR->func()->msgArg = alloc;
|
||||||
}
|
}
|
||||||
|
@ -145,23 +143,12 @@ void DtoAssert(Loc* loc, DValue* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// file param
|
// file param
|
||||||
llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
|
args.push_back(gIR->dmodule->ir.irModule->fileName);
|
||||||
if (!alloc)
|
|
||||||
{
|
|
||||||
alloc = DtoAlloca(c->getType(), ".srcfile");
|
|
||||||
gIR->func()->srcfileArg = alloc;
|
|
||||||
}
|
|
||||||
LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
|
|
||||||
DtoStore(c->getOperand(0), ptr);
|
|
||||||
ptr = DtoGEPi(alloc, 0,1, "tmp");
|
|
||||||
DtoStore(c->getOperand(1), ptr);
|
|
||||||
|
|
||||||
args.push_back(alloc);
|
|
||||||
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
|
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
|
||||||
|
|
||||||
|
|
||||||
// line param
|
// line param
|
||||||
c = DtoConstUint(loc->linnum);
|
LLConstant* c = DtoConstUint(loc->linnum);
|
||||||
args.push_back(c);
|
args.push_back(c);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "mtype.h"
|
#include "mtype.h"
|
||||||
#include "hdrgen.h"
|
#include "hdrgen.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
#include "gen/dvalue.h"
|
#include "gen/dvalue.h"
|
||||||
|
|
||||||
#include "ir/irfunction.h"
|
#include "ir/irfunction.h"
|
||||||
|
#include "ir/irmodule.h"
|
||||||
#include "ir/irlandingpad.h"
|
#include "ir/irlandingpad.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1270,27 +1272,13 @@ void SwitchErrorStatement::toIR(IRState* p)
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
|
|
||||||
std::vector<LLValue*> args;
|
std::vector<LLValue*> args;
|
||||||
LLConstant* c;
|
|
||||||
|
|
||||||
// file param
|
// file param
|
||||||
// FIXME: every use creates a global for the filename !!!
|
args.push_back(gIR->dmodule->ir.irModule->fileName);
|
||||||
c = DtoConstString(loc.filename);
|
|
||||||
llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
|
|
||||||
if (!alloc)
|
|
||||||
{
|
|
||||||
alloc = DtoAlloca(c->getType(), ".srcfile");
|
|
||||||
gIR->func()->srcfileArg = alloc;
|
|
||||||
}
|
|
||||||
LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
|
|
||||||
DtoStore(c->getOperand(0), ptr);
|
|
||||||
ptr = DtoGEPi(alloc, 0,1, "tmp");
|
|
||||||
DtoStore(c->getOperand(1), ptr);
|
|
||||||
|
|
||||||
args.push_back(alloc);
|
|
||||||
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
|
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
|
||||||
|
|
||||||
// line param
|
// line param
|
||||||
c = DtoConstUint(loc.linnum);
|
LLConstant* c = DtoConstUint(loc.linnum);
|
||||||
args.push_back(c);
|
args.push_back(c);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
|
|
|
@ -628,7 +628,7 @@ LLGlobalVariable* DtoDwarfCompileUnit(Module* m)
|
||||||
|
|
||||||
// we might be generating for an import
|
// we might be generating for an import
|
||||||
if (!m->ir.irModule)
|
if (!m->ir.irModule)
|
||||||
m->ir.irModule = new IrModule(m);
|
m->ir.irModule = new IrModule(m, m->srcfile->toChars());
|
||||||
else if (m->ir.irModule->dwarfCompileUnit)
|
else if (m->ir.irModule->dwarfCompileUnit)
|
||||||
{
|
{
|
||||||
if (m->ir.irModule->dwarfCompileUnit->getParent() == gIR->module)
|
if (m->ir.irModule->dwarfCompileUnit->getParent() == gIR->module)
|
||||||
|
|
|
@ -89,16 +89,17 @@ void Module::genobjfile(int multiobj, char** envp)
|
||||||
IrDsymbol::resetAll();
|
IrDsymbol::resetAll();
|
||||||
IrType::resetAll();
|
IrType::resetAll();
|
||||||
|
|
||||||
// module ir state
|
|
||||||
// might already exist via import, just overwrite...
|
|
||||||
this->ir.irModule = new IrModule(this);
|
|
||||||
|
|
||||||
// name the module
|
// name the module
|
||||||
std::string mname(toChars());
|
std::string mname(toChars());
|
||||||
if (md != 0)
|
if (md != 0)
|
||||||
mname = md->toChars();
|
mname = md->toChars();
|
||||||
ir.module = new llvm::Module(mname);
|
ir.module = new llvm::Module(mname);
|
||||||
|
|
||||||
|
// module ir state
|
||||||
|
// might already exist via import, just overwrite...
|
||||||
|
//FIXME: is there a good reason for overwriting?
|
||||||
|
this->ir.irModule = new IrModule(this, srcfile->toChars());
|
||||||
|
|
||||||
// set target stuff
|
// set target stuff
|
||||||
std::string target_triple(global.params.tt_arch);
|
std::string target_triple(global.params.tt_arch);
|
||||||
target_triple.append(global.params.tt_os);
|
target_triple.append(global.params.tt_os);
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
|
#include "gen/tollvm.h"
|
||||||
|
#include "gen/irstate.h"
|
||||||
#include "ir/irmodule.h"
|
#include "ir/irmodule.h"
|
||||||
|
|
||||||
IrModule::IrModule(Module* module)
|
IrModule::IrModule(Module* module, const char* srcfilename)
|
||||||
{
|
{
|
||||||
M = module;
|
M = module;
|
||||||
|
|
||||||
|
LLConstant* slice = DtoConstString(srcfilename);
|
||||||
|
fileName = new llvm::GlobalVariable(
|
||||||
|
slice->getType(), true, LLGlobalValue::InternalLinkage, slice, ".modulefilename", gIR->module);
|
||||||
|
|
||||||
dwarfCompileUnit = NULL;
|
dwarfCompileUnit = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,13 @@ struct Module;
|
||||||
|
|
||||||
struct IrModule : IrBase
|
struct IrModule : IrBase
|
||||||
{
|
{
|
||||||
IrModule(Module* module);
|
IrModule(Module* module, const char* srcfilename);
|
||||||
virtual ~IrModule();
|
virtual ~IrModule();
|
||||||
|
|
||||||
Module* M;
|
Module* M;
|
||||||
|
|
||||||
LLGlobalVariable* dwarfCompileUnit;
|
LLGlobalVariable* dwarfCompileUnit;
|
||||||
|
LLGlobalVariable* fileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue