[llvm] [IR] llvm.reloc.none intrinsic for no-op symbol references (PR #147427)
Daniel Thornburgh via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 28 12:02:01 PDT 2025
================
@@ -7757,6 +7757,20 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
return;
}
+ 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())));
----------------
mysterymath wrote:
This is because this occurs in a `MachineFunctionPass` right? In that case, I got bamboozled! I had unceremoniously copy-pasted this from the lowering of `Intrinsic::amdgcn_reloc_constant` in `SIISelLowering.cpp`, which also runs in a `MachineFunctionPass`. I'll admit that this completely slipped past me, although I was curious about the `const_cast`.
AFAIK, converting an arbitrary symbol name metadata string to a GlobalValue reference instrinsically mutates the module. So, if we wanted to fix this, we could either go back to having this be a symbol reference to a pre-existing global value, or we could forward the metadata string to `RELOC_NONE` as a string (odd in the backend; unsure if this is even possible?) to be lowered to a symbol reference at assembly time. My preference would definitely be the former, since it has fewer unknowns.
Whichever we choose, also I'd think either way we should give `amdgcn_reloc_constant` the same treatment, unless it's not possible to do so for backwards compatibility reasons.
@arsenm Do you have preferences here?
https://github.com/llvm/llvm-project/pull/147427
More information about the llvm-commits
mailing list