Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9aafb85

Browse files
committed
Delete Default and JITDefault code models
IMHO it is an antipattern to have a enum value that is Default. At any given piece of code it is not clear if we have to handle Default or if has already been mapped to a concrete value. In this case in particular, only the target can do the mapping and it is nice to make sure it is always done. This deletes the two default enum values of CodeModel and uses an explicit Optional<CodeModel> when it is possible that it is unspecified. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309911 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 65d41d8 commit 9aafb85

File tree

64 files changed

+420
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+420
-468
lines changed

include/llvm/CodeGen/CommandFlags.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ TMModel("thread-model",
7777
clEnumValN(ThreadModel::Single, "single",
7878
"Single thread model")));
7979

80-
cl::opt<llvm::CodeModel::Model>
81-
CMModel("code-model",
82-
cl::desc("Choose code model"),
83-
cl::init(CodeModel::Default),
84-
cl::values(clEnumValN(CodeModel::Default, "default",
85-
"Target default code model"),
86-
clEnumValN(CodeModel::Small, "small",
87-
"Small code model"),
88-
clEnumValN(CodeModel::Kernel, "kernel",
89-
"Kernel code model"),
90-
clEnumValN(CodeModel::Medium, "medium",
91-
"Medium code model"),
92-
clEnumValN(CodeModel::Large, "large",
93-
"Large code model")));
80+
cl::opt<llvm::CodeModel::Model> CMModel(
81+
"code-model", cl::desc("Choose code model"),
82+
cl::values(clEnumValN(CodeModel::Small, "small", "Small code model"),
83+
clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
84+
clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
85+
clEnumValN(CodeModel::Large, "large", "Large code model")));
86+
87+
static inline Optional<CodeModel::Model> getCodeModel() {
88+
if (CMModel.getNumOccurrences()) {
89+
CodeModel::Model M = CMModel;
90+
return M;
91+
}
92+
return None;
93+
}
9494

