Add LLVM module flags required for the VFE opt
To apply the optimization the `Virtual Function Elim` module flag has to be set. To apply this optimization post-link the `LTOPostLink` module flag has to be set.
This commit is contained in:
parent
def3fd8e92
commit
20f597ffcd
@ -586,9 +586,21 @@ pub(crate) fn run_pass_manager(
|
|||||||
// LTO-specific optimization passes that LLVM provides.
|
// LTO-specific optimization passes that LLVM provides.
|
||||||
//
|
//
|
||||||
// This code is based off the code found in llvm's LTO code generator:
|
// This code is based off the code found in llvm's LTO code generator:
|
||||||
// tools/lto/LTOCodeGenerator.cpp
|
// llvm/lib/LTO/LTOCodeGenerator.cpp
|
||||||
debug!("running the pass manager");
|
debug!("running the pass manager");
|
||||||
unsafe {
|
unsafe {
|
||||||
|
if !llvm::LLVMRustHasModuleFlag(
|
||||||
|
module.module_llvm.llmod(),
|
||||||
|
"LTOPostLink".as_ptr().cast(),
|
||||||
|
11,
|
||||||
|
) {
|
||||||
|
llvm::LLVMRustAddModuleFlag(
|
||||||
|
module.module_llvm.llmod(),
|
||||||
|
llvm::LLVMModFlagBehavior::Error,
|
||||||
|
"LTOPostLink\0".as_ptr().cast(),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
if llvm_util::should_use_new_llvm_pass_manager(
|
if llvm_util::should_use_new_llvm_pass_manager(
|
||||||
&config.new_llvm_pass_manager,
|
&config.new_llvm_pass_manager,
|
||||||
&cgcx.target_arch,
|
&cgcx.target_arch,
|
||||||
|
@ -326,6 +326,15 @@ pub unsafe fn create_module<'ll>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sess.opts.debugging_opts.virtual_function_elimination {
|
||||||
|
llvm::LLVMRustAddModuleFlag(
|
||||||
|
llmod,
|
||||||
|
llvm::LLVMModFlagBehavior::Error,
|
||||||
|
"Virtual Function Elim\0".as_ptr().cast(),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
llmod
|
llmod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,6 +1936,7 @@ extern "C" {
|
|||||||
name: *const c_char,
|
name: *const c_char,
|
||||||
value: u32,
|
value: u32,
|
||||||
);
|
);
|
||||||
|
pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;
|
||||||
|
|
||||||
pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
||||||
|
|
||||||
|
@ -672,6 +672,11 @@ extern "C" void LLVMRustAddModuleFlag(
|
|||||||
unwrap(M)->addModuleFlag(MergeBehavior, Name, Value);
|
unwrap(M)->addModuleFlag(MergeBehavior, Name, Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name,
|
||||||
|
size_t Len) {
|
||||||
|
return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" LLVMValueRef LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
|
extern "C" LLVMValueRef LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
|
||||||
return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
|
return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user