mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add an IsBare attribute to SILFunction for functions that do not have an
AST. Swift SVN r11236
This commit is contained in:
@@ -33,6 +33,7 @@ enum class SILLinkage : unsigned char {
|
||||
Deserialized // Deserialized from a module.
|
||||
};
|
||||
|
||||
enum IsBare_t { IsNotBare, IsBare };
|
||||
enum IsTransparent_t { IsNotTransparent, IsTransparent };
|
||||
|
||||
/// SILFunction - A function body that has been lowered to SIL. This consists of
|
||||
@@ -72,6 +73,9 @@ private:
|
||||
/// The source location and scope of the function.
|
||||
SILDebugScope *DebugScope;
|
||||
|
||||
/// The function's bare attribute. Bare means that the function is SIL-only.
|
||||
unsigned Bare : 1;
|
||||
|
||||
/// The function's transparent attribute.
|
||||
unsigned Transparent : 1; // FIXME: pack this somewhere
|
||||
|
||||
@@ -84,6 +88,7 @@ public:
|
||||
SILFunction(SILModule &Module, SILLinkage Linkage,
|
||||
StringRef MangledName, CanSILFunctionType LoweredType,
|
||||
Optional<SILLocation> Loc = Nothing,
|
||||
IsBare_t isBareSILFunction = IsNotBare,
|
||||
IsTransparent_t isTrans = IsNotTransparent,
|
||||
SILFunction *InsertBefore = nullptr,
|
||||
SILDebugScope *DebugScope = nullptr,
|
||||
@@ -150,6 +155,10 @@ public:
|
||||
/// Get the source location of the function.
|
||||
SILDebugScope *getDebugScope() const { return DebugScope; }
|
||||
|
||||
/// Get this function's bare attribute.
|
||||
IsBare_t isBare() const { return IsBare_t(Bare); }
|
||||
void setBare(IsBare_t isB) { Bare = isB; }
|
||||
|
||||
/// Get this function's transparent attribute.
|
||||
IsTransparent_t isTransparent() const { return IsTransparent_t(Transparent); }
|
||||
void setTransparent(IsTransparent_t isT) { Transparent = isT; }
|
||||
|
||||
@@ -260,6 +260,7 @@ public:
|
||||
SILFunction *getOrCreateSharedFunction(SILLocation loc,
|
||||
StringRef name,
|
||||
CanSILFunctionType type,
|
||||
IsBare_t isBareSILFunction,
|
||||
IsTransparent_t isTransparent);
|
||||
|
||||
/// \brief Return the stage of processing this module is at.
|
||||
|
||||
@@ -2411,6 +2411,7 @@ bool Parser::parseDeclSIL() {
|
||||
|
||||
FunctionState.F =
|
||||
FunctionState.getGlobalNameForDefinition(FnName, SILFnType, FnNameLoc);
|
||||
FunctionState.F->setBare(IsBare);
|
||||
FunctionState.F->setTransparent(IsTransparent_t(isTransparent));
|
||||
FunctionState.F->setLinkage(FnLinkage);
|
||||
|
||||
|
||||
@@ -30,13 +30,7 @@ SILArgument::SILArgument(SILType Ty, SILBasicBlock *ParentBB, const ValueDecl *D
|
||||
: ValueBase(ValueKind::SILArgument, Ty), ParentBB(ParentBB), Decl(D) {
|
||||
// Function arguments need to have a decl.
|
||||
assert(
|
||||
// Unless the function is transparent,
|
||||
!ParentBB->getParent()->isTransparent() &&
|
||||
// or an ObjC thunk,
|
||||
ParentBB->getParent()->getAbstractCC() != AbstractCC::ObjCMethod &&
|
||||
// or comes from a SIL file.
|
||||
!ParentBB->getParent()->getLocation().is<SILFileLocation>() &&
|
||||
// Is this the initial basic block in the function?
|
||||
!ParentBB->getParent()->isBare() &&
|
||||
ParentBB->getParent()->size() == 1
|
||||
? D != nullptr
|
||||
: true );
|
||||
|
||||
@@ -18,6 +18,7 @@ using namespace swift;
|
||||
SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage,
|
||||
StringRef Name, CanSILFunctionType LoweredType,
|
||||
Optional<SILLocation> Loc,
|
||||
IsBare_t isBareSILFunction,
|
||||
IsTransparent_t isTrans,
|
||||
SILFunction *InsertBefore,
|
||||
SILDebugScope *DebugScope,
|
||||
@@ -28,6 +29,7 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage,
|
||||
Location(Loc),
|
||||
DeclCtx(DC),
|
||||
DebugScope(DebugScope),
|
||||
Bare(isBareSILFunction),
|
||||
Transparent(isTrans) {
|
||||
if (InsertBefore)
|
||||
Module.functions.insert(SILModule::iterator(InsertBefore), this);
|
||||
|
||||
@@ -53,6 +53,7 @@ SILModule::~SILModule() {
|
||||
SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
|
||||
StringRef name,
|
||||
CanSILFunctionType type,
|
||||
IsBare_t isBareSILFunction,
|
||||
IsTransparent_t isTransparent) {
|
||||
// TODO: use a 'shared' linkage.
|
||||
auto linkage = SILLinkage::Internal;
|
||||
@@ -63,7 +64,7 @@ SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
|
||||
}
|
||||
|
||||
return new (*this) SILFunction(*this, linkage, name, type,
|
||||
loc, isTransparent);
|
||||
loc, isBareSILFunction, isTransparent);
|
||||
}
|
||||
|
||||
ArrayRef<SILType> ValueBase::getTypes() const {
|
||||
|
||||
@@ -62,7 +62,7 @@ SILGenModule::getOrCreateReabstractionThunk(SILLocation loc,
|
||||
}
|
||||
|
||||
return M.getOrCreateSharedFunction(loc, buffer.str(), thunkType,
|
||||
IsTransparent);
|
||||
IsBare, IsTransparent);
|
||||
}
|
||||
|
||||
/// Mangle this entity into the given stream.
|
||||
|
||||
@@ -285,7 +285,8 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant) {
|
||||
IsTransparent_t IsTrans = constant.isTransparent()?
|
||||
IsTransparent : IsNotTransparent;
|
||||
|
||||
auto *F = new (M) SILFunction(M, linkage, "", constantType, Nothing, IsTrans);
|
||||
auto *F = new (M) SILFunction(M, linkage, "", constantType, Nothing,
|
||||
IsNotBare, IsTrans);
|
||||
|
||||
ValueDecl *VD = nullptr;
|
||||
if (constant.hasDecl())
|
||||
@@ -496,8 +497,9 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
|
||||
C);
|
||||
auto initSILType = getLoweredType(initType).castTo<SILFunctionType>();
|
||||
|
||||
auto *f = new (M) SILFunction(M, SILLinkage::Internal, funcName,
|
||||
initSILType, binding, IsNotTransparent);
|
||||
auto *f = new (M)
|
||||
SILFunction(M, SILLinkage::Internal, funcName,
|
||||
initSILType, binding, IsNotBare, IsNotTransparent);
|
||||
f->setDebugScope(new (M) SILDebugScope(RegularLocation(binding->getInit())));
|
||||
f->setLocation(binding);
|
||||
|
||||
@@ -549,6 +551,7 @@ void SILGenModule::emitObjCMethodThunk(FuncDecl *method) {
|
||||
if (hasFunction(thunk))
|
||||
return;
|
||||
SILFunction *f = preEmitFunction(thunk, method, method);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCMethodThunk(thunk);
|
||||
postEmitFunction(thunk, f);
|
||||
}
|
||||
@@ -565,6 +568,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(VarDecl *prop) {
|
||||
RegularLocation ThunkBodyLoc(prop);
|
||||
ThunkBodyLoc.markAutoGenerated();
|
||||
SILFunction *f = preEmitFunction(getter, prop, ThunkBodyLoc);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCPropertyGetter(getter);
|
||||
postEmitFunction(getter, f);
|
||||
|
||||
@@ -577,6 +581,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(VarDecl *prop) {
|
||||
/*isObjC*/ true);
|
||||
|
||||
f = preEmitFunction(setter, prop, ThunkBodyLoc);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCPropertySetter(setter);
|
||||
postEmitFunction(setter, f);
|
||||
}
|
||||
@@ -593,6 +598,7 @@ void SILGenModule::emitObjCSubscriptMethodThunks(SubscriptDecl *subscript) {
|
||||
RegularLocation ThunkBodyLoc(subscript);
|
||||
ThunkBodyLoc.markAutoGenerated();
|
||||
SILFunction *f = preEmitFunction(getter, subscript, ThunkBodyLoc);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCSubscriptGetter(getter);
|
||||
postEmitFunction(getter, f);
|
||||
|
||||
@@ -605,6 +611,7 @@ void SILGenModule::emitObjCSubscriptMethodThunks(SubscriptDecl *subscript) {
|
||||
/*isObjC*/ true);
|
||||
|
||||
f = preEmitFunction(setter, subscript, ThunkBodyLoc);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCSubscriptSetter(setter);
|
||||
postEmitFunction(setter, f);
|
||||
}
|
||||
@@ -619,6 +626,7 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
|
||||
if (hasFunction(thunk))
|
||||
return;
|
||||
SILFunction *f = preEmitFunction(thunk, constructor, constructor);
|
||||
f->setBare(IsBare);
|
||||
SILGenFunction(*this, *f).emitObjCMethodThunk(thunk);
|
||||
postEmitFunction(thunk, f);
|
||||
}
|
||||
|
||||
@@ -1919,6 +1919,7 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
|
||||
auto *f = new (M) SILFunction(M, SILLinkage::External, "",
|
||||
witnessSILType.castTo<SILFunctionType>(),
|
||||
SILLocation(witness.getDecl()),
|
||||
IsNotBare,
|
||||
IsNotTransparent);
|
||||
|
||||
// Mangle the name of the witness thunk.
|
||||
|
||||
@@ -318,7 +318,8 @@ ClosureCloner::initCloned(SILFunction *Orig, IndicesSet &PromotableIndices) {
|
||||
|
||||
// This inserts the new cloned function before the original function.
|
||||
return new (M) SILFunction(M, SILLinkage::Internal, ClonedName, ClonedTy,
|
||||
Orig->getLocation(), IsNotTransparent, Orig,
|
||||
Orig->getLocation(), Orig->isBare(),
|
||||
IsNotTransparent, Orig,
|
||||
Orig->getDebugScope());
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ void swift::performSILLinking(SILModule *M) {
|
||||
}
|
||||
}
|
||||
|
||||
CalleeFunction->setBare(IsBare);
|
||||
|
||||
if (CalleeFunction->empty()) {
|
||||
// Try to find the definition in a serialized module when callee is
|
||||
// currently empty.
|
||||
|
||||
@@ -96,7 +96,8 @@ private:
|
||||
// Create a new empty function.
|
||||
SILFunction *NewF =
|
||||
new (M) SILFunction(M, SILLinkage::Internal, ClonedName, FTy,
|
||||
Orig->getLocation(), Orig->isTransparent(), 0,
|
||||
Orig->getLocation(), Orig->isBare(),
|
||||
Orig->isTransparent(), 0,
|
||||
Orig->getDebugScope(), Orig->getDeclContext());
|
||||
|
||||
return NewF;
|
||||
|
||||
@@ -325,6 +325,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID, SILFunction *InFunc,
|
||||
auto Fn = InFunc;
|
||||
// FIXME: what should we set the linkage to?
|
||||
Fn->setLinkage(SILLinkage::Deserialized);
|
||||
Fn->setBare(IsBare);
|
||||
Fn->setTransparent(IsTransparent_t(Transparent == 1));
|
||||
// FIXME: use the correct SILLocation from module.
|
||||
SourceLoc Loc;
|
||||
|
||||
Reference in New Issue
Block a user