Skip to content

Commit 9bf51b2

Browse files
authored
[ARM] Generate build-attributes more correctly in the presence of intrinsic declarations. (llvm#160749)
This code doesn't work very well, but this makes it work when intrinsic definitions are present. It now discounts functions declarations from the set of attributes it looks at. The code would have worked better before 0ab5b5b when module-level attributes could provide the information used to construct build-attributes.
1 parent 371b3ca commit 9bf51b2

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,20 +610,23 @@ void ARMAsmPrinter::emitEndOfAsmFile(Module &M) {
610610
// to appear in the .ARM.attributes section in ELF.
611611
// Instead of subclassing the MCELFStreamer, we do the work here.
612612

613-
// Returns true if all functions have the same function attribute value.
614-
// It also returns true when the module has no functions.
613+
// Returns true if all function definitions have the same function attribute
614+
// value. It also returns true when the module has no functions.
615615
static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr,
616616
StringRef Value) {
617-
return !any_of(M, [&](const Function &F) {
618-
return F.getFnAttribute(Attr).getValueAsString() != Value;
619-
});
617+
return !any_of(M, [&](const Function &F) {
618+
if (F.isDeclaration())
619+
return false;
620+
return F.getFnAttribute(Attr).getValueAsString() != Value;
621+
});
620622
}
621-
// Returns true if all functions have the same denormal mode.
623+
// Returns true if all functions definitions have the same denormal mode.
622624
// It also returns true when the module has no functions.
623-
static bool checkDenormalAttributeConsistency(const Module &M,
624-
StringRef Attr,
625+
static bool checkDenormalAttributeConsistency(const Module &M, StringRef Attr,
625626
DenormalMode Value) {
626627
return !any_of(M, [&](const Function &F) {
628+
if (F.isDeclaration())
629+
return false;
627630
StringRef AttrVal = F.getFnAttribute(Attr).getValueAsString();
628631
return parseDenormalFPAttribute(AttrVal) != Value;
629632
});

llvm/test/CodeGen/ARM/build-attributes-fn-attr3.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
define i32 @foo() local_unnamed_addr #0 {
1313
entry:
14+
%a = call float @llvm.fma.f32(float 0.0, float 0.0, float 0.0)
1415
ret i32 42
1516
}
1617

18+
declare float @llvm.fma.f32(float, float, float)
19+
1720
attributes #0 = { minsize norecurse nounwind optsize readnone "no-trapping-math"="true" "denormal-fp-math"="ieee"}

llvm/test/CodeGen/ARM/build-attributes-fn-attr4.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
define i32 @foo1() local_unnamed_addr #0 {
1212
entry:
13+
%a = call float @llvm.fma.f32(float 0.0, float 0.0, float 0.0)
1314
ret i32 42
1415
}
1516

17+
declare float @llvm.fma.f32(float, float, float)
18+
1619
attributes #0 = { minsize norecurse nounwind optsize readnone "denormal-fp-math"="positive-zero,positive-zero" }

llvm/test/CodeGen/ARM/build-attributes-fn-attr5.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
define i32 @foo1() local_unnamed_addr #0 {
1212
entry:
13+
%a = call float @llvm.fma.f32(float 0.0, float 0.0, float 0.0)
1314
ret i32 42
1415
}
1516

17+
declare float @llvm.fma.f32(float, float, float)
18+
1619
attributes #0 = { minsize norecurse nounwind optsize readnone "denormal-fp-math"="preserve-sign,preserve-sign"}

llvm/test/CodeGen/ARM/build-attributes-fn-attr6.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
define i32 @foo1() local_unnamed_addr #0 {
1313
entry:
14+
%a = call float @llvm.fma.f32(float 0.0, float 0.0, float 0.0)
1415
ret i32 42
1516
}
1617

@@ -19,5 +20,7 @@ entry:
1920
ret i32 42
2021
}
2122

23+
declare float @llvm.fma.f32(float, float, float)
24+
2225
attributes #0 = { minsize norecurse nounwind optsize readnone "denormal-fp-math"="preserve-sign,preserve-sign"}
2326
attributes #1 = { minsize norecurse nounwind optsize readnone "denormal-fp-math"="positive-zero,positive-zero"}

0 commit comments

Comments
 (0)