Take symbol name by GlobalValue again to avoid modifying Module

This commit is contained in:
Daniel Thornburgh 2025-08-20 16:24:34 -07:00
parent 904c996355
commit 75c4d315dc
9 changed files with 35 additions and 38 deletions

View File

@ -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

View File

@ -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 --------------===//

View File

@ -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<MetadataAsValue>(CI.getArgOperand(0))->getMetadata();
StringRef SymbolName = cast<MDString>(MD)->getString();
auto *M = const_cast<Module *>(CI.getModule());
auto *RelocSymbol = cast<GlobalVariable>(
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
MIRBuilder.buildInstr(TargetOpcode::RELOC_NONE)
.addGlobalAddress(RelocSymbol);
.addGlobalAddress(cast<GlobalValue>(CI.getArgOperand(0)));
return true;
}
}

View File

@ -7752,15 +7752,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
}
case Intrinsic::reloc_none: {
Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(0))->getMetadata();
StringRef SymbolName = cast<MDString>(MD)->getString();
auto *M = const_cast<Module *>(I.getModule());
auto *RelocSymbol = cast<GlobalVariable>(
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
SDValue V = getValue(I.getArgOperand(0));
const auto *GA = cast<GlobalAddressSDNode>(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;
}

View File

@ -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<MDString>(
cast<MetadataAsValue>(Call.getArgOperand(0))->getMetadata()),
"llvm.reloc.none argument must be a metadata string", &Call);
Check(isa<GlobalValue>(Call.getArgOperand(0)),
"llvm.reloc.none argument must be a global value", &Call);
break;
}
case Intrinsic::stackprotector:

View File

@ -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)

View File

@ -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)

View File

@ -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 = !{}

View File

@ -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 = !{}