Enzyme
main
Loading...
Searching...
No Matches
PreserveNVVM.h
Go to the documentation of this file.
1
//===- PreserveNVVM.h - Mark NVVM attributes for preservation. -------===//
2
//
3
// Enzyme Project
4
//
5
// Part of the Enzyme Project, under the Apache License v2.0 with LLVM
6
// Exceptions. See https://llvm.org/LICENSE.txt for license information.
7
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
//
9
// If using this code in an academic setting, please cite the following:
10
// @incollection{enzymeNeurips,
11
// title = {Instead of Rewriting Foreign Code for Machine Learning,
12
// Automatically Synthesize Fast Gradients},
13
// author = {Moses, William S. and Churavy, Valentin},
14
// booktitle = {Advances in Neural Information Processing Systems 33},
15
// year = {2020},
16
// note = {To appear in},
17
// }
18
//
19
//===----------------------------------------------------------------------===//
20
//
21
// This file contains createPreserveNVVM, a transformation pass that marks
22
// calls to __nv_* functions, marking them as noinline as implementing the llvm
23
// intrinsic.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#ifndef ENZYME_PRESERVE_NVVM_H
28
#define ENZYME_PRESERVE_NVVM_H
29
30
#include "
PassUtils.h
"
31
#include "llvm/IR/PassManager.h"
32
33
namespace
llvm
{
34
class
ModulePass
;
35
class
FunctionPass;
36
}
// namespace llvm
37
38
llvm::ModulePass *
createPreserveNVVMPass
(
bool
Begin);
39
llvm::FunctionPass *
createPreserveNVVMFnPass
(
bool
Begin);
40
41
class
PreserveNVVMNewPM
final :
public
PassParent
<PreserveNVVMNewPM> {
42
friend
PassParent<PreserveNVVMNewPM>
;
43
44
private
:
45
bool
Begin;
46
// Whether a function named as one half of a custom derivative rule is kept
47
// external and uninlined so the rule can still be resolved later. A pipeline
48
// that does not implement custom rules -- the MLIR one -- has nothing to
49
// resolve them with, and holding the rule's functions in place only keeps
50
// dead code, and the kernels it launches, alive. The globals are consumed
51
// either way.
52
bool
PreserveCustomRuleLinkage;
53
// Only meaningful with !Begin: the end of an LTO pre-link pipeline that
54
// deferred differentiation to the post-link run. The functions Begin made
55
// external get their original linkage back, so the bitcode does not export a
56
// strong copy of every static or inline function a rule names, and are kept
57
// alive through llvm.compiler.used instead. Their inlining attributes stay as
58
// Begin left them; the post-link end pass restores those and drops the
59
// llvm.compiler.used entries.
60
bool
LTOPreLink;
61
static
llvm::AnalysisKey Key;
62
63
public
:
64
using
Result
= llvm::PreservedAnalyses;
65
PreserveNVVMNewPM
(
bool
Begin,
bool
PreserveCustomRuleLinkage =
true
,
66
bool
LTOPreLink =
false
)
67
: Begin(Begin), PreserveCustomRuleLinkage(PreserveCustomRuleLinkage),
68
LTOPreLink(LTOPreLink) {}
69
70
Result
run
(llvm::Module &M, llvm::ModuleAnalysisManager &MAM);
71
72
static
bool
isRequired
() {
return
true
; }
73
};
74
75
#endif
// ENZYME_PRESERVE_NVVM_H
PassUtils.h
createPreserveNVVMPass
llvm::ModulePass * createPreserveNVVMPass(bool Begin)
Definition
PreserveNVVM.cpp:1290
createPreserveNVVMFnPass
llvm::FunctionPass * createPreserveNVVMFnPass(bool Begin)
Definition
PreserveNVVM.cpp:1294
ModulePass
PassParent
PreserveNVVMNewPM
Definition
PreserveNVVM.h:41
PreserveNVVMNewPM::Result
llvm::PreservedAnalyses Result
Definition
PreserveNVVM.h:64
PreserveNVVMNewPM::PreserveNVVMNewPM
PreserveNVVMNewPM(bool Begin, bool PreserveCustomRuleLinkage=true, bool LTOPreLink=false)
Definition
PreserveNVVM.h:65
PreserveNVVMNewPM::run
Result run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM)
Definition
PreserveNVVM.cpp:1308
PreserveNVVMNewPM::isRequired
static bool isRequired()
Definition
PreserveNVVM.h:72
llvm
Definition
ActivityAnalysisPrinter.h:34
Generated on Tue Oct 13 2026 01:33:28 for Enzyme by
1.12.0