Skip to content

Commit

Permalink
Delete Reloc::Default.
Browse files Browse the repository at this point in the history
Having an enum member named Default is quite confusing: Is it distinct
from the others?

This patch removes that member and instead uses Optional<Reloc> in
places where we have a user input that still hasn't been maped to the
default value, which is now clear has no be one of the remaining 3
options.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269988 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed May 18, 2016
1 parent 57380a7 commit ac8db59
Show file tree
Hide file tree
Showing 55 changed files with 319 additions and 228 deletions.
11 changes: 8 additions & 3 deletions include/llvm/CodeGen/CommandFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ MAttrs("mattr",

cl::opt<Reloc::Model> RelocModel(
"relocation-model", cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));

static inline Optional<Reloc::Model> getRelocModel() {
if (RelocModel.getNumOccurrences()) {
Reloc::Model R = RelocModel;
return R;
}
return None;
}

cl::opt<ThreadModel::Model>
TMModel("thread-model",
cl::desc("Choose threading model"),
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/ExecutionEngine/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class EngineBuilder {
std::shared_ptr<MCJITMemoryManager> MemMgr;
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver;
TargetOptions Options;
Reloc::Model RelocModel;
Optional<Reloc::Model> RelocModel;
CodeModel::Model CMModel;
std::string MArch;
std::string MCPU;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/LTO/LTOCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct LTOCodeGenerator {

void setTargetOptions(TargetOptions Options);
void setDebugInfo(lto_debug_model);
void setCodePICModel(Reloc::Model Model) { RelocModel = Model; }
void setCodePICModel(Optional<Reloc::Model> Model) { RelocModel = Model; }

/// Set the file type to be emitted (assembly or object code).
/// The default is TargetMachine::CGFT_ObjectFile.
Expand Down Expand Up @@ -211,7 +211,7 @@ struct LTOCodeGenerator {
bool EmitDwarfDebugInfo = false;
bool ScopeRestrictionsDone = false;
bool HasVerifiedInput = false;
Reloc::Model RelocModel = Reloc::Default;
Optional<Reloc::Model> RelocModel;
StringSet<> MustPreserveSymbols;
StringSet<> AsmUndefinedRefs;
StringMap<GlobalValue::LinkageTypes> ExternalSymbols;
Expand Down
6 changes: 4 additions & 2 deletions include/llvm/LTO/ThinLTOCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct TargetMachineBuilder {
std::string MCpu;
std::string MAttr;
TargetOptions Options;
Reloc::Model RelocModel = Reloc::Default;
Optional<Reloc::Model> RelocModel;
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;

std::unique_ptr<TargetMachine> create() const;
Expand Down Expand Up @@ -168,7 +168,9 @@ class ThinLTOCodeGenerator {
}

/// CodeModel
void setCodePICModel(Reloc::Model Model) { TMBuilder.RelocModel = Model; }
void setCodePICModel(Optional<Reloc::Model> Model) {
TMBuilder.RelocModel = Model;
}

/// CodeGen optimization level
void setCodeGenOptLevel(CodeGenOpt::Level CGOptLevel) {
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Support/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace llvm {

// Relocation model types.
namespace Reloc {
enum Model { Default, Static, PIC_, DynamicNoPIC };
enum Model { Static, PIC_, DynamicNoPIC };
}

// Code model types.
Expand Down
11 changes: 6 additions & 5 deletions include/llvm/Support/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LLVM_SUPPORT_TARGETREGISTRY_H

#include "llvm-c/Disassembler.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/FormattedStream.h"
Expand Down Expand Up @@ -104,8 +105,8 @@ class Target {
StringRef Features);
typedef TargetMachine *(*TargetMachineCtorTy)(
const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL);
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL);
// If it weren't for layering issues (this header is in llvm/Support, but
// depends on MC?) this should take the Streamer by value rather than rvalue
// reference.
Expand Down Expand Up @@ -359,8 +360,7 @@ class Target {
/// host if that does not exist.
TargetMachine *
createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
const TargetOptions &Options,
Reloc::Model RM = Reloc::Default,
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM = CodeModel::Default,
CodeGenOpt::Level OL = CodeGenOpt::Default) const {
if (!TargetMachineCtorFn)
Expand Down Expand Up @@ -1097,7 +1097,8 @@ template <class TargetMachineImpl> struct RegisterTargetMachine {
private:
static TargetMachine *Allocator(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
const TargetOptions &Options, Reloc::Model RM,
const TargetOptions &Options,
Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL) {
return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/ExecutionEngine/ExecutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ EngineBuilder::EngineBuilder() : EngineBuilder(nullptr) {}
EngineBuilder::EngineBuilder(std::unique_ptr<Module> M)
: M(std::move(M)), WhichEngine(EngineKind::Either), ErrorStr(nullptr),
OptLevel(CodeGenOpt::Default), MemMgr(nullptr), Resolver(nullptr),
RelocModel(Reloc::Default), CMModel(CodeModel::JITDefault),
UseOrcMCJITReplacement(false) {
CMModel(CodeModel::JITDefault), UseOrcMCJITReplacement(false) {
// IR module verification is enabled by default in debug builds, and disabled
// by default in release builds.
#ifndef NDEBUG
Expand Down
4 changes: 2 additions & 2 deletions lib/LTO/LTOModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, TargetOptions options,
CPU = "cyclone";
}

TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
options);
TargetMachine *target =
march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None);
M->setDataLayout(target->createDataLayout());

std::unique_ptr<object::IRObjectFile> IRObj(
Expand Down
33 changes: 22 additions & 11 deletions lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,29 @@ static void initReciprocals(AArch64TargetMachine& TM, AArch64Subtarget& ST)
TM.Options.Reciprocals.setDefaults("vec-divd", false, ExtraStepsD);
}

static Reloc::Model getEffectiveRelocModel(const Triple &TT,
Optional<Reloc::Model> RM) {
// AArch64 Darwin is always PIC.
if (TT.isOSDarwin())
return Reloc::PIC_;
// On ELF platforms the default static relocation model has a smart enough
// linker to cope with referencing external symbols defined in a shared
// library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
if (!RM.hasValue() || *RM == Reloc::DynamicNoPIC)
return Reloc::Static;
return *RM;
}

/// Create an AArch64 architecture model.
///
AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
const TargetOptions &Options,
Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL,
bool LittleEndian)
AArch64TargetMachine::AArch64TargetMachine(
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL, bool LittleEndian)
// This nested ternary is horrible, but DL needs to be properly
// initialized before TLInfo is constructed.
: LLVMTargetMachine(T, computeDataLayout(TT, LittleEndian), TT, CPU, FS,
Options, RM, CM, OL),
Options, getEffectiveRelocModel(TT, RM), CM, OL),
TLOF(createTLOF(getTargetTriple())),
Subtarget(TT, CPU, FS, *this, LittleEndian) {
initReciprocals(*this, Subtarget);
Expand Down Expand Up @@ -235,16 +246,16 @@ void AArch64leTargetMachine::anchor() { }

AArch64leTargetMachine::AArch64leTargetMachine(
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL)
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL)
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}

void AArch64beTargetMachine::anchor() { }

AArch64beTargetMachine::AArch64beTargetMachine(
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL)
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL)
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}

namespace {
Expand Down
6 changes: 3 additions & 3 deletions lib/Target/AArch64/AArch64TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AArch64TargetMachine : public LLVMTargetMachine {
public:
AArch64TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Reloc::Model RM, CodeModel::Model CM,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL, bool IsLittleEndian);

~AArch64TargetMachine() override;
Expand All @@ -56,7 +56,7 @@ class AArch64leTargetMachine : public AArch64TargetMachine {
public:
AArch64leTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Reloc::Model RM, CodeModel::Model CM,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL);
};

Expand All @@ -67,7 +67,7 @@ class AArch64beTargetMachine : public AArch64TargetMachine {
public:
AArch64beTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Reloc::Model RM, CodeModel::Model CM,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL);
};

Expand Down
9 changes: 0 additions & 9 deletions lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ static MCCodeGenInfo *createAArch64MCCodeGenInfo(const Triple &TT,
report_fatal_error(
"Only small and large code models are allowed on AArch64");

// AArch64 Darwin is always PIC.
if (TT.isOSDarwin())
RM = Reloc::PIC_;
// On ELF platforms the default static relocation model has a smart enough
// linker to cope with referencing external symbols defined in a shared
// library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
else if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
RM = Reloc::Static;

MCCodeGenInfo *X = new MCCodeGenInfo();
X->initMCCodeGenInfo(RM, CM, OL);
return X;
Expand Down
23 changes: 15 additions & 8 deletions lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,22 @@ static StringRef getGPUOrDefault(const Triple &TT, StringRef GPU) {
return "";
}

static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::PIC_;
return *RM;
}

AMDGPUTargetMachine::AMDGPUTargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
TargetOptions Options, Reloc::Model RM,
TargetOptions Options,
Optional<Reloc::Model> RM,
CodeModel::Model CM,
CodeGenOpt::Level OptLevel)
: LLVMTargetMachine(T, computeDataLayout(TT), TT,
getGPUOrDefault(TT, CPU), FS, Options, RM, CM,
OptLevel),
: LLVMTargetMachine(T, computeDataLayout(TT), TT, getGPUOrDefault(TT, CPU),
FS, Options, getEffectiveRelocModel(RM), CM, OptLevel),
TLOF(createTLOF(getTargetTriple())),
Subtarget(TT, getTargetCPU(), FS, *this),
IntrinsicInfo() {
Subtarget(TT, getTargetCPU(), FS, *this), IntrinsicInfo() {
setRequiresStructuredCFG(true);
initAsmInfo();
}
Expand All @@ -126,7 +131,8 @@ AMDGPUTargetMachine::~AMDGPUTargetMachine() { }

R600TargetMachine::R600TargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
TargetOptions Options, Reloc::Model RM,
TargetOptions Options,
Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL)
: AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}

