summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVedant Paranjape <vedant.paranjape@amd.com>2024-02-23 13:47:58 +0530
committerGitHub <noreply@github.com>2024-02-23 13:47:58 +0530
commitee9c02cf74a3e8f83db814363b9e095eb290b083 (patch)
treed39a724d72cc2484e2c79db98f5666605264e8f2
parent531e8c26b3f2626e7f1a997e0e8b61d67d10aded (diff)
Revert "[llvm][AArch64] Autoupgrade function attributes from Module attributeā€¦"upstream/revert-80640-autoupgrade
This reverts commit 531e8c26b3f2626e7f1a997e0e8b61d67d10aded.
-rw-r--r--llvm/include/llvm/IR/AutoUpgrade.h3
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp2
-rw-r--r--llvm/lib/IR/AutoUpgrade.cpp72
-rw-r--r--llvm/lib/Linker/IRMover.cpp4
-rw-r--r--llvm/test/Bitcode/upgrade-arc-runtime-calls.ll4
-rw-r--r--llvm/test/LTO/AArch64/link-branch-target-enforcement.ll1
-rw-r--r--llvm/test/LTO/AArch64/link-sign-return-address.ll43
-rw-r--r--llvm/test/Linker/link-arm-and-thumb.ll7
8 files changed, 8 insertions, 128 deletions
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h
index c0d96efc5475..152f781ffa9b 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -67,8 +67,7 @@ namespace llvm {
void UpgradeSectionAttributes(Module &M);
/// Correct any IR that is relying on old function attribute behavior.
- void UpgradeFunctionAttributes(Function &F,
- bool ModuleMetadataIsMaterialized = false);
+ void UpgradeFunctionAttributes(Function &F);
/// If the given TBAA tag uses the scalar TBAA format, create a new node
/// corresponding to the upgrade to the struct-path aware TBAA format.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 8c860101afa0..832907a3f53f 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -6706,7 +6706,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
}
// Look for functions that rely on old function attribute behavior.
- UpgradeFunctionAttributes(*F, true);
+ UpgradeFunctionAttributes(*F);
// Bring in any functions that this function forward-referenced via
// blockaddresses.
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index edff13c796b3..b90bbe71ac18 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5155,46 +5155,7 @@ struct StrictFPUpgradeVisitor : public InstVisitor<StrictFPUpgradeVisitor> {
};
} // namespace
-// Check if the module attribute is present and not zero.
-static bool isModuleAttributeSet(const Module *M, const StringRef &ModAttr) {
- const auto *Attr =
- mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr));
- return Attr && Attr->getZExtValue();
-}
-
-// Copy an attribute from module to the function if exists.
-// First value of the pair is used when the module attribute is not zero
-// the second otherwise.
-static void
-CopyModuleAttributeToFunction(Function &F, StringRef FnAttrName,
- StringRef ModAttrName,
- std::pair<StringRef, StringRef> Values) {
- if (F.hasFnAttribute(FnAttrName))
- return;
- F.addFnAttr(FnAttrName, isModuleAttributeSet(F.getParent(), ModAttrName)
- ? Values.first
- : Values.second);
-}
-
-// Copy a boolean attribute from module to the function if exists.
-// Module attribute treated false if zero otherwise true.
-static void CopyModuleAttributeToFunction(Function &F, StringRef AttrName) {
- CopyModuleAttributeToFunction(
- F, AttrName, AttrName,
- std::make_pair<StringRef, StringRef>("true", "false"));
-}
-
-// Copy an attribute from module to the function if exists.
-// First value of the pair is used when the module attribute is not zero
-// the second otherwise.
-static void
-CopyModuleAttributeToFunction(Function &F, StringRef AttrName,
- std::pair<StringRef, StringRef> Values) {
- CopyModuleAttributeToFunction(F, AttrName, AttrName, Values);
-}
-
-void llvm::UpgradeFunctionAttributes(Function &F,
- bool ModuleMetadataIsMaterialized) {
+void llvm::UpgradeFunctionAttributes(Function &F) {
// If a function definition doesn't have the strictfp attribute,
// convert any callsite strictfp attributes to nobuiltin.
if (!F.isDeclaration() && !F.hasFnAttribute(Attribute::StrictFP)) {
@@ -5206,37 +5167,6 @@ void llvm::UpgradeFunctionAttributes(Function &F,
F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType()));
for (auto &Arg : F.args())
Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType()));
-
- if (!ModuleMetadataIsMaterialized)
- return;
- if (F.isDeclaration())
- return;
- Module *M = F.getParent();
- if (!M)
- return;
-
- Triple T(M->getTargetTriple());
- // Convert module level attributes to function level attributes because
- // after merging modules the attributes might change and would have different
- // effect on the functions as the original module would have.
- if (T.isThumb() || T.isARM() || T.isAArch64()) {
- if (!F.hasFnAttribute("sign-return-address")) {
- StringRef SignType = "none";
- if (isModuleAttributeSet(M, "sign-return-address"))
- SignType = "non-leaf";
-
- if (isModuleAttributeSet(M, "sign-return-address-all"))
- SignType = "all";
-
- F.addFnAttr("sign-return-address", SignType);
- }
- CopyModuleAttributeToFunction(F, "branch-target-enforcement");
- CopyModuleAttributeToFunction(F, "branch-protection-pauth-lr");
- CopyModuleAttributeToFunction(F, "guarded-control-stack");
- CopyModuleAttributeToFunction(
- F, "sign-return-address-key",
- std::make_pair<StringRef, StringRef>("b_key", "a_key"));
- }
}
static bool isOldLoopArgument(Metadata *MD) {
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 9f45ebc6eda0..37d21119447b 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1606,10 +1606,6 @@ Error IRLinker::run() {
// Loop over all of the linked values to compute type mappings.
computeTypeMapping();
- // Update function attributes before copying them to destation module.
- for (Function &F : SrcM->getFunctionList())
- UpgradeFunctionAttributes(F, true);
-
std::reverse(Worklist.begin(), Worklist.end());
while (!Worklist.empty()) {
GlobalValue *GV = Worklist.back();
diff --git a/llvm/test/Bitcode/upgrade-arc-runtime-calls.ll b/llvm/test/Bitcode/upgrade-arc-runtime-calls.ll
index d2edec18d55e..19f25f98953f 100644
--- a/llvm/test/Bitcode/upgrade-arc-runtime-calls.ll
+++ b/llvm/test/Bitcode/upgrade-arc-runtime-calls.ll
@@ -55,7 +55,7 @@ unwindBlock:
// Check that auto-upgrader converts function calls to intrinsic calls. Note that
// the auto-upgrader doesn't touch invoke instructions.
-// ARC: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) #0 personality
+// ARC: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) personality
// ARC: %[[V0:.*]] = tail call ptr @llvm.objc.autorelease(ptr %[[A]])
// ARC-NEXT: tail call void @llvm.objc.autoreleasePoolPop(ptr %[[A]])
// ARC-NEXT: %[[V1:.*]] = tail call ptr @llvm.objc.autoreleasePoolPush()
@@ -88,7 +88,7 @@ unwindBlock:
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.bottomup.bbend(ptr %[[B]], ptr %[[C]])
// ARC-NEXT: invoke void @objc_autoreleasePoolPop(ptr %[[A]])
-// NOUPGRADE: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) #0 personality
+// NOUPGRADE: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) personality
// NOUPGRADE: %[[V0:.*]] = tail call ptr @objc_autorelease(ptr %[[A]])
// NOUPGRADE-NEXT: tail call void @objc_autoreleasePoolPop(ptr %[[A]])
// NOUPGRADE-NEXT: %[[V1:.*]] = tail call ptr @objc_autoreleasePoolPush()
diff --git a/llvm/test/LTO/AArch64/link-branch-target-enforcement.ll b/llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
index 74d9c86881d5..ccf8cf67ede6 100644
--- a/llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
+++ b/llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
@@ -32,7 +32,6 @@ entry:
; CHECK-DUMP: <main>:
; CHECK-DUMP: bl 0x8 <main+0x8>
; CHECK-DUMP: <foo>:
-; CHECK-DUMP: paciasp
; `main` doesn't support BTI while `foo` does, so in the binary
; we should see only PAC which is supported by both.
diff --git a/llvm/test/LTO/AArch64/link-sign-return-address.ll b/llvm/test/LTO/AArch64/link-sign-return-address.ll
deleted file mode 100644
index c25857ceed7b..000000000000
--- a/llvm/test/LTO/AArch64/link-sign-return-address.ll
+++ /dev/null
@@ -1,43 +0,0 @@
-; Testcase to check that module with different branch-target-enforcement can
-; be mixed.
-;
-; RUN: llvm-as %s -o %t1.bc
-; RUN: llvm-as %p/Inputs/foo.ll -o %t2.bc
-; RUN: llvm-lto -exported-symbol main \
-; RUN: -exported-symbol foo \
-; RUN: -filetype=obj \
-; RUN: %t2.bc %t1.bc \
-; RUN: -o %t1.exe 2>&1
-; RUN: llvm-objdump -d %t1.exe | FileCheck --check-prefix=CHECK-DUMP %s
-; RUN: llvm-readelf -n %t1.exe | FileCheck --allow-empty --check-prefix=CHECK-PROP %s
-
-target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
-target triple = "aarch64-unknown-linux-gnu"
-
-declare i32 @foo();
-
-define i32 @main() {
-entry:
- %add = call i32 @foo()
- ret i32 %add
-}
-
-!llvm.module.flags = !{!0, !1, !2, !3 }
-!0 = !{i32 8, !"branch-target-enforcement", i32 0}
-!1 = !{i32 8, !"sign-return-address", i32 0}
-!2 = !{i32 8, !"sign-return-address-all", i32 0}
-!3 = !{i32 8, !"sign-return-address-with-bkey", i32 0}
-
-; CHECK-DUMP: <foo>:
-; CHECK-DUMP: paciasp
-; CHECK-DUMP: mov w0, #0x2a
-; CHECK-DUMP: autiasp
-; CHECK-DUMP: ret
-; CHECK-DUMP: <main>:
-; CHECK-DUMP-NOT: paciasp
-; CHECK-DUMP: str x30,
-; CHECK-DUMP: bl 0x14 <main+0x4>
-
-; `main` doesn't support PAC sign-return-address while `foo` does, so in the binary
-; we should not see anything.
-; CHECK-PROP-NOT: Properties: aarch64 feature: PAC \ No newline at end of file
diff --git a/llvm/test/Linker/link-arm-and-thumb.ll b/llvm/test/Linker/link-arm-and-thumb.ll
index 37bd8c37f8b5..a90f2128e443 100644
--- a/llvm/test/Linker/link-arm-and-thumb.ll
+++ b/llvm/test/Linker/link-arm-and-thumb.ll
@@ -13,12 +13,11 @@ entry:
ret i32 %add
}
-; CHECK: define i32 @main() [[MAIN_ATTRS:#[0-9]+]]
+; CHECK: define i32 @main() {
; CHECK: define i32 @foo(i32 %a, i32 %b) [[ARM_ATTRS:#[0-9]+]]
; CHECK: define i32 @bar(i32 %a, i32 %b) [[THUMB_ATTRS:#[0-9]+]]
-; CHECK: attributes [[MAIN_ATTRS]] = { {{.*}} }
-; CHECK: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="-thumb-mode" }
-; CHECK: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="+thumb-mode" }
+; CHECK: attributes [[ARM_ATTRS]] = { "target-features"="-thumb-mode" }
+; CHECK: attributes [[THUMB_ATTRS]] = { "target-features"="+thumb-mode" }
; STDERR-NOT: warning: Linking two modules of different target triples: