llvm.org GIT mirror llvm / 5e8144d
Switch the type field in DIVariable and DIGlobalVariable over to DITypeRefs. This allows us to catch more opportunities for ODR-based type uniquing during LTO. Paired commit with CFE which updates some testcases to verify the new DIBuilder behavior. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204106 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 6 years ago
9 changed file(s) with 51 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
566566 metadata, ;; Reference to file where defined
567567 i32, ;; 24 bit - Line number where defined
568568 ;; 8 bit - Argument number. 1 indicates 1st argument.
569 metadata, ;; Type descriptor
569 metadata, ;; Reference to the type descriptor
570570 i32, ;; flags
571571 metadata ;; (optional) Reference to inline location
572572 }
465465 /// @param Val llvm::Value of the variable.
466466 DIGlobalVariable
467467 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
468 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
468 DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val);
469469
470470 /// \brief Create a new descriptor for the specified global.
471471 /// @param Name Name of the variable.
478478 /// @param Val llvm::Value of the variable.
479479 DIGlobalVariable
480480 createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile File,
481 unsigned LineNo, DIType Ty, bool isLocalToUnit,
481 unsigned LineNo, DITypeRef Ty, bool isLocalToUnit,
482482 llvm::Value *Val);
483483
484484 /// createStaticVariable - Create a new descriptor for the specified
496496 DIGlobalVariable
497497 createStaticVariable(DIDescriptor Context, StringRef Name,
498498 StringRef LinkageName, DIFile File, unsigned LineNo,
499 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
499 DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val,
500500 MDNode *Decl = NULL);
501501
502502
517517 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
518518 StringRef Name,
519519 DIFile File, unsigned LineNo,
520 DIType Ty, bool AlwaysPreserve = false,
520 DITypeRef Ty, bool AlwaysPreserve = false,
521521 unsigned Flags = 0,
522522 unsigned ArgNo = 0);
523523
536536 /// number. 1 indicates 1st argument.
537537 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
538538 StringRef Name, DIFile F, unsigned LineNo,
539 DIType Ty, ArrayRef Addr,
539 DITypeRef Ty, ArrayRef Addr,
540540 unsigned ArgNo = 0);
541541
542542 /// createFunction - Create a new descriptor for the specified subprogram.
223223 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
224224 friend DIScopeRef DIScope::getContext() const;
225225 friend DIScopeRef DIScope::getRef() const;
226 friend class DIType;
226227
227228 /// Val can be either a MDNode or a MDString, in the latter,
228229 /// MDString specifies the type identifier.
283284
284285 public:
285286 explicit DIType(const MDNode *N = 0) : DIScope(N) {}
287 operator DITypeRef () const {
288 assert(isType() &&
289 "constructing DITypeRef from an MDNode that is not a type");
290 return DITypeRef(&*getRef());
291 }
286292
287293 /// Verify - Verify that a type descriptor is well formed.
288294 bool Verify() const;
615621 }
616622
617623 unsigned getLineNumber() const { return getUnsignedField(7); }
618 DIType getType() const { return getFieldAs>(8); }
624 DITypeRef getType() const { return getFieldAs>(8); }
619625 unsigned isLocalToUnit() const { return getUnsignedField(9); }
620626 unsigned isDefinition() const { return getUnsignedField(10); }
621627
647653 unsigned L = getUnsignedField(4);
648654 return L >> 24;
649655 }
650 DIType getType() const { return getFieldAs>(5); }
656 DITypeRef getType() const { return getFieldAs>(5); }
651657
652658 /// isArtificial - Return true if this variable is marked as "artificial".
653659 bool isArtificial() const {
680686
681687 /// isBlockByrefVariable - Return true if the variable was declared as
682688 /// a "__block" variable (Apple Blocks).
683 bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
689 bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const {
690 return (getType().resolve(Map)).isBlockByrefStruct();
691 }
684692
685693 /// isInlinedFnArgument - Return true if this variable provides debugging
686694 /// information for an inlined function arguments.
114114 return DD->resolve(Ref);
115115 }
116116
117 bool DbgVariable::isBlockByrefVariable() const {
118 assert(Var.isVariable() && "Invalid complex DbgVariable!");
119 return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
120 }
121
122
117123 DIType DbgVariable::getType() const {
118 DIType Ty = Var.getType();
124 DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap());
119125 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
120126 // addresses instead.
121 if (Var.isBlockByrefVariable()) {
127 if (Var.isBlockByrefVariable(DD->getTypeIdentifierMap())) {
122128 /* Byref variables, in Blocks, are declared by the programmer as
123129 "SomeType VarName;", but the compiler creates a
124130 __Block_byref_x_VarName struct, and gives the variable VarName
23002306 const DebugLocEntry &Entry) {
23012307 DIVariable DV(Entry.getVariable());
23022308 if (Entry.isInt()) {
2303 DIBasicType BTy(DV.getType());
2309 DIBasicType BTy(resolve(DV.getType()));
23042310 if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
23052311 BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
23062312 Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts");
198198 assert(Var.isVariable() && "Invalid complex DbgVariable!");
199199 return Var.hasComplexAddress();
200200 }
201 bool isBlockByrefVariable() const {
202 assert(Var.isVariable() && "Invalid complex DbgVariable!");
203 return Var.isBlockByrefVariable();
204 }
201 bool isBlockByrefVariable() const;
205202 unsigned getNumAddrElements() const {
206203 assert(Var.isVariable() && "Invalid complex DbgVariable!");
207204 return Var.getNumAddrElements();
776773 return Ref.resolve(TypeIdentifierMap);
777774 }
778775
776 /// \brief Return the TypeIdentifierMap.
777 const DITypeIdentifierMap& getTypeIdentifierMap() const {
778 return TypeIdentifierMap;
779 }
780
779781 /// Find the DwarfCompileUnit for the given CU Die.
780782 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
781783 return CUDieMap.lookup(CU);
16031603 assert(GV.isGlobalVariable());
16041604
16051605 DIScope GVContext = GV.getContext();
1606 DIType GTy = GV.getType();
1606 DIType GTy = DD->resolve(GV.getType());
16071607
16081608 // If this is a static data member definition, some attributes belong
16091609 // to the declaration DIE.
926926 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
927927 StringRef LinkageName,
928928 DIFile F, unsigned LineNumber,
929 DIType Ty, bool isLocalToUnit,
929 DITypeRef Ty, bool isLocalToUnit,
930930 Value *Val) {
931931 Value *Elts[] = {
932932 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
950950
951951 /// \brief Create a new descriptor for the specified global.
952952 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
953 unsigned LineNumber, DIType Ty,
953 unsigned LineNumber,
954 DITypeRef Ty,
954955 bool isLocalToUnit,
955956 Value *Val) {
956957 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
963964 StringRef Name,
964965 StringRef LinkageName,
965966 DIFile F, unsigned LineNumber,
966 DIType Ty, bool isLocalToUnit,
967 DITypeRef Ty,
968 bool isLocalToUnit,
967969 Value *Val, MDNode *Decl) {
968970 Value *Elts[] = {
969971 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
988990 /// createVariable - Create a new descriptor for the specified variable.
989991 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
990992 StringRef Name, DIFile File,
991 unsigned LineNo, DIType Ty,
993 unsigned LineNo, DITypeRef Ty,
992994 bool AlwaysPreserve, unsigned Flags,
993995 unsigned ArgNo) {
994996 DIDescriptor Context(getNonCompileUnitScope(Scope));
995997 assert((!Context || Context.isScope()) &&
996998 "createLocalVariable should be called with a valid Context");
997 assert(Ty.isType() &&
998 "createLocalVariable should be called with a valid type");
999999 Value *Elts[] = {
10001000 GetTagConstant(VMContext, Tag),
10011001 getNonCompileUnitScope(Scope),
10261026 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
10271027 StringRef Name, DIFile F,
10281028 unsigned LineNo,
1029 DIType Ty, ArrayRef Addr,
1029 DITypeRef Ty,
1030 ArrayRef Addr,
10301031 unsigned ArgNo) {
10311032 SmallVector Elts;
10321033 Elts.push_back(GetTagConstant(VMContext, Tag));
540540
541541 if (getDisplayName().empty())
542542 return false;
543 // Make sure context @ field 2 and type @ field 8 are MDNodes.
543 // Make sure context @ field 2 is an MDNode.
544544 if (!fieldIsMDNode(DbgNode, 2))
545545 return false;
546 if (!fieldIsMDNode(DbgNode, 8))
546 // Make sure that type @ field 8 is a DITypeRef.
547 if (!fieldIsTypeRef(DbgNode, 8))
547548 return false;
548549 // Make sure StaticDataMemberDeclaration @ field 12 is MDNode.
549550 if (!fieldIsMDNode(DbgNode, 12))
557558 if (!isVariable())
558559 return false;
559560
560 // Make sure context @ field 1 and type @ field 5 are MDNodes.
561 // Make sure context @ field 1 is an MDNode.
561562 if (!fieldIsMDNode(DbgNode, 1))
562563 return false;
563 if (!fieldIsMDNode(DbgNode, 5))
564 // Make sure that type @ field 5 is a DITypeRef.
565 if (!fieldIsTypeRef(DbgNode, 5))
564566 return false;
565567 return DbgNode->getNumOperands() >= 8;
566568 }
9981000 DIGlobalVariable DIG(GVs.getElement(i));
9991001 if (addGlobalVariable(DIG)) {
10001002 processScope(DIG.getContext());
1001 processType(DIG.getType());
1003 processType(DIG.getType().resolve(TypeIdentifierMap));
10021004 }
10031005 }
10041006 DIArray SPs = CU.getSubprograms();
11321134 if (!NodesSeen.insert(DV))
11331135 return;
11341136 processScope(DIVariable(N).getContext());
1135 processType(DIVariable(N).getType());
1137 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
11361138 }
11371139
11381140 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
11481150 if (!NodesSeen.insert(DV))
11491151 return;
11501152 processScope(DIVariable(N).getContext());
1151 processType(DIVariable(N).getType());
1153 processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
11521154 }
11531155
11541156 /// addType - Add type into Tys.
9292 !21 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
9393 !22 = metadata !{metadata !"clang version 3.5.0 "}
9494 !23 = metadata !{i32 11, i32 0, metadata !15, null}
95 !24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8]
95 !24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !"_ZTS1A", i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8]
9696 !25 = metadata !{i32 8, i32 0, metadata !19, null} ; [ DW_TAG_imported_declaration ]
9797 !26 = metadata !{i32 9, i32 0, metadata !19, null}