mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 00:20:40 +03:00
Use LLVM headers for shared codegen command-line options (#2148)
I.e., llvm/CodeGen/CommandFlags.h which in turn includes llvm/MC/MCTargetOptionsCommandFlags.h. This gets rid of a few duplicates on our side and includes about 35 (depending on LLVM version) new command-line options. LLVM provides a helper function to set up the TargetOptions according to (most of) these options. Newer LLVM versions may add new options and we'll automatically inherit them, including setting up the TargetOptions accordingly. I did my best (TM) to remove a few unused/undesirable options and hide all remaining new ones except for `-fp-contract`. The lists will need to be tweaked from time to time.
This commit is contained in:
parent
0546bd406b
commit
ae9d43c167
14 changed files with 261 additions and 201 deletions
|
@ -104,18 +104,6 @@ static cl::opt<bool> linkDebugLib(
|
|||
"link-debuglib", cl::ZeroOrMore,
|
||||
cl::desc("Link with libraries specified in -debuglib, not -defaultlib"));
|
||||
|
||||
#if LDC_LLVM_VER >= 309
|
||||
static inline llvm::Optional<llvm::Reloc::Model> getRelocModel() {
|
||||
if (mRelocModel.getNumOccurrences()) {
|
||||
llvm::Reloc::Model R = mRelocModel;
|
||||
return R;
|
||||
}
|
||||
return llvm::None;
|
||||
}
|
||||
#else
|
||||
static inline llvm::Reloc::Model getRelocModel() { return mRelocModel; }
|
||||
#endif
|
||||
|
||||
// This function exits the program.
|
||||
void printVersion(llvm::raw_ostream &OS) {
|
||||
OS << "LDC - the LLVM D compiler (" << global.ldc_version << "):\n";
|
||||
|
@ -372,8 +360,7 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
|||
const_cast<char **>(allArguments.data()),
|
||||
"LDC - the LLVM D compiler\n");
|
||||
|
||||
helpOnly = mCPU == "help" ||
|
||||
(std::find(mAttrs.begin(), mAttrs.end(), "help") != mAttrs.end());
|
||||
helpOnly = opts::printTargetFeaturesHelp();
|
||||
if (helpOnly) {
|
||||
auto triple = llvm::Triple(cfg_triple);
|
||||
std::string errMsg;
|
||||
|
@ -599,19 +586,12 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
|||
error(Loc(), "-lib and -shared switches cannot be used together");
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER >= 309
|
||||
if (global.params.dll && !mRelocModel.getNumOccurrences()) {
|
||||
#else
|
||||
if (global.params.dll && mRelocModel == llvm::Reloc::Default) {
|
||||
#endif
|
||||
mRelocModel = llvm::Reloc::PIC_;
|
||||
}
|
||||
|
||||
if (soname.getNumOccurrences() > 0 && !global.params.dll) {
|
||||
error(Loc(), "-soname can be used only when building a shared library");
|
||||
}
|
||||
|
||||
global.params.hdrStripPlainFunctions = !opts::hdrKeepAllBodies;
|
||||
global.params.disableRedZone = opts::disableRedZone();
|
||||
}
|
||||
|
||||
void initializePasses() {
|
||||
|
@ -1010,7 +990,8 @@ int cppmain(int argc, char **argv) {
|
|||
}
|
||||
|
||||
// Set up the TargetMachine.
|
||||
if ((m32bits || m64bits) && (!mArch.empty() || !mTargetTriple.empty())) {
|
||||
const auto arch = getArchStr();
|
||||
if ((m32bits || m64bits) && (!arch.empty() || !mTargetTriple.empty())) {
|
||||
error(Loc(), "-m32 and -m64 switches cannot be used together with -march "
|
||||
"and -mtriple switches");
|
||||
}
|
||||
|
@ -1025,9 +1006,21 @@ int cppmain(int argc, char **argv) {
|
|||
fatal();
|
||||
}
|
||||
|
||||
auto relocModel = getRelocModel();
|
||||
#if LDC_LLVM_VER >= 309
|
||||
if (global.params.dll && !relocModel.hasValue()) {
|
||||
#else
|
||||
if (global.params.dll && relocModel == llvm::Reloc::Default) {
|
||||
#endif
|
||||
relocModel = llvm::Reloc::PIC_;
|
||||
}
|
||||
|
||||
gTargetMachine = createTargetMachine(
|
||||
mTargetTriple, mArch, mCPU, mAttrs, bitness, mFloatABI, getRelocModel(),
|
||||
mCodeModel, codeGenOptLevel(), disableFpElim, disableLinkerStripDead);
|
||||
mTargetTriple, arch, opts::getCPUStr(), opts::getFeaturesStr(), bitness,
|
||||
floatABI, relocModel, opts::getCodeModel(), codeGenOptLevel(),
|
||||
disableLinkerStripDead);
|
||||
|
||||
opts::setDefaultMathOptions(gTargetMachine->Options);
|
||||
|
||||
#if LDC_LLVM_VER >= 308
|
||||
static llvm::DataLayout DL = gTargetMachine->createDataLayout();
|
||||
|
@ -1043,6 +1036,7 @@ int cppmain(int argc, char **argv) {
|
|||
global.params.isLP64 = gDataLayout->getPointerSizeInBits() == 64;
|
||||
global.params.is64bit = triple->isArch64Bit();
|
||||
global.params.hasObjectiveC = objc_isSupported(*triple);
|
||||
global.params.dwarfVersion = gTargetMachine->Options.MCOptions.DwarfVersion;
|
||||
// mscoff enables slightly different handling of interface functions
|
||||
// in the front end
|
||||
global.params.mscoff = triple->isKnownWindowsMSVCEnvironment();
|
||||
|
@ -1050,8 +1044,6 @@ int cppmain(int argc, char **argv) {
|
|||
global.obj_ext = "obj";
|
||||
}
|
||||
|
||||
opts::setDefaultMathOptions(*gTargetMachine);
|
||||
|
||||
// allocate the target abi
|
||||
gABI = TargetABI::getTarget();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue