Enzyme main
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1//===- Utils.h - Utilities for gradient interfaces -------* C++
2//-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#pragma once
10
11#include "mlir/IR/Operation.h"
12#include "mlir/Interfaces/FunctionInterfaces.h"
13#include "mlir/Interfaces/SideEffectInterfaces.h"
14
15namespace mlir {
16namespace enzyme {
17namespace oputils {
18
19const std::set<std::string> &getNonCapturingFunctions();
20
21// Checks if the operation/function has any memory write effects. This enables
22// batching specific AD optimiziations(which are triggered only if the primal
23// function doesnt modify memory operands)
24bool isReadOnly(Operation *op);
25
26bool isReadNone(Operation *op);
27
28// Checks if 2 values v1 and v2 may alias with each other locally
29bool mayAlias(Value v1, Value v2);
30
31// check if 2 memory effects' underlying values alias with each other
32bool mayAlias(MemoryEffects::EffectInstance &A,
33 MemoryEffects::EffectInstance &B);
34
35// check if a memory effect's underlying values alias with a value
36bool mayAlias(mlir::MemoryEffects::EffectInstance a, mlir::Value v2);
37
38/// Returns the side effects of an operation(similar to
39/// `mlir::getEffectsRecursively`). If the operation has RecursiveMemoryEffects,
40/// include all side effects of child operations.
41///
42/// Also accounts for LLVM and autodiff-specific memory effects which are not
43/// captured by the default `mlir::getEffectsRecursively`
44bool collectOpEffects(Operation *rootOp,
45 SmallVector<MemoryEffects::EffectInstance> &effects);
46
47// Specialize memory effect collection for a FunctionOpInterface
48SmallVector<MemoryEffects::EffectInstance>
49collectFnEffects(FunctionOpInterface fnOp);
50
51MemoryEffects::EffectInstance getEffectOfVal(Value val,
52 MemoryEffects::Effect *effect,
53 SideEffects::Resource *resource);
54} // namespace oputils
55} // namespace enzyme
56} // namespace mlir
bool mayAlias(Value v1, Value v2)
Definition Utils.cpp:136
const std::set< std::string > & getNonCapturingFunctions()
Definition Utils.cpp:27
bool collectOpEffects(Operation *rootOp, SmallVector< MemoryEffects::EffectInstance > &effects)
Returns the side effects of an operation(similar to mlir::getEffectsRecursively).
Definition Utils.cpp:297
SmallVector< MemoryEffects::EffectInstance > collectFnEffects(FunctionOpInterface fnOp)
Definition Utils.cpp:409
MemoryEffects::EffectInstance getEffectOfVal(Value val, MemoryEffects::Effect *effect, SideEffects::Resource *resource)
Definition Utils.cpp:422
bool isReadNone(Operation *op)
Definition Utils.cpp:266
bool isReadOnly(Operation *op)
Definition Utils.cpp:237