mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00
Reduce size of IrDsymbol even more
resolved/defined/declared/initialized are turned into flags.
This commit is contained in:
parent
18f33b1815
commit
32b1d4cc55
8 changed files with 76 additions and 64 deletions
|
@ -34,8 +34,8 @@
|
|||
|
||||
void DtoResolveClass(ClassDeclaration* cd)
|
||||
{
|
||||
if (cd->ir.resolved) return;
|
||||
cd->ir.resolved = true;
|
||||
if (cd->ir.isResolved()) return;
|
||||
cd->ir.setResolved();
|
||||
|
||||
IF_LOG Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
|
|
@ -55,8 +55,8 @@ public:
|
|||
IF_LOG Logger::println("InterfaceDeclaration::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (decl->type->ty == Terror)
|
||||
{ error(decl->loc, "had semantic errors when compiling");
|
||||
|
@ -92,9 +92,8 @@ public:
|
|||
IF_LOG Logger::println("StructDeclaration::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
IrDsymbol &ir = decl->ir;
|
||||
if (ir.defined) return;
|
||||
ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (decl->type->ty == Terror)
|
||||
{ error(decl->loc, "had semantic errors when compiling");
|
||||
|
@ -135,8 +134,8 @@ public:
|
|||
IF_LOG Logger::println("ClassDeclaration::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (decl->type->ty == Terror)
|
||||
{ error(decl->loc, "had semantic errors when compiling");
|
||||
|
@ -179,8 +178,8 @@ public:
|
|||
IF_LOG Logger::println("TupleDeclaration::codegen(): '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
assert(decl->isexp);
|
||||
assert(decl->objects);
|
||||
|
@ -201,8 +200,8 @@ public:
|
|||
IF_LOG Logger::println("VarDeclaration::codegen(): '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (decl->type->ty == Terror)
|
||||
{ error(decl->loc, "had semantic errors when compiling");
|
||||
|
@ -288,8 +287,8 @@ public:
|
|||
IF_LOG Logger::println("TypedefDeclaration::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (decl->type->ty == Terror)
|
||||
{ error(decl->loc, "had semantic errors when compiling");
|
||||
|
@ -327,8 +326,8 @@ public:
|
|||
IF_LOG Logger::println("TemplateInstance::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (!decl->errors && decl->members)
|
||||
{
|
||||
|
@ -347,8 +346,8 @@ public:
|
|||
IF_LOG Logger::println("TemplateInstance::codegen: '%s'", decl->toPrettyChars());
|
||||
LOG_SCOPE
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
if (!decl->errors && decl->members)
|
||||
{
|
||||
|
|
|
@ -514,8 +514,8 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
|||
return; // ignore declaration completely
|
||||
}
|
||||
|
||||
if (fdecl->ir.resolved) return;
|
||||
fdecl->ir.resolved = true;
|
||||
if (fdecl->ir.isResolved()) return;
|
||||
fdecl->ir.setResolved();
|
||||
|
||||
Type *type = fdecl->type;
|
||||
// If errors occurred compiling it, such as bugzilla 6118
|
||||
|
@ -536,10 +536,10 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
|||
{
|
||||
Logger::println("magic va_arg found");
|
||||
fdecl->llvmInternal = LLVMva_arg;
|
||||
fdecl->ir.resolved = true;
|
||||
fdecl->ir.declared = true;
|
||||
fdecl->ir.initialized = true;
|
||||
fdecl->ir.defined = true;
|
||||
fdecl->ir.setResolved();
|
||||
fdecl->ir.setDeclared();
|
||||
fdecl->ir.setInitialized();
|
||||
fdecl->ir.setDefined();
|
||||
return; // this gets mapped to an instruction so a declaration makes no sence
|
||||
}
|
||||
else if (tempdecl->llvmInternal == LLVMva_start)
|
||||
|
@ -563,17 +563,17 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
|||
fatal();
|
||||
}
|
||||
fdecl->llvmInternal = LLVMinline_asm;
|
||||
fdecl->ir.resolved = true;
|
||||
fdecl->ir.declared = true;
|
||||
fdecl->ir.initialized = true;
|
||||
fdecl->ir.defined = true;
|
||||
fdecl->ir.setResolved();
|
||||
fdecl->ir.setDeclared();
|
||||
fdecl->ir.setInitialized();
|
||||
fdecl->ir.setDefined();
|
||||
return; // this gets mapped to a special inline asm call, no point in going on.
|
||||
}
|
||||
else if (tempdecl->llvmInternal == LLVMinline_ir)
|
||||
{
|
||||
fdecl->llvmInternal = LLVMinline_ir;
|
||||
fdecl->linkage = LINKc;
|
||||
fdecl->ir.defined = true;
|
||||
fdecl->ir.setDefined();
|
||||
Type* type = fdecl->type;
|
||||
assert(type->ty == Tfunction);
|
||||
static_cast<TypeFunction*>(type)->linkage = LINKc;
|
||||
|
@ -743,8 +743,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
|||
{
|
||||
DtoResolveFunction(fdecl);
|
||||
|
||||
if (fdecl->ir.declared) return;
|
||||
fdecl->ir.declared = true;
|
||||
if (fdecl->ir.isDeclared()) return;
|
||||
fdecl->ir.setDeclared();
|
||||
|
||||
IF_LOG Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
@ -932,21 +932,21 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
IF_LOG Logger::println("DtoDefineFunction(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (fd->ir.defined) return;
|
||||
if (fd->ir.isDefined()) return;
|
||||
|
||||
if ((fd->type && fd->type->ty == Terror) ||
|
||||
(fd->type && fd->type->ty == Tfunction && static_cast<TypeFunction *>(fd->type)->next == NULL) ||
|
||||
(fd->type && fd->type->ty == Tfunction && static_cast<TypeFunction *>(fd->type)->next->ty == Terror))
|
||||
{
|
||||
IF_LOG Logger::println("Ignoring; has error type, no return type or returns error type");
|
||||
fd->ir.defined = true;
|
||||
fd->ir.setDefined();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd->isUnitTestDeclaration() && !global.params.useUnitTests)
|
||||
{
|
||||
IF_LOG Logger::println("No code generation for unit test declaration %s", fd->toChars());
|
||||
fd->ir.defined = true;
|
||||
fd->ir.setDefined();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -957,7 +957,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
* Try to reproduce those errors, and then fail.
|
||||
*/
|
||||
error(fd->loc, "errors compiling function %s", fd->toPrettyChars());
|
||||
fd->ir.defined = true;
|
||||
fd->ir.setDefined();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -969,17 +969,17 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
if (!fd->needsCodegen())
|
||||
{
|
||||
IF_LOG Logger::println("No code generation for %s", fd->toChars());
|
||||
fd->ir.defined = true;
|
||||
fd->ir.setDefined();
|
||||
return;
|
||||
}
|
||||
|
||||
DtoDeclareFunction(fd);
|
||||
assert(fd->ir.declared);
|
||||
assert(fd->ir.isDeclared());
|
||||
|
||||
// DtoResolveFunction might also set the defined flag for functions we
|
||||
// should not touch.
|
||||
if (fd->ir.defined) return;
|
||||
fd->ir.defined = true;
|
||||
if (fd->ir.isDefined()) return;
|
||||
fd->ir.setDefined();
|
||||
|
||||
// We cannot emit nested functions with parents that have not gone through
|
||||
// semantic analysis. This can happen as DMD leaks some template instances
|
||||
|
|
|
@ -1028,9 +1028,9 @@ void DtoResolveVariable(VarDeclaration* vd)
|
|||
#endif
|
||||
|
||||
// don't duplicate work
|
||||
if (vd->ir.resolved) return;
|
||||
vd->ir.resolved = true;
|
||||
vd->ir.declared = true;
|
||||
if (vd->ir.isResolved()) return;
|
||||
vd->ir.setResolved();
|
||||
vd->ir.setDeclared();
|
||||
|
||||
getIrGlobal(vd, true);
|
||||
|
||||
|
@ -1043,8 +1043,9 @@ void DtoResolveVariable(VarDeclaration* vd)
|
|||
|
||||
const bool isLLConst = (vd->isConst() || vd->isImmutable()) && vd->init;
|
||||
|
||||
assert(!vd->ir.initialized);
|
||||
vd->ir.initialized = gIR->dmodule;
|
||||
assert(!vd->ir.isInitialized());
|
||||
if (gIR->dmodule)
|
||||
vd->ir.setInitialized();
|
||||
std::string llName(vd->mangle());
|
||||
|
||||
// Since the type of a global must exactly match the type of its
|
||||
|
|
|
@ -36,8 +36,8 @@ void DtoResolveStruct(StructDeclaration* sd)
|
|||
void DtoResolveStruct(StructDeclaration* sd, Loc& callerLoc)
|
||||
{
|
||||
// Make sure to resolve each struct type exactly once.
|
||||
if (sd->ir.resolved) return;
|
||||
sd->ir.resolved = true;
|
||||
if (sd->ir.isResolved()) return;
|
||||
sd->ir.setResolved();
|
||||
|
||||
IF_LOG Logger::println("Resolving struct type: %s (%s)", sd->toChars(), sd->loc.toChars());
|
||||
LOG_SCOPE;
|
||||
|
|
|
@ -320,8 +320,8 @@ static void emitTypeMetadata(TypeInfoDeclaration *tid)
|
|||
|
||||
void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
|
||||
{
|
||||
if (tid->ir.resolved) return;
|
||||
tid->ir.resolved = true;
|
||||
if (tid->ir.isResolved()) return;
|
||||
tid->ir.setResolved();
|
||||
|
||||
// TypeInfo instances (except ClassInfo ones) are always emitted as weak
|
||||
// symbols when they are used.
|
||||
|
@ -333,8 +333,8 @@ void TypeInfoDeclaration_codegen(TypeInfoDeclaration *decl, IRState* p)
|
|||
IF_LOG Logger::println("TypeInfoDeclaration::codegen(%s)", decl->toPrettyChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (decl->ir.defined) return;
|
||||
decl->ir.defined = true;
|
||||
if (decl->ir.isDefined()) return;
|
||||
decl->ir.setDefined();
|
||||
|
||||
std::string mangled(decl->mangle());
|
||||
IF_LOG {
|
||||
|
|
|
@ -32,12 +32,9 @@ IrDsymbol::IrDsymbol() :
|
|||
IrDsymbol::IrDsymbol(const IrDsymbol& s)
|
||||
{
|
||||
list.push_back(this);
|
||||
irData = s.irData;
|
||||
m_type = s.m_type;
|
||||
resolved = s.resolved;
|
||||
declared = s.declared;
|
||||
initialized = s.initialized;
|
||||
defined = s.defined;
|
||||
irData = s.irData;
|
||||
m_type = s.m_type;
|
||||
m_flags = s.m_flags;
|
||||
}
|
||||
|
||||
IrDsymbol::~IrDsymbol()
|
||||
|
@ -55,6 +52,7 @@ IrDsymbol::~IrDsymbol()
|
|||
|
||||
void IrDsymbol::reset()
|
||||
{
|
||||
irData = NULL;
|
||||
resolved = declared = initialized = defined = false;
|
||||
irData = NULL;
|
||||
m_type = NotSet;
|
||||
m_flags = 0;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,14 @@ struct IrDsymbol
|
|||
FieldType
|
||||
};
|
||||
|
||||
enum Flag
|
||||
{
|
||||
Resolved = 0x1,
|
||||
Declared = 0x2,
|
||||
Initialized = 0x4,
|
||||
Defined = 0x8
|
||||
};
|
||||
|
||||
static std::vector<IrDsymbol*> list;
|
||||
static void resetAll();
|
||||
|
||||
|
@ -61,10 +69,15 @@ struct IrDsymbol
|
|||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
bool resolved;
|
||||
bool declared;
|
||||
bool initialized;
|
||||
bool defined;
|
||||
bool isResolved() const { return m_flags & Resolved; }
|
||||
bool isDeclared() const { return m_flags & Declared; }
|
||||
bool isInitialized() const { return m_flags & Initialized; }
|
||||
bool isDefined() const { return m_flags & Defined; }
|
||||
|
||||
void setResolved() { m_flags |= Resolved; }
|
||||
void setDeclared() { m_flags |= Declared; }
|
||||
void setInitialized() { m_flags |= Initialized; }
|
||||
void setDefined() { m_flags |= Defined; }
|
||||
private:
|
||||
friend IrModule* getIrModule(Module *m);
|
||||
friend IrAggr *getIrAggr(AggregateDeclaration *decl, bool create);
|
||||
|
@ -75,7 +88,6 @@ private:
|
|||
friend IrParameter *getIrParameter(VarDeclaration *decl, bool create);
|
||||
friend IrField *getIrField(VarDeclaration *decl, bool create);
|
||||
|
||||
Type m_type;
|
||||
union {
|
||||
void* irData;
|
||||
IrModule* irModule;
|
||||
|
@ -87,6 +99,8 @@ private:
|
|||
IrParameter* irParam;
|
||||
IrField* irField;
|
||||
};
|
||||
Type m_type;
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue