Index: include/llvm/IR/DebugInfoMetadata.h =================================================================== --- include/llvm/IR/DebugInfoMetadata.h +++ include/llvm/IR/DebugInfoMetadata.h @@ -1396,19 +1396,20 @@ friend class MDNode; DILocation(LLVMContext &C, StorageType Storage, unsigned Line, - unsigned Column, ArrayRef MDs); + unsigned Column, ArrayRef MDs, bool ImplicitCode); ~DILocation() { dropAllReferences(); } static DILocation *getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope, - Metadata *InlinedAt, StorageType Storage, - bool ShouldCreate = true); + Metadata *InlinedAt, bool ImplicitCode, + StorageType Storage, bool ShouldCreate = true); static DILocation *getImpl(LLVMContext &Context, unsigned Line, unsigned Column, DILocalScope *Scope, - DILocation *InlinedAt, StorageType Storage, - bool ShouldCreate = true) { + DILocation *InlinedAt, bool ImplicitCode, + StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Line, Column, static_cast(Scope), - static_cast(InlinedAt), Storage, ShouldCreate); + static_cast(InlinedAt), ImplicitCode, Storage, + ShouldCreate); } /// With a given unsigned int \p U, use up to 13 bits to represent it. @@ -1437,7 +1438,7 @@ // Get the raw scope/inlinedAt since it is possible to invoke this on // a DILocation containing temporary metadata. return getTemporary(getContext(), getLine(), getColumn(), getRawScope(), - getRawInlinedAt()); + getRawInlinedAt(), isImplicitCode()); } public: @@ -1446,12 +1447,13 @@ DEFINE_MDNODE_GET(DILocation, (unsigned Line, unsigned Column, Metadata *Scope, - Metadata *InlinedAt = nullptr), - (Line, Column, Scope, InlinedAt)) + Metadata *InlinedAt = nullptr, bool ImplicitCode = false), + (Line, Column, Scope, InlinedAt, ImplicitCode)) DEFINE_MDNODE_GET(DILocation, (unsigned Line, unsigned Column, DILocalScope *Scope, - DILocation *InlinedAt = nullptr), - (Line, Column, Scope, InlinedAt)) + DILocation *InlinedAt = nullptr, + bool ImplicitCode = false), + (Line, Column, Scope, InlinedAt, ImplicitCode)) /// Return a (temporary) clone of this. TempDILocation clone() const { return cloneImpl(); } @@ -1464,6 +1466,10 @@ return cast_or_null(getRawInlinedAt()); } + /// Check if the location corresponds to an implicit code. + bool isImplicitCode() const { return ImplicitCode; } + void setImplicitCode(bool ImplicitCode) { this->ImplicitCode = ImplicitCode; } + DIFile *getFile() const { return getScope()->getFile(); } StringRef getFilename() const { return getScope()->getFilename(); } StringRef getDirectory() const { return getScope()->getDirectory(); } Index: include/llvm/IR/DebugLoc.h =================================================================== --- include/llvm/IR/DebugLoc.h +++ include/llvm/IR/DebugLoc.h @@ -78,7 +78,8 @@ /// /// FIXME: Remove this. Users should use DILocation::get(). static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope, - const MDNode *InlinedAt = nullptr); + const MDNode *InlinedAt = nullptr, + bool ImplicitCode = false); enum { ReplaceLastInlinedAt = true }; /// Rebuild the entire inlined-at chain for this instruction so that the top of @@ -112,6 +113,10 @@ /// Return \c this as a bar \a MDNode. MDNode *getAsMDNode() const { return Loc; } + /// Check if the DebugLoc corresponds to an implicit code. + bool isImplicitCode() const; + void setImplicitCode(bool ImplicitCode); + bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; } bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; } Index: include/llvm/IR/Metadata.h =================================================================== --- include/llvm/IR/Metadata.h +++ include/llvm/IR/Metadata.h @@ -66,9 +66,11 @@ enum StorageType { Uniqued, Distinct, Temporary }; /// Storage flag for non-uniqued, otherwise unowned, metadata. - unsigned char Storage; + unsigned char Storage : 7; // TODO: expose remaining bits to subclasses. + bool ImplicitCode : 1; + unsigned short SubclassData16 = 0; unsigned SubclassData32 = 0; @@ -80,7 +82,7 @@ protected: Metadata(unsigned ID, StorageType Storage) - : SubclassID(ID), Storage(Storage) { + : SubclassID(ID), Storage(Storage), ImplicitCode(false) { static_assert(sizeof(*this) == 8, "Metadata fields poorly packed"); } Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -4221,18 +4221,21 @@ (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS) /// ParseDILocationFields: -/// ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6) +/// ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6, +/// isImplicitCode: true) bool LLParser::ParseDILocation(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ OPTIONAL(line, LineField, ); \ OPTIONAL(column, ColumnField, ); \ REQUIRED(scope, MDField, (/* AllowNull */ false)); \ - OPTIONAL(inlinedAt, MDField, ); + OPTIONAL(inlinedAt, MDField, ); \ + OPTIONAL(isImplicitCode, MDBoolField, (false)); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS - Result = GET_OR_DISTINCT( - DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val)); + Result = + GET_OR_DISTINCT(DILocation, (Context, line.Val, column.Val, scope.Val, + inlinedAt.Val, isImplicitCode.Val)); return false; } Index: lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- lib/Bitcode/Reader/MetadataLoader.cpp +++ lib/Bitcode/Reader/MetadataLoader.cpp @@ -1147,8 +1147,10 @@ unsigned Column = Record[2]; Metadata *Scope = getMD(Record[3]); Metadata *InlinedAt = getMDOrNull(Record[4]); + bool ImplicitCode = Record[5]; MetadataList.assignValue( - GET_OR_DISTINCT(DILocation, (Context, Line, Column, Scope, InlinedAt)), + GET_OR_DISTINCT(DILocation, (Context, Line, Column, Scope, InlinedAt, + ImplicitCode)), NextMetadataNo); NextMetadataNo++; break; Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1401,6 +1401,7 @@ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); return Stream.EmitAbbrev(std::move(Abbv)); } @@ -1415,6 +1416,7 @@ Record.push_back(N->getColumn()); Record.push_back(VE.getMetadataID(N->getScope())); Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt())); + Record.push_back(N->isImplicitCode()); Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev); Record.clear(); Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1753,6 +1753,7 @@ Printer.printInt("column", DL->getColumn()); Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false); Printer.printMetadata("inlinedAt", DL->getRawInlinedAt()); + Printer.printBool("isImplicitCode", DL->isImplicitCode()); Out << ")"; } Index: lib/IR/DebugInfoMetadata.cpp =================================================================== --- lib/IR/DebugInfoMetadata.cpp +++ lib/IR/DebugInfoMetadata.cpp @@ -23,7 +23,8 @@ using namespace llvm; DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line, - unsigned Column, ArrayRef MDs) + unsigned Column, ArrayRef MDs, + bool ImplicitCode) : MDNode(C, DILocationKind, Storage, MDs) { assert((MDs.size() == 1 || MDs.size() == 2) && "Expected a scope and optional inlined-at"); @@ -33,6 +34,8 @@ SubclassData32 = Line; SubclassData16 = Column; + + setImplicitCode(ImplicitCode); } static void adjustColumn(unsigned &Column) { @@ -43,15 +46,15 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope, - Metadata *InlinedAt, StorageType Storage, - bool ShouldCreate) { + Metadata *InlinedAt, bool ImplicitCode, + StorageType Storage, bool ShouldCreate) { // Fixup column. adjustColumn(Column); if (Storage == Uniqued) { - if (auto *N = - getUniqued(Context.pImpl->DILocations, - DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt))) + if (auto *N = getUniqued(Context.pImpl->DILocations, + DILocationInfo::KeyTy(Line, Column, Scope, + InlinedAt, ImplicitCode))) return N; if (!ShouldCreate) return nullptr; @@ -63,8 +66,8 @@ Ops.push_back(Scope); if (InlinedAt) Ops.push_back(InlinedAt); - return storeImpl(new (Ops.size()) - DILocation(Context, Storage, Line, Column, Ops), + return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line, Column, + Ops, ImplicitCode), Storage, Context.pImpl->DILocations); } Index: lib/IR/DebugLoc.cpp =================================================================== --- lib/IR/DebugLoc.cpp +++ lib/IR/DebugLoc.cpp @@ -56,15 +56,28 @@ return DebugLoc(); } +bool DebugLoc::isImplicitCode() const { + if (DILocation *Loc = get()) { + return Loc->isImplicitCode(); + } + return true; +} + +void DebugLoc::setImplicitCode(bool ImplicitCode) { + if (DILocation *Loc = get()) { + Loc->setImplicitCode(ImplicitCode); + } +} + DebugLoc DebugLoc::get(unsigned Line, unsigned Col, const MDNode *Scope, - const MDNode *InlinedAt) { + const MDNode *InlinedAt, bool ImplicitCode) { // If no scope is available, this is an unknown location. if (!Scope) return DebugLoc(); return DILocation::get(Scope->getContext(), Line, Col, const_cast(Scope), - const_cast(InlinedAt)); + const_cast(InlinedAt), ImplicitCode); } DebugLoc DebugLoc::appendInlinedAt(DebugLoc DL, DILocation *InlinedAt, Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -280,21 +280,24 @@ unsigned Column; Metadata *Scope; Metadata *InlinedAt; + bool ImplicitCode; MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, - Metadata *InlinedAt) - : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} + Metadata *InlinedAt, bool ImplicitCode) + : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt), + ImplicitCode(ImplicitCode) {} MDNodeKeyImpl(const DILocation *L) : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), - InlinedAt(L->getRawInlinedAt()) {} + InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {} bool isKeyOf(const DILocation *RHS) const { return Line == RHS->getLine() && Column == RHS->getColumn() && - Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt(); + Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() && + ImplicitCode == RHS->isImplicitCode(); } unsigned getHashValue() const { - return hash_combine(Line, Column, Scope, InlinedAt); + return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode); } }; Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -605,7 +605,8 @@ continue; // Artificial lines such as calls to the global constructors. - if (Loc.getLine() == 0) continue; + if (Loc.getLine() == 0 || Loc.isImplicitCode()) + continue; if (Line == Loc.getLine()) continue; Line = Loc.getLine();