llvm.org GIT mirror llvm / b54df52
DebugInfo: Remove DIScope Replace uses of `DIScope` with `MDScope*`. There was one spot where I've left an `MDScope*` uninitialized (where `DIScope` would have been default-initialized to `nullptr`) -- this is intentional, since the if/else that follows should unconditional assign it to a value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235327 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
6 changed file(s) with 49 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
9292 }
9393 static IRBuilder<> Builder(getGlobalContext());
9494 struct DebugInfo {
95 DICompileUnit TheCU;
96 DIType DblTy;
97 std::vector LexicalBlocks;
98 std::map FnScopeMap;
95 MDCompileUnit *TheCU;
96 MDType *DblTy;
97 std::vector LexicalBlocks;
98 std::map FnScopeMap;
9999
100100 void emitLocation(ExprAST *AST);
101 DIType getDoubleTy();
101 MDType *getDoubleTy();
102102 } KSDbgInfo;
103103
104104 static std::string IdentifierStr; // Filled in if tok_identifier
815815
816816 static DIBuilder *DBuilder;
817817
818 DIType DebugInfo::getDoubleTy() {
818 MDType *DebugInfo::getDoubleTy() {
819819 if (DblTy)
820820 return DblTy;
821821
835835 DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
836836 }
837837
838 static MDSubroutineType *CreateFunctionType(unsigned NumArgs, DIFile Unit) {
838 static MDSubroutineType *CreateFunctionType(unsigned NumArgs, MDFile *Unit) {
839839 SmallVector EltTys;
840 DIType DblTy = KSDbgInfo.getDoubleTy();
840 MDType *DblTy = KSDbgInfo.getDoubleTy();
841841
842842 // Add the result type.
843843 EltTys.push_back(DblTy);
845845 for (unsigned i = 0, e = NumArgs; i != e; ++i)
846846 EltTys.push_back(DblTy);
847847
848 DITypeArray EltTypeArray = DBuilder->getOrCreateTypeArray(EltTys);
849 return DBuilder->createSubroutineType(Unit, EltTypeArray);
848 return DBuilder->createSubroutineType(Unit,
849 DBuilder->getOrCreateTypeArray(EltTys));
850850 }
851851
852852 //===----------------------------------------------------------------------===//
12231223 AI->setName(Args[Idx]);
12241224
12251225 // Create a subprogram DIE for this function.
1226 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1227 KSDbgInfo.TheCU->getDirectory());
1226 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1227 KSDbgInfo.TheCU->getDirectory());
12281228 MDScope *FContext = Unit;
12291229 unsigned LineNo = Line;
12301230 unsigned ScopeLine = Line;
1231 DISubprogram SP = DBuilder->createFunction(
1231 MDSubprogram *SP = DBuilder->createFunction(
12321232 FContext, Name, StringRef(), Unit, LineNo,
12331233 CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
12341234 true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
12461246 AllocaInst *Alloca = CreateEntryBlockAlloca(F, Args[Idx]);
12471247
12481248 // Create a debug descriptor for the variable.
1249 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
1250 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1251 KSDbgInfo.TheCU->getDirectory());
1252 DIVariable D = DBuilder->createLocalVariable(dwarf::DW_TAG_arg_variable,
1253 *Scope, Args[Idx], Unit, Line,
1254 KSDbgInfo.getDoubleTy(), Idx);
1249 MDScope *Scope = KSDbgInfo.LexicalBlocks.back();
1250 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1251 KSDbgInfo.TheCU->getDirectory());
1252 MDLocalVariable *D = DBuilder->createLocalVariable(
1253 dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
1254 KSDbgInfo.getDoubleTy(), Idx);
12551255
12561256 DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
1257 DebugLoc::get(Line, 0, *Scope),
1257 DebugLoc::get(Line, 0, Scope),
12581258 Builder.GetInsertBlock());
12591259
12601260 // Store the initial value into the alloca.
5151 class DILexicalBlockFile;
5252 class DIVariable;
5353 class DIType;
54 class DIScope;
5554 class DIObjCProperty;
5655
5756 /// \brief Maps from type identifier to the actual MDNode.
6362 template <> struct simplify_type;
6463 DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
6564 DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
66 DECLARE_SIMPLIFY_DESCRIPTOR(DIScope)
6765 DECLARE_SIMPLIFY_DESCRIPTOR(DIType)
6866 DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType)
6967 DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType)
111109 MDEnumerator &operator*() const { return *N; }
112110 };
113111
114 class DIScope {
115 MDScope *N;
116
117 public:
118 DIScope(const MDScope *N = nullptr) : N(const_cast(N)) {}
119
120 operator MDScope *() const { return N; }
121 MDScope *operator->() const { return N; }
122 MDScope &operator*() const { return *N; }
123 };
124
125112 class DIType {
126113 MDType *N;
127114
128115 public:
129116 DIType(const MDType *N = nullptr) : N(const_cast(N)) {}
130117
131 operator DIScope() const { return N; }
132118 operator MDType *() const { return N; }
133119 MDType *operator->() const { return N; }
134120 MDType &operator*() const { return *N; }
193179 public:
194180 DIFile(const MDFile *N = nullptr) : N(const_cast(N)) {}
195181
196 operator DIScope() const { return N; }
197182 operator MDFile *() const { return N; }
198183 MDFile *operator->() const { return N; }
199184 MDFile &operator*() const { return *N; }
206191 DICompileUnit(const MDCompileUnit *N = nullptr)
207192 : N(const_cast(N)) {}
208193
209 operator DIScope() const { return N; }
210194 operator MDCompileUnit *() const { return N; }
211195 MDCompileUnit *operator->() const { return N; }
212196 MDCompileUnit &operator*() const { return *N; }
219203 DISubprogram(const MDSubprogram *N = nullptr)
220204 : N(const_cast(N)) {}
221205
222 operator DIScope() const { return N; }
223206 operator MDSubprogram *() const { return N; }
224207 MDSubprogram *operator->() const { return N; }
225208 MDSubprogram &operator*() const { return *N; }
256239 DINameSpace(const MDNamespace *N = nullptr)
257240 : N(const_cast(N)) {}
258241
259 operator DIScope() const { return N; }
260242 operator MDNamespace *() const { return N; }
261243 MDNamespace *operator->() const { return N; }
262244 MDNamespace &operator*() const { return *N; }
365347 template <> struct simplify_type : simplify_type {};
366348 SIMPLIFY_DESCRIPTOR(DISubrange)
367349 SIMPLIFY_DESCRIPTOR(DIEnumerator)
368 SIMPLIFY_DESCRIPTOR(DIScope)
369350 SIMPLIFY_DESCRIPTOR(DIType)
370351 SIMPLIFY_DESCRIPTOR(DIBasicType)
371352 SIMPLIFY_DESCRIPTOR(DIDerivedType)
103103
104104 assert(GV);
105105
106 DIScope GVContext = GV->getScope();
107 DIType GTy = DD->resolve(GV->getType());
106 auto *GVContext = GV->getScope();
107 auto *GTy = DD->resolve(GV->getType());
108108
109109 // Construct the context before querying for the existence of the DIE in
110110 // case such construction creates the DIE.
112112
113113 // Add to map.
114114 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
115 DIScope DeclContext;
116
115 MDScope *DeclContext;
117116 if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
118117 DeclContext = resolve(SDMDecl->getScope());
119118 assert(SDMDecl->isStaticMember() && "Expected static member decl");
305304 if (!Scope || !Scope->getScopeNode())
306305 return;
307306
308 DIScope DS(Scope->getScopeNode());
307 auto *DS = Scope->getScopeNode();
309308
310309 assert((Scope->getInlinedAt() || !isa(DS)) &&
311310 "Only handle inlined subprograms here, use "
418417 std::unique_ptr
419418 DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
420419 assert(Scope->getScopeNode());
421 DIScope DS(Scope->getScopeNode());
422 DISubprogram InlinedSP = getDISubprogram(DS);
420 auto *DS = Scope->getScopeNode();
421 auto *InlinedSP = getDISubprogram(DS);
423422 // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
424423 // was inlined from another compile unit.
425424 DIE *OriginDIE = DU->getAbstractSPDies()[InlinedSP];
707706
708707 /// addGlobalName - Add a new global name to the compile unit.
709708 void DwarfCompileUnit::addGlobalName(StringRef Name, DIE &Die,
710 DIScope Context) {
709 const MDScope *Context) {
711710 if (includeMinimalInlineScopes())
712711 return;
713712 std::string FullName = getParentContextString(Context) + Name.str();
715714 }
716715
717716 /// Add a new global type to the unit.
718 void DwarfCompileUnit::addGlobalType(DIType Ty, const DIE &Die,
719 DIScope Context) {
717 void DwarfCompileUnit::addGlobalType(const MDType *Ty, const DIE &Die,
718 const MDScope *Context) {
720719 if (includeMinimalInlineScopes())
721720 return;
722721 std::string FullName = getParentContextString(Context) + Ty->getName().str();
808807 void DwarfCompileUnit::applySubprogramAttributesToDefinition(DISubprogram SP,
809808 DIE &SPDie) {
810809 auto *SPDecl = SP->getDeclaration();
811 DIScope Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
810 auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
812811 applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes());
813812 addGlobalName(SP->getName(), SPDie, Context);
814813 }
182182 }
183183
184184 /// Add a new global name to the compile unit.
185 void addGlobalName(StringRef Name, DIE &Die, DIScope Context) override;
185 void addGlobalName(StringRef Name, DIE &Die, const MDScope *Context) override;
186186
187187 /// Add a new global type to the compile unit.
188 void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) override;
188 void addGlobalType(const MDType *Ty, const DIE &Die,
189 const MDScope *Context) override;
189190
190191 const StringMap &getGlobalNames() const { return GlobalNames; }
191192 const StringMap &getGlobalTypes() const { return GlobalTypes; }
771771 }
772772
773773 /// getOrCreateContextDIE - Get context owner's DIE.
774 DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) {
774 DIE *DwarfUnit::getOrCreateContextDIE(const MDScope *Context) {
775775 if (!Context || isa(Context))
776776 return &getUnitDie();
777777 if (auto *T = dyn_cast(Context))
784784 }
785785
786786 DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
787 DIScope Context = resolve(Ty->getScope());
787 auto *Context = resolve(Ty->getScope());
788788 DIE *ContextDIE = getOrCreateContextDIE(Context);
789789
790790 if (DIE *TyDIE = getDIE(Ty))
816816
817817 // Construct the context before querying for the existence of the DIE in case
818818 // such construction creates the DIE.
819 DIScope Context = resolve(Ty->getScope());
819 auto *Context = resolve(Ty->getScope());
820820 DIE *ContextDIE = getOrCreateContextDIE(Context);
821821 assert(ContextDIE);
822822
845845 return &TyDIE;
846846 }
847847
848 void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
849 const DIE &TyDIE) {
848 void DwarfUnit::updateAcceleratorTables(const MDScope *Context,
849 const MDType *Ty, const DIE &TyDIE) {
850850 if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
851851 bool IsImplementation = 0;
852852 if (auto *CT = dyn_cast(Ty)) {
889889 /// it as a string. This is done at the metadata level because DIEs may
890890 /// not currently have been added to the parent context and walking the
891891 /// DIEs looking for names is more expensive than walking the metadata.
892 std::string DwarfUnit::getParentContextString(DIScope Context) const {
892 std::string DwarfUnit::getParentContextString(const MDScope *Context) const {
893893 if (!Context)
894894 return "";
895895
898898 return "";
899899
900900 std::string CS;
901 SmallVector<DIScope, 1> Parents;
901 SmallVector<const MDScope *, 1> Parents;
902902 while (!isa(Context)) {
903903 Parents.push_back(Context);
904904 if (Context->getScope())
911911
912912 // Reverse iterate over our list to go from the outermost construct to the
913913 // innermost.
914 for (SmallVectorImpl::reverse_iterator I = Parents.rbegin(),
915 E = Parents.rend();
916 I != E; ++I) {
914 for (auto I = Parents.rbegin(), E = Parents.rend(); I != E; ++I) {
917915 const MDScope *Ctx = *I;
918916 StringRef Name = Ctx->getName();
919917 if (Name.empty() && isa(Ctx))
152152
153153 /// getParentContextString - Get a string containing the language specific
154154 /// context for a global name.
155 std::string getParentContextString(DIScope Context) const;
155 std::string getParentContextString(const MDScope *Context) const;
156156
157157 /// Add a new global name to the compile unit.
158 virtual void addGlobalName(StringRef Name, DIE &Die, DIScope Context) {}
158 virtual void addGlobalName(StringRef Name, DIE &Die, const MDScope *Context) {
159 }
159160
160161 /// Add a new global type to the compile unit.
161 virtual void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) {}
162 virtual void addGlobalType(const MDType *Ty, const DIE &Die,
163 const MDScope *Context) {}
162164
163165 /// addAccelNamespace - Add a new name to the namespace accelerator table.
164166 void addAccelNamespace(StringRef Name, const DIE &Die);
301303 DIE *createTypeDIE(DICompositeType Ty);
302304
303305 /// getOrCreateContextDIE - Get context owner's DIE.
304 DIE *getOrCreateContextDIE(DIScope Context);
306 DIE *getOrCreateContextDIE(const MDScope *Context);
305307
306308 /// constructContainingTypeDIEs - Construct DIEs for types that contain
307309 /// vtables.
401403
402404 /// If this is a named finished type then include it in the list of types for
403405 /// the accelerator tables.
404 void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE);
406 void updateAcceleratorTables(const MDScope *Context, const MDType *Ty,
407 const DIE &TyDIE);
405408
406409 virtual bool isDwoUnit() const = 0;
407410 };