Skip to content

Commit 75c4d31

Browse files
committed
Take symbol name by GlobalValue again to avoid modifying Module
1 parent 904c996 commit 75c4d31

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
@@ -30653,14 +30653,14 @@ that purpose.
3065330653
Arguments:
3065430654
""""""""""
3065530655

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

3065930659
Semantics:
3066030660
""""""""""
3066130661

30662-
This intrinsic emits a no-op relocation for the symbol the location of the
30663-
intrinsic call.
30662+
This intrinsic emits a no-op relocation at the location of the intrinsic call
30663+
for the symbol that corresponds to the global value argument.
3066430664

3066530665

3066630666
Stack Map Intrinsics

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatch
19131913
def int_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
19141914
[], [IntrNoMem]>;
19151915

1916-
def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_metadata_ty],
1916+
def int_reloc_none : DefaultAttrsIntrinsic<[], [llvm_ptr_ty],
19171917
[IntrHasSideEffects, IntrInaccessibleMemOnly, IntrWillReturn]>;
19181918

19191919
//===---------------- Vector Predication Intrinsics --------------===//

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

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

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

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

77547754
case Intrinsic::reloc_none: {
7755-
Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(0))->getMetadata();
7756-
StringRef SymbolName = cast<MDString>(MD)->getString();
7757-
auto *M = const_cast<Module *>(I.getModule());
7758-
auto *RelocSymbol = cast<GlobalVariable>(
7759-
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
7755+
SDValue V = getValue(I.getArgOperand(0));
7756+
const auto *GA = cast<GlobalAddressSDNode>(V);
77607757
SDValue Ops[2];
77617758
Ops[0] = getRoot();
7762-
Ops[1] = DAG.getTargetGlobalAddress(
7763-
RelocSymbol, sdl, TLI.getPointerTy(DAG.getDataLayout()), 0);
7759+
Ops[1] = DAG.getTargetGlobalAddress(GA->getGlobal(), sdl, V.getValueType(),
7760+
GA->getOffset());
77647761
DAG.setRoot(DAG.getNode(ISD::RELOC_NONE, sdl, MVT::Other, Ops));
77657762
return;
77667763
}

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5922,9 +5922,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
59225922
"cache type argument to llvm.prefetch must be 0-1", Call);
59235923
break;
59245924
case Intrinsic::reloc_none: {
5925-
Check(isa<MDString>(
5926-
cast<MetadataAsValue>(Call.getArgOperand(0))->getMetadata()),
5927-
"llvm.reloc.none argument must be a metadata string", &Call);
5925+
Check(isa<GlobalValue>(Call.getArgOperand(0)),
5926+
"llvm.reloc.none argument must be a global value", &Call);
59285927
break;
59295928
}
59305929
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)