mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 13:36:49 +00:00
Merge 530b56523b
into 65fa0ab924
This commit is contained in:
commit
b43ab86220
@ -28,8 +28,9 @@ use crate::back::write::{
|
||||
use crate::errors::{
|
||||
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
|
||||
};
|
||||
use crate::llvm::{self, build_string};
|
||||
use crate::{LlvmCodegenBackend, ModuleLlvm};
|
||||
use crate::llvm::AttributePlace::Function;
|
||||
use crate::llvm::{self, build_string, get_value_name};
|
||||
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, attributes};
|
||||
|
||||
/// We keep track of the computed LTO cache keys from the previous
|
||||
/// session to determine which CGUs we can reuse.
|
||||
@ -664,6 +665,19 @@ pub(crate) fn run_pass_manager(
|
||||
unsafe { llvm::LLVMDumpModule(module.module_llvm.llmod()) };
|
||||
}
|
||||
|
||||
let cx =
|
||||
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
|
||||
|
||||
for function in cx.get_functions() {
|
||||
let name = get_value_name(function);
|
||||
let name = std::str::from_utf8(name).unwrap();
|
||||
|
||||
if name.starts_with("__enzyme") {
|
||||
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
|
||||
attributes::apply_to_llfn(function, Function, &[attr]);
|
||||
}
|
||||
}
|
||||
|
||||
let opt_stage = llvm::OptStage::FatLTO;
|
||||
let stage = write::AutodiffStage::PostAD;
|
||||
unsafe {
|
||||
|
@ -698,6 +698,16 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
||||
llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr() as *const c_char, name.len())
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_functions(&self) -> Vec<&'ll Value> {
|
||||
let mut functions = vec![];
|
||||
let mut func = unsafe { llvm::LLVMGetFirstFunction(self.llmod()) };
|
||||
while let Some(f) = func {
|
||||
functions.push(f);
|
||||
func = unsafe { llvm::LLVMGetNextFunction(f) }
|
||||
}
|
||||
functions
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
|
@ -1157,6 +1157,10 @@ unsafe extern "C" {
|
||||
pub(crate) fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
|
||||
pub(crate) fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
|
||||
pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
|
||||
|
||||
pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
|
||||
pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
|
||||
|
||||
pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value);
|
||||
pub(crate) fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
|
||||
pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
|
||||
|
@ -128,6 +128,10 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
||||
(**self).borrow().llcx
|
||||
}
|
||||
|
||||
pub(crate) fn llmod(&self) -> &'ll llvm::Module {
|
||||
(**self).borrow().llmod
|
||||
}
|
||||
|
||||
pub(crate) fn isize_ty(&self) -> &'ll Type {
|
||||
(**self).borrow().isize_ty
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user