| 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/ArrayRef.h" |
| 19 |
#include "llvm/ADT/Optional.h" |
| 20 |
#include "llvm/ADT/SmallVector.h" |
| 21 |
#include "llvm/ADT/StringRef.h" |
| 22 |
#include "llvm/ADT/Twine.h" |
| 23 |
#include "llvm/IR/DebugLoc.h" |
| 24 |
#include "llvm/Support/CBindingWrapping.h" |
| 25 |
#include "llvm/Support/ErrorHandling.h" |
| 26 |
#include "llvm/Support/SourceMgr.h" |
| 27 |
#include "llvm/Support/TypeSize.h" |
| 28 |
#include <algorithm> |
| 29 |
#include <cstdint> |
| 30 |
#include <functional> |
| 31 |
#include <iterator> |
| 32 |
#include <string> |
| 33 |
|
| 34 |
namespace llvm { |
| 35 |
|
| 36 |
|
| 37 |
class DiagnosticPrinter; |
| 38 |
class DIFile; |
| 39 |
class DISubprogram; |
| 40 |
class CallInst; |
| 41 |
class Function; |
| 42 |
class Instruction; |
| 43 |
class InstructionCost; |
| 44 |
class Module; |
| 45 |
class Type; |
| 46 |
class Value; |
| 47 |
|
| 48 |
|
| 49 |
enum DiagnosticSeverity : char { |
| 50 |
DS_Error, |
| 51 |
DS_Warning, |
| 52 |
DS_Remark, |
| 53 |
|
| 54 |
|
| 55 |
DS_Note |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
enum DiagnosticKind { |
| 61 |
DK_InlineAsm, |
| 62 |
DK_ResourceLimit, |
| 63 |
DK_StackSize, |
| 64 |
DK_Linker, |
| 65 |
DK_Lowering, |
| 66 |
DK_DebugMetadataVersion, |
| 67 |
DK_DebugMetadataInvalid, |
| 68 |
DK_ISelFallback, |
| 69 |
DK_SampleProfile, |
| 70 |
DK_OptimizationRemark, |
| 71 |
DK_OptimizationRemarkMissed, |
| 72 |
DK_OptimizationRemarkAnalysis, |
| 73 |
DK_OptimizationRemarkAnalysisFPCommute, |
| 74 |
DK_OptimizationRemarkAnalysisAliasing, |
| 75 |
DK_OptimizationFailure, |
| 76 |
DK_FirstRemark = DK_OptimizationRemark, |
| 77 |
DK_LastRemark = DK_OptimizationFailure, |
| 78 |
DK_MachineOptimizationRemark, |
| 79 |
DK_MachineOptimizationRemarkMissed, |
| 80 |
DK_MachineOptimizationRemarkAnalysis, |
| 81 |
DK_FirstMachineRemark = DK_MachineOptimizationRemark, |
| 82 |
DK_LastMachineRemark = DK_MachineOptimizationRemarkAnalysis, |
| 83 |
DK_MIRParser, |
| 84 |
DK_PGOProfile, |
| 85 |
DK_Unsupported, |
| 86 |
DK_SrcMgr, |
| 87 |
DK_DontCall, |
| 88 |
DK_FirstPluginKind |
| 89 |
|
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
int getNextAvailablePluginDiagnosticKind(); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
class DiagnosticInfo { |
| 108 |
private: |
| 109 |
|
| 110 |
const int Kind; |
| 111 |
|
| 112 |
const DiagnosticSeverity Severity; |
| 113 |
|
| 114 |
virtual void anchor(); |
| 115 |
public: |
| 116 |
DiagnosticInfo( int Kind, DiagnosticSeverity Severity) |
| 117 |
: Kind(Kind), Severity(Severity) {} |
| 118 |
|
| 119 |
virtual ~DiagnosticInfo() = default; |
| 120 |
|
| 121 |
int getKind() const { return Kind; } |
| 122 |
DiagnosticSeverity getSeverity() const { return Severity; } |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
virtual void print(DiagnosticPrinter &DP) const = 0; |
| 131 |
}; |
| 132 |
|
| 133 |
using DiagnosticHandlerFunction = std::function<void(const DiagnosticInfo &)>; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
class DiagnosticInfoInlineAsm : public DiagnosticInfo { |
| 138 |
private: |
| 139 |
|
| 140 |
uint64_t LocCookie = 0; |
| 141 |
|
| 142 |
const Twine &MsgStr; |
| 143 |
|
| 144 |
const Instruction *Instr = nullptr; |
| 145 |
|
| 146 |
public: |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
DiagnosticInfoInlineAsm(const Twine &MsgStr, |
| 151 |
DiagnosticSeverity Severity = DS_Error) |
| 152 |
: DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr, |
| 159 |
DiagnosticSeverity Severity = DS_Error) |
| 160 |
: DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie), |
| 161 |
MsgStr(MsgStr) {} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, |
| 169 |
DiagnosticSeverity Severity = DS_Error); |
| 170 |
|
| 171 |
uint64_t getLocCookie() const { return LocCookie; } |
| 172 |
const Twine &getMsgStr() const { return MsgStr; } |
| 173 |
const Instruction *getInstruction() const { return Instr; } |
| 174 |
|
| 175 |
|
| 176 |
void print(DiagnosticPrinter &DP) const override; |
| 177 |
|
| 178 |
static bool classof(const DiagnosticInfo *DI) { |
| 179 |
return DI->getKind() == DK_InlineAsm; |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
class DiagnosticInfoResourceLimit : public DiagnosticInfo { |
| 186 |
private: |
| 187 |
|
| 188 |
const Function &Fn; |
| 189 |
|
| 190 |
|
| 191 |
const char *ResourceName; |
| 192 |
|
| 193 |
|
| 194 |
uint64_t ResourceSize; |
| 195 |
|
| 196 |
|
| 197 |
uint64_t ResourceLimit; |
| 198 |
|
| 199 |
public: |
| 200 |
|
| 201 |
|
| 202 |
DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName, |
| 203 |
uint64_t ResourceSize, uint64_t ResourceLimit, |
| 204 |
DiagnosticSeverity Severity = DS_Warning, |
| 205 |
DiagnosticKind Kind = DK_ResourceLimit) |
| 206 |
: DiagnosticInfo(Kind, Severity), Fn(Fn), ResourceName(ResourceName), |
| 207 |
ResourceSize(ResourceSize), ResourceLimit(ResourceLimit) {} |
| 208 |
|
| 209 |
const Function &getFunction() const { return Fn; } |
| 210 |
const char *getResourceName() const { return ResourceName; } |
| 211 |
uint64_t getResourceSize() const { return ResourceSize; } |
| 212 |
uint64_t getResourceLimit() const { return ResourceLimit; } |
| 213 |
|
| 214 |
|
| 215 |
void print(DiagnosticPrinter &DP) const override; |
| 216 |
|
| 217 |
static bool classof(const DiagnosticInfo *DI) { |
| 218 |
return DI->getKind() == DK_ResourceLimit || DI->getKind() == DK_StackSize; |
| 219 |
} |
| 220 |
}; |
| 221 |
|
| 222 |
class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit { |
| 223 |
void anchor() override; |
| 224 |
public: |
| 225 |
DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize, |
| 226 |
uint64_t StackLimit, |
| 227 |
DiagnosticSeverity Severity = DS_Warning) |
| 228 |
: DiagnosticInfoResourceLimit(Fn, "stack frame size", StackSize, |
| 229 |
StackLimit, Severity, DK_StackSize) {} |
| 230 |
|
| 231 |
uint64_t getStackSize() const { return getResourceSize(); } |
| 232 |
uint64_t getStackLimit() const { return getResourceLimit(); } |
| 233 |
|
| 234 |
static bool classof(const DiagnosticInfo *DI) { |
| 235 |
return DI->getKind() == DK_StackSize; |
| 236 |
} |
| 237 |
}; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo { |
| 242 |
private: |
| 243 |
|
| 244 |
const Module &M; |
| 245 |
|
| 246 |
unsigned MetadataVersion; |
| 247 |
|
| 248 |
public: |
| 249 |
|
| 250 |
|
| 251 |
DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion, |
| 252 |
DiagnosticSeverity Severity = DS_Warning) |
| 253 |
: DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M), |
| 254 |
MetadataVersion(MetadataVersion) {} |
| 255 |
|
| 256 |
const Module &getModule() const { return M; } |
| 257 |
unsigned getMetadataVersion() const { return MetadataVersion; } |
| 258 |
|
| 259 |
|
| 260 |
void print(DiagnosticPrinter &DP) const override; |
| 261 |
|
| 262 |
static bool classof(const DiagnosticInfo *DI) { |
| 263 |
return DI->getKind() == DK_DebugMetadataVersion; |
| 264 |
} |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo { |
| 269 |
private: |
| 270 |
|
| 271 |
const Module &M; |
| 272 |
|
| 273 |
public: |
| 274 |
|
| 275 |
DiagnosticInfoIgnoringInvalidDebugMetadata( |
| 276 |
const Module &M, DiagnosticSeverity Severity = DS_Warning) |
| 277 |
: DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {} |
| 278 |
|
| 279 |
const Module &getModule() const { return M; } |
| 280 |
|
| 281 |
|
| 282 |
void print(DiagnosticPrinter &DP) const override; |
| 283 |
|
| 284 |
static bool classof(const DiagnosticInfo *DI) { |
| 285 |
return DI->getKind() == DK_DebugMetadataInvalid; |
| 286 |
} |
| 287 |
}; |
| 288 |
|
| 289 |
|
| 290 |
class DiagnosticInfoSampleProfile : public DiagnosticInfo { |
| 291 |
public: |
| 292 |
DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum, |
| 293 |
const Twine &Msg, |
| 294 |
DiagnosticSeverity Severity = DS_Error) |
| 295 |
: DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), |
| 296 |
LineNum(LineNum), Msg(Msg) {} |
| 297 |
DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg, |
| 298 |
DiagnosticSeverity Severity = DS_Error) |
| 299 |
: DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), |
| 300 |
Msg(Msg) {} |
| 301 |
DiagnosticInfoSampleProfile(const Twine &Msg, |
| 302 |
DiagnosticSeverity Severity = DS_Error) |
| 303 |
: DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {} |
| 304 |
|
| 305 |
|
| 306 |
void print(DiagnosticPrinter &DP) const override; |
| 307 |
|
| 308 |
static bool classof(const DiagnosticInfo *DI) { |
| 309 |
return DI->getKind() == DK_SampleProfile; |
| 310 |
} |
| 311 |
|
| 312 |
StringRef getFileName() const { return FileName; } |
| 313 |
unsigned getLineNum() const { return LineNum; } |
| 314 |
const Twine &getMsg() const { return Msg; } |
| 315 |
|
| 316 |
private: |
| 317 |
|
| 318 |
StringRef FileName; |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
unsigned LineNum = 0; |
| 323 |
|
| 324 |
|
| 325 |
const Twine &Msg; |
| 326 |
}; |
| 327 |
|
| 328 |
|
| 329 |
class DiagnosticInfoPGOProfile : public DiagnosticInfo { |
| 330 |
public: |
| 331 |
DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg, |
| 332 |
DiagnosticSeverity Severity = DS_Error) |
| 333 |
: DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {} |
| 334 |
|
| 335 |
|
| 336 |
void print(DiagnosticPrinter &DP) const override; |
| 337 |
|
| 338 |
static bool classof(const DiagnosticInfo *DI) { |
| 339 |
return DI->getKind() == DK_PGOProfile; |
| 340 |
} |
| 341 |
|
| 342 |
const char *getFileName() const { return FileName; } |
| 343 |
const Twine &getMsg() const { return Msg; } |
| 344 |
|
| 345 |
private: |
| 346 |
|
| 347 |
const char *FileName; |
| 348 |
|
| 349 |
|
| 350 |
const Twine &Msg; |
| 351 |
}; |
| 352 |
|
| 353 |
class DiagnosticLocation { |
| 354 |
DIFile *File = nullptr; |
| 355 |
unsigned Line = 0; |
| 356 |
unsigned Column = 0; |
| 357 |
|
| 358 |
public: |
| 359 |
DiagnosticLocation() = default; |
| 360 |
DiagnosticLocation(const DebugLoc &DL); |
| 361 |
DiagnosticLocation(const DISubprogram *SP); |
| 362 |
|
| 363 |
bool isValid() const { return File; } |
| 364 |
|
| 365 |
std::string getAbsolutePath() const; |
| 366 |
|
| 367 |
StringRef getRelativePath() const; |
| 368 |
unsigned getLine() const { return Line; } |
| 369 |
unsigned getColumn() const { return Column; } |
| 370 |
}; |
| 371 |
|
| 372 |
|
| 373 |
class DiagnosticInfoWithLocationBase : public DiagnosticInfo { |
| 374 |
void anchor() override; |
| 375 |
public: |
| 376 |
|
| 377 |
|
| 378 |
DiagnosticInfoWithLocationBase(enum DiagnosticKind Kind, |
| 379 |
enum DiagnosticSeverity Severity, |
| 380 |
const Function &Fn, |
| 381 |
const DiagnosticLocation &Loc) |
| 382 |
: DiagnosticInfo(Kind, Severity), Fn(Fn), Loc(Loc) {} |
| 383 |
|
| 384 |
|
| 385 |
bool isLocationAvailable() const { return Loc.isValid(); } |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
std::string getLocationStr() const; |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
void getLocation(StringRef &RelativePath, unsigned &Line, |
| 395 |
unsigned &Column) const; |
| 396 |
|
| 397 |
|
| 398 |
std::string getAbsolutePath() const; |
| 399 |
|
| 400 |
const Function &getFunction() const { return Fn; } |
| 401 |
DiagnosticLocation getLocation() const { return Loc; } |
| 402 |
|
| 403 |
private: |
| 404 |
|
| 405 |
const Function &Fn; |
| 406 |
|
| 407 |
|
| 408 |
DiagnosticLocation Loc; |
| 409 |
}; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase { |
| 414 |
public: |
| 415 |
|
| 416 |
struct setIsVerbose {}; |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
struct setExtraArgs {}; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
struct Argument { |
| 427 |
std::string Key; |
| 428 |
std::string Val; |
| 429 |
|
| 430 |
DiagnosticLocation Loc; |
| 431 |
|
| 432 |
explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {} |
| 433 |
Argument(StringRef Key, const Value *V); |
| 434 |
Argument(StringRef Key, const Type *T); |
| 435 |
Argument(StringRef Key, StringRef S); |
| 436 |
Argument(StringRef Key, const char *S) : Argument(Key, StringRef(S)) {}; |
| 437 |
Argument(StringRef Key, int N); |
| 438 |
Argument(StringRef Key, float N); |
| 439 |
Argument(StringRef Key, long N); |
| 440 |
Argument(StringRef Key, long long N); |
| 441 |
Argument(StringRef Key, unsigned N); |
| 442 |
Argument(StringRef Key, unsigned long N); |
| 443 |
Argument(StringRef Key, unsigned long long N); |
| 444 |
Argument(StringRef Key, ElementCount EC); |
| 445 |
Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {} |
| 446 |
Argument(StringRef Key, DebugLoc dl); |
| 447 |
Argument(StringRef Key, InstructionCost C); |
| 448 |
}; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, |
| 457 |
enum DiagnosticSeverity Severity, |
| 458 |
const char *PassName, StringRef RemarkName, |
| 459 |
const Function &Fn, |
| 460 |
const DiagnosticLocation &Loc) |
| 461 |
: DiagnosticInfoWithLocationBase(Kind, Severity, Fn, Loc), |
| 462 |
PassName(PassName), RemarkName(RemarkName) {} |
| 463 |
|
| 464 |
void insert(StringRef S); |
| 465 |
void insert(Argument A); |
| 466 |
void insert(setIsVerbose V); |
| 467 |
void insert(setExtraArgs EA); |
| 468 |
|
| 469 |
|
| 470 |
void print(DiagnosticPrinter &DP) const override; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
virtual bool isEnabled() const = 0; |
| 478 |
|
| 479 |
StringRef getPassName() const { return PassName; } |
| 480 |
StringRef getRemarkName() const { return RemarkName; } |
| 481 |
std::string getMsg() const; |
| 482 |
Optional<uint64_t> getHotness() const { return Hotness; } |
| 483 |
void setHotness(Optional<uint64_t> H) { Hotness = H; } |
| 484 |
|
| 485 |
bool isVerbose() const { return IsVerbose; } |
| 486 |
|
| 487 |
ArrayRef<Argument> getArgs() const { return Args; } |
| 488 |
|
| 489 |
static bool classof(const DiagnosticInfo *DI) { |
| 490 |
return (DI->getKind() >= DK_FirstRemark && |
| 491 |
DI->getKind() <= DK_LastRemark) || |
| 492 |
(DI->getKind() >= DK_FirstMachineRemark && |
| 493 |
DI->getKind() <= DK_LastMachineRemark); |
| 494 |
} |
| 495 |
|
| 496 |
bool isPassed() const { |
| 497 |
return (getKind() == DK_OptimizationRemark || |
| 498 |
getKind() == DK_MachineOptimizationRemark); |
| 499 |
} |
| 500 |
|
| 501 |
bool isMissed() const { |
| 502 |
return (getKind() == DK_OptimizationRemarkMissed || |
| 503 |
getKind() == DK_MachineOptimizationRemarkMissed); |
| 504 |
} |
| 505 |
|
| 506 |
bool isAnalysis() const { |
| 507 |
return (getKind() == DK_OptimizationRemarkAnalysis || |
| 508 |
getKind() == DK_MachineOptimizationRemarkAnalysis); |
| 509 |
} |
| 510 |
|
| 511 |
protected: |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
const char *PassName; |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
StringRef RemarkName; |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
Optional<uint64_t> Hotness; |
| 525 |
|
| 526 |
|
| 527 |
SmallVector<Argument, 4> Args; |
| 528 |
|
| 529 |
|
| 530 |
bool IsVerbose = false; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
int FirstExtraArgIndex = -1; |
| 536 |
}; |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
template <class RemarkT> |
| 542 |
RemarkT & |
| 543 |
operator<<(RemarkT &R, |
| 544 |
std::enable_if_t< |
| 545 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 546 |
StringRef> |
| 547 |
S) { |
| 548 |
R.insert(S); |
| 549 |
return R; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
template <class RemarkT> |
| 555 |
RemarkT & |
| 556 |
operator<<(RemarkT &&R, |
| 557 |
std::enable_if_t< |
| 558 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 559 |
StringRef> |
| 560 |
S) { |
| 561 |
R.insert(S); |
| 562 |
return R; |
| 563 |
} |
| 564 |
|
| 565 |
template <class RemarkT> |
| 566 |
RemarkT & |
| 567 |
operator<<(RemarkT &R, |
| 568 |
std::enable_if_t< |
| 569 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 570 |
DiagnosticInfoOptimizationBase::Argument> |
| 571 |
A) { |
| 572 |
R.insert(A); |
| 573 |
return R; |
| 574 |
} |
| 575 |
|
| 576 |
template <class RemarkT> |
| 577 |
RemarkT & |
| 578 |
operator<<(RemarkT &&R, |
| 579 |
std::enable_if_t< |
| 580 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 581 |
DiagnosticInfoOptimizationBase::Argument> |
| 582 |
A) { |
| 583 |
R.insert(A); |
| 584 |
return R; |
| 585 |
} |
| 586 |
|
| 587 |
template <class RemarkT> |
| 588 |
RemarkT & |
| 589 |
operator<<(RemarkT &R, |
| 590 |
std::enable_if_t< |
| 591 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 592 |
DiagnosticInfoOptimizationBase::setIsVerbose> |
| 593 |
V) { |
| 594 |
R.insert(V); |
| 595 |
return R; |
| 596 |
} |
| 597 |
|
| 598 |
template <class RemarkT> |
| 599 |
RemarkT & |
| 600 |
operator<<(RemarkT &&R, |
| 601 |
std::enable_if_t< |
| 602 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 603 |
DiagnosticInfoOptimizationBase::setIsVerbose> |
| 604 |
V) { |
| 605 |
R.insert(V); |
| 606 |
return R; |
| 607 |
} |
| 608 |
|
| 609 |
template <class RemarkT> |
| 610 |
RemarkT & |
| 611 |
operator<<(RemarkT &R, |
| 612 |
std::enable_if_t< |
| 613 |
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value, |
| 614 |
DiagnosticInfoOptimizationBase::setExtraArgs> |
| 615 |
EA) { |
| 616 |
R.insert(EA); |
| 617 |
return R; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase { |
| 623 |
void anchor() override; |
| 624 |
public: |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
DiagnosticInfoIROptimization(enum DiagnosticKind Kind, |
| 634 |
enum DiagnosticSeverity Severity, |
| 635 |
const char *PassName, StringRef RemarkName, |
| 636 |
const Function &Fn, |
| 637 |
const DiagnosticLocation &Loc, |
| 638 |
const Value *CodeRegion = nullptr) |
| 639 |
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn, |
| 640 |
Loc), |
| 641 |
CodeRegion(CodeRegion) {} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
DiagnosticInfoIROptimization(const char *PassName, StringRef Prepend, |
| 651 |
const DiagnosticInfoIROptimization &Orig) |
| 652 |
: DiagnosticInfoOptimizationBase( |
| 653 |
(DiagnosticKind)Orig.getKind(), Orig.getSeverity(), PassName, |
| 654 |
Orig.RemarkName, Orig.getFunction(), Orig.getLocation()), |
| 655 |
CodeRegion(Orig.getCodeRegion()) { |
| 656 |
*this << Prepend; |
| 657 |
std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args)); |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
DiagnosticInfoIROptimization(enum DiagnosticKind Kind, |
| 669 |
enum DiagnosticSeverity Severity, |
| 670 |
const char *PassName, const Function &Fn, |
| 671 |
const DiagnosticLocation &Loc, const Twine &Msg) |
| 672 |
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, "", Fn, Loc) { |
| 673 |
*this << Msg.str(); |
| 674 |
} |
| 675 |
|
| 676 |
const Value *getCodeRegion() const { return CodeRegion; } |
| 677 |
|
| 678 |
static bool classof(const DiagnosticInfo *DI) { |
| 679 |
return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark; |
| 680 |
} |
| 681 |
|
| 682 |
private: |
| 683 |
|
| 684 |
|
| 685 |
const Value *CodeRegion = nullptr; |
| 686 |
}; |
| 687 |
|
| 688 |
|
| 689 |
class OptimizationRemark : public DiagnosticInfoIROptimization { |
| 690 |
public: |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 698 |
const DiagnosticLocation &Loc, const Value *CodeRegion); |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 703 |
const Instruction *Inst); |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
OptimizationRemark(const char *PassName, StringRef RemarkName, |
| 708 |
const Function *Func); |
| 709 |
|
| 710 |
static bool classof(const DiagnosticInfo *DI) { |
| 711 |
return DI->getKind() == DK_OptimizationRemark; |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
bool isEnabled() const override; |
| 716 |
|
| 717 |
private: |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
OptimizationRemark(const char *PassName, const Function &Fn, |
| 728 |
const DiagnosticLocation &Loc, const Twine &Msg) |
| 729 |
: DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName, |
| 730 |
Fn, Loc, Msg) {} |
| 731 |
}; |
| 732 |
|
| 733 |
|
| 734 |
class OptimizationRemarkMissed : public DiagnosticInfoIROptimization { |
| 735 |
public: |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 743 |
const DiagnosticLocation &Loc, |
| 744 |
const Value *CodeRegion); |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 749 |
const Instruction *Inst); |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
OptimizationRemarkMissed(const char *PassName, StringRef RemarkName, |
| 754 |
const Function *F); |
| 755 |
|
| 756 |
static bool classof(const DiagnosticInfo *DI) { |
| 757 |
return DI->getKind() == DK_OptimizationRemarkMissed; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
bool isEnabled() const override; |
| 762 |
|
| 763 |
private: |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
OptimizationRemarkMissed(const char *PassName, const Function &Fn, |
| 774 |
const DiagnosticLocation &Loc, const Twine &Msg) |
| 775 |
: DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark, |
| 776 |
PassName, Fn, Loc, Msg) {} |
| 777 |
}; |
| 778 |
|
| 779 |
|
| 780 |
class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization { |
| 781 |
public: |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 789 |
const DiagnosticLocation &Loc, |
| 790 |
const Value *CodeRegion); |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend, |
| 800 |
const OptimizationRemarkAnalysis &Orig) |
| 801 |
: DiagnosticInfoIROptimization(PassName, Prepend, Orig) {} |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 806 |
const Instruction *Inst); |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, |
| 811 |
const Function *F); |
| 812 |
|
| 813 |
static bool classof(const DiagnosticInfo *DI) { |
| 814 |
return DI->getKind() == DK_OptimizationRemarkAnalysis; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
bool isEnabled() const override; |
| 819 |
|
| 820 |
static const char *AlwaysPrint; |
| 821 |
|
| 822 |
bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; } |
| 823 |
|
| 824 |
protected: |
| 825 |
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName, |
| 826 |
const Function &Fn, const DiagnosticLocation &Loc, |
| 827 |
const Twine &Msg) |
| 828 |
: DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {} |
| 829 |
|
| 830 |
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName, |
| 831 |
StringRef RemarkName, |
| 832 |
const DiagnosticLocation &Loc, |
| 833 |
const Value *CodeRegion); |
| 834 |
|
| 835 |
private: |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
OptimizationRemarkAnalysis(const char *PassName, const Function &Fn, |
| 846 |
const DiagnosticLocation &Loc, const Twine &Msg) |
| 847 |
: DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark, |
| 848 |
PassName, Fn, Loc, Msg) {} |
| 849 |
}; |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis { |
| 854 |
void anchor() override; |
| 855 |
public: |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
OptimizationRemarkAnalysisFPCommute(const char *PassName, |
| 864 |
StringRef RemarkName, |
| 865 |
const DiagnosticLocation &Loc, |
| 866 |
const Value *CodeRegion) |
| 867 |
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute, |
| 868 |
PassName, RemarkName, Loc, CodeRegion) {} |
| 869 |
|
| 870 |
static bool classof(const DiagnosticInfo *DI) { |
| 871 |
return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute; |
| 872 |
} |
| 873 |
|
| 874 |
private: |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn, |
| 887 |
const DiagnosticLocation &Loc, |
| 888 |
const Twine &Msg) |
| 889 |
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute, |
| 890 |
PassName, Fn, Loc, Msg) {} |
| 891 |
}; |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis { |
| 896 |
void anchor() override; |
| 897 |
public: |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName, |
| 906 |
const DiagnosticLocation &Loc, |
| 907 |
const Value *CodeRegion) |
| 908 |
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing, |
| 909 |
PassName, RemarkName, Loc, CodeRegion) {} |
| 910 |
|
| 911 |
static bool classof(const DiagnosticInfo *DI) { |
| 912 |
return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing; |
| 913 |
} |
| 914 |
|
| 915 |
private: |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn, |
| 928 |
const DiagnosticLocation &Loc, |
| 929 |
const Twine &Msg) |
| 930 |
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing, |
| 931 |
PassName, Fn, Loc, Msg) {} |
| 932 |
}; |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
class DiagnosticInfoMIRParser : public DiagnosticInfo { |
| 937 |
const SMDiagnostic &Diagnostic; |
| 938 |
|
| 939 |
public: |
| 940 |
DiagnosticInfoMIRParser(DiagnosticSeverity Severity, |
| 941 |
const SMDiagnostic &Diagnostic) |
| 942 |
: DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {} |
| 943 |
|
| 944 |
const SMDiagnostic &getDiagnostic() const { return Diagnostic; } |
| 945 |
|
| 946 |
void print(DiagnosticPrinter &DP) const override; |
| 947 |
|
| 948 |
static bool classof(const DiagnosticInfo *DI) { |
| 949 |
return DI->getKind() == DK_MIRParser; |
| 950 |
} |
| 951 |
}; |
| 952 |
|
| 953 |
|
| 954 |
class DiagnosticInfoISelFallback : public DiagnosticInfo { |
| 955 |
|
| 956 |
const Function &Fn; |
| 957 |
|
| 958 |
public: |
| 959 |
DiagnosticInfoISelFallback(const Function &Fn, |
| 960 |
DiagnosticSeverity Severity = DS_Warning) |
| 961 |
: DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {} |
| 962 |
|
| 963 |
const Function &getFunction() const { return Fn; } |
| 964 |
|
| 965 |
void print(DiagnosticPrinter &DP) const override; |
| 966 |
|
| 967 |
static bool classof(const DiagnosticInfo *DI) { |
| 968 |
return DI->getKind() == DK_ISelFallback; |
| 969 |
} |
| 970 |
}; |
| 971 |
|
| 972 |
|
| 973 |
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef) |
| 974 |
|
| 975 |
|
| 976 |
class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization { |
| 977 |
public: |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
DiagnosticInfoOptimizationFailure(const Function &Fn, |
| 985 |
const DiagnosticLocation &Loc, |
| 986 |
const Twine &Msg) |
| 987 |
: DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, |
| 988 |
nullptr, Fn, Loc, Msg) {} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName, |
| 996 |
const DiagnosticLocation &Loc, |
| 997 |
const Value *CodeRegion); |
| 998 |
|
| 999 |
static bool classof(const DiagnosticInfo *DI) { |
| 1000 |
return DI->getKind() == DK_OptimizationFailure; |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
bool isEnabled() const override; |
| 1005 |
}; |
| 1006 |
|
| 1007 |
|
| 1008 |
class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase { |
| 1009 |
private: |
| 1010 |
Twine Msg; |
| 1011 |
|
| 1012 |
public: |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
DiagnosticInfoUnsupported( |
| 1020 |
const Function &Fn, const Twine &Msg, |
| 1021 |
const DiagnosticLocation &Loc = DiagnosticLocation(), |
| 1022 |
DiagnosticSeverity Severity = DS_Error) |
| 1023 |
: DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc), |
| 1024 |
Msg(Msg) {} |
| 1025 |
|
| 1026 |
static bool classof(const DiagnosticInfo *DI) { |
| 1027 |
return DI->getKind() == DK_Unsupported; |
| 1028 |
} |
| 1029 |
|
| 1030 |
const Twine &getMessage() const { return Msg; } |
| 1031 |
|
| 1032 |
void print(DiagnosticPrinter &DP) const override; |
| 1033 |
}; |
| 1034 |
|
| 1035 |
static DiagnosticSeverity getDiagnosticSeverity(SourceMgr::DiagKind DK) { |
| 1036 |
switch (DK) { |
| 1037 |
case llvm::SourceMgr::DK_Error: |
| 1038 |
return DS_Error; |
| 1039 |
break; |
| 1040 |
case llvm::SourceMgr::DK_Warning: |
| 1041 |
return DS_Warning; |
| 1042 |
break; |
| 1043 |
case llvm::SourceMgr::DK_Note: |
| 1044 |
return DS_Note; |
| 1045 |
break; |
| 1046 |
case llvm::SourceMgr::DK_Remark: |
| 1047 |
return DS_Remark; |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
llvm_unreachable("unknown SourceMgr::DiagKind"); |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
class DiagnosticInfoSrcMgr : public DiagnosticInfo { |
| 1055 |
const SMDiagnostic &Diagnostic; |
| 1056 |
StringRef ModName; |
| 1057 |
|
| 1058 |
|
| 1059 |
bool InlineAsmDiag; |
| 1060 |
unsigned LocCookie; |
| 1061 |
|
| 1062 |
public: |
| 1063 |
DiagnosticInfoSrcMgr(const SMDiagnostic &Diagnostic, StringRef ModName, |
| 1064 |
bool InlineAsmDiag = true, unsigned LocCookie = 0) |
| 1065 |
: DiagnosticInfo(DK_SrcMgr, getDiagnosticSeverity(Diagnostic.getKind())), |
| 1066 |
Diagnostic(Diagnostic), ModName(ModName), InlineAsmDiag(InlineAsmDiag), |
| 1067 |
LocCookie(LocCookie) {} |
| 1068 |
|
| 1069 |
StringRef getModuleName() const { return ModName; } |
| 1070 |
bool isInlineAsmDiag() const { return InlineAsmDiag; } |
| 1071 |
const SMDiagnostic &getSMDiag() const { return Diagnostic; } |
| 1072 |
unsigned getLocCookie() const { return LocCookie; } |
| 1073 |
void print(DiagnosticPrinter &DP) const override; |
| 1074 |
|
| 1075 |
static bool classof(const DiagnosticInfo *DI) { |
| 1076 |
return DI->getKind() == DK_SrcMgr; |
| 1077 |
} |
| 1078 |
}; |
| 1079 |
|
| 1080 |
void diagnoseDontCall(const CallInst &CI); |
| 1081 |
|
| 1082 |
class DiagnosticInfoDontCall : public DiagnosticInfo { |
| 1083 |
StringRef CalleeName; |
| 1084 |
StringRef Note; |
| 1085 |
unsigned LocCookie; |
| 1086 |
|
| 1087 |
public: |
| 1088 |
DiagnosticInfoDontCall(StringRef CalleeName, StringRef Note, |
| 1089 |
DiagnosticSeverity DS, unsigned LocCookie) |
| 1090 |
: DiagnosticInfo(DK_DontCall, DS), CalleeName(CalleeName), Note(Note), |
| 1091 |
LocCookie(LocCookie) {} |
| 1092 |
StringRef getFunctionName() const { return CalleeName; } |
| 1093 |
StringRef getNote() const { return Note; } |
| 1094 |
unsigned getLocCookie() const { return LocCookie; } |
| 1095 |
void print(DiagnosticPrinter &DP) const override; |
| 1096 |
static bool classof(const DiagnosticInfo *DI) { |
| 1097 |
return DI->getKind() == DK_DontCall; |
| 1098 |
} |
| 1099 |
}; |
| 1100 |
|
| 1101 |
} |
| 1102 |
|
| 1103 |
#endif |