[llvm] r235069 - DebugInfo: Gut DIDescriptor

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Apr 15 18:53:33 PDT 2015


Author: dexonsmith
Date: Wed Apr 15 20:53:33 2015
New Revision: 235069

URL: http://llvm.org/viewvc/llvm-project?rev=235069&view=rev
Log:
DebugInfo: Gut DIDescriptor

PR23080 is almost finished.  With this commit, there's no consequential
API in `DIDescriptor` and its subclasses.  What's left?

  - Default-constructed to `nullptr`.
  - Handy `const_cast<>` (constructed from `const`, but accessors are
    non-`const`).

I think the safe way to catch those is to delete the classes and fix
compile errors.  That'll be my next step, after I delete the `DITypeRef`
(etc.) wrapper around `MDTypeRef`.

Modified:
    llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp
    llvm/trunk/include/llvm/IR/DIBuilder.h
    llvm/trunk/include/llvm/IR/DebugInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/lib/IR/DIBuilder.cpp
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/unittests/IR/MetadataTest.cpp

Modified: llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp Wed Apr 15 20:53:33 2015
@@ -1232,7 +1232,7 @@ Function *PrototypeAST::Codegen() {
   DISubprogram SP = DBuilder->createFunction(
       FContext, Name, StringRef(), Unit, LineNo,
       CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
-      true /* definition */, ScopeLine, DIDescriptor::FlagPrototyped, false, F);
+      true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
 
   KSDbgInfo.FnScopeMap[this] = SP;
   return F;

Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Wed Apr 15 20:53:33 2015
@@ -428,7 +428,7 @@ namespace llvm {
     DICompositeType createReplaceableCompositeType(
         unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F,
         unsigned Line, unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
-        uint64_t AlignInBits = 0, unsigned Flags = DIDescriptor::FlagFwdDecl,
+        uint64_t AlignInBits = 0, unsigned Flags = DebugNode::FlagFwdDecl,
         StringRef UniqueIdentifier = StringRef());
 
     /// retainType - Retain DIType in a module even if it is not referenced

Modified: llvm/trunk/include/llvm/IR/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfo.h Wed Apr 15 20:53:33 2015
@@ -58,51 +58,15 @@ class DIObjCProperty;
 /// \brief Maps from type identifier to the actual MDNode.
 typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
 
-/// \brief A thin wraper around MDNode to access encoded debug info.
-///
-/// This should not be stored in a container, because the underlying MDNode may
-/// change in certain situations.
 class DIDescriptor {
-public:
-  /// \brief Duplicated debug info flags.
-  ///
-  /// \see DebugNode::DIFlags.
-  enum {
-#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = DebugNode::Flag##NAME,
-#include "llvm/IR/DebugInfoFlags.def"
-    FlagAccessibility = DebugNode::FlagAccessibility
-  };
-
-protected:
-  const MDNode *DbgNode;
+  MDNode *N;
 
 public:
-  explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
-  DIDescriptor(const DebugNode *N) : DbgNode(N) {}
-
-  MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
-  operator MDNode *() const { return get(); }
-  MDNode *operator->() const { return get(); }
-  MDNode &operator*() const { return *get(); }
-
-  // An explicit operator bool so that we can do testing of DI values
-  // easily.
-  // FIXME: This operator bool isn't actually protecting anything at the
-  // moment due to the conversion operator above making DIDescriptor nodes
-  // implicitly convertable to bool.
-  explicit operator bool() const { return DbgNode != nullptr; }
-
-  bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
-  bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
-
-  uint16_t getTag() const {
-    if (auto *N = dyn_cast_or_null<DebugNode>(get()))
-      return N->getTag();
-    return 0;
-  }
+  DIDescriptor(const MDNode *N = nullptr) : N(const_cast<MDNode *>(N)) {}
 
-  void print(raw_ostream &OS) const;
-  void dump() const;
+  operator MDNode *() const { return N; }
+  MDNode *operator->() const { return N; }
+  MDNode &operator*() const { return *N; }
 };
 
 #define DECLARE_SIMPLIFY_DESCRIPTOR(DESC)                                      \

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Wed Apr 15 20:53:33 2015
@@ -1405,9 +1405,10 @@ void DwarfUnit::constructArrayTypeDIE(DI
   // Add subranges to array type.
   DIArray Elements = CTy->getElements();
   for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
-    DIDescriptor Element = Elements[i];
-    if (Element.getTag() == dwarf::DW_TAG_subrange_type)
-      constructSubrangeDIE(Buffer, cast<MDSubrange>(Element), IdxTy);
+    // FIXME: Should this really be such a loose cast?
+    if (auto *Element = dyn_cast_or_null<DebugNode>(Elements[i]))
+      if (Element->getTag() == dwarf::DW_TAG_subrange_type)
+        constructSubrangeDIE(Buffer, cast<MDSubrange>(Element), IdxTy);
   }
 }
 

Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Wed Apr 15 20:53:33 2015
@@ -203,7 +203,7 @@ DIImportedEntity DIBuilder::createImport
   // types that have one.
   return ::createImportedModule(
       VMContext, dwarf::DW_TAG_imported_declaration, Context,
-      DebugNodeRef::get(cast_or_null<DebugNode>(Decl.get())), Line, Name,
+      DebugNodeRef::get(cast_or_null<DebugNode>(Decl)), Line, Name,
       AllImportedModules);
 }
 
@@ -318,7 +318,7 @@ DIDerivedType DIBuilder::createStaticMem
                                                 unsigned Flags,
                                                 llvm::Constant *Val) {
   // TAG_member is encoded in DIDerivedType format.
-  Flags |= DIDescriptor::FlagStaticMember;
+  Flags |= DebugNode::FlagStaticMember;
   return MDDerivedType::get(
       VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
       MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))),
@@ -529,8 +529,8 @@ DIBuilder::createForwardDecl(unsigned Ta
   DICompositeType RetTy = MDCompositeType::get(
       VMContext, Tag, Name, F, Line,
       MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr,
-      SizeInBits, AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr,
-      RuntimeLang, nullptr, nullptr, UniqueIdentifier);
+      SizeInBits, AlignInBits, 0, DebugNode::FlagFwdDecl, nullptr, RuntimeLang,
+      nullptr, nullptr, UniqueIdentifier);
   if (!UniqueIdentifier.empty())
     retainType(RetTy);
   trackIfUnresolved(RetTy);

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Wed Apr 15 20:53:33 2015
@@ -307,21 +307,6 @@ bool DebugInfoFinder::addScope(DIScope S
   return true;
 }
 
-//===----------------------------------------------------------------------===//
-// DIDescriptor: dump routines for all descriptors.
-//===----------------------------------------------------------------------===//
-
-void DIDescriptor::dump() const {
-  print(dbgs());
-  dbgs() << '\n';
-}
-
-void DIDescriptor::print(raw_ostream &OS) const {
-  if (!get())
-    return;
-  get()->print(OS);
-}
-
 template <>
 DIDescriptor
 DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const {

Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=235069&r1=235068&r2=235069&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Wed Apr 15 20:53:33 2015
@@ -947,15 +947,15 @@ TEST_F(MDTypeTest, setFlags) {
 
   MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types);
   EXPECT_EQ(0u, D->getFlags());
-  D->setFlags(DIDescriptor::FlagRValueReference);
-  EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags());
+  D->setFlags(DebugNode::FlagRValueReference);
+  EXPECT_EQ(DebugNode::FlagRValueReference, D->getFlags());
   D->setFlags(0u);
   EXPECT_EQ(0u, D->getFlags());
 
   TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types);
   EXPECT_EQ(0u, T->getFlags());
-  T->setFlags(DIDescriptor::FlagRValueReference);
-  EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags());
+  T->setFlags(DebugNode::FlagRValueReference);
+  EXPECT_EQ(DebugNode::FlagRValueReference, T->getFlags());
   T->setFlags(0u);
   EXPECT_EQ(0u, T->getFlags());
 }





More information about the llvm-commits mailing list