LLVM 23.0.0git
VerifierInternal.h
Go to the documentation of this file.
1//===-- VerifierInternal.h - Internal verifier infrastructure --------------==//
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// Shared definitions used by the verifier implementation files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_IR_VERIFIERINTERNAL_H
14#define LLVM_LIB_IR_VERIFIERINTERNAL_H
15
16#include "llvm/ADT/Twine.h"
17#include "llvm/IR/Attributes.h"
20#include "llvm/IR/Metadata.h"
21#include "llvm/IR/Module.h"
23#include "llvm/IR/Value.h"
28
29namespace llvm {
30
33 const Module &M;
35 const Triple &TT;
36 const DataLayout &DL;
38
39 /// Track the brokenness of the module while recursively visiting.
40 bool Broken = false;
41 /// Broken debug info can be "recovered" from by stripping the debug info.
42 bool BrokenDebugInfo = false;
43 /// Whether to treat broken debug info as an error.
45
47 : OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()),
48 Context(M.getContext()) {}
49
50private:
51 void Write(const Module *M) {
52 *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
53 }
54
55 void Write(const Value *V) {
56 if (V)
57 Write(*V);
58 }
59
60 void Write(const Value &V) {
61 if (isa<Instruction>(V)) {
62 V.print(*OS, MST);
63 *OS << '\n';
64 } else {
65 V.printAsOperand(*OS, true, MST);
66 *OS << '\n';
67 }
68 }
69
70 void Write(const DbgRecord *DR) {
71 if (DR) {
72 DR->print(*OS, MST, false);
73 *OS << '\n';
74 }
75 }
76
78 switch (Type) {
80 *OS << "value";
81 break;
83 *OS << "declare";
84 break;
86 *OS << "declare_value";
87 break;
89 *OS << "assign";
90 break;
92 *OS << "end";
93 break;
95 *OS << "any";
96 break;
97 };
98 }
99
100 void Write(const Metadata *MD) {
101 if (!MD)
102 return;
103 MD->print(*OS, MST, &M);
104 *OS << '\n';
105 }
106
107 template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) {
108 Write(MD.get());
109 }
110
111 void Write(const NamedMDNode *NMD) {
112 if (!NMD)
113 return;
114 NMD->print(*OS, MST);
115 *OS << '\n';
116 }
117
118 void Write(Type *T) {
119 if (!T)
120 return;
121 *OS << ' ' << *T;
122 }
123
124 void Write(const Comdat *C) {
125 if (!C)
126 return;
127 *OS << *C;
128 }
129
130 void Write(const APInt *AI) {
131 if (!AI)
132 return;
133 *OS << *AI << '\n';
134 }
135
136 void Write(const unsigned i) { *OS << i << '\n'; }
137
138 // NOLINTNEXTLINE(readability-identifier-naming)
139 void Write(const Attribute *A) {
140 if (!A)
141 return;
142 *OS << A->getAsString() << '\n';
143 }
144
145 // NOLINTNEXTLINE(readability-identifier-naming)
146 void Write(const AttributeSet *AS) {
147 if (!AS)
148 return;
149 *OS << AS->getAsString() << '\n';
150 }
151
152 // NOLINTNEXTLINE(readability-identifier-naming)
153 void Write(const AttributeList *AL) {
154 if (!AL)
155 return;
156 AL->print(*OS);
157 }
158
159 void Write(Printable P) { *OS << P << '\n'; }
160
161 template <typename T> void Write(ArrayRef<T> Vs) {
162 for (const T &V : Vs)
163 Write(V);
164 }
165
166 template <typename T1, typename... Ts>
167 void WriteTs(const T1 &V1, const Ts &...Vs) {
168 Write(V1);
169 WriteTs(Vs...);
170 }
171
172 template <typename... Ts> void WriteTs() {}
173
174public:
175 /// A check failed, so printout out the condition and the message.
176 ///
177 /// This provides a nice place to put a breakpoint if you want to see why
178 /// something is not correct.
179 void CheckFailed(const Twine &Message) {
180 if (OS)
181 *OS << Message << '\n';
182 Broken = true;
183 }
184
185 /// A check failed (with values to print).
186 ///
187 /// This calls the Message-only version so that the above is easier to set a
188 /// breakpoint on.
189 template <typename T1, typename... Ts>
190 void CheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs) {
191 CheckFailed(Message);
192 if (OS)
193 WriteTs(V1, Vs...);
194 }
195
196 /// A debug info check failed.
197 void DebugInfoCheckFailed(const Twine &Message) {
198 if (OS)
199 *OS << Message << '\n';
201 BrokenDebugInfo = true;
202 }
203
204 /// A debug info check failed (with values to print).
205 template <typename T1, typename... Ts>
206 void DebugInfoCheckFailed(const Twine &Message, const T1 &V1,
207 const Ts &...Vs) {
208 DebugInfoCheckFailed(Message);
209 if (OS)
210 WriteTs(V1, Vs...);
211 }
212};
213
214//==============================================================================
215// AMDGPU-specific verification functions
216
217void verifyAMDGPUModuleFlag(VerifierSupport &VS, const MDString *ID,
218 Module::ModFlagBehavior MFB, const MDNode *Op);
219
220void verifyAMDGPUFunctionMetadata(VerifierSupport &VS, const Function &F);
221
222void verifyAMDGPUAlloca(VerifierSupport &VS, const AllocaInst &AI);
223
224void verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
225 CallBase &Call);
226
228
229//==============================================================================
230
231} // namespace llvm
232
233#endif // LLVM_LIB_IR_VERIFIERINTERNAL_H
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil translate DXIL Translate Metadata
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
This file contains the declarations for metadata subclasses.
#define T
#define T1
#define P(N)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition Module.h:117
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
CallInst * Call
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
void verifyAMDGPUAlloca(VerifierSupport &VS, const AllocaInst &AI)
void verifyAMDGPUFunctionMetadata(VerifierSupport &VS, const Function &F)
void verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID, CallBase &Call)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
void verifyAMDGPUModuleFlag(VerifierSupport &VS, const MDString *ID, Module::ModFlagBehavior MFB, const MDNode *Op)
bool isAMDGPUCallBrIntrinsic(Intrinsic::ID ID)
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs)
A check failed (with values to print).
void DebugInfoCheckFailed(const Twine &Message)
A debug info check failed.
VerifierSupport(raw_ostream *OS, const Module &M)
bool Broken
Track the brokenness of the module while recursively visiting.
bool BrokenDebugInfo
Broken debug info can be "recovered" from by stripping the debug info.
bool TreatBrokenDebugInfoAsError
Whether to treat broken debug info as an error.
void CheckFailed(const Twine &Message)
A check failed, so printout out the condition and the message.
const DataLayout & DL
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs)
A debug info check failed (with values to print).
ModuleSlotTracker MST