llvm.org GIT mirror llvm / b07e129
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`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235069 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
7 changed file(s) with 22 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
12311231 DISubprogram SP = DBuilder->createFunction(
12321232 FContext, Name, StringRef(), Unit, LineNo,
12331233 CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
1234 true /* definition */, ScopeLine, DIDescriptor::FlagPrototyped, false, F);
1234 true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
12351235
12361236 KSDbgInfo.FnScopeMap[this] = SP;
12371237 return F;
427427 DICompositeType createReplaceableCompositeType(
428428 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F,
429429 unsigned Line, unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
430 uint64_t AlignInBits = 0, unsigned Flags = DIDescriptor::FlagFwdDecl,
430 uint64_t AlignInBits = 0, unsigned Flags = DebugNode::FlagFwdDecl,
431431 StringRef UniqueIdentifier = StringRef());
432432
433433 /// retainType - Retain DIType in a module even if it is not referenced
5757 /// \brief Maps from type identifier to the actual MDNode.
5858 typedef DenseMap DITypeIdentifierMap;
5959
60 /// \brief A thin wraper around MDNode to access encoded debug info.
61 ///
62 /// This should not be stored in a container, because the underlying MDNode may
63 /// change in certain situations.
6460 class DIDescriptor {
65 public:
66 /// \brief Duplicated debug info flags.
67 ///
68 /// \see DebugNode::DIFlags.
69 enum {
70 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = DebugNode::Flag##NAME,
71 #include "llvm/IR/DebugInfoFlags.def"
72 FlagAccessibility = DebugNode::FlagAccessibility
73 };
74
75 protected:
76 const MDNode *DbgNode;
77
78 public:
79 explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
80 DIDescriptor(const DebugNode *N) : DbgNode(N) {}
81
82 MDNode *get() const { return const_cast(DbgNode); }
83 operator MDNode *() const { return get(); }
84 MDNode *operator->() const { return get(); }
85 MDNode &operator*() const { return *get(); }
86
87 // An explicit operator bool so that we can do testing of DI values
88 // easily.
89 // FIXME: This operator bool isn't actually protecting anything at the
90 // moment due to the conversion operator above making DIDescriptor nodes
91 // implicitly convertable to bool.
92 explicit operator bool() const { return DbgNode != nullptr; }
93
94 bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
95 bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
96
97 uint16_t getTag() const {
98 if (auto *N = dyn_cast_or_null(get()))
99 return N->getTag();
100 return 0;
101 }
102
103 void print(raw_ostream &OS) const;
104 void dump() const;
61 MDNode *N;
62
63 public:
64 DIDescriptor(const MDNode *N = nullptr) : N(const_cast(N)) {}
65
66 operator MDNode *() const { return N; }
67 MDNode *operator->() const { return N; }
68 MDNode &operator*() const { return *N; }
10569 };
10670
10771 #define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
14041404 // Add subranges to array type.
14051405 DIArray Elements = CTy->getElements();
14061406 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
1407 DIDescriptor Element = Elements[i];
1408 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
1409 constructSubrangeDIE(Buffer, cast(Element), IdxTy);
1407 // FIXME: Should this really be such a loose cast?
1408 if (auto *Element = dyn_cast_or_null(Elements[i]))
1409 if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1410 constructSubrangeDIE(Buffer, cast(Element), IdxTy);
14101411 }
14111412 }
14121413
202202 // types that have one.
203203 return ::createImportedModule(
204204 VMContext, dwarf::DW_TAG_imported_declaration, Context,
205 DebugNodeRef::get(cast_or_null(Decl.get())), Line, Name,
205 DebugNodeRef::get(cast_or_null(Decl)), Line, Name,
206206 AllImportedModules);
207207 }
208208
317317 unsigned Flags,
318318 llvm::Constant *Val) {
319319 // TAG_member is encoded in DIDerivedType format.
320 Flags |= DIDescriptor::FlagStaticMember;
320 Flags |= DebugNode::FlagStaticMember;
321321 return MDDerivedType::get(
322322 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
323323 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))),
528528 DICompositeType RetTy = MDCompositeType::get(
529529 VMContext, Tag, Name, F, Line,
530530 MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr,
531 SizeInBits, AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr,
532 RuntimeLang, nullptr, nullptr, UniqueIdentifier);
531 SizeInBits, AlignInBits, 0, DebugNode::FlagFwdDecl, nullptr, RuntimeLang,
532 nullptr, nullptr, UniqueIdentifier);
533533 if (!UniqueIdentifier.empty())
534534 retainType(RetTy);
535535 trackIfUnresolved(RetTy);
306306 return true;
307307 }
308308
309 //===----------------------------------------------------------------------===//
310 // DIDescriptor: dump routines for all descriptors.
311 //===----------------------------------------------------------------------===//
312
313 void DIDescriptor::dump() const {
314 print(dbgs());
315 dbgs() << '\n';
316 }
317
318 void DIDescriptor::print(raw_ostream &OS) const {
319 if (!get())
320 return;
321 get()->print(OS);
322 }
323
324309 template <>
325310 DIDescriptor
326311 DIRef::resolve(const DITypeIdentifierMap &Map) const {
946946
947947 MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types);
948948 EXPECT_EQ(0u, D->getFlags());
949 D->setFlags(DIDescriptor::FlagRValueReference);
950 EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags());
949 D->setFlags(DebugNode::FlagRValueReference);
950 EXPECT_EQ(DebugNode::FlagRValueReference, D->getFlags());
951951 D->setFlags(0u);
952952 EXPECT_EQ(0u, D->getFlags());
953953
954954 TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types);
955955 EXPECT_EQ(0u, T->getFlags());
956 T->setFlags(DIDescriptor::FlagRValueReference);
957 EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags());
956 T->setFlags(DebugNode::FlagRValueReference);
957 EXPECT_EQ(DebugNode::FlagRValueReference, T->getFlags());
958958 T->setFlags(0u);
959959 EXPECT_EQ(0u, T->getFlags());
960960 }