Skip to content

Commit e94aae0

Browse files
author
Manman Ren
committed
[Function Attribute] add target-cpu and target-features sets if they're non-null.
All llvm::Functions created during IRGen will have target-cpu and target-features attributes if they are non-null. Update testing cases to expect the attribute in function definition. Add testing case function-target-features.swift to verify target-cpu and target-features. rdar://20772331 Swift SVN r28186
1 parent 0453656 commit e94aae0

File tree

80 files changed

+493
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+493
-411
lines changed

lib/IRGen/GenCast.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ static llvm::Function *emitExistentialScalarCastFn(IRGenModule &IGM,
316316
auto fnTy = llvm::FunctionType::get(returnTy, argTys, /*vararg*/ false);
317317
auto fn = llvm::Function::Create(fnTy, llvm::GlobalValue::PrivateLinkage,
318318
llvm::Twine(name), IGM.getModule());
319+
fn->setAttributes(IGM.constructInitialAttributes());
319320

320321
auto IGF = IRGenFunction(IGM, fn);
321322
Explosion args = IGF.collectParameters();

lib/IRGen/GenDecl.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ void IRGenModule::emitRuntimeRegistration() {
550550
llvm::GlobalValue::PrivateLinkage,
551551
"runtime_registration",
552552
getModule());
553+
RegistrationFunction->setAttributes(constructInitialAttributes());
553554

554555
// Insert a call into the entry function.
555556
{
@@ -827,6 +828,7 @@ void IRGenModule::emitVTableStubs() {
827828
stub = llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
828829
llvm::GlobalValue::LinkOnceODRLinkage,
829830
"_swift_dead_method_stub");
831+
stub->setAttributes(constructInitialAttributes());
830832
Module.getFunctionList().push_back(stub);
831833
stub->setVisibility(llvm::GlobalValue::HiddenVisibility);
832834
stub->setCallingConv(RuntimeCC);
@@ -905,6 +907,7 @@ void IRGenModule::emitTypeVerifier() {
905907
llvm::GlobalValue::PrivateLinkage,
906908
"type_verifier",
907909
getModule());
910+
VerifierFunction->setAttributes(constructInitialAttributes());
908911

909912
// Insert a call into the entry function.
910913
{
@@ -1160,8 +1163,13 @@ llvm::Function *LinkInfo::createFunction(IRGenModule &IGM,
11601163
}
11611164
fn->setVisibility(getVisibility());
11621165
fn->setCallingConv(cc);
1163-
if (!attrs.isEmpty())
1164-
fn->setAttributes(attrs);
1166+
1167+
auto initialAttrs = IGM.constructInitialAttributes();
1168+
// Merge initialAttrs with attrs.
1169+
auto updatedAttrs = attrs.addAttributes(IGM.getLLVMContext(),
1170+
llvm::AttributeSet::FunctionIndex, initialAttrs);
1171+
if (!updatedAttrs.isEmpty())
1172+
fn->setAttributes(updatedAttrs);
11651173

11661174
// Everything externally visible is considered used in Swift.
11671175
// That mostly means we need to be good at not marking things external.

lib/IRGen/GenFunc.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,12 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
31943194
llvm::Function *fwd =
31953195
llvm::Function::Create(fwdTy, llvm::Function::InternalLinkage,
31963196
llvm::StringRef(thunkName), &IGM.Module);
3197-
fwd->setAttributes(outAttrs);
3197+
3198+
auto initialAttrs = IGM.constructInitialAttributes();
3199+
// Merge initialAttrs with outAttrs.
3200+
auto updatedAttrs = outAttrs.addAttributes(IGM.getLLVMContext(),
3201+
llvm::AttributeSet::FunctionIndex, initialAttrs);
3202+
fwd->setAttributes(updatedAttrs);
31983203

31993204
IRGenFunction subIGF(IGM, fwd);
32003205
if (IGM.DebugInfo)
@@ -3697,6 +3702,7 @@ static llvm::Function *emitBlockCopyHelper(IRGenModule &IGM,
36973702
auto func = llvm::Function::Create(copyTy, llvm::GlobalValue::InternalLinkage,
36983703
"block_copy_helper",
36993704
IGM.getModule());
3705+
func->setAttributes(IGM.constructInitialAttributes());
37003706
IRGenFunction IGF(IGM, func);
37013707

37023708
// Copy the captures from the source to the destination.
@@ -3731,6 +3737,7 @@ static llvm::Function *emitBlockDisposeHelper(IRGenModule &IGM,
37313737
llvm::GlobalValue::InternalLinkage,
37323738
"block_destroy_helper",
37333739
IGM.getModule());
3740+
func->setAttributes(IGM.constructInitialAttributes());
37343741
IRGenFunction IGF(IGM, func);
37353742

37363743
// Destroy the captures.

lib/IRGen/GenHeap.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ static llvm::Function *createDtorFn(IRGenModule &IGM,
177177
llvm::Function::Create(IGM.DeallocatingDtorTy,
178178
llvm::Function::PrivateLinkage,
179179
"objectdestroy", &IGM.Module);
180+
fn->setAttributes(IGM.constructInitialAttributes());
180181

181182
IRGenFunction IGF(IGM, fn);
182183
if (IGM.DebugInfo)
@@ -220,6 +221,7 @@ llvm::Constant *HeapLayout::createSizeFn(IRGenModule &IGM) const {
220221
llvm::Function::Create(IGM.DeallocatingDtorTy,
221222
llvm::Function::PrivateLinkage,
222223
"objectsize", &IGM.Module);
224+
fn->setAttributes(IGM.constructInitialAttributes());
223225

224226
IRGenFunction IGF(IGM, fn);
225227
if (IGM.DebugInfo)

lib/IRGen/GenMeta.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ namespace {
17881788
llvm::Twine("get_field_types_")
17891789
+ type->getName().str(),
17901790
IGM.getModule());
1791+
fn->setAttributes(IGM.constructInitialAttributes());
17911792

17921793
// Emit the body of the field type accessor later. We need to access
17931794
// the type metadata for the fields, which could lead to infinite recursion
@@ -2279,6 +2280,7 @@ namespace {
22792280
llvm::GlobalValue::PrivateLinkage,
22802281
"create_generic_metadata",
22812282
&IGM.Module);
2283+
f->setAttributes(IGM.constructInitialAttributes());
22822284

22832285
IRGenFunction IGF(IGM, f);
22842286
if (IGM.DebugInfo)

lib/IRGen/GenObjC.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,12 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
754754
llvm::Function *fwd =
755755
llvm::Function::Create(fwdTy, llvm::Function::InternalLinkage,
756756
"_TPAo", &IGM.Module);
757-
fwd->setAttributes(attrs);
757+
758+
auto initialAttrs = IGM.constructInitialAttributes();
759+
// Merge initialAttrs with attrs.
760+
auto updatedAttrs = attrs.addAttributes(IGM.getLLVMContext(),
761+
llvm::AttributeSet::FunctionIndex, initialAttrs);
762+
fwd->setAttributes(updatedAttrs);
758763

759764
IRGenFunction subIGF(IGM, fwd);
760765

lib/IRGen/IRGenModule.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "Linking.h"
4444

4545
#include <initializer_list>
46+
#include <sstream>
4647

4748
using namespace swift;
4849
using namespace irgen;
@@ -452,6 +453,38 @@ llvm::AttributeSet IRGenModule::getAllocAttrs() {
452453
return AllocAttrs;
453454
}
454455

456+
/// Construct initial attributes from options.
457+
llvm::AttributeSet IRGenModule::constructInitialAttributes() {
458+
llvm::AttributeSet attrsUpdated;
459+
// Add DisableFPElim.
460+
if (!Opts.DisableFPElim) {
461+
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
462+
llvm::AttributeSet::FunctionIndex,
463+
"no-frame-pointer-elim", "false");
464+
}
465+
466+
// Add target-cpu and target-features if they are non-null.
467+
auto *Clang = static_cast<ClangImporter *>(Context.getClangModuleLoader());
468+
clang::TargetOptions &ClangOpts = Clang->getTargetInfo().getTargetOpts();
469+
470+
std::string &CPU = ClangOpts.CPU;
471+
if (CPU != "")
472+
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
473+
llvm::AttributeSet::FunctionIndex, "target-cpu", CPU);
474+
475+
std::vector<std::string> &Features = ClangOpts.Features;
476+
if (!Features.empty()) {
477+
std::stringstream S;
478+
std::copy(Features.begin(), Features.end(),
479+
std::ostream_iterator<std::string>(S, ","));
480+
// The drop_back gets rid of the trailing space.
481+
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
482+
llvm::AttributeSet::FunctionIndex, "target-features",
483+
StringRef(S.str()).drop_back(1));
484+
}
485+
return attrsUpdated;
486+
}
487+
455488
llvm::Constant *IRGenModule::getSize(Size size) {
456489
return llvm::ConstantInt::get(SizeTy, size.getValue());
457490
}

lib/IRGen/IRGenModule.h

+2
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ private: \
578578
void addLinkLibrary(const LinkLibrary &linkLib);
579579
void finalize();
580580

581+
llvm::AttributeSet constructInitialAttributes();
582+
581583
void emitProtocolDecl(ProtocolDecl *D);
582584
void emitEnumDecl(EnumDecl *D);
583585
void emitStructDecl(StructDecl *D);

test/ClangModules/objc_ir.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ func almostSubscriptable(#as1: AlmostSubscriptable, #a: A) {
8585
as1.objectForKeyedSubscript(a)
8686
}
8787

88-
// CHECK: define hidden void @_TF7objc_ir13protocolTypesFT1aCSo7NSMince1bPSo9NSRuncing__T_(%CSo7NSMince*, %objc_object*) {
88+
// CHECK: define hidden void @_TF7objc_ir13protocolTypesFT1aCSo7NSMince1bPSo9NSRuncing__T_(%CSo7NSMince*, %objc_object*) {{.*}} {
8989
func protocolTypes(#a: NSMince, #b: NSRuncing) {
9090
// - (void)eatWith:(id <NSRuncing>)runcer;
9191
a.eatWith(b)
9292
// CHECK: [[SEL:%.*]] = load i8*, i8** @"\01L_selector(eatWith:)", align 8
9393
// CHECK: call void bitcast (void ()* @objc_msgSend to void ([[OPAQUE:%.*]]*, i8*, i8*)*)([[OPAQUE:%.*]]* {{%.*}}, i8* [[SEL]], i8* {{%.*}})
9494
}
9595

96-
// CHECK-LABEL: define hidden void @_TF7objc_ir6getsetFT1pPSo8FooProto__T_(%objc_object*) {
96+
// CHECK-LABEL: define hidden void @_TF7objc_ir6getsetFT1pPSo8FooProto__T_(%objc_object*) {{.*}} {
9797
func getset(#p: FooProto) {
9898
// CHECK: load i8*, i8** @"\01L_selector(bar)"
9999
// CHECK: load i8*, i8** @"\01L_selector(setBar:)"
100100
let prop = p.bar
101101
p.bar = prop
102102
}
103103

104-
// CHECK-LABEL: define hidden void @_TF7objc_ir17pointerPropertiesFCSo14PointerWrapperT_(%CSo14PointerWrapper*) {
104+
// CHECK-LABEL: define hidden void @_TF7objc_ir17pointerPropertiesFCSo14PointerWrapperT_(%CSo14PointerWrapper*) {{.*}} {
105105
func pointerProperties(obj: PointerWrapper) {
106106
// CHECK: load i8*, i8** @"\01L_selector(setVoidPtr:)"
107107
// CHECK: load i8*, i8** @"\01L_selector(setIntPtr:)"

test/DebugInfo/initializer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ protocol Named {
77
}
88

99
// initializer.Person.init (initializer.Person.Type)() -> initializer.Person
10-
// CHECK: define hidden %C11initializer6Person* @_TFC11initializer6PersoncfMS0_FT_S0_(%C11initializer6Person*) {
10+
// CHECK: define hidden %C11initializer6Person* @_TFC11initializer6PersoncfMS0_FT_S0_(%C11initializer6Person*) {{.*}} {
1111

1212
// initializer.Person.__allocating_init (initializer.Person.Type)() -> initializer.Person
13-
// CHECK: define hidden %C11initializer6Person* @_TFC11initializer6PersonCfMS0_FT_S0_(%swift.type*) {
13+
// CHECK: define hidden %C11initializer6Person* @_TFC11initializer6PersonCfMS0_FT_S0_(%swift.type*) {{.*}} {
1414
// CHECK: call %C11initializer6Person* @_TFC11initializer6PersoncfMS0_FT_S0_(%C11initializer6Person* %3), !dbg ![[ALLOCATING_INIT:.*]]
1515

1616
// CHECK-DAG: ![[ALLOCATING_INIT]] = !DILocation(line: 0, scope

test/DebugInfo/protocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Point : PointUtils {
2121

2222
}
2323

24-
// CHECK-DAG: define hidden i64 @_TF8protocol4mainFT_VSs5Int64() {
24+
// CHECK-DAG: define hidden i64 @_TF8protocol4mainFT_VSs5Int64() {{.*}} {
2525
func main() -> Int64 {
2626
var pt = Point(_x: 2.5, _y: 4.25)
2727
// CHECK: [[LOC2D:%[a-zA-Z0-9]+]] = alloca %P8protocol10PointUtils_, align {{(4|8)}}

0 commit comments

Comments
 (0)