/usr/lib/llvm-3.9/include/polly/ScopDetectionDiagnostic.h is in libclang-common-3.9-dev 1:3.9.1-19ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | //=== ScopDetectionDiagnostic.h -- Diagnostic for ScopDetection -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Small set of diagnostic helper classes to encapsulate any errors occurred
// during the detection of Scops.
//
// The ScopDetection defines a set of error classes (via Statistic variables)
// that groups a number of individual errors into a group, e.g. non-affinity
// related errors.
// On error we generate an object that carries enough additional information
// to diagnose the error and generate a helpful error message.
//
//===----------------------------------------------------------------------===//
#ifndef POLLY_SCOP_DETECTION_DIAGNOSTIC_H
#define POLLY_SCOP_DETECTION_DIAGNOSTIC_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include <memory>
#include <string>
using namespace llvm;
namespace llvm {
class SCEV;
class BasicBlock;
class Value;
class Region;
} // namespace llvm
namespace polly {
/// @brief Type to hold region delimitors (entry & exit block).
using BBPair = std::pair<BasicBlock *, BasicBlock *>;
/// @brief Return the region delimitors (entry & exit block) of @p R.
BBPair getBBPairForRegion(const Region *R);
/// @brief Set the begin and end source location for the region limited by @p P.
void getDebugLocations(const BBPair &P, DebugLoc &Begin, DebugLoc &End);
class RejectLog;
/// @brief Emit optimization remarks about the rejected regions to the user.
///
/// This emits the content of the reject log as optimization remarks.
/// Remember to at least track failures (-polly-detect-track-failures).
/// @param P The region delimitors (entry & exit) we emit remarks for.
/// @param Log The error log containing all messages being emitted as remark.
void emitRejectionRemarks(const BBPair &P, const RejectLog &Log);
// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
enum RejectReasonKind {
// CFG Category
rrkCFG,
rrkInvalidTerminator,
rrkCondition,
rrkLastCFG,
rrkIrreducibleRegion,
// Non-Affinity
rrkAffFunc,
rrkUndefCond,
rrkInvalidCond,
rrkUndefOperand,
rrkNonAffBranch,
rrkNoBasePtr,
rrkUndefBasePtr,
rrkVariantBasePtr,
rrkNonAffineAccess,
rrkDifferentElementSize,
rrkLastAffFunc,
rrkLoopBound,
rrkLoopOverlapWithNonAffineSubRegion,
rrkFuncCall,
rrkNonSimpleMemoryAccess,
rrkAlias,
// Other
rrkOther,
rrkIntToPtr,
rrkAlloca,
rrkUnknownInst,
rrkEntry,
rrkUnprofitable,
rrkLastOther
};
//===----------------------------------------------------------------------===//
/// @brief Base class of all reject reasons found during Scop detection.
///
/// Subclasses of RejectReason should provide means to capture enough
/// diagnostic information to help clients figure out what and where something
/// went wrong in the Scop detection.
class RejectReason {
//===--------------------------------------------------------------------===//
private:
const RejectReasonKind Kind;
protected:
static const DebugLoc Unknown;
public:
RejectReasonKind getKind() const { return Kind; }
RejectReason(RejectReasonKind K) : Kind(K) {}
virtual ~RejectReason() {}
/// @brief Generate a reasonable diagnostic message describing this error.
///
/// @return A debug message representing this error.
virtual std::string getMessage() const = 0;
/// @brief Generate a message for the end-user describing this error.
///
/// The message provided has to be suitable for the end-user. So it should
/// not reference any LLVM internal data structures or terminology.
/// Ideally, the message helps the end-user to increase the size of the
/// regions amenable to Polly.
///
/// @return A short message representing this error.
virtual std::string getEndUserMessage() const { return "Unspecified error."; }
/// @brief Get the source location of this error.
///
/// @return The debug location for this error.
virtual const llvm::DebugLoc &getDebugLoc() const;
};
typedef std::shared_ptr<RejectReason> RejectReasonPtr;
/// @brief Stores all errors that ocurred during the detection.
class RejectLog {
Region *R;
llvm::SmallVector<RejectReasonPtr, 1> ErrorReports;
public:
explicit RejectLog(Region *R) : R(R) {}
typedef llvm::SmallVector<RejectReasonPtr, 1>::const_iterator iterator;
iterator begin() const { return ErrorReports.begin(); }
iterator end() const { return ErrorReports.end(); }
size_t size() const { return ErrorReports.size(); }
/// @brief Returns true, if we store at least one error.
///
/// @return true, if we store at least one error.
bool hasErrors() const { return size() > 0; }
void print(raw_ostream &OS, int level = 0) const;
const Region *region() const { return R; }
void report(RejectReasonPtr Reject) { ErrorReports.push_back(Reject); }
};
//===----------------------------------------------------------------------===//
/// @brief Base class for CFG related reject reasons.
///
/// Scop candidates that violate structural restrictions can be grouped under
/// this reject reason class.
class ReportCFG : public RejectReason {
//===--------------------------------------------------------------------===//
public:
ReportCFG(const RejectReasonKind K);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures bad terminator within a Scop candidate.
class ReportInvalidTerminator : public ReportCFG {
BasicBlock *BB;
public:
ReportInvalidTerminator(BasicBlock *BB)
: ReportCFG(rrkInvalidTerminator), BB(BB) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures irreducible regions in CFG.
class ReportIrreducibleRegion : public ReportCFG {
Region *R;
DebugLoc DbgLoc;
public:
ReportIrreducibleRegion(Region *R, DebugLoc DbgLoc)
: ReportCFG(rrkIrreducibleRegion), R(R), DbgLoc(DbgLoc) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Base class for non-affine reject reasons.
///
/// Scop candidates that violate restrictions to affinity are reported under
/// this class.
class ReportAffFunc : public RejectReason {
//===--------------------------------------------------------------------===//
// The instruction that caused non-affinity to occur.
const Instruction *Inst;
public:
ReportAffFunc(const RejectReasonKind K, const Instruction *Inst);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual const DebugLoc &getDebugLoc() const override {
return Inst->getDebugLoc();
}
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures a condition that is based on an 'undef' value.
class ReportUndefCond : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the broken condition in.
BasicBlock *BB;
public:
ReportUndefCond(const Instruction *Inst, BasicBlock *BB)
: ReportAffFunc(rrkUndefCond, Inst), BB(BB) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures an invalid condition
///
/// Conditions have to be either constants or icmp instructions.
class ReportInvalidCond : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the broken condition in.
BasicBlock *BB;
public:
ReportInvalidCond(const Instruction *Inst, BasicBlock *BB)
: ReportAffFunc(rrkInvalidCond, Inst), BB(BB) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures an undefined operand.
class ReportUndefOperand : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the undefined operand in.
BasicBlock *BB;
public:
ReportUndefOperand(BasicBlock *BB, const Instruction *Inst)
: ReportAffFunc(rrkUndefOperand, Inst), BB(BB) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures a non-affine branch.
class ReportNonAffBranch : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the non-affine branch in.
BasicBlock *BB;
/// @brief LHS & RHS of the failed condition.
//@{
const SCEV *LHS;
const SCEV *RHS;
//@}
public:
ReportNonAffBranch(BasicBlock *BB, const SCEV *LHS, const SCEV *RHS,
const Instruction *Inst)
: ReportAffFunc(rrkNonAffBranch, Inst), BB(BB), LHS(LHS), RHS(RHS) {}
const SCEV *lhs() { return LHS; }
const SCEV *rhs() { return RHS; }
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures a missing base pointer.
class ReportNoBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
public:
ReportNoBasePtr(const Instruction *Inst)
: ReportAffFunc(rrkNoBasePtr, Inst) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures an undefined base pointer.
class ReportUndefBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
public:
ReportUndefBasePtr(const Instruction *Inst)
: ReportAffFunc(rrkUndefBasePtr, Inst) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures a base pointer that is not invariant in the region.
class ReportVariantBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The variant base pointer.
Value *BaseValue;
public:
ReportVariantBasePtr(Value *BaseValue, const Instruction *Inst)
: ReportAffFunc(rrkVariantBasePtr, Inst), BaseValue(BaseValue) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures a non-affine access function.
class ReportNonAffineAccess : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The non-affine access function.
const SCEV *AccessFunction;
// The base pointer of the memory access.
const Value *BaseValue;
public:
ReportNonAffineAccess(const SCEV *AccessFunction, const Instruction *Inst,
const Value *V)
: ReportAffFunc(rrkNonAffineAccess, Inst), AccessFunction(AccessFunction),
BaseValue(V) {}
const SCEV *get() { return AccessFunction; }
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Report array accesses with differing element size.
class ReportDifferentArrayElementSize : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The base pointer of the memory access.
const Value *BaseValue;
public:
ReportDifferentArrayElementSize(const Instruction *Inst, const Value *V)
: ReportAffFunc(rrkDifferentElementSize, Inst), BaseValue(V) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with non affine loop bounds.
class ReportLoopBound : public RejectReason {
//===--------------------------------------------------------------------===//
// The offending loop.
Loop *L;
// The non-affine loop bound.
const SCEV *LoopCount;
// A copy of the offending loop's debug location.
const DebugLoc Loc;
public:
ReportLoopBound(Loop *L, const SCEV *LoopCount);
const SCEV *loopCount() { return LoopCount; }
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors when loop overlap with nonaffine subregion.
class ReportLoopOverlapWithNonAffineSubRegion : public RejectReason {
//===--------------------------------------------------------------------===//
/// @brief If L and R are set then L and R overlap.
/// The loop contains stmt overlapping nonaffine subregion.
Loop *L;
/// The nonaffine subregion that contains infinite loop.
Region *R;
const DebugLoc Loc;
public:
ReportLoopOverlapWithNonAffineSubRegion(Loop *L, Region *R);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with non-side-effect-known function calls.
class ReportFuncCall : public RejectReason {
//===--------------------------------------------------------------------===//
// The offending call instruction.
Instruction *Inst;
public:
ReportFuncCall(Instruction *Inst);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with aliasing.
class ReportAlias : public RejectReason {
//===--------------------------------------------------------------------===//
public:
typedef std::vector<const llvm::Value *> PointerSnapshotTy;
private:
/// @brief Format an invalid alias set.
///
// @param Prefix A prefix string to put before the list of aliasing pointers.
// @param Suffix A suffix string to put after the list of aliasing pointers.
std::string formatInvalidAlias(std::string Prefix = "",
std::string Suffix = "") const;
Instruction *Inst;
// A snapshot of the llvm values that took part in the aliasing error.
mutable PointerSnapshotTy Pointers;
public:
ReportAlias(Instruction *Inst, AliasSet &AS);
const PointerSnapshotTy &getPointers() const { return Pointers; }
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Base class for otherwise ungrouped reject reasons.
class ReportOther : public RejectReason {
//===--------------------------------------------------------------------===//
public:
ReportOther(const RejectReasonKind K);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with bad IntToPtr instructions.
class ReportIntToPtr : public ReportOther {
//===--------------------------------------------------------------------===//
// The offending base value.
Instruction *BaseValue;
public:
ReportIntToPtr(Instruction *BaseValue);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with alloca instructions.
class ReportAlloca : public ReportOther {
//===--------------------------------------------------------------------===//
Instruction *Inst;
public:
ReportAlloca(Instruction *Inst);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with unknown instructions.
class ReportUnknownInst : public ReportOther {
//===--------------------------------------------------------------------===//
Instruction *Inst;
public:
ReportUnknownInst(Instruction *Inst);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with regions containing the function entry block.
class ReportEntry : public ReportOther {
//===--------------------------------------------------------------------===//
BasicBlock *BB;
public:
ReportEntry(BasicBlock *BB);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Report regions that seem not profitable to be optimized.
class ReportUnprofitable : public ReportOther {
//===--------------------------------------------------------------------===//
Region *R;
public:
ReportUnprofitable(Region *R);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// @brief Captures errors with non-simple memory accesses.
class ReportNonSimpleMemoryAccess : public ReportOther {
//===--------------------------------------------------------------------===//
// The offending call instruction.
Instruction *Inst;
public:
ReportNonSimpleMemoryAccess(Instruction *Inst);
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
} // namespace polly
#endif // POLLY_SCOP_DETECTION_DIAGNOSTIC_H
|