9595
cl::opt<llvm::ExceptionHandling>
9696
ExceptionModel("exception-model",

include/llvm/ExecutionEngine/ExecutionEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class EngineBuilder {
535535
std::shared_ptr<JITSymbolResolver> Resolver;
536536
TargetOptions Options;
537537
Optional<Reloc::Model> RelocModel;
538-
CodeModel::Model CMModel;
538+
Optional<CodeModel::Model> CMModel;
539539
std::string MArch;
540540
std::string MCPU;
541541
SmallVector<std::string, 4> MAttrs;

include/llvm/LTO/Config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct Config {
4040
TargetOptions Options;
4141
std::vector<std::string> MAttrs;
4242
Optional<Reloc::Model> RelocModel = Reloc::PIC_;
43-
CodeModel::Model CodeModel = CodeModel::Default;
43+
Optional<CodeModel::Model> CodeModel = None;
4444
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
4545
TargetMachine::CodeGenFileType CGFileType = TargetMachine::CGFT_ObjectFile;
4646
unsigned OptLevel = 2;

include/llvm/Support/CodeGen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace llvm {
2525
// Code model types.
2626
namespace CodeModel {
2727
// Sync changes with CodeGenCWrappers.h.
28-
enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
28+
enum Model { Small, Kernel, Medium, Large };
2929
}
3030

3131
namespace PICLevel {

include/llvm/Support/CodeGenCWrappers.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222

2323
namespace llvm {
2424

25-
inline CodeModel::Model unwrap(LLVMCodeModel Model) {
25+
inline Optional<CodeModel::Model> unwrap(LLVMCodeModel Model, bool &JIT) {
26+
JIT = false;
2627
switch (Model) {
27-
case LLVMCodeModelDefault:
28-
return CodeModel::Default;
2928
case LLVMCodeModelJITDefault:
30-
return CodeModel::JITDefault;
29+
JIT = true;
30+
case LLVMCodeModelDefault:
31+
return None;
3132
case LLVMCodeModelSmall:
3233
return CodeModel::Small;
3334
case LLVMCodeModelKernel:
@@ -37,15 +38,11 @@ inline CodeModel::Model unwrap(LLVMCodeModel Model) {
3738
case LLVMCodeModelLarge:
3839
return CodeModel::Large;
3940
}
40-
return CodeModel::Default;
41+
return CodeModel::Small;
4142
}
4243

4344
inline LLVMCodeModel wrap(CodeModel::Model Model) {
4445
switch (Model) {
45-
case CodeModel::Default:
46-
return LLVMCodeModelDefault;
47-
case CodeModel::JITDefault:
48-
return LLVMCodeModelJITDefault;
4946
case CodeModel::Small:
5047
return LLVMCodeModelSmall;
5148
case CodeModel::Kernel:

include/llvm/Support/TargetRegistry.h

+17-38
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,16 @@ class Target {
101101

102102
using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
103103
const Triple &TT);
104-
using MCAdjustCodeGenOptsFnTy = void (*)(const Triple &TT, Reloc::Model RM,
105-
CodeModel::Model &CM);
106-
107104
using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
108105
using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
109106
using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
110107
using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
111108
StringRef CPU,
112109
StringRef Features);
113-
using TargetMachineCtorTy = TargetMachine *(*)(
114-
const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
115-
const TargetOptions &Options, Optional<Reloc::Model> RM,
116-
CodeModel::Model CM, CodeGenOpt::Level OL);
110+
using TargetMachineCtorTy = TargetMachine
111+
*(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
112+
const TargetOptions &Options, Optional<Reloc::Model> RM,
113+
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT);
117114
// If it weren't for layering issues (this header is in llvm/Support, but
118115
// depends on MC?) this should take the Streamer by value rather than rvalue
119116
// reference.
@@ -191,8 +188,6 @@ class Target {
191188
/// registered.
192189
MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
193190

194-
MCAdjustCodeGenOptsFnTy MCAdjustCodeGenOptsFn;
195-
196191
/// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
197192
/// if registered.
198193
MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
@@ -312,12 +307,6 @@ class Target {
312307
return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
313308
}
314309

315-
void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
316-
CodeModel::Model &CM) const {
317-
if (MCAdjustCodeGenOptsFn)
318-
MCAdjustCodeGenOptsFn(TT, RM, CM);
319-
}
320-
321310
/// createMCInstrInfo - Create a MCInstrInfo implementation.
322311
///
323312
MCInstrInfo *createMCInstrInfo() const {
@@ -365,15 +354,17 @@ class Target {
365354
/// feature set; it should always be provided. Generally this should be
366355
/// either the target triple from the module, or the target triple of the
367356
/// host if that does not exist.
368-
TargetMachine *
369-
createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
370-
const TargetOptions &Options, Optional<Reloc::Model> RM,
371-
CodeModel::Model CM = CodeModel::Default,
372-
CodeGenOpt::Level OL = CodeGenOpt::Default) const {
357+
TargetMachine *createTargetMachine(StringRef TT, StringRef CPU,
358+
StringRef Features,
359+
const TargetOptions &Options,
360+
Optional<Reloc::Model> RM,
361+
Optional<CodeModel::Model> CM = None,
362+
CodeGenOpt::Level OL = CodeGenOpt::Default,
363+
bool JIT = false) const {
373364
if (!TargetMachineCtorFn)
374365
return nullptr;
375366
return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
376-
CM, OL);
367+
CM, OL, JIT);
377368
}
378369

379370
/// createMCAsmBackend - Create a target specific assembly parser.
@@ -663,11 +654,6 @@ struct TargetRegistry {
663654
T.MCAsmInfoCtorFn = Fn;
664655
}
665656

666-
static void registerMCAdjustCodeGenOpts(Target &T,
667-
Target::MCAdjustCodeGenOptsFnTy Fn) {
668-
T.MCAdjustCodeGenOptsFn = Fn;
669-
}
670-
671657
/// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
672658
/// given target.
673659
///
@@ -929,12 +915,6 @@ struct RegisterMCAsmInfoFn {
929915
}
930916
};
931917

932-
struct RegisterMCAdjustCodeGenOptsFn {
933-
RegisterMCAdjustCodeGenOptsFn(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn) {
934-
TargetRegistry::registerMCAdjustCodeGenOpts(T, Fn);
935-
}
936-
};
937-
938918
/// RegisterMCInstrInfo - Helper template for registering a target instruction
939919
/// info implementation. This invokes the static "Create" method on the class
940920
/// to actually do the construction. Usage:
@@ -1080,12 +1060,11 @@ template <class TargetMachineImpl> struct RegisterTargetMachine {
10801060
}
10811061

10821062
private:
1083-
static TargetMachine *Allocator(const Target &T, const Triple &TT,
1084-
StringRef CPU, StringRef FS,
1085-
const TargetOptions &Options,
1086-
Optional<Reloc::Model> RM,
1087-
CodeModel::Model CM, CodeGenOpt::Level OL) {
1088-
return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1063+
static TargetMachine *
1064+
Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1065+
const TargetOptions &Options, Optional<Reloc::Model> RM,
1066+
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT) {
1067+
return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
10891068
}
10901069
};
10911070

include/llvm/Target/TargetMachine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class TargetMachine {
7878
std::string TargetFS;
7979

8080
Reloc::Model RM = Reloc::Static;
81-
CodeModel::Model CMModel = CodeModel::Default;
81+
CodeModel::Model CMModel = CodeModel::Small;
8282
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
8383

8484
/// Contains target specific asm information.

lib/CodeGen/LLVMTargetMachine.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
7777
Reloc::Model RM, CodeModel::Model CM,
7878
CodeGenOpt::Level OL)
7979
: TargetMachine(T, DataLayoutString, TT, CPU, FS, Options) {
80-
T.adjustCodeGenOpts(TT, RM, CM);
8180
this->RM = RM;
8281
this->CMModel = CM;
8382
this->OptLevel = OL;

lib/ExecutionEngine/ExecutionEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ EngineBuilder::EngineBuilder() : EngineBuilder(nullptr) {}
476476
EngineBuilder::EngineBuilder(std::unique_ptr<Module> M)
477477
: M(std::move(M)), WhichEngine(EngineKind::Either), ErrorStr(nullptr),
478478
OptLevel(CodeGenOpt::Default), MemMgr(nullptr), Resolver(nullptr),
479-
CMModel(CodeModel::JITDefault), UseOrcMCJITReplacement(false) {
479+
UseOrcMCJITReplacement(false) {
480480
// IR module verification is enabled by default in debug builds, and disabled
481481
// by default in release builds.
482482
#ifndef NDEBUG

lib/ExecutionEngine/ExecutionEngineBindings.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ LLVMBool LLVMCreateMCJITCompilerForModule(
198198
builder.setEngineKind(EngineKind::JIT)
199199
.setErrorStr(&Error)
200200
.setOptLevel((CodeGenOpt::Level)options.OptLevel)
201-
.setCodeModel(unwrap(options.CodeModel))
202201
.setTargetOptions(targetOptions);
202+
bool JIT;
203+
if (Optional<CodeModel::Model> CM = unwrap(options.CodeModel, JIT))
204+
builder.setCodeModel(*CM);
203205
if (options.MCJMM)
204206
builder.setMCJITMemoryManager(
205207
std::unique_ptr<RTDyldMemoryManager>(unwrap(options.MCJMM)));

lib/ExecutionEngine/TargetSelect.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
9292
}
9393

9494
// Allocate a target...
95-
TargetMachine *Target = TheTarget->createTargetMachine(TheTriple.getTriple(),
96-
MCPU, FeaturesStr,
97-
Options,
98-
RelocModel, CMModel,
99-
OptLevel);
95+
TargetMachine *Target =
96+
TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr,
97+
Options, RelocModel, CMModel, OptLevel,
98+
/*JIT*/ true);
10099
assert(Target && "Could not allocate target machine!");
101100
return Target;
102101
}

lib/LTO/LTO.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ static void computeCacheKey(
118118
AddUnsigned(*Conf.RelocModel);
119119
else
120120
AddUnsigned(-1);
121-
AddUnsigned(Conf.CodeModel);
121+
if (Conf.CodeModel)
122+
AddUnsigned(*Conf.CodeModel);
123+
else
124+
AddUnsigned(-1);
122125
AddUnsigned(Conf.CGOptLevel);
123126
AddUnsigned(Conf.CGFileType);
124127
AddUnsigned(Conf.OptLevel);

lib/LTO/LTOCodeGenerator.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ bool LTOCodeGenerator::determineTarget() {
368368
}
369369

370370
std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
371-
return std::unique_ptr<TargetMachine>(
372-
MArch->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
373-
RelocModel, CodeModel::Default, CGOptLevel));
371+
return std::unique_ptr<TargetMachine>(MArch->createTargetMachine(
372+
TripleStr, MCpu, FeatureStr, Options, RelocModel, None, CGOptLevel));
374373
}
375374

376375
// If a linkonce global is present in the MustPreserveSymbols, we need to make

lib/LTO/ThinLTOCodeGenerator.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
583583
Features.getDefaultSubtargetFeatures(TheTriple);
584584
std::string FeatureStr = Features.getString();
585585

586-
return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
587-
TheTriple.str(), MCpu, FeatureStr, Options, RelocModel,
588-
CodeModel::Default, CGOptLevel));
586+
return std::unique_ptr<TargetMachine>(
587+
TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
588+
RelocModel, None, CGOptLevel));
589589
}
590590

591591
/**

lib/Target/AArch64/AArch64TargetMachine.cpp

+38-14
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,42 @@ static Reloc::Model getEffectiveRelocModel(const Triple &TT,
206206
return *RM;
207207
}
208208

209+
static CodeModel::Model getEffectiveCodeModel(const Triple &TT,
210+
Optional<CodeModel::Model> CM,
211+
bool JIT) {
212+
if (CM) {
213+
if (*CM != CodeModel::Small && *CM != CodeModel::Large) {
214+
if (!TT.isOSFuchsia())
215+
report_fatal_error(
216+
"Only small and large code models are allowed on AArch64");
217+
else if (CM != CodeModel::Kernel)
218+
report_fatal_error(
219+
"Only small, kernel, and large code models are allowed on AArch64");
220+
}
221+
return *CM;
222+
}
223+
// The default MCJIT memory managers make no guarantees about where they can
224+
// find an executable page; JITed code needs to be able to refer to globals
225+
// no matter how far away they are.
226+
if (JIT)
227+
return CodeModel::Large;
228+
return CodeModel::Small;
229+
}
230+
209231
/// Create an AArch64 architecture model.
210232
///
211-
AArch64TargetMachine::AArch64TargetMachine(
212-
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
213-
const TargetOptions &Options, Optional<Reloc::Model> RM,
214-
CodeModel::Model CM, CodeGenOpt::Level OL, bool LittleEndian)
215-
: LLVMTargetMachine(T, computeDataLayout(TT, Options.MCOptions,
216-
LittleEndian),
217-
TT, CPU, FS, Options,
218-
getEffectiveRelocModel(TT, RM), CM, OL),
219-
TLOF(createTLOF(getTargetTriple())),
220-
isLittle(LittleEndian) {
233+
AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
234+
StringRef CPU, StringRef FS,
235+
const TargetOptions &Options,
236+
Optional<Reloc::Model> RM,
237+
Optional<CodeModel::Model> CM,
238+
CodeGenOpt::Level OL, bool JIT,
239+
bool LittleEndian)
240+
: LLVMTargetMachine(T,
241+
computeDataLayout(TT, Options.MCOptions, LittleEndian),
242+
TT, CPU, FS, Options, getEffectiveRelocModel(TT, RM),
243+
getEffectiveCodeModel(TT, CM, JIT), OL),
244+
TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
221245
initAsmInfo();
222246
}
223247

@@ -252,16 +276,16 @@ void AArch64leTargetMachine::anchor() { }
252276
AArch64leTargetMachine::AArch64leTargetMachine(
253277
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
254278
const TargetOptions &Options, Optional<Reloc::Model> RM,
255-
CodeModel::Model CM, CodeGenOpt::Level OL)
256-
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
279+
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT)
280+
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
257281

258282
void AArch64beTargetMachine::anchor() { }
259283

260284
AArch64beTargetMachine::AArch64beTargetMachine(
261285
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
262286
const TargetOptions &Options, Optional<Reloc::Model> RM,
263-
CodeModel::Model CM, CodeGenOpt::Level OL)
264-
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
287+
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT)
288+
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, false) {}
265289

266290
namespace {
267291

0 commit comments

Comments
 (0)