[llvm] [CodeGen][ARM64EC] Add support for hybrid_patchable attribute. (PR #92965)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 17:03:52 PDT 2024
================
@@ -670,10 +746,40 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
GuardFnType = FunctionType::get(PtrTy, {PtrTy, PtrTy}, false);
GuardFnPtrType = PointerType::get(GuardFnType, 0);
+ DispatchFnType = FunctionType::get(PtrTy, {PtrTy, PtrTy, PtrTy}, false);
+ DispatchFnPtrType = PointerType::get(DispatchFnType, 0);
GuardFnCFGlobal =
M->getOrInsertGlobal("__os_arm64x_check_icall_cfg", GuardFnPtrType);
GuardFnGlobal =
M->getOrInsertGlobal("__os_arm64x_check_icall", GuardFnPtrType);
+ DispatchFnGlobal =
+ M->getOrInsertGlobal("__os_arm64x_dispatch_call", DispatchFnPtrType);
+
+ // Rename hybrid patchable functions and change callers to use an external
+ // linkage function call instead.
+ SetVector<Function *> PatchableFns;
+ for (Function &F : Mod) {
+ if (!F.hasFnAttribute(Attribute::HybridPatchable) ||
+ F.getName().ends_with("$hp_target"))
+ continue;
+
+ if (F.isDeclaration() || F.hasLocalLinkage()) {
+ F.removeFnAttr(Attribute::HybridPatchable);
+ continue;
+ }
+
+ if (std::optional<std::string> MangledName =
+ getArm64ECMangledFunctionName(F.getName().str())) {
+ std::string OrigName(F.getName());
+ F.setName(MangledName.value() + "$hp_target");
+
+ Function *EF = Function::Create(
----------------
cjacek wrote:
GlobalAlias seems to work fine out of the box for the mangled alias (which points to the thunk). However, global aliases need to point to function definition, while we need to emit a weak alias to an undefined symbol for the unmangled alias. I worked around it by overriding `AsmPrintet::emitGlobalAlias` and special-casing those aliases based on aliasee's metadata. `emitGlobalAlias` was already a virtual function, but I needed to change it to protected in `AsmPrinter` to be able to fall back to it in aarch64 code. This allowed to reduce the gap between IR and generated code, but it's not really eliminated (FWIW, I think it would be possible to similarly define aliases for anti-dependencies if we want to).
https://github.com/llvm/llvm-project/pull/92965
More information about the llvm-commits
mailing list