Skip to content

Commit

Permalink
add new debug helper to print module
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 committed Sep 18, 2023
1 parent 1133603 commit 3dd3c8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ cargo +enzyme test --examples
```

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

We want to make sure that we have EnzymeStrictAliasing=0 all the time to make sure
that Enzyme handles enums correctly. Other flags might be enabled for debug purpose.
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use llvm::{
LLVMVoidTypeInContext, LLVMGlobalGetValueType, LLVMGetStringAttributeAtIndex,
LLVMIsStringAttribute, LLVMRemoveStringAttributeAtIndex, LLVMRemoveEnumAttributeAtIndex, AttributeKind,
LLVMGetFirstFunction, LLVMGetNextFunction, LLVMGetEnumAttributeAtIndex, LLVMIsEnumAttribute,
LLVMCreateStringAttribute, LLVMRustAddFunctionAttributes, LLVMCreateEnumAttribute
LLVMCreateStringAttribute, LLVMRustAddFunctionAttributes, LLVMCreateEnumAttribute, LLVMDumpModule
};
//use llvm::LLVMRustGetNamedValue;
use rustc_codegen_ssa::back::link::ensure_removed;
Expand Down Expand Up @@ -746,6 +746,10 @@ pub(crate) unsafe fn differentiate(

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

if std::env::var("ENZYME_PRINT_MOD").is_ok() {
unsafe {LLVMDumpModule(llmod);}

}
for item in diff_items {
let res = enzyme_ad(llmod, llcx, item);
assert!(res.is_ok());
Expand Down

0 comments on commit 3dd3c8e

Please sign in to comment.