From 1a125c95deb911abf03587db35e9173fcb9f2b9e Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 28 Jul 2014 19:33:20 +0000 Subject: [PATCH] [Debug Info] add a template class DITypedArray. Typedef DIArray to DITypedArray. Also typedef DITypeArray as DITypedArray. This is the third of a series of patches to handle type uniqueing of the type array for a subroutine type. This commit should have no functionality change. llvm-svn: 214115 --- llvm/include/llvm/IR/DIBuilder.h | 4 +++- llvm/include/llvm/IR/DebugInfo.h | 27 +++++++++++++++++++-------- llvm/lib/IR/DIBuilder.cpp | 12 ++++++++++++ llvm/lib/IR/DebugInfo.cpp | 11 +---------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h index 156017b..2287529 100644 --- a/llvm/include/llvm/IR/DIBuilder.h +++ b/llvm/include/llvm/IR/DIBuilder.h @@ -38,7 +38,6 @@ namespace llvm { class DIFile; class DIEnumerator; class DIType; - class DIArray; class DIGlobalVariable; class DIImportedEntity; class DINameSpace; @@ -470,6 +469,9 @@ namespace llvm { /// getOrCreateArray - Get a DIArray, create one if required. DIArray getOrCreateArray(ArrayRef Elements); + /// getOrCreateTypeArray - Get a DITypeArray, create one if required. + DITypeArray getOrCreateTypeArray(ArrayRef Elements); + /// getOrCreateSubrange - Create a descriptor for a value range. This /// implicitly uniques the values returned. DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count); diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h index 1cc4b53..d9cd7c2 100644 --- a/llvm/include/llvm/IR/DebugInfo.h +++ b/llvm/include/llvm/IR/DebugInfo.h @@ -167,17 +167,20 @@ public: bool Verify() const; }; -/// DIArray - This descriptor holds an array of descriptors. -class DIArray : public DIDescriptor { +/// DITypedArray - This descriptor holds an array of nodes with type T. +template class DITypedArray : public DIDescriptor { public: - explicit DIArray(const MDNode *N = nullptr) : DIDescriptor(N) {} - - unsigned getNumElements() const; - DIDescriptor getElement(unsigned Idx) const { - return getDescriptorField(Idx); + explicit DITypedArray(const MDNode *N = nullptr) : DIDescriptor(N) {} + unsigned getNumElements() const { + return DbgNode ? DbgNode->getNumOperands() : 0; + } + T getElement(unsigned Idx) const { + return getFieldAs(Idx); } }; +typedef DITypedArray DIArray; + /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). /// FIXME: it seems strange that this doesn't have either a reference to the /// type/precision or a file/line pair for location info. @@ -196,6 +199,7 @@ public: template class DIRef; typedef DIRef DIScopeRef; typedef DIRef DITypeRef; +typedef DITypedArray DITypeArray; /// DIScope - A base class for various scopes. /// @@ -421,12 +425,19 @@ public: class DICompositeType : public DIDerivedType { friend class DIDescriptor; void printInternal(raw_ostream &OS) const; + void setArraysHelper(MDNode *Elements, MDNode *TParams); public: explicit DICompositeType(const MDNode *N = nullptr) : DIDerivedType(N) {} DIArray getElements() const { return getFieldAs(10); } - void setArrays(DIArray Elements, DIArray TParams = DIArray()); + template + void setArrays(DITypedArray Elements, DIArray TParams = DIArray()) { + assert((!TParams || DbgNode->getNumOperands() == 15) && + "If you're setting the template parameters this should include a slot " + "for that!"); + setArraysHelper(Elements, TParams); + } unsigned getRunTimeLang() const { return getUnsignedField(11); } DITypeRef getContainingType() const { return getFieldAs(12); } void setContainingType(DICompositeType ContainingType); diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 2df302c..5eb195e 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -956,6 +956,18 @@ DIArray DIBuilder::getOrCreateArray(ArrayRef Elements) { return DIArray(MDNode::get(VMContext, Elements)); } +/// getOrCreateTypeArray - Get a DITypeArray, create one if required. +DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef Elements) { + SmallVector Elts; + for (unsigned i = 0, e = Elements.size(); i != e; ++i) { + if (Elements[i] && isa(Elements[i])) + Elts.push_back(DIType(cast(Elements[i])).getRef()); + else + Elts.push_back(Elements[i]); + } + return DITypeArray(MDNode::get(VMContext, Elts)); +} + /// getOrCreateSubrange - Create a descriptor for a value range. This /// implicitly uniques the values returned. DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 6c06bf1..543e8e5 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -338,12 +338,6 @@ bool DIDescriptor::isImportedEntity() const { // Simple Descriptor Constructors and other Methods //===----------------------------------------------------------------------===// -unsigned DIArray::getNumElements() const { - if (!DbgNode) - return 0; - return DbgNode->getNumOperands(); -} - /// replaceAllUsesWith - Replace all uses of the MDNode used by this /// type with the one in the passed descriptor. void DIType::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) { @@ -676,10 +670,7 @@ static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) { #endif /// \brief Set the array of member DITypes. -void DICompositeType::setArrays(DIArray Elements, DIArray TParams) { - assert((!TParams || DbgNode->getNumOperands() == 15) && - "If you're setting the template parameters this should include a slot " - "for that!"); +void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) { TrackingVH N(*this); if (Elements) { #ifndef NDEBUG -- 2.7.4