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