blob: 2d219c2db6fa4372596eea951ebb5ee7d7c22c55 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- GenericConvergenceVerifier.h ---------------------------*- C++ -*---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
///
/// A verifier for the static rules of convergence control tokens that works
/// with both LLVM IR and MIR.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
#define LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
#include "llvm/ADT/GenericCycleInfo.h"
namespace llvm {
template <typename ContextT> class GenericConvergenceVerifier {
public:
using BlockT = typename ContextT::BlockT;
using FunctionT = typename ContextT::FunctionT;
using ValueRefT = typename ContextT::ValueRefT;
using InstructionT = typename ContextT::InstructionT;
using DominatorTreeT = typename ContextT::DominatorTreeT;
using CycleInfoT = GenericCycleInfo<ContextT>;
using CycleT = typename CycleInfoT::CycleT;
void initialize(raw_ostream *OS,
function_ref<void(const Twine &Message)> FailureCB,
const FunctionT &F) {
clear();
this->OS = OS;
this->FailureCB = FailureCB;
Context = ContextT(&F);
}
void clear();
void visit(const BlockT &BB);
void visit(const InstructionT &I);
void verify(const DominatorTreeT &DT);
bool sawTokens() const { return ConvergenceKind == ControlledConvergence; }
private:
raw_ostream *OS;
std::function<void(const Twine &Message)> FailureCB;
DominatorTreeT *DT;
CycleInfoT CI;
ContextT Context;
/// Whether the current function has convergencectrl operand bundles.
enum {
ControlledConvergence,
UncontrolledConvergence,
NoConvergence
} ConvergenceKind = NoConvergence;
// Cache token uses found so far. Note that we track the unique definitions
// and not the token values.
DenseMap<const InstructionT *, const InstructionT *> Tokens;
bool SeenFirstConvOp = false;
static bool isInsideConvergentFunction(const InstructionT &I);
static bool isConvergent(const InstructionT &I);
const InstructionT *findAndCheckConvergenceTokenUsed(const InstructionT &I);
void reportFailure(const Twine &Message, ArrayRef<Printable> Values);
};
} // end namespace llvm
#endif // LLVM_ADT_GENERICCONVERGENCEVERIFIER_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|