Skip to content

Commit ccafe0c

Browse files
committed
Take symbol name by GlobalValue again to avoid modifying Module
1 parent 984b060 commit ccafe0c

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
@@ -30691,14 +30691,14 @@ that purpose.
3069130691
Arguments:
3069230692
""""""""""
3069330693

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

3069730697
Semantics:
3069830698
""""""""""
3069930699

30700-
This intrinsic emits a no-op relocation for the symbol the location of the
30701-
intrinsic call.
30700+
This intrinsic emits a no-op relocation at the location of the intrinsic call
30701+
for the symbol that corresponds to the global value argument.
3070230702

3070330703

3070430704
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
@@ -2669,13 +2669,8 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
26692669
case Intrinsic::experimental_convergence_loop:
26702670
return translateConvergenceControlIntrinsic(CI, ID, MIRBuilder);
26712671
case Intrinsic::reloc_none: {
2672-
Metadata *MD = cast<MetadataAsValue>(CI.getArgOperand(0))->getMetadata();
2673-
StringRef SymbolName = cast<MDString>(MD)->getString();
2674-
auto *M = const_cast<Module *>(CI.getModule());
2675-
auto *RelocSymbol = cast<GlobalVariable>(
2676-
M->getOrInsertGlobal(SymbolName, StructType::create(M->getContext())));
26772672
MIRBuilder.buildInstr(TargetOpcode::RELOC_NONE)
2678-
.addGlobalAddress(RelocSymbol);
2673+
.addGlobalAddress(cast<GlobalValue>(CI.getArgOperand(0)));
26792674
return true;
26802675
}
26812676
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

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

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

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5934,9 +5934,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
59345934
"cache type argument to llvm.prefetch must be 0-1", Call);
59355935
break;
59365936
case Intrinsic::reloc_none: {
5937-
Check(isa<MDString>(
5938-
cast<MetadataAsValue>(Call.getArgOperand(0))->getMetadata()),
5939-
"llvm.reloc.none argument must be a metadata string", &Call);
5937+
Check(isa<GlobalValue>(Call.getArgOperand(0)),
5938+
"llvm.reloc.none argument must be a global value", &Call);
59405939
break;
59415940
}
59425941
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)