Expand All @@ -136,7 +142,8 @@ R600TargetMachine::R600TargetMachine(const Target &T, const Triple &TT,

GCNTargetMachine::GCNTargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
TargetOptions Options, Reloc::Model RM,
TargetOptions Options,
Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL)
: AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}

Expand Down
15 changes: 9 additions & 6 deletions lib/Target/AMDGPU/AMDGPUTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class AMDGPUTargetMachine : public LLVMTargetMachine {

public:
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, TargetOptions Options, Reloc::Model RM,
CodeModel::Model CM, CodeGenOpt::Level OL);
StringRef FS, TargetOptions Options,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL);
~AMDGPUTargetMachine();

const AMDGPUSubtarget *getSubtargetImpl() const { return &Subtarget; }
Expand All @@ -64,8 +65,9 @@ class R600TargetMachine final : public AMDGPUTargetMachine {

public:
R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, TargetOptions Options, Reloc::Model RM,
CodeModel::Model CM, CodeGenOpt::Level OL);
StringRef FS, TargetOptions Options,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL);

TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
};
Expand All @@ -78,8 +80,9 @@ class GCNTargetMachine final : public AMDGPUTargetMachine {

public:
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, TargetOptions Options, Reloc::Model RM,
CodeModel::Model CM, CodeGenOpt::Level OL);
StringRef FS, TargetOptions Options,
Optional<Reloc::Model> RM, CodeModel::Model CM,
CodeGenOpt::Level OL);

TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
};
Expand Down
Loading

0 comments on commit ac8db59

Please sign in to comment.