Auto merge of #72248 - petrochenkov:codemodel, r=Amanieu

Cleanup and document `-C code-model`

r? @Amanieu
This commit is contained in:
bors 2020-05-17 21:22:48 +00:00
commit 5f472813df
15 changed files with 125 additions and 57 deletions

View file

@ -274,7 +274,7 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
}
enum class LLVMRustCodeModel {
Other,
Tiny,
Small,
Kernel,
Medium,
@ -282,8 +282,10 @@ enum class LLVMRustCodeModel {
None,
};
static CodeModel::Model fromRust(LLVMRustCodeModel Model) {
static Optional<CodeModel::Model> fromRust(LLVMRustCodeModel Model) {
switch (Model) {
case LLVMRustCodeModel::Tiny:
return CodeModel::Tiny;
case LLVMRustCodeModel::Small:
return CodeModel::Small;
case LLVMRustCodeModel::Kernel:
@ -292,6 +294,8 @@ static CodeModel::Model fromRust(LLVMRustCodeModel Model) {
return CodeModel::Medium;
case LLVMRustCodeModel::Large:
return CodeModel::Large;
case LLVMRustCodeModel::None:
return None;
default:
report_fatal_error("Bad CodeModel.");
}
@ -452,6 +456,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
auto CM = fromRust(RustCM);
std::string Error;
Triple Trip(Triple::normalize(TripleStr));
@ -490,9 +495,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
Options.EmitStackSizeSection = EmitStackSizeSection;
Optional<CodeModel::Model> CM;
if (RustCM != LLVMRustCodeModel::None)
CM = fromRust(RustCM);
TargetMachine *TM = TheTarget->createTargetMachine(
Trip.getTriple(), CPU, Feature, Options, RM, CM, OptLevel);
return wrap(TM);