Only allocate the module file name once. Fixes #90.

This commit is contained in:
Christian Kamm 2008-10-12 10:35:16 +02:00
parent 40f724234d
commit 6cb213badf
7 changed files with 29 additions and 57 deletions

View file

@ -1,6 +1,7 @@
#include "gen/llvm.h"
#include "mtype.h"
#include "module.h"
#include "dsymbol.h"
#include "aggregate.h"
#include "declaration.h"
@ -13,6 +14,7 @@
#include "gen/runtime.h"
#include "gen/logger.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;
// file param
// FIXME: every array bounds check creates a global for the 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);
args.push_back(gIR->dmodule->ir.irModule->fileName);
palist = palist.addAttr(1, llvm::Attribute::ByVal);
// line param
c = DtoConstUint(loc.linnum);
LLConstant* c = DtoConstUint(loc.linnum);
args.push_back(c);
// call

View file

@ -6,6 +6,7 @@
#include "id.h"
#include "expression.h"
#include "template.h"
#include "module.h"
#include "gen/tollvm.h"
#include "gen/llvmhelpers.h"
@ -19,6 +20,7 @@
#include "gen/functions.h"
#include "gen/typeinf.h"
#include "gen/todebug.h"
#include "ir/irmodule.h"
#include <stack>
@ -110,7 +112,6 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std:
void DtoAssert(Loc* loc, DValue* msg)
{
std::vector<LLValue*> args;
LLConstant* c;
// func
const char* fname = msg ? "_d_assert_msg" : "_d_assert";
@ -120,9 +121,6 @@ void DtoAssert(Loc* loc, DValue* msg)
llvm::AttrListPtr palist;
int idx = 1;
// FIXME: every assert creates a global for the filename !!!
c = DtoConstString(loc->filename);
// msg param
if (msg)
{
@ -131,7 +129,7 @@ void DtoAssert(Loc* loc, DValue* msg)
llvm::AllocaInst* alloc = gIR->func()->msgArg;
if (!alloc)
{
alloc = DtoAlloca(c->getType(), ".assertmsg");
alloc = DtoAlloca(DtoArrayType(LLType::Int8Ty), ".assertmsg");
DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
gIR->func()->msgArg = alloc;
}
@ -145,23 +143,12 @@ void DtoAssert(Loc* loc, DValue* msg)
}
// file param
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);
args.push_back(gIR->dmodule->ir.irModule->fileName);
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
// line param
c = DtoConstUint(loc->linnum);
LLConstant* c = DtoConstUint(loc->linnum);
args.push_back(c);
// call

View file

@ -16,6 +16,7 @@
#include "mtype.h"
#include "hdrgen.h"
#include "port.h"
#include "module.h"
#include "gen/irstate.h"
#include "gen/logger.h"
@ -27,6 +28,7 @@
#include "gen/dvalue.h"
#include "ir/irfunction.h"
#include "ir/irmodule.h"
#include "ir/irlandingpad.h"
//////////////////////////////////////////////////////////////////////////////
@ -1270,27 +1272,13 @@ void SwitchErrorStatement::toIR(IRState* p)
int idx = 1;
std::vector<LLValue*> args;
LLConstant* c;
// file param
// FIXME: every use creates a global for the 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);
args.push_back(gIR->dmodule->ir.irModule->fileName);
palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
// line param
c = DtoConstUint(loc.linnum);
LLConstant* c = DtoConstUint(loc.linnum);
args.push_back(c);
// call

View file

@ -628,7 +628,7 @@ LLGlobalVariable* DtoDwarfCompileUnit(Module* m)
// we might be generating for an import
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)
{
if (m->ir.irModule->dwarfCompileUnit->getParent() == gIR->module)

View file

@ -89,16 +89,17 @@ void Module::genobjfile(int multiobj, char** envp)
IrDsymbol::resetAll();
IrType::resetAll();
// module ir state
// might already exist via import, just overwrite...
this->ir.irModule = new IrModule(this);
// name the module
std::string mname(toChars());
if (md != 0)
mname = md->toChars();
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
std::string target_triple(global.params.tt_arch);
target_triple.append(global.params.tt_os);

View file

@ -1,9 +1,16 @@
#include "gen/llvm.h"
#include "gen/tollvm.h"
#include "gen/irstate.h"
#include "ir/irmodule.h"
IrModule::IrModule(Module* module)
IrModule::IrModule(Module* module, const char* srcfilename)
{
M = module;
LLConstant* slice = DtoConstString(srcfilename);
fileName = new llvm::GlobalVariable(
slice->getType(), true, LLGlobalValue::InternalLinkage, slice, ".modulefilename", gIR->module);
dwarfCompileUnit = NULL;
}

View file

@ -7,12 +7,13 @@ struct Module;
struct IrModule : IrBase
{
IrModule(Module* module);
IrModule(Module* module, const char* srcfilename);
virtual ~IrModule();
Module* M;
LLGlobalVariable* dwarfCompileUnit;
LLGlobalVariable* fileName;
};
#endif