Skip to content

Commit b13c8e5

Browse files
Revert "[llvm][AArch64] Autoupgrade function attributes from Module attributes. (#80640)"
This reverts commit 531e8c2.
1 parent 59ff4d1 commit b13c8e5

File tree

8 files changed

+8
-128
lines changed

8 files changed

+8
-128
lines changed

llvm/include/llvm/IR/AutoUpgrade.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ namespace llvm {
6767
void UpgradeSectionAttributes(Module &M);
6868

6969
/// Correct any IR that is relying on old function attribute behavior.
70-
void UpgradeFunctionAttributes(Function &F,
71-
bool ModuleMetadataIsMaterialized = false);
70+
void UpgradeFunctionAttributes(Function &F);
7271

7372
/// If the given TBAA tag uses the scalar TBAA format, create a new node
7473
/// corresponding to the upgrade to the struct-path aware TBAA format.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6706,7 +6706,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
67066706
}
67076707

67086708
// Look for functions that rely on old function attribute behavior.
6709-
UpgradeFunctionAttributes(*F, true);
6709+
UpgradeFunctionAttributes(*F);
67106710

67116711
// Bring in any functions that this function forward-referenced via
67126712
// blockaddresses.

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5155,46 +5155,7 @@ struct StrictFPUpgradeVisitor : public InstVisitor<StrictFPUpgradeVisitor> {
51555155
};
51565156
} // namespace
51575157

5158-
// Check if the module attribute is present and not zero.
5159-
static bool isModuleAttributeSet(const Module *M, const StringRef &ModAttr) {
5160-
const auto *Attr =
5161-
mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr));
5162-
return Attr && Attr->getZExtValue();
5163-
}
5164-
5165-
// Copy an attribute from module to the function if exists.
5166-
// First value of the pair is used when the module attribute is not zero
5167-
// the second otherwise.
5168-
static void
5169-
CopyModuleAttributeToFunction(Function &F, StringRef FnAttrName,
5170-
StringRef ModAttrName,
5171-
std::pair<StringRef, StringRef> Values) {
5172-
if (F.hasFnAttribute(FnAttrName))
5173-
return;
5174-
F.addFnAttr(FnAttrName, isModuleAttributeSet(F.getParent(), ModAttrName)
5175-
? Values.first
5176-
: Values.second);
5177-
}
5178-
5179-
// Copy a boolean attribute from module to the function if exists.
5180-
// Module attribute treated false if zero otherwise true.
5181-
static void CopyModuleAttributeToFunction(Function &F, StringRef AttrName) {
5182-
CopyModuleAttributeToFunction(
5183-
F, AttrName, AttrName,
5184-
std::make_pair<StringRef, StringRef>("true", "false"));
5185-
}
5186-
5187-
// Copy an attribute from module to the function if exists.
5188-
// First value of the pair is used when the module attribute is not zero
5189-
// the second otherwise.
5190-
static void
5191-
CopyModuleAttributeToFunction(Function &F, StringRef AttrName,
5192-
std::pair<StringRef, StringRef> Values) {
5193-
CopyModuleAttributeToFunction(F, AttrName, AttrName, Values);
5194-
}
5195-
5196-
void llvm::UpgradeFunctionAttributes(Function &F,
5197-
bool ModuleMetadataIsMaterialized) {
5158+
void llvm::UpgradeFunctionAttributes(Function &F) {
51985159
// If a function definition doesn't have the strictfp attribute,
51995160
// convert any callsite strictfp attributes to nobuiltin.
52005161
if (!F.isDeclaration() && !F.hasFnAttribute(Attribute::StrictFP)) {
@@ -5206,37 +5167,6 @@ void llvm::UpgradeFunctionAttributes(Function &F,
52065167
F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType()));
52075168
for (auto &Arg : F.args())
52085169
Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType()));
5209-
5210-
if (!ModuleMetadataIsMaterialized)
5211-
return;
5212-
if (F.isDeclaration())
5213-
return;
5214-
Module *M = F.getParent();
5215-
if (!M)
5216-
return;
5217-
5218-
Triple T(M->getTargetTriple());
5219-
// Convert module level attributes to function level attributes because
5220-
// after merging modules the attributes might change and would have different
5221-
// effect on the functions as the original module would have.
5222-
if (T.isThumb() || T.isARM() || T.isAArch64()) {
5223-
if (!F.hasFnAttribute("sign-return-address")) {
5224-
StringRef SignType = "none";
5225-
if (isModuleAttributeSet(M, "sign-return-address"))
5226-
SignType = "non-leaf";
5227-
5228-
if (isModuleAttributeSet(M, "sign-return-address-all"))
5229-
SignType = "all";
5230-
5231-
F.addFnAttr("sign-return-address", SignType);
5232-
}
5233-
CopyModuleAttributeToFunction(F, "branch-target-enforcement");
5234-
CopyModuleAttributeToFunction(F, "branch-protection-pauth-lr");
5235-
CopyModuleAttributeToFunction(F, "guarded-control-stack");
5236-
CopyModuleAttributeToFunction(
5237-
F, "sign-return-address-key",
5238-
std::make_pair<StringRef, StringRef>("b_key", "a_key"));
5239-
}
52405170
}
52415171

