diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp | 202 |
1 files changed, 155 insertions, 47 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp b/contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp index 7cd29b40da12..80024f9a6d5d 100644 --- a/contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp +++ b/contrib/llvm-project/llvm/lib/Target/TargetMachineC.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/CodeGenCWrappers.h" @@ -28,6 +29,24 @@ using namespace llvm; +namespace llvm { + +/// Options for LLVMCreateTargetMachine(). +struct LLVMTargetMachineOptions { + std::string CPU; + std::string Features; + std::string ABI; + CodeGenOptLevel OL = CodeGenOptLevel::Default; + std::optional<Reloc::Model> RM; + std::optional<CodeModel::Model> CM; + bool JIT; +}; + +} // namespace llvm + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMTargetMachineOptions, + LLVMTargetMachineOptionsRef) + static TargetMachine *unwrap(LLVMTargetMachineRef P) { return reinterpret_cast<TargetMachine *>(P); } @@ -96,56 +115,114 @@ LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T) { return unwrap(T)->hasMCAsmBackend(); } -LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, - const char *Triple, const char *CPU, const char *Features, - LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, - LLVMCodeModel CodeModel) { - std::optional<Reloc::Model> RM; - switch (Reloc){ - case LLVMRelocStatic: - RM = Reloc::Static; - break; - case LLVMRelocPIC: - RM = Reloc::PIC_; - break; - case LLVMRelocDynamicNoPic: - RM = Reloc::DynamicNoPIC; - break; - case LLVMRelocROPI: - RM = Reloc::ROPI; - break; - case LLVMRelocRWPI: - RM = Reloc::RWPI; - break; - case LLVMRelocROPI_RWPI: - RM = Reloc::ROPI_RWPI; - break; - default: - break; - } +LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void) { + return wrap(new LLVMTargetMachineOptions()); +} - bool JIT; - std::optional<CodeModel::Model> CM = unwrap(CodeModel, JIT); +void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options) { + delete unwrap(Options); +} + +void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options, + const char *CPU) { + unwrap(Options)->CPU = CPU; +} + +void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options, + const char *Features) { + unwrap(Options)->Features = Features; +} + +void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options, + const char *ABI) { + unwrap(Options)->ABI = ABI; +} + +void LLVMTargetMachineOptionsSetCodeGenOptLevel( + LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level) { + CodeGenOptLevel OL; - CodeGenOpt::Level OL; switch (Level) { - case LLVMCodeGenLevelNone: - OL = CodeGenOpt::None; - break; - case LLVMCodeGenLevelLess: - OL = CodeGenOpt::Less; - break; - case LLVMCodeGenLevelAggressive: - OL = CodeGenOpt::Aggressive; - break; - default: - OL = CodeGenOpt::Default; - break; + case LLVMCodeGenLevelNone: + OL = CodeGenOptLevel::None; + break; + case LLVMCodeGenLevelLess: + OL = CodeGenOptLevel::Less; + break; + case LLVMCodeGenLevelAggressive: + OL = CodeGenOptLevel::Aggressive; + break; + case LLVMCodeGenLevelDefault: + OL = CodeGenOptLevel::Default; + break; + } + + unwrap(Options)->OL = OL; +} + +void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options, + LLVMRelocMode Reloc) { + std::optional<Reloc::Model> RM; + + switch (Reloc) { + case LLVMRelocStatic: + RM = Reloc::Static; + break; + case LLVMRelocPIC: + RM = Reloc::PIC_; + break; + case LLVMRelocDynamicNoPic: + RM = Reloc::DynamicNoPIC; + break; + case LLVMRelocROPI: + RM = Reloc::ROPI; + break; + case LLVMRelocRWPI: + RM = Reloc::RWPI; + break; + case LLVMRelocROPI_RWPI: + RM = Reloc::ROPI_RWPI; + break; + case LLVMRelocDefault: + break; } - TargetOptions opt; - return wrap(unwrap(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, - OL, JIT)); + unwrap(Options)->RM = RM; +} + +void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options, + LLVMCodeModel CodeModel) { + auto CM = unwrap(CodeModel, unwrap(Options)->JIT); + unwrap(Options)->CM = CM; +} + +LLVMTargetMachineRef +LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple, + LLVMTargetMachineOptionsRef Options) { + auto *Opt = unwrap(Options); + TargetOptions TO; + TO.MCOptions.ABIName = Opt->ABI; + return wrap(unwrap(T)->createTargetMachine(Triple, Opt->CPU, Opt->Features, + TO, Opt->RM, Opt->CM, Opt->OL, + Opt->JIT)); +} + +LLVMTargetMachineRef +LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, + const char *Features, LLVMCodeGenOptLevel Level, + LLVMRelocMode Reloc, LLVMCodeModel CodeModel) { + auto *Options = LLVMCreateTargetMachineOptions(); + + LLVMTargetMachineOptionsSetCPU(Options, CPU); + LLVMTargetMachineOptionsSetFeatures(Options, Features); + LLVMTargetMachineOptionsSetCodeGenOptLevel(Options, Level); + LLVMTargetMachineOptionsSetRelocMode(Options, Reloc); + LLVMTargetMachineOptionsSetCodeModel(Options, CodeModel); + + auto *Machine = LLVMCreateTargetMachineWithOptions(T, Triple, Options); + + LLVMDisposeTargetMachineOptions(Options); + return Machine; } void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { delete unwrap(T); } @@ -175,6 +252,37 @@ void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm; } +void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable) { + unwrap(T)->setFastISel(Enable); +} + +void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable) { + unwrap(T)->setGlobalISel(Enable); +} + +void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, + LLVMGlobalISelAbortMode Mode) { + GlobalISelAbortMode AM = GlobalISelAbortMode::Enable; + switch (Mode) { + case LLVMGlobalISelAbortDisable: + AM = GlobalISelAbortMode::Disable; + break; + case LLVMGlobalISelAbortEnable: + AM = GlobalISelAbortMode::Enable; + break; + case LLVMGlobalISelAbortDisableWithDiag: + AM = GlobalISelAbortMode::DisableWithDiag; + break; + } + + unwrap(T)->setGlobalISelAbort(AM); +} + +void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, + LLVMBool Enable) { + unwrap(T)->setMachineOutliner(Enable); +} + LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T) { return wrap(new DataLayout(unwrap(T)->createDataLayout())); } @@ -195,10 +303,10 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, CodeGenFileType ft; switch (codegen) { case LLVMAssemblyFile: - ft = CGFT_AssemblyFile; + ft = CodeGenFileType::AssemblyFile; break; default: - ft = CGFT_ObjectFile; + ft = CodeGenFileType::ObjectFile; break; } if (TM->addPassesToEmitFile(pass, OS, nullptr, ft)) { |