LLVM 19.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 using CycleT = typename CycleInfoT::CycleT;
32
34 function_ref<void(const Twine &Message)> FailureCB,
35 const FunctionT &F) {
36 clear();
37 this->OS = OS;
38 this->FailureCB = FailureCB;
39 Context = ContextT(&F);
40 }
41
42 void clear();
43 void visit(const BlockT &BB);
44 void visit(const InstructionT &I);
45 void verify(const DominatorTreeT &DT);
46
47 bool sawTokens() const { return ConvergenceKind == ControlledConvergence; }
48
49private:
51 std::function<void(const Twine &Message)> FailureCB;
53 CycleInfoT CI;
54 ContextT Context;
55
56 /// Whether the current function has convergencectrl operand bundles.
57 enum {
58 ControlledConvergence,
59 UncontrolledConvergence,
60 NoConvergence
61 } ConvergenceKind = NoConvergence;
62
63 // Cache token uses found so far. Note that we track the unique definitions
64 // and not the token values.
65 DenseMap<const InstructionT *, const InstructionT *> Tokens;
66
67 bool SeenFirstConvOp = false;
68
69 static bool isInsideConvergentFunction(const InstructionT &I);
70 static bool isConvergent(const InstructionT &I);
71 const InstructionT *findAndCheckConvergenceTokenUsed(const InstructionT &I);
72
73 void reportFailure(const Twine &Message, ArrayRef<Printable> Values);
74};
75
76} // end namespace llvm
77
78#endif // LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
Find all cycles in a control-flow graph, including irreducible loops.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
ppc ctr loops verify
raw_pwrite_stream & OS
typename ContextT::InstructionT InstructionT
typename ContextT::DominatorTreeT DominatorTreeT
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
typename ContextT::FunctionT FunctionT
typename ContextT::ValueRefT ValueRefT
GenericCycleInfo< ContextT > CycleInfoT
Cycle information for a function.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18