52425172
static bool isOldLoopArgument(Metadata *MD) {

llvm/lib/Linker/IRMover.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,10 +1606,6 @@ Error IRLinker::run() {
16061606
// Loop over all of the linked values to compute type mappings.
16071607
computeTypeMapping();
16081608

1609-
// Update function attributes before copying them to destation module.
1610-
for (Function &F : SrcM->getFunctionList())
1611-
UpgradeFunctionAttributes(F, true);
1612-
16131609
std::reverse(Worklist.begin(), Worklist.end());
16141610
while (!Worklist.empty()) {
16151611
GlobalValue *GV = Worklist.back();

llvm/test/Bitcode/upgrade-arc-runtime-calls.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ unwindBlock:
5555
// Check that auto-upgrader converts function calls to intrinsic calls. Note that
5656
// the auto-upgrader doesn't touch invoke instructions.
5757

58-
// ARC: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) #0 personality
58+
// ARC: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) personality
5959
// ARC: %[[V0:.*]] = tail call ptr @llvm.objc.autorelease(ptr %[[A]])
6060
// ARC-NEXT: tail call void @llvm.objc.autoreleasePoolPop(ptr %[[A]])
6161
// ARC-NEXT: %[[V1:.*]] = tail call ptr @llvm.objc.autoreleasePoolPush()
@@ -88,7 +88,7 @@ unwindBlock:
8888
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.bottomup.bbend(ptr %[[B]], ptr %[[C]])
8989
// ARC-NEXT: invoke void @objc_autoreleasePoolPop(ptr %[[A]])
9090

91-
// NOUPGRADE: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) #0 personality
91+
// NOUPGRADE: define void @testRuntimeCalls(ptr %[[A:.*]], ptr %[[B:.*]], ptr %[[C:.*]], ptr %[[D:.*]], ptr %[[E:.*]]) personality
9292
// NOUPGRADE: %[[V0:.*]] = tail call ptr @objc_autorelease(ptr %[[A]])
9393
// NOUPGRADE-NEXT: tail call void @objc_autoreleasePoolPop(ptr %[[A]])
9494
// NOUPGRADE-NEXT: %[[V1:.*]] = tail call ptr @objc_autoreleasePoolPush()

llvm/test/LTO/AArch64/link-branch-target-enforcement.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ entry:
3232
; CHECK-DUMP: <main>:
3333
; CHECK-DUMP: bl 0x8 <main+0x8>
3434
; CHECK-DUMP: <foo>:
35-
; CHECK-DUMP: paciasp
3635

3736
; `main` doesn't support BTI while `foo` does, so in the binary
3837
; we should see only PAC which is supported by both.

llvm/test/LTO/AArch64/link-sign-return-address.ll

Lines changed: 0 additions & 43 deletions
This file was deleted.

llvm/test/Linker/link-arm-and-thumb.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ entry:
1313
ret i32 %add
1414
}
1515

16-
; CHECK: define i32 @main() [[MAIN_ATTRS:#[0-9]+]]
16+
; CHECK: define i32 @main() {
1717
; CHECK: define i32 @foo(i32 %a, i32 %b) [[ARM_ATTRS:#[0-9]+]]
1818
; CHECK: define i32 @bar(i32 %a, i32 %b) [[THUMB_ATTRS:#[0-9]+]]
1919

20-
; CHECK: attributes [[MAIN_ATTRS]] = { {{.*}} }
21-
; CHECK: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="-thumb-mode" }
22-
; CHECK: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="+thumb-mode" }
20+
; CHECK: attributes [[ARM_ATTRS]] = { "target-features"="-thumb-mode" }
21+
; CHECK: attributes [[THUMB_ATTRS]] = { "target-features"="+thumb-mode" }
2322

2423
; STDERR-NOT: warning: Linking two modules of different target triples:

0 commit comments

Comments
 (0)