[llvm] [CodeGen][ARM64EC] Add support for hybrid_patchable attribute. (PR #92965)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed May 22 11:43:09 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(
----------------
efriedma-quic wrote:
I think I'd like to avoid the situation where we emit a declaration for the function at the IR level as if it isn't defined, but then we actually end up defining the symbol in the assembly. I'm not sure it really has any particular effect here: I think the symbol only ends up being used for the thunk table. But I'd prefer to reduce the gap between the IR and the actual generated code as much as possible.
Not sure if this actually works, but can we emit a GlobalAlias at the IR level? (It doesn't work for anti-dep symbols because we currently can't represent those, but I think maybe a normal weak alias lowers to the right thing?)
https://github.com/llvm/llvm-project/pull/92965
More information about the llvm-commits
mailing list