Skip to content

Commit b01bf98

Browse files
committed
Take symbol name by GlobalValue again to avoid modifying Module
1 parent 5729a2b commit b01bf98

File tree

9 files changed

+35
-38
lines changed

9 files changed

+35
-38
lines changed

llvm/docs/LangRef.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30922,14 +30922,14 @@ that purpose.
3092230922
Arguments:
3092330923
""""""""""
3092430924

30925-
The ``llvm.reloc.none`` intrinsic takes the symbol as a metadata string
30926-
argument.
30925+
The ``llvm.reloc.none`` intrinsic takes one argument, which may be any global
30926+
value.
3092730927

3092830928
Semantics:
3092930929
""""""""""
3093030930

30931-
This intrinsic emits a no-op relocation for the symbol the location of the
30932-
intrinsic call.
30931+
This intrinsic emits a no-op relocation at the location of the intrinsic call
30932+
for the symbol that corresponds to the global value argument.
3093330933

3093430934

3093530935
Stack Map Intrinsics

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatch
19021902
def int_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
19031903
[], [IntrNoMem]>;
19041904

1905-
def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_metadata_ty],
1905+
def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_ptr_ty],
19061906
[IntrHasSideEffects, IntrInaccessibleMemOnly, IntrWillReturn]>;
19071907

19081908
//===---------------- Vector Predication Intrinsics --------------===//

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,13 +2672,8 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
26722672
case Intrinsic::experimental_convergence_loop:
26732673
return translateConvergenceControlIntrinsic(CI, ID, MIRBuilder);
26742674
case Intrinsic::reloc_none: {
2675-
Metadata *MD = cast<MetadataAsValue>(CI.getArgOperand(0))->getMetadata();
2676-
StringRef SymbolName = cast<MDString>(MD)->getString();
2677-
auto *M = const_cast<Module *>(CI.getModule());
2678-
auto *RelocSymbol = cast<GlobalVariable>(
2679-
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
26802675
MIRBuilder.buildInstr(TargetOpcode::RELOC_NONE)
2681-
.addGlobalAddress(RelocSymbol);
2676+
.addGlobalAddress(cast<GlobalValue>(CI.getArgOperand(0)));
26822677
return true;
26832678
}
26842679
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7746,15 +7746,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
77467746
}
77477747

77487748
case Intrinsic::reloc_none: {
7749-
Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(0))->getMetadata();
7750-
StringRef SymbolName = cast<MDString>(MD)->getString();
7751-
auto *M = const_cast<Module *>(I.getModule());
7752-
auto *RelocSymbol = cast<GlobalVariable>(
7753-
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
7749+
SDValue V = getValue(I.getArgOperand(0));
7750+
const auto *GA = cast<GlobalAddressSDNode>(V);
77547751
SDValue Ops[2];
77557752
Ops[0] = getRoot();
7756-
Ops[1] = DAG.getTargetGlobalAddress(
7757-
RelocSymbol, sdl, TLI.getPointerTy(DAG.getDataLayout()), 0);
7753+
Ops[1] = DAG.getTargetGlobalAddress(GA->getGlobal(), sdl, V.getValueType(),
7754+
GA->getOffset());
77587755
DAG.setRoot(DAG.getNode(ISD::RELOC_NONE, sdl, MVT::Other, Ops));
77597756
return;
77607757
}

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5978,9 +5978,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
59785978
"cache type argument to llvm.prefetch must be 0-1", Call);
59795979
break;
59805980
case Intrinsic::reloc_none: {
5981-
Check(isa<MDString>(
5982-
cast<MetadataAsValue>(Call.getArgOperand(0))->getMetadata()),
5983-
"llvm.reloc.none argument must be a metadata string", &Call);
5981+
Check(isa<GlobalValue>(Call.getArgOperand(0)),
5982+
"llvm.reloc.none argument must be a global value", &Call);
59845983
break;
59855984
}
59865985
case Intrinsic::stackprotector:

llvm/test/CodeGen/Generic/reloc-none.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
; CHECK: .reloc {{.*}}, BFD_RELOC_NONE, foo
44

5+
%1 = type opaque
6+
@foo = external global %1
7+
58
define void @test_reloc_none() {
6-
call void @llvm.reloc.none(metadata !"foo")
9+
call void @llvm.reloc.none(ptr @foo)
710
ret void
811
}
912

10-
declare void @llvm.reloc.none(metadata)
13+
declare void @llvm.reloc.none(ptr)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=CHECK
33

4+
%1 = type opaque
5+
@foo = external global %1
6+
47
define void @test_reloc_none() {
58
; CHECK-LABEL: test_reloc_none:
69
; CHECK: # %bb.0:
710
; CHECK-NEXT: .Lreloc_none0:
811
; CHECK-NEXT: .reloc .Lreloc_none0, BFD_RELOC_NONE, foo
912
; CHECK-NEXT: retq
10-
call void @llvm.reloc.none(metadata !"foo")
13+
call void @llvm.reloc.none(ptr @foo)
1114
ret void
1215
}
1316

14-
declare void @llvm.reloc.none(metadata)
17+
declare void @llvm.reloc.none(ptr)

llvm/test/Verifier/reloc-none.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: not llvm-as -disable-output 2>&1 %s | FileCheck %s
2+
3+
; CHECK: llvm.reloc.none argument must be a global value
4+
; CHECK-NEXT: call void @llvm.reloc.none(ptr %foo)
5+
6+
define void @test_reloc_none_bad_arg(ptr %foo) {
7+
call void @llvm.reloc.none(ptr %foo)
8+
ret void
9+
}
10+
11+
declare void @llvm.reloc.none(ptr)
12+
13+
!0 = !{}

llvm/test/Verifier/reloc_none.ll

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)