From 75c4d315dc85dfbb9ccb28781de4dc3f17b3263d Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Wed, 20 Aug 2025 16:24:34 -0700 Subject: [PATCH] Take symbol name by GlobalValue again to avoid modifying Module --- llvm/docs/LangRef.rst | 8 ++++---- llvm/include/llvm/IR/Intrinsics.td | 2 +- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 7 +------ .../CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 11 ++++------- llvm/lib/IR/Verifier.cpp | 5 ++--- llvm/test/CodeGen/Generic/reloc-none.ll | 7 +++++-- llvm/test/CodeGen/X86/GlobalISel/reloc-none.ll | 7 +++++-- llvm/test/Verifier/reloc-none.ll | 13 +++++++++++++ llvm/test/Verifier/reloc_none.ll | 13 ------------- 9 files changed, 35 insertions(+), 38 deletions(-) create mode 100644 llvm/test/Verifier/reloc-none.ll delete mode 100644 llvm/test/Verifier/reloc_none.ll diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 085b9c669219..ebfef5d357ba 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -30653,14 +30653,14 @@ that purpose. Arguments: """""""""" -The ``llvm.reloc.none`` intrinsic takes the symbol as a metadata string -argument. +The ``llvm.reloc.none`` intrinsic takes one argument, which may be any global +value. Semantics: """""""""" -This intrinsic emits a no-op relocation for the symbol the location of the -intrinsic call. +This intrinsic emits a no-op relocation at the location of the intrinsic call +for the symbol that corresponds to the global value argument. Stack Map Intrinsics diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td index dd93bb6b1960..88b1918c022c 100644 --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -1913,7 +1913,7 @@ def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatch def int_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty], [], [IntrNoMem]>; -def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_metadata_ty], +def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [IntrHasSideEffects, IntrInaccessibleMemOnly, IntrWillReturn]>; //===---------------- Vector Predication Intrinsics --------------===// diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index e33cadac2cb7..2cdf778da9fe 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2670,13 +2670,8 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, case Intrinsic::experimental_convergence_loop: return translateConvergenceControlIntrinsic(CI, ID, MIRBuilder); case Intrinsic::reloc_none: { - Metadata *MD = cast(CI.getArgOperand(0))->getMetadata(); - StringRef SymbolName = cast(MD)->getString(); - auto *M = const_cast(CI.getModule()); - auto *RelocSymbol = cast( - M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext()))); MIRBuilder.buildInstr(TargetOpcode::RELOC_NONE) - .addGlobalAddress(RelocSymbol); + .addGlobalAddress(cast(CI.getArgOperand(0))); return true; } } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 8c6c2749c3d6..918f364c0b8d 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -7752,15 +7752,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, } case Intrinsic::reloc_none: { - Metadata *MD = cast(I.getArgOperand(0))->getMetadata(); - StringRef SymbolName = cast(MD)->getString(); - auto *M = const_cast(I.getModule()); - auto *RelocSymbol = cast( - M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext()))); + SDValue V = getValue(I.getArgOperand(0)); + const auto *GA = cast(V); SDValue Ops[2]; Ops[0] = getRoot(); - Ops[1] = DAG.getTargetGlobalAddress( - RelocSymbol, sdl, TLI.getPointerTy(DAG.getDataLayout()), 0); + Ops[1] = DAG.getTargetGlobalAddress(GA->getGlobal(), sdl, V.getValueType(), + GA->getOffset()); DAG.setRoot(DAG.getNode(ISD::RELOC_NONE, sdl, MVT::Other, Ops)); return; } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 155417515074..be951e3daea6 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5922,9 +5922,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { "cache type argument to llvm.prefetch must be 0-1", Call); break; case Intrinsic::reloc_none: { - Check(isa( - cast(Call.getArgOperand(0))->getMetadata()), - "llvm.reloc.none argument must be a metadata string", &Call); + Check(isa(Call.getArgOperand(0)), + "llvm.reloc.none argument must be a global value", &Call); break; } case Intrinsic::stackprotector: diff --git a/llvm/test/CodeGen/Generic/reloc-none.ll b/llvm/test/CodeGen/Generic/reloc-none.ll index 0c8b7a57aca8..e87d81b6d046 100644 --- a/llvm/test/CodeGen/Generic/reloc-none.ll +++ b/llvm/test/CodeGen/Generic/reloc-none.ll @@ -2,9 +2,12 @@ ; CHECK: .reloc {{.*}}, BFD_RELOC_NONE, foo +%1 = type opaque +@foo = external global %1 + define void @test_reloc_none() { - call void @llvm.reloc.none(metadata !"foo") + call void @llvm.reloc.none(ptr @foo) ret void } -declare void @llvm.reloc.none(metadata) +declare void @llvm.reloc.none(ptr) diff --git a/llvm/test/CodeGen/X86/GlobalISel/reloc-none.ll b/llvm/test/CodeGen/X86/GlobalISel/reloc-none.ll index 841c9a6d62d9..247d9bd798bc 100644 --- a/llvm/test/CodeGen/X86/GlobalISel/reloc-none.ll +++ b/llvm/test/CodeGen/X86/GlobalISel/reloc-none.ll @@ -1,14 +1,17 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=CHECK +%1 = type opaque +@foo = external global %1 + define void @test_reloc_none() { ; CHECK-LABEL: test_reloc_none: ; CHECK: # %bb.0: ; CHECK-NEXT: .Lreloc_none0: ; CHECK-NEXT: .reloc .Lreloc_none0, BFD_RELOC_NONE, foo ; CHECK-NEXT: retq - call void @llvm.reloc.none(metadata !"foo") + call void @llvm.reloc.none(ptr @foo) ret void } -declare void @llvm.reloc.none(metadata) +declare void @llvm.reloc.none(ptr) diff --git a/llvm/test/Verifier/reloc-none.ll b/llvm/test/Verifier/reloc-none.ll new file mode 100644 index 000000000000..f025b7a7c9cb --- /dev/null +++ b/llvm/test/Verifier/reloc-none.ll @@ -0,0 +1,13 @@ +; RUN: not llvm-as -disable-output 2>&1 %s | FileCheck %s + +; CHECK: llvm.reloc.none argument must be a global value +; CHECK-NEXT: call void @llvm.reloc.none(ptr %foo) + +define void @test_reloc_none_bad_arg(ptr %foo) { + call void @llvm.reloc.none(ptr %foo) + ret void +} + +declare void @llvm.reloc.none(ptr) + +!0 = !{} diff --git a/llvm/test/Verifier/reloc_none.ll b/llvm/test/Verifier/reloc_none.ll deleted file mode 100644 index 9c96799a36a3..000000000000 --- a/llvm/test/Verifier/reloc_none.ll +++ /dev/null @@ -1,13 +0,0 @@ -; RUN: not llvm-as -disable-output 2>&1 %s | FileCheck %s - -; CHECK: llvm.reloc.none argument must be a metadata string -; CHECK-NEXT: call void @llvm.reloc.none(metadata !0) - -define void @test_reloc_none_bad_arg() { - call void @llvm.reloc.none(metadata !0) - ret void -} - -declare void @llvm.reloc.none(metadata) - -!0 = !{}