Skip to content

Commit 3e2965f

Browse files
committed
IRGen: Omit frame pointers from metadata accessors.
1 parent afceb4e commit 3e2965f

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class SILFunction
198198
/// Whether cross-module references to this function should use weak linking.
199199
unsigned IsWeakLinked : 1;
200200

201-
// Whether the implementation can be dynamically replaced.
201+
/// Whether the implementation can be dynamically replaced.
202202
unsigned IsDynamicReplaceable : 1;
203203

204204
/// If != OptimizationMode::NotSet, the optimization mode specified with an

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ static void emitMetadataCompletionFunction(IRGenModule &IGM,
172172
llvm::Function *f =
173173
IGM.getAddrOfTypeMetadataCompletionFunction(typeDecl, ForDefinition);
174174
f->setAttributes(IGM.constructInitialAttributes());
175+
f->setDoesNotThrow();
176+
IGM.setHasFramePointer(f, false);
175177

176178
IRGenFunction IGF(IGM, f);
177179

@@ -2133,6 +2135,8 @@ namespace {
21332135
llvm::Function *f =
21342136
IGM.getAddrOfTypeMetadataInstantiationFunction(Target, ForDefinition);
21352137
f->setAttributes(IGM.constructInitialAttributes());
2138+
f->setDoesNotThrow();
2139+
IGM.setHasFramePointer(f, false);
21362140

21372141
IRGenFunction IGF(IGM, f);
21382142

lib/IRGen/IRGenModule.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,17 +891,30 @@ bool swift::irgen::shouldRemoveTargetFeature(StringRef feature) {
891891
return feature == "+thumb-mode";
892892
}
893893

894-
/// Construct initial function attributes from options.
895-
void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
896-
OptimizationMode FuncOptMode) {
897-
// Add DisableFPElim.
898-
if (!IRGen.Opts.DisableFPElim) {
899-
Attrs.addAttribute("no-frame-pointer-elim", "false");
900-
} else {
894+
void IRGenModule::setHasFramePointer(llvm::AttrBuilder &Attrs,
895+
bool HasFramePointer) {
896+
if (HasFramePointer) {
901897
Attrs.addAttribute("no-frame-pointer-elim", "true");
902898
Attrs.addAttribute("no-frame-pointer-elim-non-leaf");
899+
} else {
900+
Attrs.addAttribute("no-frame-pointer-elim", "false");
901+
Attrs.removeAttribute("no-frame-pointer-elim-non-leaf");
903902
}
903+
}
904904

905+
void IRGenModule::setHasFramePointer(llvm::Function *F,
906+
bool HasFramePointer) {
907+
llvm::AttrBuilder b;
908+
setHasFramePointer(b, HasFramePointer);
909+
F->addAttributes(llvm::AttributeList::FunctionIndex, b);
910+
}
911+
912+
/// Construct initial function attributes from options.
913+
void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
914+
OptimizationMode FuncOptMode) {
915+
// Add frame pointer attributes.
916+
setHasFramePointer(Attrs, IRGen.Opts.DisableFPElim);
917+
905918
// Add target-cpu and target-features if they are non-null.
906919
auto *Clang = static_cast<ClangImporter *>(Context.getClangModuleLoader());
907920
clang::TargetOptions &ClangOpts = Clang->getTargetInfo().getTargetOpts();

lib/IRGen/IRGenModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ private: \
12021202
void constructInitialFnAttributes(llvm::AttrBuilder &Attrs,
12031203
OptimizationMode FuncOptMode =
12041204
OptimizationMode::NotSet);
1205+
void setHasFramePointer(llvm::AttrBuilder &Attrs, bool HasFP);
1206+
void setHasFramePointer(llvm::Function *F, bool HasFP);
12051207
llvm::AttributeList constructInitialAttributes();
12061208

12071209
void emitProtocolDecl(ProtocolDecl *D);

lib/IRGen/MetadataRequest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,8 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM,
14041404
// overall performance.
14051405
accessor->addAttribute(llvm::AttributeList::FunctionIndex,
14061406
llvm::Attribute::NoInline);
1407+
// Accessor functions don't need frame pointers.
1408+
IGM.setHasFramePointer(accessor, false);
14071409

14081410
// This function is logically 'readnone': the caller does not need
14091411
// to reason about any side effects or stores it might perform.
@@ -1689,6 +1691,7 @@ emitGenericTypeMetadataAccessFunction(IRGenFunction &IGF,
16891691
thunkFn->setCallingConv(IGM.SwiftCC);
16901692
thunkFn->addAttribute(llvm::AttributeList::FunctionIndex,
16911693
llvm::Attribute::NoInline);
1694+
IGM.setHasFramePointer(thunkFn, false);
16921695

16931696
[&IGM, thunkFn]{
16941697
IRGenFunction subIGF(IGM, thunkFn);
@@ -2145,6 +2148,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
21452148
instantiationFn->setDoesNotThrow();
21462149
instantiationFn->addAttribute(llvm::AttributeList::FunctionIndex,
21472150
llvm::Attribute::NoInline);
2151+
IGM.setHasFramePointer(instantiationFn, false);
21482152

21492153
[&IGM, instantiationFn]{
21502154
IRGenFunction subIGF(IGM, instantiationFn);

0 commit comments

Comments
 (0)