Clean up the linkage model and the computation of linkage.

In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
This commit is contained in:
John McCall
2014-01-09 08:58:07 +00:00
parent 622c2f6ce8
commit 5da6defa1f
48 changed files with 1289 additions and 617 deletions

View File

@@ -46,9 +46,8 @@ private:
friend class SILBasicBlock;
friend class SILModule;
/// ModuleAndLinkage - The SIL module that the function belongs to, and
/// the function's linkage.
llvm::PointerIntPair<SILModule*, 2, SILLinkage> ModuleAndLinkage;
/// Module - The SIL module that the function belongs to.
SILModule &Module;
/// The mangled name of the SIL function, which will be propagated
/// to the binary. A pointer into the module's lookup table.
@@ -79,6 +78,9 @@ private:
/// The function's transparent attribute.
unsigned Transparent : 1; // FIXME: pack this somewhere
/// The linkage of the function.
unsigned Linkage : NumSILLinkageBits;
/// This is the number of function_ref instructions using this SILFunction.
friend class FunctionRefInst;
@@ -106,7 +108,7 @@ public:
DeclContext *DC = nullptr);
~SILFunction();
SILModule &getModule() const { return *ModuleAndLinkage.getPointer(); }
SILModule &getModule() const { return Module; }
SILType getLoweredType() const {
return SILType::getPrimitiveObjectType(LoweredType);
@@ -128,10 +130,11 @@ public:
/// True if this is a declaration of a function defined in another module.
bool isExternalDeclaration() const { return BlockList.empty(); }
bool isDefinition() const { return !isExternalDeclaration(); }
/// Get this function's linkage attribute.
SILLinkage getLinkage() const { return ModuleAndLinkage.getInt(); }
void setLinkage(SILLinkage L) { ModuleAndLinkage.setInt(L); }
SILLinkage getLinkage() const { return SILLinkage(Linkage); }
void setLinkage(SILLinkage linkage) { Linkage = unsigned(linkage); }
/// Get the DeclContext of this function. (Debug info only).
DeclContext *getDeclContext() const { return DeclCtx; }