Skip to content

Commit

Permalink
Revert "[llvm][AArch64] Autoupgrade function attributes from Module a…
Browse files Browse the repository at this point in the history
…ttributes. (#80640)"

This reverts commit 531e8c2.
  • Loading branch information
DanielKristofKiss committed Feb 23, 2024
1 parent 59ff4d1 commit b13c8e5
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 128 deletions.
3 changes: 1 addition & 2 deletions llvm/include/llvm/IR/AutoUpgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 1 addition & 71 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Bitcode/upgrade-arc-runtime-calls.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion llvm/test/LTO/AArch64/link-branch-target-enforcement.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 0 additions & 43 deletions llvm/test/LTO/AArch64/link-sign-return-address.ll

This file was deleted.

7 changes: 3 additions & 4 deletions llvm/test/Linker/link-arm-and-thumb.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit b13c8e5

Please sign in to comment.