clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name LLVMContext.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Analysis -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ASMParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/BinaryFormat -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitstream -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /include/llvm/CodeGen -I /include/llvm/CodeGen/PBQP -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Coroutines -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData/Coverage -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/CodeView -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/DWARF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/MSF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/PDB -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Demangle -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/JITLink -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/Orc -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenACC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenMP -I /include/llvm/CodeGen/GlobalISel -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IRReader -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/LTO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Linker -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC/MCParser -I /include/llvm/CodeGen/MIRParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Object -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Option -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Passes -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Scalar -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ADT -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Support -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/Symbolize -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Target -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Utils -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Vectorize -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/IPO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libLLVM/../include -I /usr/src/gnu/usr.bin/clang/libLLVM/obj -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/IR/LLVMContext.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "llvm/IR/LLVMContext.h" |
| 15 | #include "LLVMContextImpl.h" |
| 16 | #include "llvm/ADT/SmallVector.h" |
| 17 | #include "llvm/ADT/StringMap.h" |
| 18 | #include "llvm/ADT/StringRef.h" |
| 19 | #include "llvm/ADT/Twine.h" |
| 20 | #include "llvm/IR/DiagnosticInfo.h" |
| 21 | #include "llvm/IR/DiagnosticPrinter.h" |
| 22 | #include "llvm/IR/LLVMRemarkStreamer.h" |
| 23 | #include "llvm/IR/Metadata.h" |
| 24 | #include "llvm/IR/Module.h" |
| 25 | #include "llvm/Remarks/RemarkStreamer.h" |
| 26 | #include "llvm/Support/Casting.h" |
| 27 | #include "llvm/Support/ErrorHandling.h" |
| 28 | #include "llvm/Support/raw_ostream.h" |
| 29 | #include <cassert> |
| 30 | #include <cstdlib> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | |
| 34 | using namespace llvm; |
| 35 | |
| 36 | LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { |
| 37 | |
| 38 | |
| 39 | std::pair<unsigned, StringRef> MDKinds[] = { |
| 40 | #define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name}, |
| 41 | #include "llvm/IR/FixedMetadataKinds.def" |
| 42 | #undef LLVM_FIXED_MD_KIND |
| 43 | }; |
| 44 | |
| 45 | for (auto &MDKind : MDKinds) { |
| 46 | unsigned ID = getMDKindID(MDKind.second); |
| 47 | assert(ID == MDKind.first && "metadata kind id drifted"); |
| 48 | (void)ID; |
| 49 | } |
| 50 | |
| 51 | auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt"); |
| 52 | assert(DeoptEntry->second == LLVMContext::OB_deopt && |
| 53 | "deopt operand bundle id drifted!"); |
| 54 | (void)DeoptEntry; |
| 55 | |
| 56 | auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet"); |
| 57 | assert(FuncletEntry->second == LLVMContext::OB_funclet && |
| 58 | "funclet operand bundle id drifted!"); |
| 59 | (void)FuncletEntry; |
| 60 | |
| 61 | auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition"); |
| 62 | assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition && |
| 63 | "gc-transition operand bundle id drifted!"); |
| 64 | (void)GCTransitionEntry; |
| 65 | |
| 66 | auto *CFGuardTargetEntry = pImpl->getOrInsertBundleTag("cfguardtarget"); |
| 67 | assert(CFGuardTargetEntry->second == LLVMContext::OB_cfguardtarget && |
| 68 | "cfguardtarget operand bundle id drifted!"); |
| 69 | (void)CFGuardTargetEntry; |
| 70 | |
| 71 | auto *PreallocatedEntry = pImpl->getOrInsertBundleTag("preallocated"); |
| 72 | assert(PreallocatedEntry->second == LLVMContext::OB_preallocated && |
| 73 | "preallocated operand bundle id drifted!"); |
| 74 | (void)PreallocatedEntry; |
| 75 | |
| 76 | auto *GCLiveEntry = pImpl->getOrInsertBundleTag("gc-live"); |
| 77 | assert(GCLiveEntry->second == LLVMContext::OB_gc_live && |
| 78 | "gc-transition operand bundle id drifted!"); |
| 79 | (void)GCLiveEntry; |
| 80 | |
| 81 | auto *ClangAttachedCall = |
| 82 | pImpl->getOrInsertBundleTag("clang.arc.attachedcall"); |
| 83 | assert(ClangAttachedCall->second == LLVMContext::OB_clang_arc_attachedcall && |
| 84 | "clang.arc.attachedcall operand bundle id drifted!"); |
| 85 | (void)ClangAttachedCall; |
| 86 | |
| 87 | SyncScope::ID SingleThreadSSID = |
| 88 | pImpl->getOrInsertSyncScopeID("singlethread"); |
| 89 | assert(SingleThreadSSID == SyncScope::SingleThread && |
| 90 | "singlethread synchronization scope ID drifted!"); |
| 91 | (void)SingleThreadSSID; |
| 92 | |
| 93 | SyncScope::ID SystemSSID = |
| 94 | pImpl->getOrInsertSyncScopeID(""); |
| 95 | assert(SystemSSID == SyncScope::System && |
| 96 | "system synchronization scope ID drifted!"); |
| 97 | (void)SystemSSID; |
| 98 | } |
| 99 | |
| 100 | LLVMContext::~LLVMContext() { delete pImpl; } |
| 101 | |
| 102 | void LLVMContext::addModule(Module *M) { |
| 103 | pImpl->OwnedModules.insert(M); |
| 104 | } |
| 105 | |
| 106 | void LLVMContext::removeModule(Module *M) { |
| 107 | pImpl->OwnedModules.erase(M); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | void LLVMContext::setDiagnosticHandlerCallBack( |
| 115 | DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler, |
| 116 | void *DiagnosticContext, bool RespectFilters) { |
| 117 | pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler; |
| 118 | pImpl->DiagHandler->DiagnosticContext = DiagnosticContext; |
| 119 | pImpl->RespectDiagnosticFilters = RespectFilters; |
| 120 | } |
| 121 | |
| 122 | void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH, |
| 123 | bool RespectFilters) { |
| 124 | pImpl->DiagHandler = std::move(DH); |
| 125 | pImpl->RespectDiagnosticFilters = RespectFilters; |
| 126 | } |
| 127 | |
| 128 | void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) { |
| 129 | pImpl->DiagnosticsHotnessRequested = Requested; |
| 130 | } |
| 131 | bool LLVMContext::getDiagnosticsHotnessRequested() const { |
| 132 | return pImpl->DiagnosticsHotnessRequested; |
| 133 | } |
| 134 | |
| 135 | void LLVMContext::setDiagnosticsHotnessThreshold(Optional<uint64_t> Threshold) { |
| 136 | pImpl->DiagnosticsHotnessThreshold = Threshold; |
| 137 | } |
| 138 | |
| 139 | uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const { |
| 140 | return pImpl->DiagnosticsHotnessThreshold.getValueOr(UINT64_MAX); |
| 141 | } |
| 142 | |
| 143 | bool LLVMContext::isDiagnosticsHotnessThresholdSetFromPSI() const { |
| 144 | return !pImpl->DiagnosticsHotnessThreshold.hasValue(); |
| 145 | } |
| 146 | |
| 147 | remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() { |
| 148 | return pImpl->MainRemarkStreamer.get(); |
| 149 | } |
| 150 | const remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() const { |
| 151 | return const_cast<LLVMContext *>(this)->getMainRemarkStreamer(); |
| 152 | } |
| 153 | void LLVMContext::setMainRemarkStreamer( |
| 154 | std::unique_ptr<remarks::RemarkStreamer> RemarkStreamer) { |
| 155 | pImpl->MainRemarkStreamer = std::move(RemarkStreamer); |
| 156 | } |
| 157 | |
| 158 | LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() { |
| 159 | return pImpl->LLVMRS.get(); |
| 160 | } |
| 161 | const LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() const { |
| 162 | return const_cast<LLVMContext *>(this)->getLLVMRemarkStreamer(); |
| 163 | } |
| 164 | void LLVMContext::setLLVMRemarkStreamer( |
| 165 | std::unique_ptr<LLVMRemarkStreamer> RemarkStreamer) { |
| 166 | pImpl->LLVMRS = std::move(RemarkStreamer); |
| 167 | } |
| 168 | |
| 169 | DiagnosticHandler::DiagnosticHandlerTy |
| 170 | LLVMContext::getDiagnosticHandlerCallBack() const { |
| 171 | return pImpl->DiagHandler->DiagHandlerCallback; |
| 172 | } |
| 173 | |
| 174 | void *LLVMContext::getDiagnosticContext() const { |
| 175 | return pImpl->DiagHandler->DiagnosticContext; |
| 176 | } |
| 177 | |
| 178 | void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle) |
| 179 | { |
| 180 | pImpl->YieldCallback = Callback; |
| 181 | pImpl->YieldOpaqueHandle = OpaqueHandle; |
| 182 | } |
| 183 | |
| 184 | void LLVMContext::yield() { |
| 185 | if (pImpl->YieldCallback) |
| 186 | pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle); |
| 187 | } |
| 188 | |
| 189 | void LLVMContext::emitError(const Twine &ErrorStr) { |
| 190 | diagnose(DiagnosticInfoInlineAsm(ErrorStr)); |
| 191 | } |
| 192 | |
| 193 | void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { |
| 194 | assert (I && "Invalid instruction"); |
| 195 | diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); |
| 196 | } |
| 197 | |
| 198 | static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) |
| 7 | | The object is a 'DiagnosticInfoOptimizationBase' | |
|
| |
| 207 | return Remark->isEnabled() && |
| 9 | | Assuming the condition is true | |
|
| 208 | (!Remark->isVerbose() || Remark->getHotness()); |
| 10 | | Calling 'DiagnosticInfoOptimizationBase::isVerbose' | |
|
| 209 | |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | const char * |
| 214 | LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { |
| 215 | switch (Severity) { |
| 216 | case DS_Error: |
| 217 | return "error"; |
| 218 | case DS_Warning: |
| 219 | return "warning"; |
| 220 | case DS_Remark: |
| 221 | return "remark"; |
| 222 | case DS_Note: |
| 223 | return "note"; |
| 224 | } |
| 225 | llvm_unreachable("Unknown DiagnosticSeverity"); |
| 226 | } |
| 227 | |
| 228 | void LLVMContext::diagnose(const DiagnosticInfo &DI) { |
| 229 | if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) |
| 2 | | Assuming the object is a 'DiagnosticInfoOptimizationBase' | |
|
| |
| 230 | if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer()) |
| |
| |
| 231 | RS->emit(*OptDiagBase); |
| 232 | |
| 233 | |
| 234 | if (pImpl->DiagHandler && |
| 235 | (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) && |
| 236 | pImpl->DiagHandler->handleDiagnostics(DI)) |
| 237 | return; |
| 238 | |
| 239 | if (!isDiagnosticEnabled(DI)) |
| 6 | | Calling 'isDiagnosticEnabled' | |
|
| 240 | return; |
| 241 | |
| 242 | |
| 243 | DiagnosticPrinterRawOStream DP(errs()); |
| 244 | errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; |
| 245 | DI.print(DP); |
| 246 | errs() << "\n"; |
| 247 | if (DI.getSeverity() == DS_Error) |
| 248 | exit(1); |
| 249 | } |
| 250 | |
| 251 | void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { |
| 252 | diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); |
| 1 | Calling 'LLVMContext::diagnose' | |
|
| 253 | } |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | unsigned LLVMContext::getMDKindID(StringRef Name) const { |
| 261 | |
| 262 | return pImpl->CustomMDKindNames.insert( |
| 263 | std::make_pair( |
| 264 | Name, pImpl->CustomMDKindNames.size())) |
| 265 | .first->second; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | |
| 270 | void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const { |
| 271 | Names.resize(pImpl->CustomMDKindNames.size()); |
| 272 | for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(), |
| 273 | E = pImpl->CustomMDKindNames.end(); I != E; ++I) |
| 274 | Names[I->second] = I->first(); |
| 275 | } |
| 276 | |
| 277 | void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const { |
| 278 | pImpl->getOperandBundleTags(Tags); |
| 279 | } |
| 280 | |
| 281 | StringMapEntry<uint32_t> * |
| 282 | LLVMContext::getOrInsertBundleTag(StringRef TagName) const { |
| 283 | return pImpl->getOrInsertBundleTag(TagName); |
| 284 | } |
| 285 | |
| 286 | uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const { |
| 287 | return pImpl->getOperandBundleTagID(Tag); |
| 288 | } |
| 289 | |
| 290 | SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) { |
| 291 | return pImpl->getOrInsertSyncScopeID(SSN); |
| 292 | } |
| 293 | |
| 294 | void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const { |
| 295 | pImpl->getSyncScopeNames(SSNs); |
| 296 | } |
| 297 | |
| 298 | void LLVMContext::setGC(const Function &Fn, std::string GCName) { |
| 299 | auto It = pImpl->GCNames.find(&Fn); |
| 300 | |
| 301 | if (It == pImpl->GCNames.end()) { |
| 302 | pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName))); |
| 303 | return; |
| 304 | } |
| 305 | It->second = std::move(GCName); |
| 306 | } |
| 307 | |
| 308 | const std::string &LLVMContext::getGC(const Function &Fn) { |
| 309 | return pImpl->GCNames[&Fn]; |
| 310 | } |
| 311 | |
| 312 | void LLVMContext::deleteGC(const Function &Fn) { |
| 313 | pImpl->GCNames.erase(&Fn); |
| 314 | } |
| 315 | |
| 316 | bool LLVMContext::shouldDiscardValueNames() const { |
| 317 | return pImpl->DiscardValueNames; |
| 318 | } |
| 319 | |
| 320 | bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; } |
| 321 | |
| 322 | void LLVMContext::enableDebugTypeODRUniquing() { |
| 323 | if (pImpl->DITypeMap) |
| 324 | return; |
| 325 | |
| 326 | pImpl->DITypeMap.emplace(); |
| 327 | } |
| 328 | |
| 329 | void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } |
| 330 | |
| 331 | void LLVMContext::setDiscardValueNames(bool Discard) { |
| 332 | pImpl->DiscardValueNames = Discard; |
| 333 | } |
| 334 | |
| 335 | OptPassGate &LLVMContext::getOptPassGate() const { |
| 336 | return pImpl->getOptPassGate(); |
| 337 | } |
| 338 | |
| 339 | void LLVMContext::setOptPassGate(OptPassGate& OPG) { |
| 340 | pImpl->setOptPassGate(OPG); |
| 341 | } |
| 342 | |
| 343 | const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const { |
| 344 | return pImpl->DiagHandler.get(); |
| 345 | } |
| 346 | |
| 347 | std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() { |
| 348 | return std::move(pImpl->DiagHandler); |
| 349 | } |
| 350 | |
| 351 | bool LLVMContext::supportsTypedPointers() const { |
| 352 | return !pImpl->ForceOpaquePointers; |
| 353 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_IR_DIAGNOSTICINFO_H |
| 15 | #define LLVM_IR_DIAGNOSTICINFO_H |
| 16 | |
| 17 | #include "llvm-c/Types.h" |
| 18 | #include "llvm/ADT/Optional.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | #include "llvm/ADT/StringRef.h" |
| 21 | #include "llvm/ADT/Twine.h" |
| 22 | #include "llvm/IR/DebugLoc.h" |
| 23 | #include "llvm/Support/CBindingWrapping.h" |
| 24 | #include "llvm/Support/TypeSize.h" |
| 25 | #include "llvm/Support/YAMLTraits.h" |
| 26 | #include <algorithm> |
| 27 | #include <cstdint> |
| 28 | #include <functional> |
| 29 | #include <iterator> |
| 30 | #include <string> |
| 31 | |
| 32 | namespace llvm { |
| 33 | |
| 34 | |
| 35 | class DiagnosticPrinter; |
| 36 | class Function; |
| 37 | class Instruction; |
| 38 | class InstructionCost; |
| 39 | class LLVMContext; |
| 40 | class Module; |
| 41 | class SMDiagnostic; |
| 42 | |
| 43 | |
| 44 | enum DiagnosticSeverity : char { |
| 45 | DS_Error, |
| 46 | DS_Warning, |
| 47 | DS_Remark, |
| 48 | |
| 49 | |
| 50 | DS_Note |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | |
| 55 | enum DiagnosticKind { |
| 56 | DK_InlineAsm, |
| 57 | DK_ResourceLimit, |
| 58 | DK_StackSize, |
| 59 | DK_Linker, |
| 60 | DK_Lowering, |
| 61 | DK_DebugMetadataVersion, |
| 62 | DK_DebugMetadataInvalid, |
| 63 | DK_ISelFallback, |
| 64 | DK_SampleProfile, |
| 65 | DK_OptimizationRemark, |
| 66 | DK_OptimizationRemarkMissed, |
| 67 | DK_OptimizationRemarkAnalysis, |
| 68 | DK_OptimizationRemarkAnalysisFPCommute, |
| 69 | DK_OptimizationRemarkAnalysisAliasing, |
| 70 | DK_OptimizationFailure, |
| 71 | DK_FirstRemark = DK_OptimizationRemark, |
| 72 | DK_LastRemark = DK_OptimizationFailure, |
| 73 | DK_MachineOptimizationRemark, |
| 74 | DK_MachineOptimizationRemarkMissed, |
| 75 | DK_MachineOptimizationRemarkAnalysis, |
| 76 | DK_FirstMachineRemark = DK_MachineOptimizationRemark, |
| 77 | DK_LastMachineRemark = DK_MachineOptimizationRemarkAnalysis, |
| 78 | DK_MIRParser, |
| 79 | DK_PGOProfile, |
| 80 | DK_Unsupported, |
| 81 | DK_SrcMgr, |
| 82 | DK_FirstPluginKind |
| 83 | |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | int getNextAvailablePluginDiagnosticKind(); |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | class DiagnosticInfo { |
| 102 | private: |
| 103 | |
| 104 | const int Kind; |
| 105 | |
| 106 | const DiagnosticSeverity Severity; |
| 107 | |
| 108 | virtual void anchor(); |
| 109 | public: |
| 110 | DiagnosticInfo( int Kind, DiagnosticSeverity Severity) |
| 111 | : Kind(Kind), Severity(Severity) {} |
| 112 | |
| 113 | virtual ~DiagnosticInfo() = default; |
| 114 | |
| 115 | int getKind() const { return Kind; } |
| 116 | DiagnosticSeverity getSeverity() const { return Severity; } |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | virtual void print(DiagnosticPrinter &DP) const = 0; |
| 125 | }; |
| 126 | |
| 127 | using DiagnosticHandlerFunction = std::function<void(const DiagnosticInfo &)>; |
| 128 | |
| 129 | |
| 130 | |
| 131 | class DiagnosticInfoInlineAsm : public DiagnosticInfo { |
| 132 | private: |
| 133 | |
| 134 | uint64_t LocCookie = 0; |
| 135 | |
| 136 | const Twine &MsgStr; |
| 137 | |
| 138 | const Instruction *Instr = nullptr; |
| 139 | |
| 140 | public: |
| 141 | |
| 142 | |
| 143 | |
| 144 | DiagnosticInfoInlineAsm(const Twine &MsgStr, |
| 145 | DiagnosticSeverity Severity = DS_Error) |
| 146 | : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {} |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr, |
| 153 | DiagnosticSeverity Severity = DS_Error) |
| 154 | : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie), |
| 155 | MsgStr(MsgStr) {} |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, |
| 163 | DiagnosticSeverity Severity = DS_Error); |
| 164 | |
| 165 | uint64_t getLocCookie() const { return LocCookie; } |
| 166 | const Twine &getMsgStr() const { return MsgStr; } |
| 167 | const Instruction *getInstruction() const { return Instr; } |
| 168 | |
| 169 | |
| 170 | void print(DiagnosticPrinter &DP) const override; |
| 171 | |
| 172 | static bool classof(const DiagnosticInfo *DI) { |
| 173 | return DI->getKind() == DK_InlineAsm; |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | |
| 179 | class DiagnosticInfoResourceLimit : public DiagnosticInfo { |
| 180 | private: |
| 181 | |
| 182 | const Function &Fn; |
| 183 | |
| 184 | |
| 185 | const char *ResourceName; |
| 186 | |
| 187 | |
| 188 | uint64_t ResourceSize; |
| 189 | |
| 190 | |
| 191 | uint64_t ResourceLimit; |
| 192 | |
| 193 | public: |
| 194 | |
| 195 | |
| 196 | DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName, |
| 197 | uint64_t ResourceSize, |
| 198 | DiagnosticSeverity Severity = DS_Warning, |
| 199 | DiagnosticKind Kind = DK_ResourceLimit, |
| 200 | uint64_t ResourceLimit = 0) |
| 201 | : DiagnosticInfo(Kind, Severity), Fn(Fn), ResourceName(ResourceName), |
| 202 | ResourceSize(ResourceSize), ResourceLimit(ResourceLimit) {} |
| 203 | |
| 204 | const Function &getFunction() const { return Fn; } |
| 205 | const char *getResourceName() const { return ResourceName; } |
| 206 | uint64_t getResourceSize() const { return ResourceSize; } |
| 207 | uint64_t getResourceLimit() const { return ResourceLimit; } |
| 208 | |
| 209 | |
| 210 | void print(DiagnosticPrinter &DP) const override; |
| 211 | |
| 212 | static bool classof(const DiagnosticInfo *DI) { |
| 213 | return DI->getKind() == DK_ResourceLimit || DI->getKind() == DK_StackSize; |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit { |
| 218 | void anchor() override; |
| 219 | public: |
| 220 | DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize, |
| 221 | DiagnosticSeverity Severity = DS_Warning, |
| 222 | uint64_t StackLimit = 0) |
| 223 | : DiagnosticInfoResourceLimit(Fn, "stack frame size", StackSize, Severity, |
| 224 | DK_StackSize, StackLimit) {} |
| 225 | |
| 226 | uint64_t getStackSize() const { return getResourceSize(); } |
| 227 | uint64_t getStackLimit() const { return getResourceLimit(); } |
| 228 | |
| 229 | static bool classof(const DiagnosticInfo *DI) { |
| 230 | return DI->getKind() == DK_StackSize; |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | |
| 235 | |
| 236 | class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo { |
| 237 | private: |
| 238 | |
| 239 | const Module &M; |
| 240 | |
| 241 | unsigned MetadataVersion; |
| 242 | |
| 243 | public: |
| 244 | |
| 245 | |
| 246 | DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion, |
| 247 | DiagnosticSeverity Severity = DS_Warning) |
| 248 | : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M), |
| 249 | MetadataVersion(MetadataVersion) {} |
| 250 | |
| 251 | const Module &getModule() const { return M; } |
| 252 | unsigned getMetadataVersion() const { return MetadataVersion; } |
| 253 | |
| 254 | |
| 255 | void print(DiagnosticPrinter &DP) const override; |
| 256 | |
| 257 | static bool classof(const DiagnosticInfo *DI) { |
| 258 | return DI->getKind() == DK_DebugMetadataVersion; |
| 259 | } |
| 260 | }; |
| 261 | |
| 262 | |
| 263 | class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo { |
| 264 | private: |
| 265 | |
| 266 | const Module &M; |
| 267 | |
| 268 | public: |
| 269 | |
| 270 | DiagnosticInfoIgnoringInvalidDebugMetadata( |
| 271 | const Module &M, DiagnosticSeverity Severity = DS_Warning) |
| 272 | : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {} |
| 273 | |
| 274 | const Module &getModule() const { return M; } |
| 275 | |
| 276 | |
| 277 | void print(DiagnosticPrinter &DP) const override; |
| 278 | |
| 279 | static bool classof(const DiagnosticInfo *DI) { |
| 280 | return DI->getKind() == DK_DebugMetadataInvalid; |
| 281 | } |
| 282 | }; |
| 283 | |
| 284 | |
| 285 | class DiagnosticInfoSampleProfile : public DiagnosticInfo { |
| 286 | public: |
| 287 | DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum, |
| 288 | const Twine &Msg, |
| 289 | DiagnosticSeverity Severity = DS_Error) |
| 290 | : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), |
| 291 | LineNum(LineNum), Msg(Msg) {} |
| 292 | DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg, |
| 293 | DiagnosticSeverity Severity = DS_Error) |
| 294 | : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), |
| 295 | Msg(Msg) {} |
| 296 | DiagnosticInfoSampleProfile(const Twine &Msg, |
| 297 | DiagnosticSeverity Severity = DS_Error) |
| 298 | : DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {} |
| 299 | |
| 300 | |
| 301 | void print(DiagnosticPrinter &DP) const override; |
| 302 | |
| 303 | static bool classof(const DiagnosticInfo *DI) { |
| 304 | return DI->getKind() == DK_SampleProfile; |
| 305 | } |
| 306 | |
| 307 | StringRef getFileName() const { return FileName; } |
| 308 | unsigned getLineNum() const { return LineNum; } |
| 309 | const Twine &getMsg() const { return Msg; } |
| 310 | |
| 311 | private: |
| 312 | |
| 313 | StringRef FileName; |
| 314 | |
| 315 | |
| 316 | |
| 317 | unsigned LineNum = 0; |
| 318 | |
| 319 | |
| 320 | const Twine &Msg; |
| 321 | }; |
| 322 | |
| 323 | |
| 324 | class DiagnosticInfoPGOProfile : public DiagnosticInfo { |
| 325 | public: |
| 326 | DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg, |
| 327 | DiagnosticSeverity Severity = DS_Error) |
| 328 | : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {} |
| 329 | |
| 330 | |
| 331 | void print(DiagnosticPrinter &DP) const override; |
| 332 | |
| 333 | static bool classof(const DiagnosticInfo *DI) { |
| 334 | return DI->getKind() == DK_PGOProfile; |
| 335 | } |
| 336 | |
| 337 | const char *getFileName() const { return FileName; } |
| 338 | const Twine &getMsg() const { return Msg; } |
| 339 | |
| 340 | private: |
| 341 | |
| 342 | const char *FileName; |
| 343 | |
| 344 | |
| 345 | const Twine &Msg; |
| 346 | }; |
| 347 | |
| 348 | class DiagnosticLocation { |
| 349 | DIFile *File = nullptr; |
| 350 | unsigned Line = 0; |
| 351 | unsigned Column = 0; |
| 352 | |
| 353 | public: |
| 354 | DiagnosticLocation() = default; |
| 355 | DiagnosticLocation(const DebugLoc &DL); |
| 356 | DiagnosticLocation(const DISubprogram *SP); |
| 357 | |
| 358 | bool isValid() const { return File; } |
| 359 | |
| 360 | std::string getAbsolutePath() const; |
| 361 | |
| 362 | StringRef getRelativePath() const; |
| 363 | unsigned getLine() const { return Line; } |
| 364 | unsigned getColumn() const { return Column; } |
| 365 | }; |
| 366 | |
| 367 | |
| 368 | class DiagnosticInfoWithLocationBase : public DiagnosticInfo { |
| 369 | void anchor() override; |
| 370 | public: |
| 371 | |
| 372 | |
| 373 | DiagnosticInfoWithLocationBase(enum DiagnosticKind Kind, |
| 374 | enum DiagnosticSeverity Severity, |
| 375 | const Function &Fn, |
| 376 | const DiagnosticLocation &Loc) |
| 377 | : DiagnosticInfo(Kind, Severity), Fn(Fn), Loc(Loc) {} |
| 378 | |
| 379 | |
| 380 | bool isLocationAvailable() const { return Loc.isValid(); } |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | std::string getLocationStr() const; |
| 386 | |
| 387 | |
| 388 | |
| 389 | void getLocation(StringRef &RelativePath, unsigned &Line, |
| 390 | unsigned &Column) const; |
| 391 | |
| 392 | |
| 393 | std::string getAbsolutePath() const; |
| 394 | |
| 395 | const Function &getFunction() const { return Fn; } |
| 396 | DiagnosticLocation getLocation() const { return Loc; } |
| 397 | |
| 398 | private: |
| 399 | |
| 400 | const Function &Fn; |
| 401 | |
| 402 | |
| 403 | DiagnosticLocation Loc; |
| 404 | }; |
| 405 | |
| 406 | |
| 407 | |
| 408 | class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase { |
| 409 | public: |
| 410 | |
| 411 | struct setIsVerbose {}; |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | struct setExtraArgs {}; |
| 418 | |
| 419 | |
| 420 | |
| 421 | struct Argument { |
| 422 | std::string Key; |
| 423 | std::string Val; |
| 424 | |
| 425 | DiagnosticLocation Loc; |
| 426 | |
| 427 | explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {} |
| 428 | Argument(StringRef Key, const Value *V); |
| 429 | Argument(StringRef Key, const Type *T); |
| 430 | Argument(StringRef Key, StringRef S); |
| 431 | Argument(StringRef Key, const char *S) : Argument(Key, StringRef(S)) {}; |
| 432 | Argument(StringRef Key, int N); |
| 433 | Argument(StringRef Key, float N); |
| 434 | Argument(StringRef Key, long N); |
| 435 | Argument(StringRef Key, long long N); |
| 436 | Argument(StringRef Key, unsigned N); |
| 437 | Argument(StringRef Key, unsigned long N); |
| 438 | Argument(StringRef Key, unsigned long long N); |
| 439 | Argument(StringRef Key, ElementCount EC); |
| 440 | Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {} |
| 441 | Argument(StringRef Key, DebugLoc dl); |
| 442 | Argument(StringRef Key, InstructionCost C); |
| 443 | }; |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, |
| 452 | enum DiagnosticSeverity Severity, |
| 453 | const char *PassName, StringRef RemarkName, |
| 454 | const Function &Fn, |
| 455 | const DiagnosticLocation &Loc) |
| 456 | : DiagnosticInfoWithLocationBase(Kind, Severity, Fn, Loc), |
| 457 | PassName(PassName), RemarkName(RemarkName) {} |
| 458 | |
| 459 | void insert(StringRef S); |
| 460 | void insert(Argument A); |
| 461 | void insert(setIsVerbose V); |
| 462 | void insert(setExtraArgs EA); |
| 463 | |
| 464 | |
| 465 | void print(DiagnosticPrinter &DP) const override; |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | virtual bool isEnabled() const = 0; |
| 473 | |
| 474 | StringRef getPassName() const { return PassName; } |
| 475 | StringRef getRemarkName() const { return RemarkName; } |
| 476 | std::string getMsg() const; |
| 477 | Optional<uint64_t> getHotness() const { return Hotness; } |
| 478 | void setHotness(Optional<uint64_t> H) { Hotness = H; } |
| 479 | |
| 480 | bool isVerbose() const { return IsVerbose; } |
| 11 | | Undefined or garbage value returned to caller |
|
| 481 | |
| 482 | ArrayRef<Argument> getArgs() const { return Args; } |
| 483 | |
| 484 | static bool classof(const DiagnosticInfo *DI) { |
| 485 | return (DI->getKind() >= DK_FirstRemark && |
| 486 | DI->getKind() <= DK_LastRemark) || |
| 487 | (DI->getKind() >= DK_FirstMachineRemark && |
| 488 | DI->getKind() <= DK_LastMachineRemark); |
| 489 | } |
| 490 | |
| 491 | bool isPassed() const { |
| 492 | return (getKind() == DK_OptimizationRemark || |
| 493 | getKind() == DK_MachineOptimizationRemark); |
| 494 | } |
| 495 | |
| 496 | bool isMissed() const { |
| 497 | return (getKind() == DK_OptimizationRemarkMissed || |
| 498 | getKind() == DK_MachineOptimizationRemarkMissed); |
| 499 | } |
| 500 | |
| 501 | bool isAnalysis() const { |
| 502 | return (getKind() == DK_OptimizationRemarkAnalysis || |
| 503 | getKind() == DK_MachineOptimizationRemarkAnalysis); |
| 504 | } |
| 505 | |
| 506 | protected: |
| 507 | |
| 508 | |
| 509 | |
| 510 | const char *PassName; |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | StringRef RemarkName; |
| 516 | |
| 517 | |
| 518 | |
| 519 | Optional<uint64_t> Hotness; |
| 520 | |
| 521 | |
| 522 | SmallVector<Argument, 4> Args; |
| 523 | |
| 524 | |
| 525 | bool IsVerbose = false; |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | int FirstExtraArgIndex = -1; |
| 531 | }; |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | template <class RemarkT> |
| 537 | RemarkT & |
| 538 | operator<<(RemarkT &R, |
| 539 | std::enable_if_t< |
| 540 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 541 | StringRef> |
| 542 | S) { |
| 543 | R.insert(S); |
| 544 | return R; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | |
| 549 | template <class RemarkT> |
| 550 | RemarkT & |
| 551 | operator<<(RemarkT &&R, |
| 552 | std::enable_if_t< |
| 553 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 554 | StringRef> |
| 555 | S) { |
| 556 | R.insert(S); |
| 557 | return R; |
| 558 | } |
| 559 | |
| 560 | template <class RemarkT> |
| 561 | RemarkT & |
| 562 | operator<<(RemarkT &R, |
| 563 | std::enable_if_t< |
| 564 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 565 | DiagnosticInfoOptimizationBase::Argument> |
| 566 | A) { |
| 567 | R.insert(A); |
| 568 | return R; |
| 569 | } |
| 570 | |
| 571 | template <class RemarkT> |
| 572 | RemarkT & |
| 573 | operator<<(RemarkT &&R, |
| 574 | std::enable_if_t< |
| 575 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 576 | DiagnosticInfoOptimizationBase::Argument> |
| 577 | A) { |
| 578 | R.insert(A); |
| 579 | return R; |
| 580 | } |
| 581 | |
| 582 | template <class RemarkT> |
| 583 | RemarkT & |
| 584 | operator<<(RemarkT &R, |
| 585 | std::enable_if_t< |
| 586 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 587 | DiagnosticInfoOptimizationBase::setIsVerbose> |
| 588 | V) { |
| 589 | R.insert(V); |
| 590 | return R; |
| 591 | } |
| 592 | |
| 593 | template <class RemarkT> |
| 594 | RemarkT & |
| 595 | operator<<(RemarkT &&R, |
| 596 | std::enable_if_t< |
| 597 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 598 | DiagnosticInfoOptimizationBase::setIsVerbose> |
| 599 | V) { |
| 600 | R.insert(V); |
| 601 | return R; |
| 602 | } |
| 603 | |
| 604 | template <class RemarkT> |
| 605 | RemarkT & |
| 606 | operator<<(RemarkT &R, |
| 607 | std::enable_if_t< |
| 608 | std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 609 | DiagnosticInfoOptimizationBase::setExtraArgs> |
| 610 | EA) { |
| 611 | R.insert(EA); |
| 612 | return R; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | |
| 617 | class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase { |
| 618 | void anchor() override; |
| 619 | public: |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | DiagnosticInfoIROptimization(enum DiagnosticKind Kind, |
| 629 | enum DiagnosticSeverity Severity, |
| 630 | const char *PassName, StringRef RemarkName, |
| 631 | const Function &Fn, |
| 632 | const DiagnosticLocation &Loc, |
| 633 | const Value *CodeRegion = nullptr) |
| 634 | : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn, |
| 635 | Loc), |
| 636 | CodeRegion(CodeRegion) {} |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | DiagnosticInfoIROptimization(const char *PassName, StringRef Prepend, |
| 646 | const DiagnosticInfoIROptimization &Orig) |
| 647 | : DiagnosticInfoOptimizationBase( |
| 648 | (DiagnosticKind)Orig.getKind(), Orig.getSeverity(), PassName, |
| 649 | Orig.RemarkName, Orig.getFunction(), Orig.getLocation()), |
| 650 | CodeRegion(Orig.getCodeRegion()) { |
| 651 | *this << Prepend; |
| 652 | std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args)); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | DiagnosticInfoIROptimization(enum DiagnosticKind Kind, |
| 664 | enum DiagnosticSeverity Severity, |
| 665 | const char *PassName, const Function &Fn, |
| 666 | const DiagnosticLocation &Loc, const Twine &Msg) |
| 667 | : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, "", Fn, Loc) { |
| 668 | *this << Msg.str(); |
| 669 | } |
| 670 | |
| 671 | const Value *getCodeRegion() const { return CodeRegion; } |
| 672 | |
| 673 | static bool classof(const DiagnosticInfo *DI) { |
| 674 | return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark; |
| 675 | } |
| 676 | |
| 677 | private: |
| 678 | |
| 679 | |
| 680 | const Value *CodeRegion = nullptr; |
| 681 | }; |
| 682 | |
| 683 | |
| 684 | class OptimizationRemark : public DiagnosticInfoIROptimization { |
| 685 | public: |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 693 | const DiagnosticLocation &Loc, const Value *CodeRegion); |
| 694 | |
| 695 | |
| 696 | |
| 697 | OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 698 | const Instruction *Inst); |
| 699 | |
| 700 | |
| 701 | |
| 702 | OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 703 | const Function *Func); |
| 704 | |
| 705 | static bool classof(const DiagnosticInfo *DI) { |
| 706 | return DI->getKind() == DK_OptimizationRemark; |
| 707 | } |
| 708 | |
| 709 | |
| 710 | bool isEnabled() const override; |
| 711 | |
| 712 | private: |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | OptimizationRemark(const char *PassName, const Function &Fn, |
| 723 | const DiagnosticLocation &Loc, const Twine &Msg) |
| 724 | : DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName, |
| 725 | Fn, Loc, Msg) {} |
| 726 | }; |
| 727 | |
| 728 | |
| 729 | class OptimizationRemarkMissed : public DiagnosticInfoIROptimization { |
| 730 | public: |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 738 | const DiagnosticLocation &Loc, |
| 739 | const Value *CodeRegion); |
| 740 | |
| 741 | |
| 742 | |
| 743 | OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 744 | const Instruction *Inst); |
| 745 | |
| 746 | |
| 747 | |
| 748 | OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 749 | const Function *F); |
| 750 | |
| 751 | static bool classof(const DiagnosticInfo *DI) { |
| 752 | return DI->getKind() == DK_OptimizationRemarkMissed; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | bool isEnabled() const override; |
| 757 | |
| 758 | private: |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | OptimizationRemarkMissed(const char *PassName, const Function &Fn, |
| 769 | const DiagnosticLocation &Loc, const Twine &Msg) |
| 770 | : DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark, |
| 771 | PassName, Fn, Loc, Msg) {} |
| 772 | }; |
| 773 | |
| 774 | |
| 775 | class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization { |
| 776 | public: |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 784 | const DiagnosticLocation &Loc, |
| 785 | const Value *CodeRegion); |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend, |
| 795 | const OptimizationRemarkAnalysis &Orig) |
| 796 | : DiagnosticInfoIROptimization(PassName, Prepend, Orig) {} |
| 797 | |
| 798 | |
| 799 | |
| 800 | OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 801 | const Instruction *Inst); |
| 802 | |
| 803 | |
| 804 | |
| 805 | OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 806 | const Function *F); |
| 807 | |
| 808 | static bool classof(const DiagnosticInfo *DI) { |
| 809 | return DI->getKind() == DK_OptimizationRemarkAnalysis; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | bool isEnabled() const override; |
| 814 | |
| 815 | static const char *AlwaysPrint; |
| 816 | |
| 817 | bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; } |
| 818 | |
| 819 | protected: |
| 820 | OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName, |
| 821 | const Function &Fn, const DiagnosticLocation &Loc, |
| 822 | const Twine &Msg) |
| 823 | : DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {} |
| 824 | |
| 825 | OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName, |
| 826 | StringRef RemarkName, |
| 827 | const DiagnosticLocation &Loc, |
| 828 | const Value *CodeRegion); |
| 829 | |
| 830 | private: |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | OptimizationRemarkAnalysis(const char *PassName, const Function &Fn, |
| 841 | const DiagnosticLocation &Loc, const Twine &Msg) |
| 842 | : DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark, |
| 843 | PassName, Fn, Loc, Msg) {} |
| 844 | }; |
| 845 | |
| 846 | |
| 847 | |
| 848 | class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis { |
| 849 | void anchor() override; |
| 850 | public: |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | OptimizationRemarkAnalysisFPCommute(const char *PassName, |
| 859 | StringRef RemarkName, |
| 860 | const DiagnosticLocation &Loc, |
| 861 | const Value *CodeRegion) |
| 862 | : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute, |
| 863 | PassName, RemarkName, Loc, CodeRegion) {} |
| 864 | |
| 865 | static bool classof(const DiagnosticInfo *DI) { |
| 866 | return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute; |
| 867 | } |
| 868 | |
| 869 | private: |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn, |
| 882 | const DiagnosticLocation &Loc, |
| 883 | const Twine &Msg) |
| 884 | : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute, |
| 885 | PassName, Fn, Loc, Msg) {} |
| 886 | }; |
| 887 | |
| 888 | |
| 889 | |
| 890 | class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis { |
| 891 | void anchor() override; |
| 892 | public: |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName, |
| 901 | const DiagnosticLocation &Loc, |
| 902 | const Value *CodeRegion) |
| 903 | : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing, |
| 904 | PassName, RemarkName, Loc, CodeRegion) {} |
| 905 | |
| 906 | static bool classof(const DiagnosticInfo *DI) { |
| 907 | return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing; |
| 908 | } |
| 909 | |
| 910 | private: |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn, |
| 923 | const DiagnosticLocation &Loc, |
| 924 | const Twine &Msg) |
| 925 | : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing, |
| 926 | PassName, Fn, Loc, Msg) {} |
| 927 | }; |
| 928 | |
| 929 | |
| 930 | |
| 931 | class DiagnosticInfoMIRParser : public DiagnosticInfo { |
| 932 | const SMDiagnostic &Diagnostic; |
| 933 | |
| 934 | public: |
| 935 | DiagnosticInfoMIRParser(DiagnosticSeverity Severity, |
| 936 | const SMDiagnostic &Diagnostic) |
| 937 | : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {} |
| 938 | |
| 939 | const SMDiagnostic &getDiagnostic() const { return Diagnostic; } |
| 940 | |
| 941 | void print(DiagnosticPrinter &DP) const override; |
| 942 | |
| 943 | static bool classof(const DiagnosticInfo *DI) { |
| 944 | return DI->getKind() == DK_MIRParser; |
| 945 | } |
| 946 | }; |
| 947 | |
| 948 | |
| 949 | class DiagnosticInfoISelFallback : public DiagnosticInfo { |
| 950 | |
| 951 | const Function &Fn; |
| 952 | |
| 953 | public: |
| 954 | DiagnosticInfoISelFallback(const Function &Fn, |
| 955 | DiagnosticSeverity Severity = DS_Warning) |
| 956 | : DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {} |
| 957 | |
| 958 | const Function &getFunction() const { return Fn; } |
| 959 | |
| 960 | void print(DiagnosticPrinter &DP) const override; |
| 961 | |
| 962 | static bool classof(const DiagnosticInfo *DI) { |
| 963 | return DI->getKind() == DK_ISelFallback; |
| 964 | } |
| 965 | }; |
| 966 | |
| 967 | |
| 968 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef) |
| 969 | |
| 970 | |
| 971 | class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization { |
| 972 | public: |
| 973 | |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | DiagnosticInfoOptimizationFailure(const Function &Fn, |
| 980 | const DiagnosticLocation &Loc, |
| 981 | const Twine &Msg) |
| 982 | : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, |
| 983 | nullptr, Fn, Loc, Msg) {} |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName, |
| 991 | const DiagnosticLocation &Loc, |
| 992 | const Value *CodeRegion); |
| 993 | |
| 994 | static bool classof(const DiagnosticInfo *DI) { |
| 995 | return DI->getKind() == DK_OptimizationFailure; |
| 996 | } |
| 997 | |
| 998 | |
| 999 | bool isEnabled() const override; |
| 1000 | }; |
| 1001 | |
| 1002 | |
| 1003 | class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase { |
| 1004 | private: |
| 1005 | Twine Msg; |
| 1006 | |
| 1007 | public: |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | DiagnosticInfoUnsupported( |
| 1015 | const Function &Fn, const Twine &Msg, |
| 1016 | const DiagnosticLocation &Loc = DiagnosticLocation(), |
| 1017 | DiagnosticSeverity Severity = DS_Error) |
| 1018 | : DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc), |
| 1019 | Msg(Msg) {} |
| 1020 | |
| 1021 | static bool classof(const DiagnosticInfo *DI) { |
| 1022 | return DI->getKind() == DK_Unsupported; |
| 1023 | } |
| 1024 | |
| 1025 | const Twine &getMessage() const { return Msg; } |
| 1026 | |
| 1027 | void print(DiagnosticPrinter &DP) const override; |
| 1028 | }; |
| 1029 | |
| 1030 | static DiagnosticSeverity getDiagnosticSeverity(SourceMgr::DiagKind DK) { |
| 1031 | switch (DK) { |
| 1032 | case llvm::SourceMgr::DK_Error: |
| 1033 | return DS_Error; |
| 1034 | break; |
| 1035 | case llvm::SourceMgr::DK_Warning: |
| 1036 | return DS_Warning; |
| 1037 | break; |
| 1038 | case llvm::SourceMgr::DK_Note: |
| 1039 | return DS_Note; |
| 1040 | break; |
| 1041 | case llvm::SourceMgr::DK_Remark: |
| 1042 | return DS_Remark; |
| 1043 | break; |
| 1044 | } |
| 1045 | llvm_unreachable("unknown SourceMgr::DiagKind"); |
| 1046 | } |
| 1047 | |
| 1048 | |
| 1049 | class DiagnosticInfoSrcMgr : public DiagnosticInfo { |
| 1050 | const SMDiagnostic &Diagnostic; |
| 1051 | |
| 1052 | |
| 1053 | bool InlineAsmDiag; |
| 1054 | unsigned LocCookie; |
| 1055 | |
| 1056 | public: |
| 1057 | DiagnosticInfoSrcMgr(const SMDiagnostic &Diagnostic, |
| 1058 | bool InlineAsmDiag = true, unsigned LocCookie = 0) |
| 1059 | : DiagnosticInfo(DK_SrcMgr, getDiagnosticSeverity(Diagnostic.getKind())), |
| 1060 | Diagnostic(Diagnostic), InlineAsmDiag(InlineAsmDiag), |
| 1061 | LocCookie(LocCookie) {} |
| 1062 | |
| 1063 | bool isInlineAsmDiag() const { return InlineAsmDiag; } |
| 1064 | const SMDiagnostic &getSMDiag() const { return Diagnostic; } |
| 1065 | unsigned getLocCookie() const { return LocCookie; } |
| 1066 | void print(DiagnosticPrinter &DP) const override; |
| 1067 | |
| 1068 | static bool classof(const DiagnosticInfo *DI) { |
| 1069 | return DI->getKind() == DK_SrcMgr; |
| 1070 | } |
| 1071 | }; |
| 1072 | |
| 1073 | } |
| 1074 | |
| 1075 | #endif // LLVM_IR_DIAGNOSTICINFO_H |