LLVM: lib/IR/LLVMContext.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
27#include
28#include
29#include
30#include
31
32using namespace llvm;
33
35 switch (BundleTagID) {
37 return "deopt";
39 return "funclet";
41 return "gc-transition";
43 return "cfguardtarget";
45 return "preallocated";
47 return "gc-live";
49 return "clang.arc.attachedcall";
51 return "ptrauth";
53 return "kcfi";
55 return "convergencectrl";
57 return "align";
59 return "deactivation-symbol";
60 default:
62 }
63
65}
66
68
69
70 std::pair<unsigned, StringRef> MDKinds[] = {
71#define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name},
72#include "llvm/IR/FixedMetadataKinds.def"
73#undef LLVM_FIXED_MD_KIND
74 };
75
76 for (auto &MDKind : MDKinds) {
78 assert(ID == MDKind.first && "metadata kind id drifted");
79 (void)ID;
80 }
81
84 [[maybe_unused]] const auto *Entry =
86 assert(Entry->second == BundleTagID && "operand bundle id drifted!");
87 }
88
90 pImpl->getOrInsertSyncScopeID("singlethread");
92 "singlethread synchronization scope ID drifted!");
93 (void)SingleThreadSSID;
94
96 pImpl->getOrInsertSyncScopeID("");
98 "system synchronization scope ID drifted!");
99 (void)SystemSSID;
100}
101
103
104void LLVMContext::addModule(Module *M) {
106}
107
108void LLVMContext::removeModule(Module *M) {
111}
112
114 Module *M = F.getParent();
115 assert(pImpl->OwnedModules.contains(M) && "Unexpected module!");
116 return pImpl->MachineFunctionNums[M]++;
117}
118
119
120
121
122
125 void *DiagnosticContext, bool RespectFilters) {
127 pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
128 pImpl->RespectDiagnosticFilters = RespectFilters;
129}
130
132 bool RespectFilters) {
133 pImpl->DiagHandler = std::move(DH);
134 pImpl->RespectDiagnosticFilters = RespectFilters;
135}
136
138 pImpl->DiagnosticsHotnessRequested = Requested;
139}
141 return pImpl->DiagnosticsHotnessRequested;
142}
143
145 pImpl->DiagnosticsHotnessThreshold = Threshold;
146}
148 pImpl->MisExpectWarningRequested = Requested;
149}
151 return pImpl->MisExpectWarningRequested;
152}
157 std::optional<uint32_t> Tolerance) {
158 pImpl->DiagnosticsMisExpectTolerance = Tolerance;
159}
161 return pImpl->DiagnosticsMisExpectTolerance.value_or(0);
162}
163
165 return ->DiagnosticsHotnessThreshold.has_value();
166}
167
169 return pImpl->MainRemarkStreamer.get();
170}
175 std::unique_ptrremarks::RemarkStreamer RemarkStreamer) {
176 pImpl->MainRemarkStreamer = std::move(RemarkStreamer);
177}
178
180 return pImpl->LLVMRS.get();
181}
186 std::unique_ptr RemarkStreamer) {
187 pImpl->LLVMRS = std::move(RemarkStreamer);
188}
189
192 return pImpl->DiagHandler->DiagHandlerCallback;
193}
194
196 return pImpl->DiagHandler->DiagnosticContext;
197}
198
200{
201 pImpl->YieldCallback = Callback;
202 pImpl->YieldOpaqueHandle = OpaqueHandle;
203}
204
206 if (pImpl->YieldCallback)
207 pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle);
208}
209
213
215 assert(I && "Invalid instruction");
217}
218
220
221
222
223
224
225
226
228 return Remark->isEnabled() &&
229 (->isVerbose() || Remark->getHotness());
230
231 return true;
232}
233
234const char *
236 switch (Severity) {
238 return "error";
240 return "warning";
242 return "remark";
244 return "note";
245 }
247}
248
252 RS->emit(*OptDiagBase);
253
254
255 if (pImpl->DiagHandler) {
257 pImpl->DiagHandler->HasErrors = true;
259 pImpl->DiagHandler->handleDiagnostics(DI))
260 return;
261 }
262
264 return;
265
266
270 errs() << "\n";
272 exit(1);
273}
274
275
276
277
278
279
281
282 return pImpl->CustomMDKindNames.insert(
283 std::make_pair(
284 Name, pImpl->CustomMDKindNames.size()))
285 .first->second;
286}
287
288
289
291 Names.resize(pImpl->CustomMDKindNames.size());
293 E = pImpl->CustomMDKindNames.end(); I != E; ++I)
294 Names[I->second] = I->first();
295}
296
298 pImpl->getOperandBundleTags(Tags);
299}
300
303 return pImpl->getOrInsertBundleTag(TagName);
304}
305
307 return pImpl->getOperandBundleTagID(Tag);
308}
309
311 return pImpl->getOrInsertSyncScopeID(SSN);
312}
313
315 pImpl->getSyncScopeNames(SSNs);
316}
317
319 return pImpl->getSyncScopeName(Id);
320}
321
323 pImpl->GCNames[&Fn] = std::move(GCName);
324}
325
327 return pImpl->GCNames[&Fn];
328}
329
331 pImpl->GCNames.erase(&Fn);
332}
333
335 return pImpl->DiscardValueNames;
336}
337
339
341 if (pImpl->DITypeMap)
342 return;
343
344 pImpl->DITypeMap.emplace();
345}
346
348
350 pImpl->DiscardValueNames = Discard;
351}
352
354 return pImpl->getOptPassGate();
355}
356
358 pImpl->setOptPassGate(OPG);
359}
360
362 return pImpl->DiagHandler.get();
363}
364
366 return std::move(pImpl->DiagHandler);
367}
368
370 return pImpl->DefaultTargetCPU;
371}
372
374 pImpl->DefaultTargetCPU = CPU;
375}
376
378 return pImpl->DefaultTargetFeatures;
379}
380
382 pImpl->DefaultTargetFeatures = Features;
383}
384
386 pImpl->NextAtomGroup = std::max(pImpl->NextAtomGroup, V);
387}
388
390 return pImpl->NextAtomGroup++;
391}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isDiagnosticEnabled(const DiagnosticInfo &DI)
Definition LLVMContext.cpp:219
static StringRef knownBundleName(unsigned BundleTagID)
Definition LLVMContext.cpp:34
This file defines the SmallVector class.
This is the base abstract class for diagnostic reporting in the backend.
DiagnosticSeverity getSeverity() const
virtual void print(DiagnosticPrinter &DP) const =0
Print using the given DP a user-friendly message.
Basic diagnostic printer that uses an underlying raw_ostream.
SmallPtrSet< Module *, 4 > OwnedModules
OwnedModules - The set of modules instantiated in this context, and which will be automatically delet...
DenseMap< Module *, unsigned > MachineFunctionNums
MachineFunctionNums - Keep the next available unique number available for a MachineFunction in given ...
LLVM_ABI uint64_t incNextDILocationAtomGroup()
Key Instructions: get the next free atom group number and increment the global tracker.
Definition LLVMContext.cpp:389
LLVM_ABI void setMisExpectWarningRequested(bool Requested)
Definition LLVMContext.cpp:147
LLVM_ABI std::optional< StringRef > getSyncScopeName(SyncScope::ID Id) const
getSyncScopeName - Returns the name of a SyncScope::ID registered with LLVMContext,...
Definition LLVMContext.cpp:318
LLVM_ABI remarks::RemarkStreamer * getMainRemarkStreamer()
The "main remark streamer" used by all the specialized remark streamers.
Definition LLVMContext.cpp:168
LLVM_ABI uint32_t getOperandBundleTagID(StringRef Tag) const
getOperandBundleTagID - Maps a bundle tag to an integer ID.
Definition LLVMContext.cpp:306
LLVM_ABI void disableDebugTypeODRUniquing()
Definition LLVMContext.cpp:347
LLVM_ABI void setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
Registers a yield callback with the given context.
Definition LLVMContext.cpp:199
LLVM_ABI void deleteGC(const Function &Fn)
Remove the GC for a function.
Definition LLVMContext.cpp:330
LLVM_ABI const std::string & getGC(const Function &Fn)
Return the GC for a function.
Definition LLVMContext.cpp:326
LLVM_ABI DiagnosticHandler::DiagnosticHandlerTy getDiagnosticHandlerCallBack() const
getDiagnosticHandlerCallBack - Return the diagnostic handler call back set by setDiagnosticHandlerCal...
Definition LLVMContext.cpp:191
LLVM_ABI void setLLVMRemarkStreamer(std::unique_ptr< LLVMRemarkStreamer > RemarkStreamer)
Definition LLVMContext.cpp:185
LLVM_ABI unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
Definition LLVMContext.cpp:280
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Definition LLVMContext.cpp:214
@ OB_clang_arc_attachedcall
static LLVM_ABI const char * getDiagnosticMessagePrefix(DiagnosticSeverity Severity)
Get the prefix that should be printed in front of a diagnostic of the given Severity.
Definition LLVMContext.cpp:235
LLVM_ABI void enableDebugTypeODRUniquing()
Definition LLVMContext.cpp:340
LLVM_ABI ~LLVMContext()
Definition LLVMContext.cpp:102
LLVM_ABI std::unique_ptr< DiagnosticHandler > getDiagnosticHandler()
getDiagnosticHandler - transfers ownership of DiagnosticHandler unique_ptr to caller.
Definition LLVMContext.cpp:365
LLVM_ABI void setDefaultTargetCPU(StringRef CPU)
Definition LLVMContext.cpp:373
LLVM_ABI LLVMContext()
Definition LLVMContext.cpp:67
LLVM_ABI bool getDiagnosticsHotnessRequested() const
Return if a code hotness metric should be included in optimization diagnostics.
Definition LLVMContext.cpp:140
LLVM_ABI bool getMisExpectWarningRequested() const
Definition LLVMContext.cpp:150
LLVM_ABI void yield()
Calls the yield callback (if applicable).
Definition LLVMContext.cpp:205
LLVM_ABI void setDiagnosticsHotnessThreshold(std::optional< uint64_t > Threshold)
Set the minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.
Definition LLVMContext.cpp:144
LLVM_ABI void setMainRemarkStreamer(std::unique_ptr< remarks::RemarkStreamer > MainRemarkStreamer)
Definition LLVMContext.cpp:174
LLVM_ABI bool isDiagnosticsHotnessThresholdSetFromPSI() const
Return if hotness threshold is requested from PSI.
Definition LLVMContext.cpp:164
LLVM_ABI void setOptPassGate(OptPassGate &)
Set the object which can disable optional passes and individual optimizations at compile time.
Definition LLVMContext.cpp:357
LLVM_ABI StringMapEntry< uint32_t > * getOrInsertBundleTag(StringRef TagName) const
getOrInsertBundleTag - Returns the Tag to use for an operand bundle of name TagName.
Definition LLVMContext.cpp:302
LLVM_ABI void setDiagnosticsHotnessRequested(bool Requested)
Set if a code hotness metric should be included in optimization diagnostics.
Definition LLVMContext.cpp:137
LLVM_ABI void setGC(const Function &Fn, std::string GCName)
Define the GC for a function.
Definition LLVMContext.cpp:322
LLVM_ABI bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
Definition LLVMContext.cpp:334
void(*)(LLVMContext *Context, void *OpaqueHandle) YieldCallbackTy
Defines the type of a yield callback.
LLVM_ABI bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
Definition LLVMContext.cpp:338
LLVM_ABI unsigned generateMachineFunctionNum(Function &)
generateMachineFunctionNum - Get a unique number for MachineFunction that associated with the given F...
Definition LLVMContext.cpp:113
LLVM_ABI StringRef getDefaultTargetFeatures()
Similar to {get,set}DefaultTargetCPU() but for default target-features.
Definition LLVMContext.cpp:377
LLVM_ABI void setDiagnosticsMisExpectTolerance(std::optional< uint32_t > Tolerance)
Definition LLVMContext.cpp:156
LLVMContextImpl *const pImpl
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition LLVMContext.cpp:249
LLVM_ABI void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
getOperandBundleTags - Populate client supplied SmallVector with the bundle tags registered in this L...
Definition LLVMContext.cpp:297
LLVM_ABI void setDiagnosticHandlerCallBack(DiagnosticHandler::DiagnosticHandlerTy DiagHandler, void *DiagContext=nullptr, bool RespectFilters=false)
setDiagnosticHandlerCallBack - This method sets a handler call back that is invoked when the backend ...
Definition LLVMContext.cpp:123
LLVM_ABI void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
Definition LLVMContext.cpp:349
LLVM_ABI StringRef getDefaultTargetCPU()
Get or set the current "default" target CPU (target-cpu function attribute).
Definition LLVMContext.cpp:369
LLVM_ABI void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
getMDKindNames - Populate client supplied SmallVector with the name for custom metadata IDs registere...
Definition LLVMContext.cpp:290
LLVM_ABI void * getDiagnosticContext() const
getDiagnosticContext - Return the diagnostic context set by setDiagnosticContext.
Definition LLVMContext.cpp:195
LLVM_ABI void updateDILocationAtomGroupWaterline(uint64_t G)
Key Instructions: update the highest number atom group emitted for any function.
Definition LLVMContext.cpp:385
LLVM_ABI SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
Definition LLVMContext.cpp:310
LLVM_ABI uint64_t getDiagnosticsHotnessThreshold() const
Return the minimum hotness value a diagnostic would need in order to be included in optimization diag...
Definition LLVMContext.cpp:153
LLVM_ABI void setDefaultTargetFeatures(StringRef Features)
Definition LLVMContext.cpp:381
LLVM_ABI const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
Definition LLVMContext.cpp:361
LLVM_ABI void setDiagnosticHandler(std::unique_ptr< DiagnosticHandler > &&DH, bool RespectFilters=false)
setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler to provide custom d...
Definition LLVMContext.cpp:131
LLVM_ABI OptPassGate & getOptPassGate() const
Access the object which can disable optional passes and individual optimizations at compile time.
Definition LLVMContext.cpp:353
LLVM_ABI LLVMRemarkStreamer * getLLVMRemarkStreamer()
The "LLVM remark streamer" used by LLVM to serialize remark diagnostics comming from IR and MIR passe...
Definition LLVMContext.cpp:179
LLVM_ABI void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
Definition LLVMContext.cpp:314
LLVM_ABI uint32_t getDiagnosticsMisExpectTolerance() const
Definition LLVMContext.cpp:160
A Module instance is used to store all the information related to an LLVM module.
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
bool erase(PtrType Ptr)
Remove pointer from the set.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMapIterBase< ValueTy, true > const_iterator
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
@ System
Synchronized with respect to all concurrently executing threads.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
This is the base class for diagnostic handling in LLVM.
void(*)(const DiagnosticInfo *DI, void *Context) DiagnosticHandlerTy