LLVM 24.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 // MDFunctionLocalContext has a very large print volume; prefer the short
104 // form for verifier errors.
105 if (auto *FLCtx = dyn_cast<MDFunctionLocalContext>(MD)) {
106 FLCtx->printShort(*OS, MST, &M);
107 *OS << '\n';
108 return;
109 }
110 MD->print(*OS, MST, &M);
111 *OS << '\n';
112 }
113
114 template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) {
115 Write(MD.get());
116 }
117
118 void Write(const NamedMDNode *NMD) {
119 if (!NMD)
120 return;
121 NMD->print(*OS, MST);
122 *OS << '\n';
123 }
124
125 void Write(Type *T) {
126 if (!T)
127 return;
128 *OS << ' ' << *T;
129 }
130
131 void Write(const Comdat *C) {
132 if (!C)
133 return;
134 *OS << *C;
135 }
136
137 void Write(const APInt *AI) {
138 if (!AI)
139 return;
140 *OS << *AI << '\n';
141 }
142
143 void Write(const unsigned i) { *OS << i << '\n'; }
144
145 // NOLINTNEXTLINE(readability-identifier-naming)
146 void Write(const Attribute *A) {
147 if (!A)
148 return;
149 *OS << A->getAsString() << '\n';
150 }
151
152 // NOLINTNEXTLINE(readability-identifier-naming)
153 void Write(const AttributeSet *AS) {
154 if (!AS)
155 return;
156 *OS << AS->getAsString() << '\n';
157 }
158
159 // NOLINTNEXTLINE(readability-identifier-naming)
160 void Write(const AttributeList *AL) {
161 if (!AL)
162 return;
163 AL->print(*OS);
164 }
165
166 void Write(Printable P) { *OS << P; }
167
168 template <typename T> void Write(ArrayRef<T> Vs) {
169 for (const T &V : Vs)
170 Write(V);
171 }
172
173 template <typename T1, typename... Ts>
174 void WriteTs(const T1 &V1, const Ts &...Vs) {
175 Write(V1);
176 WriteTs(Vs...);
177 }
178
179 template <typename... Ts> void WriteTs() {}
180
181public:
182 /// A check failed, so printout out the condition and the message.
183 ///
184 /// This provides a nice place to put a breakpoint if you want to see why
185 /// something is not correct.
186 void CheckFailed(const Twine &Message) {
187 if (OS)
188 *OS << Message << '\n';
189 Broken = true;
190 }
191
192 /// A check failed (with values to print).
193 ///
194 /// This calls the Message-only version so that the above is easier to set a
195 /// breakpoint on.
196 template <typename T1, typename... Ts>
197 void CheckFailed(const Twine &Message, const T1 &V1, const Ts &...Vs) {
198 CheckFailed(Message);
199 if (OS)
200 WriteTs(V1, Vs...);
201 }
202
203 /// A debug info check failed.
204 void DebugInfoCheckFailed(const Twine &Message) {
205 if (OS)
206 *OS << Message << '\n';
208 BrokenDebugInfo = true;
209 }
210
211 /// A debug info check failed (with values to print).
212 template <typename T1, typename... Ts>
213 void DebugInfoCheckFailed(const Twine &Message, const T1 &V1,
214 const Ts &...Vs) {
215 DebugInfoCheckFailed(Message);
216 if (OS)
217 WriteTs(V1, Vs...);
218 }
219};
220
221//==============================================================================
222// AMDGPU-specific verification functions
223
224void verifyAMDGPUModuleFlag(VerifierSupport &VS, const MDString *ID,
225 Module::ModFlagBehavior MFB, const MDNode *Op);
226
227void verifyAMDGPUFunctionMetadata(VerifierSupport &VS, const Function &F);
228
229void verifyAMDGPUGlobalVariable(VerifierSupport &VS, const GlobalVariable &GV);
230
231void verifyAMDGPUAlloca(VerifierSupport &VS, const AllocaInst &AI);
232
233void verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
234 CallBase &Call);
235
237
238//==============================================================================
239
240// NVVM-specific verification functions
241
242void verifyNVVMIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
243 CallBase &Call);
244
245//==============================================================================
246
247} // namespace llvm
248
249#endif // LLVM_LIB_IR_VERIFIERINTERNAL_H
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
@ 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:76
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:68
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition Module.h:118
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
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
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
void verifyAMDGPUAlloca(VerifierSupport &VS, const AllocaInst &AI)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
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 verifyNVVMIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID, CallBase &Call)
void verifyAMDGPUGlobalVariable(VerifierSupport &VS, const GlobalVariable &GV)
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