[llvm] f39e75b - [CodeGen][ARM64EC][NFC] Factor out emitFunctionAlias and getSymbolFromMetadata in emitFunctionEntryLabel. (#92098)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 02:35:07 PDT 2024
Author: Jacek Caban
Date: 2024-05-15T11:35:02+02:00
New Revision: f39e75b45160ae69222d6ae197ee20c365146717
URL: https://github.com/llvm/llvm-project/commit/f39e75b45160ae69222d6ae197ee20c365146717
DIFF: https://github.com/llvm/llvm-project/commit/f39e75b45160ae69222d6ae197ee20c365146717.diff
LOG: [CodeGen][ARM64EC][NFC] Factor out emitFunctionAlias and getSymbolFromMetadata in emitFunctionEntryLabel. (#92098)
Added:
Modified:
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index ee39c6355c298..3ce766fc173c8 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -1161,52 +1161,45 @@ void AArch64AsmPrinter::emitFunctionEntryLabel() {
TS->emitDirectiveVariantPCS(CurrentFnSym);
}
+ AsmPrinter::emitFunctionEntryLabel();
+
if (TM.getTargetTriple().isWindowsArm64EC() &&
!MF->getFunction().hasLocalLinkage()) {
// For ARM64EC targets, a function definition's name is mangled
diff erently
- // from the normal symbol. We emit the alias from the unmangled symbol to
- // mangled symbol name here.
- if (MDNode *Unmangled =
- MF->getFunction().getMetadata("arm64ec_unmangled_name")) {
- AsmPrinter::emitFunctionEntryLabel();
-
- if (MDNode *ECMangled =
- MF->getFunction().getMetadata("arm64ec_ecmangled_name")) {
- StringRef UnmangledStr =
- cast<MDString>(Unmangled->getOperand(0))->getString();
- MCSymbol *UnmangledSym =
- MMI->getContext().getOrCreateSymbol(UnmangledStr);
- StringRef ECMangledStr =
- cast<MDString>(ECMangled->getOperand(0))->getString();
- MCSymbol *ECMangledSym =
- MMI->getContext().getOrCreateSymbol(ECMangledStr);
- OutStreamer->emitSymbolAttribute(UnmangledSym, MCSA_WeakAntiDep);
- OutStreamer->emitAssignment(
- UnmangledSym,
- MCSymbolRefExpr::create(ECMangledSym, MCSymbolRefExpr::VK_WEAKREF,
- MMI->getContext()));
- OutStreamer->emitSymbolAttribute(ECMangledSym, MCSA_WeakAntiDep);
- OutStreamer->emitAssignment(
- ECMangledSym,
- MCSymbolRefExpr::create(CurrentFnSym, MCSymbolRefExpr::VK_WEAKREF,
- MMI->getContext()));
- return;
+ // from the normal symbol, emit required aliases here.
+ auto emitFunctionAlias = [&](MCSymbol *Src, MCSymbol *Dst) {
+ OutStreamer->emitSymbolAttribute(Src, MCSA_WeakAntiDep);
+ OutStreamer->emitAssignment(
+ Src, MCSymbolRefExpr::create(Dst, MCSymbolRefExpr::VK_WEAKREF,
+ MMI->getContext()));
+ };
+
+ auto getSymbolFromMetadata = [&](StringRef Name) {
+ MCSymbol *Sym = nullptr;
+ if (MDNode *Node = MF->getFunction().getMetadata(Name)) {
+ StringRef NameStr = cast<MDString>(Node->getOperand(0))->getString();
+ Sym = MMI->getContext().getOrCreateSymbol(NameStr);
+ }
+ return Sym;
+ };
+
+ if (MCSymbol *UnmangledSym =
+ getSymbolFromMetadata("arm64ec_unmangled_name")) {
+ MCSymbol *ECMangledSym = getSymbolFromMetadata("arm64ec_ecmangled_name");
+
+ if (ECMangledSym) {
+ // An external function, emit the alias from the unmangled symbol to
+ // mangled symbol name and the alias from the mangled symbol to guest
+ // exit thunk.
+ emitFunctionAlias(UnmangledSym, ECMangledSym);
+ emitFunctionAlias(ECMangledSym, CurrentFnSym);
} else {
- StringRef UnmangledStr =
- cast<MDString>(Unmangled->getOperand(0))->getString();
- MCSymbol *UnmangledSym =
- MMI->getContext().getOrCreateSymbol(UnmangledStr);
- OutStreamer->emitSymbolAttribute(UnmangledSym, MCSA_WeakAntiDep);
- OutStreamer->emitAssignment(
- UnmangledSym,
- MCSymbolRefExpr::create(CurrentFnSym, MCSymbolRefExpr::VK_WEAKREF,
- MMI->getContext()));
- return;
+ // A function implementation, emit the alias from the unmangled symbol
+ // to mangled symbol name.
+ emitFunctionAlias(UnmangledSym, CurrentFnSym);
}
}
}
-
- return AsmPrinter::emitFunctionEntryLabel();
}
/// Small jump tables contain an unsigned byte or half, representing the offset
More information about the llvm-commits
mailing list