Enzyme main
Loading...
Searching...
No Matches
MustExitScalarEvolution.h
Go to the documentation of this file.
1
2//===- MustExitScalarEvolution.h - ScalarEvolution assuming loops terminate-=//
3//
4// Enzyme Project
5//
6// Part of the Enzyme Project, under the Apache License v2.0 with LLVM
7// Exceptions. See https://llvm.org/LICENSE.txt for license information.
8// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9//
10// If using this code in an academic setting, please cite the following:
11// @incollection{enzymeNeurips,
12// title = {Instead of Rewriting Foreign Code for Machine Learning,
13// Automatically Synthesize Fast Gradients},
14// author = {Moses, William S. and Churavy, Valentin},
15// booktitle = {Advances in Neural Information Processing Systems 33},
16// year = {2020},
17// note = {To appear in},
18// }
19//
20//===----------------------------------------------------------------------===//
21//
22// This file declares MustExitScalarEvolution, a subclass of ScalarEvolution
23// that assumes that all loops terminate (and don't loop forever).
24//
25//===----------------------------------------------------------------------===//
26
27#ifndef ENZYME_MUST_EXIT_SCALAR_EVOLUTION_H_
28#define ENZYME_MUST_EXIT_SCALAR_EVOLUTION_H_
29
30#include <llvm/Config/llvm-config.h>
31
32#if LLVM_VERSION_MAJOR >= 16
33#define private public
34#include "llvm/Analysis/ScalarEvolution.h"
35#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
36#undef private
37#else
38#include "SCEV/ScalarEvolution.h"
39#include "SCEV/ScalarEvolutionExpander.h"
40#endif
41
42#include "llvm/IR/Dominators.h"
43
44class MustExitScalarEvolution final : public llvm::ScalarEvolution {
45public:
46 llvm::SmallPtrSet<llvm::BasicBlock *, 4> GuaranteedUnreachable;
47 using ScalarEvolution::ScalarEvolution;
48
49 MustExitScalarEvolution(llvm::Function &F, llvm::TargetLibraryInfo &TLI,
50 llvm::AssumptionCache &AC, llvm::DominatorTree &DT,
51 llvm::LoopInfo &LI);
52 ScalarEvolution::ExitLimit computeExitLimit(const llvm::Loop *L,
53 llvm::BasicBlock *ExitingBlock,
54 bool AllowPredicates);
55
56 ScalarEvolution::ExitLimit computeExitLimitFromCond(const llvm::Loop *L,
57 llvm::Value *ExitCond,
58 bool ExitIfTrue,
59 bool ControlsExit,
60 bool AllowPredicates);
61
62 ScalarEvolution::ExitLimit
63 computeExitLimitFromCondCached(ExitLimitCacheTy &Cache, const llvm::Loop *L,
64 llvm::Value *ExitCond, bool ExitIfTrue,
65 bool ControlsExit, bool AllowPredicates);
66 ScalarEvolution::ExitLimit
67 computeExitLimitFromCondImpl(ExitLimitCacheTy &Cache, const llvm::Loop *L,
68 llvm::Value *ExitCond, bool ExitIfTrue,
69 bool ControlsExit, bool AllowPredicates);
70
71 ScalarEvolution::ExitLimit
72 computeExitLimitFromICmp(const llvm::Loop *L, llvm::ICmpInst *ExitCond,
73 bool ExitIfTrue, bool ControlsExit,
74 bool AllowPredicates = false);
75
76 bool loopIsFiniteByAssumption(const llvm::Loop *L);
77
78 ScalarEvolution::ExitLimit howManyLessThans(const llvm::SCEV *LHS,
79 const llvm::SCEV *RHS,
80 const llvm::Loop *L,
81 bool IsSigned, bool ControlsExit,
82 bool AllowPredicates);
83
84 ScalarEvolution::ExitLimit computeExitLimitFromSingleExitSwitch(
85 const llvm::Loop *L, llvm::SwitchInst *Switch,
86 llvm::BasicBlock *ExitingBB, bool IsSubExpr);
87};
88
89#endif
ScalarEvolution::ExitLimit howManyLessThans(const llvm::SCEV *LHS, const llvm::SCEV *RHS, const llvm::Loop *L, bool IsSigned, bool ControlsExit, bool AllowPredicates)
llvm::SmallPtrSet< llvm::BasicBlock *, 4 > GuaranteedUnreachable
ScalarEvolution::ExitLimit computeExitLimitFromICmp(const llvm::Loop *L, llvm::ICmpInst *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates=false)
ScalarEvolution::ExitLimit computeExitLimitFromCond(const llvm::Loop *L, llvm::Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates)
ScalarEvolution::ExitLimit computeExitLimitFromSingleExitSwitch(const llvm::Loop *L, llvm::SwitchInst *Switch, llvm::BasicBlock *ExitingBB, bool IsSubExpr)
ScalarEvolution::ExitLimit computeExitLimit(const llvm::Loop *L, llvm::BasicBlock *ExitingBlock, bool AllowPredicates)
ScalarEvolution::ExitLimit computeExitLimitFromCondCached(ExitLimitCacheTy &Cache, const llvm::Loop *L, llvm::Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates)
ScalarEvolution::ExitLimit computeExitLimitFromCondImpl(ExitLimitCacheTy &Cache, const llvm::Loop *L, llvm::Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates)
MustExitScalarEvolution(llvm::Function &F, llvm::TargetLibraryInfo &TLI, llvm::AssumptionCache &AC, llvm::DominatorTree &DT, llvm::LoopInfo &LI)
bool loopIsFiniteByAssumption(const llvm::Loop *L)