Skip to content

Commit 7ebc3db

Browse files
authored
[llvm] Make getEffectiveRelocModel helper consistent across targets. NFC (#165121)
- On targets that don't require the Triple, don't pass it. - Use `.value_or` to where possible.
1 parent 42bba7f commit 7ebc3db

File tree

5 files changed

+16
-27
lines changed

5 files changed

+16
-27
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static StringRef getGPUOrDefault(const Triple &TT, StringRef GPU) {
740740
return "r600";
741741
}
742742

743-
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
743+
static Reloc::Model getEffectiveRelocModel() {
744744
// The AMDGPU toolchain only supports generating shared objects, so we
745745
// must always use PIC.
746746
return Reloc::PIC_;
@@ -754,8 +754,8 @@ AMDGPUTargetMachine::AMDGPUTargetMachine(const Target &T, const Triple &TT,
754754
CodeGenOptLevel OptLevel)
755755
: CodeGenTargetMachineImpl(
756756
T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
757-
getEffectiveRelocModel(RM),
758-
getEffectiveCodeModel(CM, CodeModel::Small), OptLevel),
757+
getEffectiveRelocModel(), getEffectiveCodeModel(CM, CodeModel::Small),
758+
OptLevel),
759759
TLOF(createTLOF(getTargetTriple())) {
760760
initAsmInfo();
761761
if (TT.isAMDGCN()) {

llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ static cl::opt<bool>
6262
cl::desc("Enable the merge base offset pass"),
6363
cl::init(true), cl::Hidden);
6464

65-
static Reloc::Model getEffectiveRelocModel(const Triple &TT,
66-
std::optional<Reloc::Model> RM) {
65+
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
6766
return RM.value_or(Reloc::Static);
6867
}
6968

@@ -92,7 +91,7 @@ LoongArchTargetMachine::LoongArchTargetMachine(
9291
const TargetOptions &Options, std::optional<Reloc::Model> RM,
9392
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
9493
: CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
95-
getEffectiveRelocModel(TT, RM),
94+
getEffectiveRelocModel(RM),
9695
getEffectiveLoongArchCodeModel(TT, CM), OL),
9796
TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
9897
initAsmInfo();

llvm/lib/Target/M68k/M68kTargetMachine.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kTarget() {
4646

4747
namespace {
4848

49-
Reloc::Model getEffectiveRelocModel(const Triple &TT,
50-
std::optional<Reloc::Model> RM) {
49+
Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
5150
// If not defined we default to static
52-
if (!RM.has_value())
53-
return Reloc::Static;
54-
55-
return *RM;
51+
return RM.value_or(Reloc::Static);
5652
}
5753

5854
CodeModel::Model getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
@@ -73,7 +69,7 @@ M68kTargetMachine::M68kTargetMachine(const Target &T, const Triple &TT,
7369
std::optional<CodeModel::Model> CM,
7470
CodeGenOptLevel OL, bool JIT)
7571
: CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
76-
getEffectiveRelocModel(TT, RM),
72+
getEffectiveRelocModel(RM),
7773
::getEffectiveCodeModel(CM, JIT), OL),
7874
TLOF(std::make_unique<M68kELFTargetObjectFile>()),
7975
Subtarget(TT, CPU, FS, *this) {

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
141141
initializeRISCVAsmPrinterPass(*PR);
142142
}
143143

144-
static Reloc::Model getEffectiveRelocModel(const Triple &TT,
145-
std::optional<Reloc::Model> RM) {
144+
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
146145
return RM.value_or(Reloc::Static);
147146
}
148147

@@ -154,7 +153,7 @@ RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT,
154153
CodeGenOptLevel OL, bool JIT)
155154
: CodeGenTargetMachineImpl(
156155
T, TT.computeDataLayout(Options.MCOptions.getABIName()), TT, CPU, FS,
157-
Options, getEffectiveRelocModel(TT, RM),
156+
Options, getEffectiveRelocModel(RM),
158157
getEffectiveCodeModel(CM, CodeModel::Small), OL),
159158
TLOF(std::make_unique<RISCVELFTargetObjectFile>()) {
160159
initAsmInfo();

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,11 @@ LLVMInitializeWebAssemblyTarget() {
127127
// WebAssembly Lowering public interface.
128128
//===----------------------------------------------------------------------===//
129129

130-
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM,
131-
const Triple &TT) {
132-
if (!RM) {
133-
// Default to static relocation model. This should always be more optimial
134-
// than PIC since the static linker can determine all global addresses and
135-
// assume direct function calls.
136-
return Reloc::Static;
137-
}
138-
139-
return *RM;
130+
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
131+
// Default to static relocation model. This should always be more optimial
132+
// than PIC since the static linker can determine all global addresses and
133+
// assume direct function calls.
134+
return RM.value_or(Reloc::Static);
140135
}
141136

142137
using WebAssembly::WasmEnableEH;
@@ -197,7 +192,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
197192
const TargetOptions &Options, std::optional<Reloc::Model> RM,
198193
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
199194
: CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
200-
getEffectiveRelocModel(RM, TT),
195+
getEffectiveRelocModel(RM),
201196
getEffectiveCodeModel(CM, CodeModel::Large), OL),
202197
TLOF(new WebAssemblyTargetObjectFile()),
203198
UsesMultivalueABI(Options.MCOptions.getABIName() == "experimental-mv") {

0 commit comments

Comments
 (0)