Skip to content

Commit 483fefb

Browse files
authored
Merge pull request #42 from EnzymeAD/print-module
add new debug helper to print module
2 parents 81db9e4 + 3dd3c8e commit 483fefb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ cargo +enzyme test --examples
3535
```
3636

3737
## Enzyme Config
38-
To help with debugging, Enzyme can be configured using three environment variables.
38+
To help with debugging, Enzyme can be configured using four environment variables.
3939
```bash
4040
export ENZYME_PRINT_TA=1
4141
export ENZYME_PRINT_AA=1
4242
export ENZYME_PRINT=1
43+
export ENZYME_PRINT_MOD=1
4344
```
44-
These will print TypeAnalysis, ActivityAnalysis and the primal + generated function respectively.
45+
The first three will print TypeAnalysis, ActivityAnalysis and the llvm-ir on a function basis, respectively.
46+
The last variable can be used to print the whole module directly before Enzyme starts
47+
differentiating functions.
4548

4649
We want to make sure that we have EnzymeStrictAliasing=0 all the time to make sure
4750
that Enzyme handles enums correctly. Other flags might be enabled for debug purpose.

compiler/rustc_codegen_llvm/src/back/write.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use llvm::{
2626
LLVMVoidTypeInContext, LLVMGlobalGetValueType, LLVMGetStringAttributeAtIndex,
2727
LLVMIsStringAttribute, LLVMRemoveStringAttributeAtIndex, LLVMRemoveEnumAttributeAtIndex, AttributeKind,
2828
LLVMGetFirstFunction, LLVMGetNextFunction, LLVMGetEnumAttributeAtIndex, LLVMIsEnumAttribute,
29-
LLVMCreateStringAttribute, LLVMRustAddFunctionAttributes, LLVMCreateEnumAttribute
29+
LLVMCreateStringAttribute, LLVMRustAddFunctionAttributes, LLVMCreateEnumAttribute, LLVMDumpModule
3030
};
3131
//use llvm::LLVMRustGetNamedValue;
3232
use rustc_codegen_ssa::back::link::ensure_removed;
@@ -746,6 +746,10 @@ pub(crate) unsafe fn differentiate(
746746

747747
llvm::EnzymeSetCLBool(std::ptr::addr_of_mut!(llvm::EnzymeStrictAliasing), 0);
748748

749+
if std::env::var("ENZYME_PRINT_MOD").is_ok() {
750+
unsafe {LLVMDumpModule(llmod);}
751+
752+
}
749753
for item in diff_items {
750754
let res = enzyme_ad(llmod, llcx, item);
751755
assert!(res.is_ok());

0 commit comments

Comments
 (0)