[PATCH 04/11] Support for LLVM-RTTI

Andreas Simbuerger simbuerg at googlemail.com
Sun Jun 8 17:42:26 PDT 2014


---
 include/polly/ScopDetectionDiagnostic.h  | 85 ++++++++++++++++++++++++++------
 lib/Analysis/ScopDetectionDiagnostic.cpp | 46 ++++++++++-------
 2 files changed, 98 insertions(+), 33 deletions(-)

diff --git a/include/polly/ScopDetectionDiagnostic.h b/include/polly/ScopDetectionDiagnostic.h
index a08bc1a..8b19159 100644
--- a/include/polly/ScopDetectionDiagnostic.h
+++ b/include/polly/ScopDetectionDiagnostic.h
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
+#include "llvm/Support/Casting.h"
 
 #include <string>
 #include <memory>
@@ -63,6 +64,49 @@ class RejectLog;
 void emitRejectionRemarks(const llvm::Function &F, const RejectLog &Log,
                           LoopInfo *LI);
 
+// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
+enum RejectReasonKind {
+  // CFG Category
+  rrkCFG,
+  rrkNonBranchTerminator,
+  rrkCondition,
+
+  // Non-Affinity
+  rrkAffFunc,
+  rrkUndefCond,
+  rrkInvalidCond,
+  rrkUndefOperand,
+  rrkNonAffBranch,
+  rrkNoBasePtr,
+  rrkUndefBasePtr,
+  rrkVariantBasePtr,
+  rrkNonAffineAccess,
+
+  // IndVar
+  rrkIndVar,
+  rrkPhiNodeRefInRegion,
+  rrkNonCanonicalPhiNode,
+  rrkLoopHeader,
+
+  rrkIndEdge,
+
+  rrkLoopBound,
+
+  rrkFuncCall,
+
+  rrkAlias,
+
+  rrkSimpleLoop,
+
+  // Other
+  rrkOther,
+  rrkIntToPtr,
+  rrkAlloca,
+  rrkUnknownInst,
+  rrkPHIinExit,
+  rrkEntry
+};
+
 //===----------------------------------------------------------------------===//
 /// @brief Base class of all reject reasons found during Scop detection.
 ///
