mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00

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.
64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
//===-- cl_options-llvm.cpp -----------------------------------------------===//
|
||
//
|
||
// LDC – the LLVM D compiler
|
||
//
|
||
// This file is distributed under the BSD-style LDC license. See the LICENSE
|
||
// file for details.
|
||
//
|
||
//===----------------------------------------------------------------------===//
|
||
|
||
#include "driver/cl_options-llvm.h"
|
||
|
||
// Pull in command-line options and helper functions from special LLVM header
|
||
// shared by multiple LLVM tools.
|
||
#include "llvm/CodeGen/CommandFlags.h"
|
||
|
||
static cl::opt<bool>
|
||
DisableRedZone("disable-red-zone", cl::ZeroOrMore,
|
||
cl::desc("Do not emit code that uses the red zone."));
|
||
|
||
// Now expose the helper functions (with static linkage) via external wrappers
|
||
// in the opts namespace, including some additional helper functions.
|
||
namespace opts {
|
||
|
||
std::string getArchStr() { return ::MArch; }
|
||
|
||
#if LDC_LLVM_VER >= 309
|
||
Optional<Reloc::Model> getRelocModel() { return ::getRelocModel(); }
|
||
#else
|
||
Reloc::Model getRelocModel() { return ::RelocModel; }
|
||
#endif
|
||
|
||
CodeModel::Model getCodeModel() { return ::CMModel; }
|
||
|
||
bool disableFPElim() { return ::DisableFPElim; }
|
||
|
||
bool disableRedZone() { return ::DisableRedZone; }
|
||
|
||
bool printTargetFeaturesHelp() {
|
||
if (MCPU == "help")
|
||
return true;
|
||
return std::any_of(MAttrs.begin(), MAttrs.end(),
|
||
[](const std::string &a) { return a == "help"; });
|
||
}
|
||
|
||
TargetOptions InitTargetOptionsFromCodeGenFlags() {
|
||
return ::InitTargetOptionsFromCodeGenFlags();
|
||
}
|
||
|
||
std::string getCPUStr() { return ::getCPUStr(); }
|
||
std::string getFeaturesStr() { return ::getFeaturesStr(); }
|
||
} // namespace opts
|
||
|
||
#if LDC_WITH_LLD && LDC_LLVM_VER >= 500
|
||
// LLD 5.0 uses the shared header too (for LTO) and exposes some wrappers in
|
||
// the lld namespace. Define them here to prevent the LLD object from being
|
||
// linked in with its conflicting command-line options.
|
||
namespace lld {
|
||
TargetOptions InitTargetOptionsFromCodeGenFlags() {
|
||
return ::InitTargetOptionsFromCodeGenFlags();
|
||
}
|
||
|
||
CodeModel::Model GetCodeModelFromCMModel() { return CMModel; }
|
||
}
|
||
#endif // LDC_WITH_LLD && LDC_LLVM_VER >= 500
|