core: Add legacy_pm and target fields to CodeGenLLVMOptions
For specifying whether to use the legacy PM and the target machine options when optimizing and linking. Both fields are currently unused but will be required in a future commit.
This commit is contained in:
parent
7c38f097cb
commit
70cb0bd898
|
@ -902,6 +902,8 @@ impl Nac3 {
|
|||
deferred_eval_store: DeferredEvaluationStore::new(),
|
||||
llvm_options: CodeGenLLVMOptions {
|
||||
opt_level: OptimizationLevel::Default,
|
||||
legacy_pm: true,
|
||||
target: Nac3::get_llvm_target_options(isa),
|
||||
emit_llvm: false,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -65,6 +65,13 @@ lazy_static!(
|
|||
pub struct CodeGenLLVMOptions {
|
||||
/// The optimization level to apply on the generated LLVM IR.
|
||||
pub opt_level: OptimizationLevel,
|
||||
|
||||
/// Whether to use LLVM's Legacy Pass Manager.
|
||||
pub legacy_pm: bool,
|
||||
|
||||
/// Options related to the target machine.
|
||||
pub target: CodeGenTargetMachineOptions,
|
||||
|
||||
/// Whether to output the LLVM IR after generation is complete.
|
||||
pub emit_llvm: bool,
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
codegen::{
|
||||
concrete_type::ConcreteTypeStore, CodeGenContext, CodeGenLLVMOptions, CodeGenTask,
|
||||
DefaultCodeGenerator, WithCall, WorkerRegistry,
|
||||
concrete_type::ConcreteTypeStore, CodeGenContext, CodeGenLLVMOptions,
|
||||
CodeGenTargetMachineOptions, CodeGenTask, DefaultCodeGenerator, WithCall, WorkerRegistry,
|
||||
},
|
||||
symbol_resolver::{SymbolResolver, ValueEnum},
|
||||
toplevel::{
|
||||
|
@ -224,6 +224,8 @@ fn test_primitives() {
|
|||
|
||||
let llvm_options = CodeGenLLVMOptions {
|
||||
opt_level: OptimizationLevel::Default,
|
||||
legacy_pm: true,
|
||||
target: CodeGenTargetMachineOptions::from_host_triple(),
|
||||
emit_llvm: false,
|
||||
};
|
||||
let (registry, handles) = WorkerRegistry::create_workers(
|
||||
|
@ -409,6 +411,8 @@ fn test_simple_call() {
|
|||
|
||||
let llvm_options = CodeGenLLVMOptions {
|
||||
opt_level: OptimizationLevel::Default,
|
||||
legacy_pm: true,
|
||||
target: CodeGenTargetMachineOptions::from_host_triple(),
|
||||
emit_llvm: false,
|
||||
};
|
||||
let (registry, handles) = WorkerRegistry::create_workers(
|
||||
|
|
|
@ -10,8 +10,8 @@ use std::{borrow::Borrow, collections::HashMap, fs, path::Path, sync::Arc};
|
|||
|
||||
use nac3core::{
|
||||
codegen::{
|
||||
concrete_type::ConcreteTypeStore, irrt::load_irrt, CodeGenLLVMOptions, CodeGenTask,
|
||||
DefaultCodeGenerator, WithCall, WorkerRegistry,
|
||||
concrete_type::ConcreteTypeStore, irrt::load_irrt, CodeGenLLVMOptions,
|
||||
CodeGenTargetMachineOptions, CodeGenTask, DefaultCodeGenerator, WithCall, WorkerRegistry,
|
||||
},
|
||||
symbol_resolver::SymbolResolver,
|
||||
toplevel::{
|
||||
|
@ -272,8 +272,11 @@ fn main() {
|
|||
|
||||
let llvm_options = CodeGenLLVMOptions {
|
||||
opt_level,
|
||||
legacy_pm: true,
|
||||
target: CodeGenTargetMachineOptions::from_host_triple(),
|
||||
emit_llvm,
|
||||
};
|
||||
|
||||
let task = CodeGenTask {
|
||||
subst: Default::default(),
|
||||
symbol_name: "run".to_string(),
|
||||
|
@ -330,17 +333,8 @@ fn main() {
|
|||
builder.populate_module_pass_manager(&passes);
|
||||
passes.run_on(&main);
|
||||
|
||||
let triple = TargetMachine::get_default_triple();
|
||||
let target = Target::from_triple(&triple).expect("couldn't create target from target triple");
|
||||
let target_machine = target
|
||||
.create_target_machine(
|
||||
&triple,
|
||||
"",
|
||||
"",
|
||||
opt_level,
|
||||
RelocMode::Default,
|
||||
CodeModel::Default,
|
||||
)
|
||||
let target_machine = llvm_options.target
|
||||
.create_target_machine(llvm_options.opt_level)
|
||||
.expect("couldn't create target machine");
|
||||
target_machine
|
||||
.write_to_file(&main, FileType::Object, Path::new("module.o"))
|
||||
|
|
Loading…
Reference in New Issue