@@ -71,8 +115,15 @@ void emitRejectionRemarks(const llvm::Function &F, const RejectLog &Log,
 /// went wrong in the Scop detection.
 class RejectReason {
   //===--------------------------------------------------------------------===//
+private:
+  const RejectReasonKind Kind;
+
 public:
-  virtual ~RejectReason() {}
+  RejectReasonKind getKind() const { return Kind; }
+
+  RejectReason(RejectReasonKind K) : Kind(K) {}
+
+  virtual ~RejectReason(){};
 
   /// @brief Generate a reasonable diagnostic message describing this error.
   ///
@@ -121,14 +172,15 @@ public:
 class ReportCFG : public RejectReason {
   //===--------------------------------------------------------------------===//
 public:
-  ReportCFG();
+  ReportCFG(const RejectReasonKind K);
 };
 
 class ReportNonBranchTerminator : public ReportCFG {
   BasicBlock *BB;
 
 public:
-  ReportNonBranchTerminator(BasicBlock *BB) : ReportCFG(), BB(BB) {}
+  ReportNonBranchTerminator(BasicBlock *BB)
+      : ReportCFG(rrkNonBranchTerminator), BB(BB) {}
 
   /// @name RejectReason interface
   //@{
@@ -147,7 +199,7 @@ class ReportCondition : public ReportCFG {
   BasicBlock *BB;
 
 public:
-  ReportCondition(BasicBlock *BB) : ReportCFG(), BB(BB) {}
+  ReportCondition(BasicBlock *BB) : ReportCFG(rrkCondition), BB(BB) {}
 
   /// @name RejectReason interface
   //@{
@@ -169,7 +221,7 @@ class ReportAffFunc : public RejectReason {
   const Instruction *Inst;
 
 public:
-  ReportAffFunc(const Instruction *Inst);
+  ReportAffFunc(const RejectReasonKind K, const Instruction *Inst);
 
   virtual const DebugLoc &getDebugLoc() const { return Inst->getDebugLoc(); };
 };
@@ -184,7 +236,7 @@ class ReportUndefCond : public ReportAffFunc {
 
 public:
   ReportUndefCond(const Instruction *Inst, BasicBlock *BB)
-      : ReportAffFunc(Inst), BB(BB) {}
+      : ReportAffFunc(rrkUndefCond, Inst), BB(BB) {}
 
   /// @name RejectReason interface
   //@{
@@ -205,7 +257,7 @@ class ReportInvalidCond : public ReportAffFunc {
 
 public:
   ReportInvalidCond(const Instruction *Inst, BasicBlock *BB)
-      : ReportAffFunc(Inst), BB(BB) {}
+      : ReportAffFunc(rrkInvalidCond, Inst), BB(BB) {}
 
   /// @name RejectReason interface
   //@{
@@ -224,7 +276,7 @@ class ReportUndefOperand : public ReportAffFunc {
 
 public:
   ReportUndefOperand(BasicBlock *BB, const Instruction *Inst)
-      : ReportAffFunc(Inst), BB(BB) {}
+      : ReportAffFunc(rrkUndefOperand, Inst), BB(BB) {}
 
   /// @name RejectReason interface
   //@{
@@ -250,7 +302,7 @@ class ReportNonAffBranch : public ReportAffFunc {
 public:
   ReportNonAffBranch(BasicBlock *BB, const SCEV *LHS, const SCEV *RHS,
                      const Instruction *Inst)
-      : ReportAffFunc(Inst), BB(BB), LHS(LHS), RHS(RHS) {}
+      : ReportAffFunc(rrkNonAffBranch, Inst), BB(BB), LHS(LHS), RHS(RHS) {}
 
   const SCEV *lhs() { return LHS; }
   const SCEV *rhs() { return RHS; }
@@ -267,7 +319,8 @@ public:
 class ReportNoBasePtr : public ReportAffFunc {
   //===--------------------------------------------------------------------===//
 public:
-  ReportNoBasePtr(const Instruction *Inst) : ReportAffFunc(Inst) {}
+  ReportNoBasePtr(const Instruction *Inst)
+      : ReportAffFunc(rrkNoBasePtr, Inst) {}
 
   /// @name RejectReason interface
   //@{
@@ -281,7 +334,8 @@ public:
 class ReportUndefBasePtr : public ReportAffFunc {
   //===--------------------------------------------------------------------===//
 public:
-  ReportUndefBasePtr(const Instruction *Inst) : ReportAffFunc(Inst) {}
+  ReportUndefBasePtr(const Instruction *Inst)
+      : ReportAffFunc(rrkUndefBasePtr, Inst) {}
 
   /// @name RejectReason interface
   //@{
@@ -300,7 +354,7 @@ class ReportVariantBasePtr : public ReportAffFunc {
 
 public:
   ReportVariantBasePtr(Value *BaseValue, const Instruction *Inst)
-      : ReportAffFunc(Inst), BaseValue(BaseValue) {}
+      : ReportAffFunc(rrkVariantBasePtr, Inst), BaseValue(BaseValue) {}
 
   /// @name RejectReason interface
   //@{
@@ -319,7 +373,8 @@ class ReportNonAffineAccess : public ReportAffFunc {
 
 public:
   ReportNonAffineAccess(const SCEV *AccessFunction, const Instruction *Inst)
-      : ReportAffFunc(Inst), AccessFunction(AccessFunction) {}
+      : ReportAffFunc(rrkNonAffineAccess, Inst),
+        AccessFunction(AccessFunction) {}
 
   const SCEV *get() { return AccessFunction; }
 
@@ -338,7 +393,7 @@ public:
 class ReportIndVar : public RejectReason {
   //===--------------------------------------------------------------------===//
 public:
-  ReportIndVar();
+  ReportIndVar(const RejectReasonKind K);
 };
 
 //===----------------------------------------------------------------------===//
@@ -503,7 +558,7 @@ public:
 class ReportOther : public RejectReason {
   //===--------------------------------------------------------------------===//
 public:
-  ReportOther();
+  ReportOther(const RejectReasonKind K);
 
   /// @name RejectReason interface
   //@{
diff --git a/lib/Analysis/ScopDetectionDiagnostic.cpp b/lib/Analysis/ScopDetectionDiagnostic.cpp
index 67a0a4d..4231c2f 100644
--- a/lib/Analysis/ScopDetectionDiagnostic.cpp
+++ b/lib/Analysis/ScopDetectionDiagnostic.cpp
@@ -106,7 +106,9 @@ void emitRejectionRemarks(const llvm::Function &F, const RejectLog &Log,
 //===----------------------------------------------------------------------===//
 // ReportCFG.
 
-ReportCFG::ReportCFG() { ++BadCFGForScop; }
+ReportCFG::ReportCFG(const RejectReasonKind K) : RejectReason(K) {
+  ++BadCFGForScop;
+}
 
 //===----------------------------------------------------------------------===//
 // ReportNonBranchTerminator.
@@ -141,8 +143,8 @@ const DebugLoc &ReportCondition::getDebugLoc() const {
 //===----------------------------------------------------------------------===//
 // ReportAffFunc.
 
-ReportAffFunc::ReportAffFunc(const Instruction *Inst)
-    : RejectReason(), Inst(Inst) {
+ReportAffFunc::ReportAffFunc(const RejectReasonKind K, const Instruction *Inst)
+    : RejectReason(K), Inst(Inst) {
   ++BadAffFuncForScop;
 }
 
@@ -237,13 +239,15 @@ std::string ReportNonAffineAccess::getMessage() const {
 //===----------------------------------------------------------------------===//
 // ReportIndVar.
 
-ReportIndVar::ReportIndVar() : RejectReason() { ++BadIndVarForScop; }
+ReportIndVar::ReportIndVar(const RejectReasonKind K) : RejectReason(K) {
+  ++BadIndVarForScop;
+}
 
 //===----------------------------------------------------------------------===//
 // ReportPhiNodeRefInRegion.
 
 ReportPhiNodeRefInRegion::ReportPhiNodeRefInRegion(Instruction *Inst)
-    : ReportIndVar(), Inst(Inst) {}
+    : ReportIndVar(rrkPhiNodeRefInRegion), Inst(Inst) {}
 
 std::string ReportPhiNodeRefInRegion::getShortMessage() const {
   return "(FIXME) SCEV of PHI node refers to SSA names in region";
@@ -261,7 +265,7 @@ const DebugLoc &ReportPhiNodeRefInRegion::getDebugLoc() const {
 // ReportNonCanonicalPhiNode.
 
 ReportNonCanonicalPhiNode::ReportNonCanonicalPhiNode(Instruction *Inst)
-    : ReportIndVar(), Inst(Inst) {}
+    : ReportIndVar(rrkNonCanonicalPhiNode), Inst(Inst) {}
 
 std::string ReportNonCanonicalPhiNode::getShortMessage() const {
   return "PHI node is not in canonical form";
@@ -278,7 +282,8 @@ const DebugLoc &ReportNonCanonicalPhiNode::getDebugLoc() const {
 //===----------------------------------------------------------------------===//
 // ReportLoopHeader.
 
-ReportLoopHeader::ReportLoopHeader(Loop *L) : ReportIndVar(), L(L) {}
+ReportLoopHeader::ReportLoopHeader(Loop *L)
+    : ReportIndVar(rrkLoopHeader), L(L) {}
 
 std::string ReportLoopHeader::getShortMessage() const {
   return "The loop's induction variable is not in canonical form";
@@ -300,7 +305,8 @@ std::string ReportIndEdge::getShortMessage() const {
   return "The loop has invalid control flow";
 }
 
-ReportIndEdge::ReportIndEdge(BasicBlock *BB) : RejectReason(), BB(BB) {
+ReportIndEdge::ReportIndEdge(BasicBlock *BB)
+    : RejectReason(rrkIndEdge), BB(BB) {
   ++BadIndEdgeForScop;
 }
 
@@ -320,7 +326,7 @@ std::string ReportLoopBound::getShortMessage() const {
 }
 
 ReportLoopBound::ReportLoopBound(Loop *L, const SCEV *LoopCount)
-    : RejectReason(), L(L), LoopCount(LoopCount) {
+    : RejectReason(rrkLoopBound), L(L), LoopCount(LoopCount) {
   ++BadLoopBoundForScop;
 }
 
@@ -341,7 +347,8 @@ std::string ReportFuncCall::getShortMessage() const {
   return "This function call needs to be inlined.";
 }
 
-ReportFuncCall::ReportFuncCall(Instruction *Inst) : RejectReason(), Inst(Inst) {
+ReportFuncCall::ReportFuncCall(Instruction *Inst)
+    : RejectReason(rrkFuncCall), Inst(Inst) {
   ++BadFuncCallForScop;
 }
 
@@ -361,7 +368,7 @@ std::string ReportAlias::getShortMessage() const {
 }
 
 ReportAlias::ReportAlias(Instruction *Inst, AliasSet *AS)
-    : RejectReason(), AS(AS), Inst(Inst) {
+    : RejectReason(rrkAlias), AS(AS), Inst(Inst) {
   ++BadAliasForScop;
 }
 
@@ -410,7 +417,7 @@ std::string ReportSimpleLoop::getShortMessage() const {
   return "Try simplifying the loop (-loop-simplify)";
 }
 
-ReportSimpleLoop::ReportSimpleLoop() : RejectReason() {
+ReportSimpleLoop::ReportSimpleLoop() : RejectReason(rrkSimpleLoop) {
   ++BadSimpleLoopForScop;
 }
 
@@ -430,7 +437,9 @@ std::string ReportOther::getShortMessage() const { return getMessage(); }
 
 std::string ReportOther::getMessage() const { return "Unknown reject reason"; }
 
-ReportOther::ReportOther() : RejectReason() { ++BadOtherForScop; }
+ReportOther::ReportOther(const RejectReasonKind K) : RejectReason(K) {
+  ++BadOtherForScop;
+}
 
 const DebugLoc &ReportOther::getDebugLoc() const {
   // FIXME:
@@ -440,7 +449,7 @@ const DebugLoc &ReportOther::getDebugLoc() const {
 //===----------------------------------------------------------------------===//
 // ReportIntToPtr.
 ReportIntToPtr::ReportIntToPtr(Instruction *BaseValue)
-    : ReportOther(), BaseValue(BaseValue) {}
+    : ReportOther(rrkIntToPtr), BaseValue(BaseValue) {}
 
 std::string ReportIntToPtr::getShortMessage() const {
   return "Do not case this int to a pointer";
@@ -457,7 +466,8 @@ const DebugLoc &ReportIntToPtr::getDebugLoc() const {
 //===----------------------------------------------------------------------===//
 // ReportAlloca.
 
-ReportAlloca::ReportAlloca(Instruction *Inst) : ReportOther(), Inst(Inst) {}
+ReportAlloca::ReportAlloca(Instruction *Inst)
+    : ReportOther(rrkAlloca), Inst(Inst) {}
 
 std::string ReportAlloca::getShortMessage() const {
   return "Try removing this stack allocation (-mem2reg)";
@@ -475,7 +485,7 @@ const DebugLoc &ReportAlloca::getDebugLoc() const {
 // ReportUnknownInst.
 
 ReportUnknownInst::ReportUnknownInst(Instruction *Inst)
-    : ReportOther(), Inst(Inst) {}
+    : ReportOther(rrkUnknownInst), Inst(Inst) {}
 
 std::string ReportUnknownInst::getShortMessage() const {
   return "There is an unknown instruction";
@@ -493,7 +503,7 @@ const DebugLoc &ReportUnknownInst::getDebugLoc() const {
 // ReportPHIinExit.
 
 ReportPHIinExit::ReportPHIinExit(Instruction *Inst)
-    : ReportOther(), Inst(Inst) {}
+    : ReportOther(rrkPHIinExit), Inst(Inst) {}
 
 std::string ReportPHIinExit::getShortMessage() const {
   return "This instruction causes a PHI node in the exit block of the loop";
@@ -509,7 +519,7 @@ const DebugLoc &ReportPHIinExit::getDebugLoc() const {
 
 //===----------------------------------------------------------------------===//
 // ReportEntry.
-ReportEntry::ReportEntry(BasicBlock *BB) : ReportOther(), BB(BB){};
+ReportEntry::ReportEntry(BasicBlock *BB) : ReportOther(rrkEntry), BB(BB){};
 
 std::string ReportEntry::getShortMessage() const {
   return "The function entry cannot be part of a Scop";
-- 
2.0.0




More information about the llvm-commits mailing list