SIL: Key functions directly without SILConstant.

Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
This commit is contained in:
Joe Groff
2013-04-23 23:29:04 +00:00
parent 82e84f4ab1
commit bcb49ce450
28 changed files with 548 additions and 468 deletions

View File

@@ -20,12 +20,13 @@
#include "swift/Basic/Range.h"
#include "swift/SIL/SILBase.h"
#include "swift/SIL/SILConstant.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILType.h"
#include "swift/SIL/TypeLowering.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/ilist.h"
#include "llvm/Support/raw_ostream.h"
namespace swift {
@@ -42,6 +43,9 @@ namespace swift {
/// SILFunction and other top-level objects generated when a translation unit is
/// lowered to SIL.
class SILModule : public SILBase {
public:
typedef llvm::ilist<SILFunction> FunctionListType;
private:
friend class SILBasicBlock;
friend class SILFunction;
@@ -52,18 +56,15 @@ private:
/// SILFunction.
ASTContext &Context;
/// The collection of all codegenned Functions in the module.
llvm::MapVector<SILConstant, SILFunction*> functions;
/// The list of Functions in the module.
FunctionListType functions;
/// The collection of global variables used in the module.
llvm::DenseSet<VarDecl*> globals;
/// The top-level SILFunction for the module.
SILFunction *toplevel;
llvm::SetVector<VarDecl*> globals;
// Intentionally marked private so that we need to use 'constructSIL()'
// to construct a SILModule.
SILModule(ASTContext &Context, bool makeToplevel = true);
SILModule(ASTContext &Context);
public:
~SILModule();
@@ -78,39 +79,11 @@ public:
/// createEmptyModule - Create and return an empty SIL module that we can
/// later parse SIL bodies directly into, without converting from an AST.
static SILModule *createEmptyModule(ASTContext &Context) {
return new SILModule(Context, false);
return new SILModule(Context);
}
ASTContext &getContext() const { return Context; }
/// Returns the SILFunction containing top-level code for the module.
SILFunction *getTopLevelFunction() const {
assert(toplevel && "no toplevel");
return toplevel;
}
/// Returns true if a SILFunction was generated from the given declaration.
bool hasFunction(SILConstant decl) const {
return functions.find(decl) != functions.end();
}
/// Returns true if a SILFunction was generated from the given declaration.
bool hasFunction(ValueDecl *decl) const {
return hasFunction(SILConstant(decl));
}
/// Returns a pointer to the SILFunction generated from the given declaration.
SILFunction *getFunction(SILConstant constant) const {
auto found = functions.find(constant);
assert(found != functions.end() && "no SILFunction generated for Decl");
return found->second;
}
/// Returns a pointer to the SILFunction generated from the given declaration.
SILFunction *getFunction(ValueDecl *decl) const {
return getFunction(SILConstant(decl));
}
using global_iterator = decltype(globals)::const_iterator;
using GlobalRange = Range<global_iterator>;
@@ -125,11 +98,13 @@ public:
return globals.end();
}
typedef llvm::MapVector<SILConstant, SILFunction*>::const_iterator iterator;
typedef iterator const_iterator;
typedef FunctionListType::iterator iterator;
typedef FunctionListType::const_iterator const_iterator;
iterator begin() const { return functions.begin(); }
iterator end() const { return functions.end(); }
iterator begin() { return functions.begin(); }
iterator end() { return functions.end(); }
const_iterator begin() const { return functions.begin(); }
const_iterator end() const { return functions.end(); }
/// verify - Run the SIL verifier to make sure that all Functions follow
/// invariants.