LLVM 24.0.0git
GenericConvergenceVerifier.h
Go to the documentation of this file.
1//===- GenericConvergenceVerifier.h ---------------------------*- C++ -*---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10///
11/// A verifier for the static rules of convergence control tokens that works
12/// with both LLVM IR and MIR.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
17#define LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
18
20
21namespace llvm {
22
23template <typename ContextT> class GenericConvergenceVerifier {
24public:
25 using BlockT = typename ContextT::BlockT;
26 using FunctionT = typename ContextT::FunctionT;
27 using ValueRefT = typename ContextT::ValueRefT;
28 using InstructionT = typename ContextT::InstructionT;
29 using DominatorTreeT = typename ContextT::DominatorTreeT;
31
33 function_ref<void(const Twine &Message)> FailureCB,
34 const FunctionT &F) {
35 clear();
36 this->OS = OS;
37 this->FailureCB = FailureCB;
38 Context = ContextT(&F);
39 }
40
41 void clear();
42 void visit(const BlockT &BB);
43 void visit(const InstructionT &I);
44 void verify(const DominatorTreeT &DT);
45
46 bool sawTokens() const { return ConvergenceKind == ControlledConvergence; }
47
48private:
49 raw_ostream *OS;
50 std::function<void(const Twine &Message)> FailureCB;
52 CycleInfoT CI;
53 ContextT Context;
54
55 /// Whether the current function has convergencectrl operand bundles.
56 enum {
57 ControlledConvergence,
58 UncontrolledConvergence,
59 NoConvergence
60 } ConvergenceKind = NoConvergence;
61
62 /// The control token operation performed by a convergence control Intrinsic
63 /// in LLVM IR, or by a CONVERGENCECTRL* instruction in MIR
64 enum ConvOpKind { CONV_ANCHOR, CONV_ENTRY, CONV_LOOP, CONV_NONE };
65
66 // Cache token uses found so far. Note that we track the unique definitions
67 // and not the token values.
68 DenseMap<const InstructionT *, const InstructionT *> Tokens;
69
70 bool SeenFirstConvOp = false;
71
72 static bool isInsideConvergentFunction(const InstructionT &I);
73 static bool isConvergent(const InstructionT &I);
74 static ConvOpKind getConvOp(const InstructionT &I);
75 void checkConvergenceTokenProduced(const InstructionT &I);
76 const InstructionT *findAndCheckConvergenceTokenUsed(const InstructionT &I);
77
78 void reportFailure(const Twine &Message, ArrayRef<Printable> Values);
79};
80
81} // end namespace llvm
82
83#endif // LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
Find all cycles in a control-flow graph, including irreducible loops.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
typename ContextT::InstructionT InstructionT
typename ContextT::DominatorTreeT DominatorTreeT
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
GenericCycleInfo< ContextT > CycleInfoT
Cycle information for a function.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
ArrayRef(const T &OneElt) -> ArrayRef< T >