Commit 4eeaa0da042055b1cd17b339e2dde518a3026033

Authored by Adrian Prantl
1 parent fa0d0a51

[PR27284] Reverse the ownership between DICompileUnit and DISubprogram.

Currently each Function points to a DISubprogram and DISubprogram has a
scope field. For member functions the scope is a DICompositeType. DIScopes
point to the DICompileUnit to facilitate type uniquing.

Distinct DISubprograms (with isDefinition: true) are not part of the type
hierarchy and cannot be uniqued. This change removes the subprograms
list from DICompileUnit and instead adds a pointer to the owning compile
unit to distinct DISubprograms. This would make it easy for ThinLTO to
strip unneeded DISubprograms and their transitively referenced debug info.

Motivation
----------

Materializing DISubprograms is currently the most expensive operation when
doing a ThinLTO build of clang.

We want the DISubprogram to be stored in a separate Bitcode block (or the
same block as the function body) so we can avoid having to expensively
deserialize all DISubprograms together with the global metadata. If a
function has been inlined into another subprogram we need to store a
reference the block containing the inlined subprogram.

Attached to https://llvm.org/bugs/show_bug.cgi?id=27284 is a python script
that updates LLVM IR testcases to the new format.

http://reviews.llvm.org/D19034
<rdar://problem/25256815>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266446 91177308-0d34-0410-b5e6-96231b3b80d8
Showing 100 changed files with 571 additions and 726 deletions

Too many changes to show.

To preserve performance only 100 of 540 files are displayed.

... ... @@ -403,9 +403,9 @@ namespace llvm {
403 403 uint64_t AlignInBits = 0, unsigned Flags = DINode::FlagFwdDecl,
404 404 StringRef UniqueIdentifier = "");
405 405  
406   - /// Retain DIType* in a module even if it is not referenced
  406 + /// Retain DIScope* in a module even if it is not referenced
407 407 /// through debug info anchors.
408   - void retainType(DIType *T);
  408 + void retainType(DIScope *T);
409 409  
410 410 /// Create unspecified parameter type
411 411 /// for a subroutine type.
... ...
... ... @@ -959,25 +959,21 @@ private:
959 959 StringRef Producer, bool IsOptimized, StringRef Flags,
960 960 unsigned RuntimeVersion, StringRef SplitDebugFilename,
961 961 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
962   - DITypeArray RetainedTypes, DISubprogramArray Subprograms,
963   - DIGlobalVariableArray GlobalVariables,
  962 + DIScopeArray RetainedTypes, DIGlobalVariableArray GlobalVariables,
964 963 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
965 964 uint64_t DWOId, StorageType Storage, bool ShouldCreate = true) {
966   - return getImpl(Context, SourceLanguage, File,
967   - getCanonicalMDString(Context, Producer), IsOptimized,
968   - getCanonicalMDString(Context, Flags), RuntimeVersion,
969   - getCanonicalMDString(Context, SplitDebugFilename),
970   - EmissionKind, EnumTypes.get(), RetainedTypes.get(),
971   - Subprograms.get(), GlobalVariables.get(),
972   - ImportedEntities.get(), Macros.get(), DWOId, Storage,
973   - ShouldCreate);
  965 + return getImpl(
  966 + Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
  967 + IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
  968 + getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
  969 + EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
  970 + ImportedEntities.get(), Macros.get(), DWOId, Storage, ShouldCreate);
974 971 }
975 972 static DICompileUnit *
976 973 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
977 974 MDString *Producer, bool IsOptimized, MDString *Flags,
978 975 unsigned RuntimeVersion, MDString *SplitDebugFilename,
979   - unsigned EmissionKind, Metadata *EnumTypes,
980   - Metadata *RetainedTypes, Metadata *Subprograms,
  976 + unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
981 977 Metadata *GlobalVariables, Metadata *ImportedEntities,
982 978 Metadata *Macros, uint64_t DWOId, StorageType Storage,
983 979 bool ShouldCreate = true);
... ... @@ -986,7 +982,7 @@ private:
986 982 return getTemporary(
987 983 getContext(), getSourceLanguage(), getFile(), getProducer(),
988 984 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
989   - getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
  985 + getEmissionKind(), getEnumTypes(), getRetainedTypes(),
990 986 getGlobalVariables(), getImportedEntities(), getMacros(), DWOId);
991 987 }
992 988  
... ... @@ -999,23 +995,22 @@ public:
999 995 (unsigned SourceLanguage, DIFile *File, StringRef Producer,
1000 996 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1001 997 StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
1002   - DICompositeTypeArray EnumTypes, DITypeArray RetainedTypes,
1003   - DISubprogramArray Subprograms, DIGlobalVariableArray GlobalVariables,
  998 + DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
  999 + DIGlobalVariableArray GlobalVariables,
1004 1000 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1005 1001 uint64_t DWOId),
1006 1002 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1007   - SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, Subprograms,
  1003 + SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1008 1004 GlobalVariables, ImportedEntities, Macros, DWOId))
1009 1005 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
1010 1006 DICompileUnit,
1011 1007 (unsigned SourceLanguage, Metadata *File, MDString *Producer,
1012 1008 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1013 1009 MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
1014   - Metadata *RetainedTypes, Metadata *Subprograms,
1015   - Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
1016   - uint64_t DWOId),
  1010 + Metadata *RetainedTypes, Metadata *GlobalVariables,
  1011 + Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId),
1017 1012 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1018   - SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, Subprograms,
  1013 + SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1019 1014 GlobalVariables, ImportedEntities, Macros, DWOId))
1020 1015  
1021 1016 TempDICompileUnit clone() const { return cloneImpl(); }
... ... @@ -1032,12 +1027,9 @@ public:
1032 1027 DICompositeTypeArray getEnumTypes() const {
1033 1028 return cast_or_null<MDTuple>(getRawEnumTypes());
1034 1029 }
1035   - DITypeArray getRetainedTypes() const {
  1030 + DIScopeArray getRetainedTypes() const {
1036 1031 return cast_or_null<MDTuple>(getRawRetainedTypes());
1037 1032 }
1038   - DISubprogramArray getSubprograms() const {
1039   - return cast_or_null<MDTuple>(getRawSubprograms());
1040   - }
1041 1033 DIGlobalVariableArray getGlobalVariables() const {
1042 1034 return cast_or_null<MDTuple>(getRawGlobalVariables());
1043 1035 }
... ... @@ -1057,10 +1049,9 @@ public:
1057 1049 }
1058 1050 Metadata *getRawEnumTypes() const { return getOperand(4); }
1059 1051 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1060   - Metadata *getRawSubprograms() const { return getOperand(6); }
1061   - Metadata *getRawGlobalVariables() const { return getOperand(7); }
1062   - Metadata *getRawImportedEntities() const { return getOperand(8); }
1063   - Metadata *getRawMacros() const { return getOperand(9); }
  1052 + Metadata *getRawGlobalVariables() const { return getOperand(6); }
  1053 + Metadata *getRawImportedEntities() const { return getOperand(7); }
  1054 + Metadata *getRawMacros() const { return getOperand(8); }
1064 1055  
1065 1056 /// \brief Replace arrays.
1066 1057 ///
... ... @@ -1074,16 +1065,13 @@ public:
1074 1065 void replaceRetainedTypes(DITypeArray N) {
1075 1066 replaceOperandWith(5, N.get());
1076 1067 }
1077   - void replaceSubprograms(DISubprogramArray N) {
1078   - replaceOperandWith(6, N.get());
1079   - }
1080 1068 void replaceGlobalVariables(DIGlobalVariableArray N) {
1081   - replaceOperandWith(7, N.get());
  1069 + replaceOperandWith(6, N.get());
1082 1070 }
1083 1071 void replaceImportedEntities(DIImportedEntityArray N) {
1084   - replaceOperandWith(8, N.get());
  1072 + replaceOperandWith(7, N.get());
1085 1073 }
1086   - void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(9, N.get()); }
  1074 + void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1087 1075 /// @}
1088 1076  
1089 1077 static bool classof(const Metadata *MD) {
... ... @@ -1266,13 +1254,13 @@ class DISubprogram : public DILocalScope {
1266 1254 DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1267 1255 unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality,
1268 1256 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1269   - DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1270   - DILocalVariableArray Variables, StorageType Storage,
1271   - bool ShouldCreate = true) {
  1257 + DICompileUnit *Unit, DITemplateParameterArray TemplateParams,
  1258 + DISubprogram *Declaration, DILocalVariableArray Variables,
  1259 + StorageType Storage, bool ShouldCreate = true) {
1272 1260 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1273 1261 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1274 1262 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1275   - Virtuality, VirtualIndex, Flags, IsOptimized,
  1263 + Virtuality, VirtualIndex, Flags, IsOptimized, Unit,
1276 1264 TemplateParams.get(), Declaration, Variables.get(), Storage,
1277 1265 ShouldCreate);
1278 1266 }
... ... @@ -1281,16 +1269,17 @@ class DISubprogram : public DILocalScope {
1281 1269 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1282 1270 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1283 1271 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1284   - unsigned Flags, bool IsOptimized, Metadata *TemplateParams,
1285   - Metadata *Declaration, Metadata *Variables, StorageType Storage,
1286   - bool ShouldCreate = true);
  1272 + unsigned Flags, bool IsOptimized, Metadata *Unit,
  1273 + Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
  1274 + StorageType Storage, bool ShouldCreate = true);
1287 1275  
1288 1276 TempDISubprogram cloneImpl() const {
1289   - return getTemporary(
1290   - getContext(), getScope(), getName(), getLinkageName(), getFile(),
1291   - getLine(), getType(), isLocalToUnit(), isDefinition(), getScopeLine(),
1292   - getContainingType(), getVirtuality(), getVirtualIndex(), getFlags(),
1293   - isOptimized(), getTemplateParams(), getDeclaration(), getVariables());
  1277 + return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
  1278 + getFile(), getLine(), getType(), isLocalToUnit(),
  1279 + isDefinition(), getScopeLine(), getContainingType(),
  1280 + getVirtuality(), getVirtualIndex(), getFlags(),
  1281 + isOptimized(), getUnit(), getTemplateParams(),
  1282 + getDeclaration(), getVariables());
1294 1283 }
1295 1284  
1296 1285 public:
... ... @@ -1300,12 +1289,13 @@ public:
1300 1289 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1301 1290 DITypeRef ContainingType, unsigned Virtuality,
1302 1291 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
  1292 + DICompileUnit *Unit,
1303 1293 DITemplateParameterArray TemplateParams = nullptr,
1304 1294 DISubprogram *Declaration = nullptr,
1305 1295 DILocalVariableArray Variables = nullptr),
1306 1296 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1307 1297 IsDefinition, ScopeLine, ContainingType, Virtuality,
1308   - VirtualIndex, Flags, IsOptimized, TemplateParams,
  1298 + VirtualIndex, Flags, IsOptimized, Unit, TemplateParams,
1309 1299 Declaration, Variables))
1310 1300 DEFINE_MDNODE_GET(
1311 1301 DISubprogram,
... ... @@ -1313,11 +1303,11 @@ public:
1313 1303 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1314 1304 unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1315 1305 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
1316   - Metadata *TemplateParams = nullptr, Metadata *Declaration = nullptr,
1317   - Metadata *Variables = nullptr),
  1306 + Metadata *Unit, Metadata *TemplateParams = nullptr,
  1307 + Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
1318 1308 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1319 1309 ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1320   - TemplateParams, Declaration, Variables))
  1310 + Unit, TemplateParams, Declaration, Variables))
1321 1311  
1322 1312 TempDISubprogram clone() const { return cloneImpl(); }
1323 1313  
... ... @@ -1376,6 +1366,12 @@ public:
1376 1366 return DITypeRef(getRawContainingType());
1377 1367 }
1378 1368  
  1369 + DICompileUnit *getUnit() const {
  1370 + return cast_or_null<DICompileUnit>(getRawUnit());
  1371 + }
  1372 + void replaceUnit(DICompileUnit *CU) {
  1373 + replaceOperandWith(7, CU);
  1374 + }
1379 1375 DITemplateParameterArray getTemplateParams() const {
1380 1376 return cast_or_null<MDTuple>(getRawTemplateParams());
1381 1377 }
... ... @@ -1389,9 +1385,10 @@ public:
1389 1385 Metadata *getRawScope() const { return getOperand(1); }
1390 1386 Metadata *getRawType() const { return getOperand(5); }
1391 1387 Metadata *getRawContainingType() const { return getOperand(6); }
1392   - Metadata *getRawTemplateParams() const { return getOperand(7); }
1393   - Metadata *getRawDeclaration() const { return getOperand(8); }
1394   - Metadata *getRawVariables() const { return getOperand(9); }
  1388 + Metadata *getRawUnit() const { return getOperand(7); }
  1389 + Metadata *getRawTemplateParams() const { return getOperand(8); }
  1390 + Metadata *getRawDeclaration() const { return getOperand(9); }
  1391 + Metadata *getRawVariables() const { return getOperand(10); }
1395 1392  
1396 1393 /// \brief Check if this subprogram describes the given function.
1397 1394 ///
... ...
... ... @@ -3875,8 +3875,7 @@ bool LLParser::ParseDIFile(MDNode *&amp;Result, bool IsDistinct) {
3875 3875 /// ::= !DICompileUnit(language: DW_LANG_C99, file: !0, producer: "clang",
3876 3876 /// isOptimized: true, flags: "-O2", runtimeVersion: 1,
3877 3877 /// splitDebugFilename: "abc.debug",
3878   -/// emissionKind: FullDebug,
3879   -/// enums: !1, retainedTypes: !2, subprograms: !3,
  3878 +/// emissionKind: FullDebug, enums: !1, retainedTypes: !2,
3880 3879 /// globals: !4, imports: !5, macros: !6, dwoId: 0x0abcd)
3881 3880 bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
3882 3881 if (!IsDistinct)
... ... @@ -3893,7 +3892,6 @@ bool LLParser::ParseDICompileUnit(MDNode *&amp;Result, bool IsDistinct) {
3893 3892 OPTIONAL(emissionKind, EmissionKindField, ); \
3894 3893 OPTIONAL(enums, MDField, ); \
3895 3894 OPTIONAL(retainedTypes, MDField, ); \
3896   - OPTIONAL(subprograms, MDField, ); \
3897 3895 OPTIONAL(globals, MDField, ); \
3898 3896 OPTIONAL(imports, MDField, ); \
3899 3897 OPTIONAL(macros, MDField, ); \
... ... @@ -3904,8 +3902,7 @@ bool LLParser::ParseDICompileUnit(MDNode *&amp;Result, bool IsDistinct) {
3904 3902 Result = DICompileUnit::getDistinct(
3905 3903 Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
3906 3904 runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
3907   - retainedTypes.Val, subprograms.Val, globals.Val, imports.Val, macros.Val,
3908   - dwoId.Val);
  3905 + retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val);
3909 3906 return false;
3910 3907 }
3911 3908  
... ... @@ -3934,6 +3931,7 @@ bool LLParser::ParseDISubprogram(MDNode *&amp;Result, bool IsDistinct) {
3934 3931 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \
3935 3932 OPTIONAL(flags, DIFlagField, ); \
3936 3933 OPTIONAL(isOptimized, MDBoolField, ); \
  3934 + OPTIONAL(unit, MDField, ); \
3937 3935 OPTIONAL(templateParams, MDField, ); \
3938 3936 OPTIONAL(declaration, MDField, ); \
3939 3937 OPTIONAL(variables, MDField, );
... ... @@ -3946,11 +3944,11 @@ bool LLParser::ParseDISubprogram(MDNode *&amp;Result, bool IsDistinct) {
3946 3944 "missing 'distinct', required for !DISubprogram when 'isDefinition'");
3947 3945  
3948 3946 Result = GET_OR_DISTINCT(
3949   - DISubprogram,
3950   - (Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val,
3951   - type.Val, isLocal.Val, isDefinition.Val, scopeLine.Val,
3952   - containingType.Val, virtuality.Val, virtualIndex.Val, flags.Val,
3953   - isOptimized.Val, templateParams.Val, declaration.Val, variables.Val));
  3947 + DISubprogram, (Context, scope.Val, name.Val, linkageName.Val, file.Val,
  3948 + line.Val, type.Val, isLocal.Val, isDefinition.Val,
  3949 + scopeLine.Val, containingType.Val, virtuality.Val,
  3950 + virtualIndex.Val, flags.Val, isOptimized.Val, unit.Val,
  3951 + templateParams.Val, declaration.Val, variables.Val));
3954 3952 return false;
3955 3953 }
3956 3954  
... ...
... ... @@ -1948,6 +1948,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
1948 1948 if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
1949 1949 return error("Invalid record");
1950 1950  
  1951 + std::vector<std::pair<DICompileUnit *, Metadata *>> CUSubprograms;
1951 1952 SmallVector<uint64_t, 64> Record;
1952 1953  
1953 1954 auto getMD = [&](unsigned ID) -> Metadata * {
... ... @@ -1976,6 +1977,13 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
1976 1977 case BitstreamEntry::Error:
1977 1978 return error("Malformed block");
1978 1979 case BitstreamEntry::EndBlock:
  1980 + // Upgrade old-style CU <-> SP pointers to point from SP to CU.
  1981 + for (auto CU_SP : CUSubprograms)
  1982 + if (auto *SPs = dyn_cast_or_null<MDTuple>(CU_SP.second))
  1983 + for (auto &Op : SPs->operands())
  1984 + if (auto *SP = dyn_cast_or_null<MDNode>(Op))
  1985 + SP->replaceOperandWith(7, CU_SP.first);
  1986 +
1979 1987 MetadataList.tryToResolveCycles();
1980 1988 return std::error_code();
1981 1989 case BitstreamEntry::Record:
... ... @@ -2232,24 +2240,32 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
2232 2240  
2233 2241 // Ignore Record[0], which indicates whether this compile unit is
2234 2242 // distinct. It's always distinct.
2235   - MetadataList.assignValue(
2236   - DICompileUnit::getDistinct(
2237   - Context, Record[1], getMDOrNull(Record[2]),
2238   - getMDString(Record[3]), Record[4], getMDString(Record[5]),
2239   - Record[6], getMDString(Record[7]), Record[8],
2240   - getMDOrNull(Record[9]), getMDOrNull(Record[10]),
2241   - getMDOrNull(Record[11]), getMDOrNull(Record[12]),
2242   - getMDOrNull(Record[13]),
2243   - Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
2244   - Record.size() <= 14 ? 0 : Record[14]),
2245   - NextMetadataNo++);
  2243 + auto *CU = DICompileUnit::getDistinct(
  2244 + Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]),
  2245 + Record[4], getMDString(Record[5]), Record[6], getMDString(Record[7]),
  2246 + Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]),
  2247 + getMDOrNull(Record[12]), getMDOrNull(Record[13]),
  2248 + Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
  2249 + Record.size() <= 14 ? 0 : Record[14]);
  2250 +
  2251 + MetadataList.assignValue(CU, NextMetadataNo++);
  2252 +
  2253 + // Move the Upgrade the list of subprograms.
  2254 + if (Metadata *SPs = getMDOrNull(Record[11]))
  2255 + CUSubprograms.push_back({CU, SPs});
2246 2256 break;
2247 2257 }
2248 2258 case bitc::METADATA_SUBPROGRAM: {
2249 2259 if (Record.size() != 18 && Record.size() != 19)
2250 2260 return error("Invalid record");
2251 2261  
2252   - bool HasFn = Record.size() == 19;
  2262 + // Version 1 has a Function as Record[15].
  2263 + // Version 2 has removed Record[15].
  2264 + // Version 3 has the Unit as Record[15].
  2265 + Metadata *CUorFn = getMDOrNull(Record[15]);
  2266 + unsigned Offset = Record.size() == 19 ? 1 : 0;
  2267 + bool HasFn = Offset && dyn_cast_or_null<ConstantAsMetadata>(CUorFn);
  2268 + bool HasCU = Offset && !HasFn;
2253 2269 DISubprogram *SP = GET_OR_DISTINCT(
2254 2270 DISubprogram,
2255 2271 Record[0] || Record[8], // All definitions should be distinct.
... ... @@ -2257,13 +2273,14 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
2257 2273 getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
2258 2274 getMDOrNull(Record[6]), Record[7], Record[8], Record[9],
2259 2275 getMDOrNull(Record[10]), Record[11], Record[12], Record[13],
2260   - Record[14], getMDOrNull(Record[15 + HasFn]),
2261   - getMDOrNull(Record[16 + HasFn]), getMDOrNull(Record[17 + HasFn])));
  2276 + Record[14], HasCU ? CUorFn : nullptr,
  2277 + getMDOrNull(Record[15 + Offset]), getMDOrNull(Record[16 + Offset]),
  2278 + getMDOrNull(Record[17 + Offset])));
2262 2279 MetadataList.assignValue(SP, NextMetadataNo++);
2263 2280  
2264 2281 // Upgrade sp->function mapping to function->sp mapping.
2265   - if (HasFn && Record[15]) {
2266   - if (auto *CMD = dyn_cast<ConstantAsMetadata>(getMDOrNull(Record[15])))
  2282 + if (HasFn) {
  2283 + if (auto *CMD = dyn_cast<ConstantAsMetadata>(CUorFn))
2267 2284 if (auto *F = dyn_cast<Function>(CMD->getValue())) {
2268 2285 if (F->isMaterializable())
2269 2286 // Defer until materialized; unmaterialized functions may not have
... ...
... ... @@ -1098,7 +1098,7 @@ static void writeDICompileUnit(const DICompileUnit *N,
1098 1098 Record.push_back(N->getEmissionKind());
1099 1099 Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes().get()));
1100 1100 Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes().get()));
1101   - Record.push_back(VE.getMetadataOrNullID(N->getSubprograms().get()));
  1101 + Record.push_back(/* subprograms */ 0);
1102 1102 Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables().get()));
1103 1103 Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities().get()));
1104 1104 Record.push_back(N->getDWOId());
... ... @@ -1127,6 +1127,7 @@ static void writeDISubprogram(const DISubprogram *N, const ValueEnumerator &amp;VE,
1127 1127 Record.push_back(N->getVirtualIndex());
1128 1128 Record.push_back(N->getFlags());
1129 1129 Record.push_back(N->isOptimized());
  1130 + Record.push_back(VE.getMetadataOrNullID(N->getRawUnit()));
1130 1131 Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1131 1132 Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
1132 1133 Record.push_back(VE.getMetadataOrNullID(N->getVariables().get()));
... ...
... ... @@ -365,8 +365,8 @@ void DwarfDebug::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
365 365  
366 366 // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
367 367 // was inlined from another compile unit.
368   - auto &CU = SPMap[SP];
369   - forBothCUs(*CU, [&](DwarfCompileUnit &CU) {
  368 + auto &CU = *CUMap.lookup(cast<DISubprogram>(SP)->getUnit());
  369 + forBothCUs(CU, [&](DwarfCompileUnit &CU) {
370 370 CU.constructAbstractSubprogramScopeDIE(Scope);
371 371 });
372 372 }
... ... @@ -483,8 +483,6 @@ void DwarfDebug::beginModule() {
483 483 CU.addImportedEntity(IE);
484 484 for (auto *GV : CUNode->getGlobalVariables())
485 485 CU.getOrCreateGlobalVariableDIE(GV);
486   - for (auto *SP : CUNode->getSubprograms())
487   - SPMap.insert(std::make_pair(SP, &CU));
488 486 for (auto *Ty : CUNode->getEnumTypes()) {
489 487 // The enum types array by design contains pointers to
490 488 // MDNodes rather than DIRefs. Unique them here.
... ... @@ -493,10 +491,10 @@ void DwarfDebug::beginModule() {
493 491 for (auto *Ty : CUNode->getRetainedTypes()) {
494 492 // The retained types array by design contains pointers to
495 493 // MDNodes rather than DIRefs. Unique them here.
496   - DIType *RT = cast<DIType>(resolve(Ty->getRef()));
497   - if (!RT->isExternalTypeRef())
498   - // There is no point in force-emitting a forward declaration.
499   - CU.getOrCreateTypeDIE(RT);
  494 + if (DIType *RT = dyn_cast<DIType>(resolve(Ty->getRef())))
  495 + if (!RT->isExternalTypeRef())
  496 + // There is no point in force-emitting a forward declaration.
  497 + CU.getOrCreateTypeDIE(RT);
500 498 }
501 499 // Emit imported_modules last so that the relevant context is already
502 500 // available.
... ... @@ -525,10 +523,19 @@ void DwarfDebug::finishVariableDefinitions() {
525 523 }
526 524  
527 525 void DwarfDebug::finishSubprogramDefinitions() {
528   - for (const auto &P : SPMap)
529   - if (ProcessedSPNodes.count(P.first))
530   - forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
531   - CU.finishSubprogramDefinition(cast<DISubprogram>(P.first));
  526 + for (auto &F : MMI->getModule()->functions())
  527 + if (auto *SP = F.getSubprogram())
  528 + if (ProcessedSPNodes.count(SP) &&
  529 + SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug)
  530 + forBothCUs(*CUMap.lookup(SP->getUnit()), [&](DwarfCompileUnit &CU) {
  531 + CU.finishSubprogramDefinition(SP);
  532 + });
  533 + for (auto *AbsScope : LScopes.getAbstractScopesList())
  534 + if (auto *SP = dyn_cast<DISubprogram>(AbsScope->getScopeNode()))
  535 + if (ProcessedSPNodes.count(SP) &&
  536 + SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug)
  537 + forBothCUs(*CUMap.lookup(SP->getUnit()), [&](DwarfCompileUnit &CU) {
  538 + CU.finishSubprogramDefinition(SP);
532 539 });
533 540 }
534 541  
... ... @@ -668,7 +675,6 @@ void DwarfDebug::endModule() {
668 675 }
669 676  
670 677 // clean up.
671   - SPMap.clear();
672 678 AbstractVariables.clear();
673 679 }
674 680  
... ... @@ -1067,11 +1073,13 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
1067 1073 // isn't structurally identical (see: file path/name info from clang, which
1068 1074 // includes the directory of the cpp file being built, even when the file name
1069 1075 // is absolute (such as an <> lookup header)))
1070   - DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
1071   - if (!TheCU)
1072   - // Once DISubprogram points to the owning CU, we can assert that the CU has
1073   - // a NoDebug EmissionKind here.
  1076 + auto *SP = cast<DISubprogram>(FnScope->getScopeNode());
  1077 + DwarfCompileUnit *TheCU = CUMap.lookup(SP->getUnit());
  1078 + if (!TheCU) {
  1079 + assert(SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug &&
  1080 + "DICompileUnit missing from llvm.dbg.cu?");
1074 1081 return;
  1082 + }
1075 1083 if (Asm->OutStreamer->hasRawTextSupport())
1076 1084 // Use a single line table if we are generating assembly.
1077 1085 Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
... ... @@ -1093,11 +1101,9 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1093 1101 assert(CurFn == MF &&
1094 1102 "endFunction should be called with the same function as beginFunction");
1095 1103  
1096   - if (!MMI->hasDebugInfo() || LScopes.empty() ||
1097   - !MF->getFunction()->getSubprogram() ||
1098   - // Once DISubprogram points to the owning CU, we can check for a
1099   - // CU with a NoDebug EmissionKind here.
1100   - !SPMap.lookup(MF->getFunction()->getSubprogram())) {
  1104 + const DISubprogram *SP = MF->getFunction()->getSubprogram();
  1105 + if (!MMI->hasDebugInfo() || LScopes.empty() || !SP ||
  1106 + SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) {
1101 1107 // If we don't have a lexical scope for this function then there will
1102 1108 // be a hole in the range information. Keep note of this by setting the
1103 1109 // previously used section to nullptr.
... ... @@ -1106,7 +1112,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1106 1112 DebugHandlerBase::endFunction(MF);
1107 1113 // Mark functions with no debug info on any instructions, but a
1108 1114 // valid DISubprogram as processed.
1109   - if (auto *SP = MF->getFunction()->getSubprogram())
  1115 + if (SP)
1110 1116 ProcessedSPNodes.insert(SP);
1111 1117 return;
1112 1118 }
... ... @@ -1115,8 +1121,8 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1115 1121 Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
1116 1122  
1117 1123 LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
1118   - auto *SP = cast<DISubprogram>(FnScope->getScopeNode());
1119   - DwarfCompileUnit &TheCU = *SPMap.lookup(SP);
  1124 + SP = cast<DISubprogram>(FnScope->getScopeNode());
  1125 + DwarfCompileUnit &TheCU = *CUMap.lookup(SP->getUnit());
1120 1126  
1121 1127 DenseSet<InlinedVariable> ProcessedVars;
1122 1128 collectVariableInfo(TheCU, SP, ProcessedVars);
... ...
... ... @@ -199,9 +199,6 @@ class DwarfDebug : public DebugHandlerBase {
199 199 /// Maps MDNode with its corresponding DwarfCompileUnit.
200 200 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
201 201  
202   - /// Maps subprogram MDNode with its corresponding DwarfCompileUnit.
203   - MapVector<const MDNode *, DwarfCompileUnit *> SPMap;
204   -
205 202 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
206 203 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
207 204  
... ...
... ... @@ -1673,7 +1673,6 @@ static void writeDICompileUnit(raw_ostream &amp;Out, const DICompileUnit *N,
1673 1673 Printer.printEmissionKind("emissionKind", N->getEmissionKind());
1674 1674 Printer.printMetadata("enums", N->getRawEnumTypes());
1675 1675 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes());
1676   - Printer.printMetadata("subprograms", N->getRawSubprograms());
1677 1676 Printer.printMetadata("globals", N->getRawGlobalVariables());
1678 1677 Printer.printMetadata("imports", N->getRawImportedEntities());
1679 1678 Printer.printMetadata("macros", N->getRawMacros());
... ... @@ -1703,6 +1702,7 @@ static void writeDISubprogram(raw_ostream &amp;Out, const DISubprogram *N,
1703 1702 Printer.printInt("virtualIndex", N->getVirtualIndex(), false);
1704 1703 Printer.printDIFlags("flags", N->getFlags());
1705 1704 Printer.printBool("isOptimized", N->isOptimized());
  1705 + Printer.printMetadata("unit", N->getRawUnit());
1706 1706 Printer.printMetadata("templateParams", N->getRawTemplateParams());
1707 1707 Printer.printMetadata("declaration", N->getRawDeclaration());
1708 1708 Printer.printMetadata("variables", N->getRawVariables());
... ...
... ... @@ -96,17 +96,19 @@ void DIBuilder::finalize() {
96 96 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
97 97  
98 98 DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
99   - if (!AllSubprograms.empty())
100   - CUNode->replaceSubprograms(SPs.get());
101   -
102   - for (auto *SP : SPs) {
  99 + auto resolveVariables = [&](DISubprogram *SP) {
103 100 if (MDTuple *Temp = SP->getVariables().get()) {
104 101 const auto &PV = PreservedVariables.lookup(SP);
105 102 SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
106 103 DINodeArray AV = getOrCreateArray(Variables);
107 104 TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
108 105 }
109   - }
  106 + };
  107 + for (auto *SP : SPs)
  108 + resolveVariables(SP);
  109 + for (auto *N : RetainValues)
  110 + if (auto *SP = dyn_cast<DISubprogram>(N))
  111 + resolveVariables(SP);
110 112  
111 113 if (!AllGVs.empty())
112 114 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
... ... @@ -148,8 +150,8 @@ DICompileUnit *DIBuilder::createCompileUnit(
148 150 assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
149 151 CUNode = DICompileUnit::getDistinct(
150 152 VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
151   - isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr,
152   - nullptr, nullptr, nullptr, nullptr, nullptr, DWOId);
  153 + isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, nullptr,
  154 + nullptr, nullptr, nullptr, DWOId);
153 155  
154 156 // Create a named metadata so that it is easier to find cu in a module.
155 157 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
... ... @@ -505,8 +507,11 @@ DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
505 507 return createTypeWithFlags(VMContext, Ty, Flags);
506 508 }
507 509  
508   -void DIBuilder::retainType(DIType *T) {
  510 +void DIBuilder::retainType(DIScope *T) {
509 511 assert(T && "Expected non-null type");
  512 + assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
  513 + cast<DISubprogram>(T)->isDefinition() == false)) &&
  514 + "Expected type or subprogram declaration");
510 515 AllRetainTypes.emplace_back(T);
511 516 }
512 517  
... ... @@ -684,12 +689,12 @@ DISubprogram *DIBuilder::createFunction(
684 689 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
685 690 bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized,
686 691 DITemplateParameterArray TParams, DISubprogram *Decl) {
687   - auto *Node =
688   - getSubprogram(/* IsDistinct = */ isDefinition, VMContext,
689   - DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
690   - LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition,
691   - ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl,
692   - MDTuple::getTemporary(VMContext, None).release());
  692 + auto *Node = getSubprogram(
  693 + /* IsDistinct = */ isDefinition, VMContext,
  694 + DIScopeRef::get(getNonCompileUnitScope(Context)), Name, LinkageName, File,
  695 + LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
  696 + isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
  697 + MDTuple::getTemporary(VMContext, None).release());
693 698  
694 699 if (isDefinition)
695 700 AllSubprograms.push_back(Node);
... ... @@ -705,8 +710,8 @@ DISubprogram *DIBuilder::createTempFunctionFwdDecl(
705 710 return DISubprogram::getTemporary(
706 711 VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
707 712 LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition,
708   - ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl,
709   - nullptr)
  713 + ScopeLine, nullptr, 0, 0, Flags, isOptimized,
  714 + isDefinition ? CUNode : nullptr, TParams, Decl, nullptr)
710 715 .release();
711 716 }
712 717  
... ... @@ -724,7 +729,8 @@ DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName,
724 729 /* IsDistinct = */ isDefinition, VMContext,
725 730 DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F, LineNo, Ty,
726 731 isLocalToUnit, isDefinition, LineNo, DITypeRef::get(VTableHolder), VK,
727   - VIndex, Flags, isOptimized, TParams, nullptr, nullptr);
  732 + VIndex, Flags, isOptimized, isDefinition ? CUNode : nullptr, TParams,
  733 + nullptr, nullptr);
728 734  
729 735 if (isDefinition)
730 736 AllSubprograms.push_back(SP);
... ...
... ... @@ -94,12 +94,13 @@ void DebugInfoFinder::processModule(const Module &amp;M) {
94 94 processType(DIG->getType().resolve(TypeIdentifierMap));
95 95 }
96 96 }
97   - for (auto *SP : CU->getSubprograms())
98   - processSubprogram(SP);
99 97 for (auto *ET : CU->getEnumTypes())
100 98 processType(ET);
101 99 for (auto *RT : CU->getRetainedTypes())
102   - processType(RT);
  100 + if (auto *T = dyn_cast<DIType>(RT))
  101 + processType(T);
  102 + else
  103 + processSubprogram(cast<DISubprogram>(RT));
103 104 for (auto *Import : CU->getImportedEntities()) {
104 105 auto *Entity = Import->getEntity().resolve(TypeIdentifierMap);
105 106 if (auto *T = dyn_cast<DIType>(Entity))
... ... @@ -112,6 +113,9 @@ void DebugInfoFinder::processModule(const Module &amp;M) {
112 113 processScope(M->getScope());
113 114 }
114 115 }
  116 + for (auto &F : M.functions())
  117 + if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
  118 + processSubprogram(SP);
115 119 }
116 120  
117 121 void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
... ...
... ... @@ -289,17 +289,17 @@ DICompileUnit *DICompileUnit::getImpl(
289 289 MDString *Producer, bool IsOptimized, MDString *Flags,
290 290 unsigned RuntimeVersion, MDString *SplitDebugFilename,
291 291 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
292   - Metadata *Subprograms, Metadata *GlobalVariables,
293   - Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
294   - StorageType Storage, bool ShouldCreate) {
  292 + Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
  293 + uint64_t DWOId, StorageType Storage, bool ShouldCreate) {
295 294 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
296 295 assert(isCanonical(Producer) && "Expected canonical MDString");
297 296 assert(isCanonical(Flags) && "Expected canonical MDString");
298 297 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
299 298  
300   - Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
301   - RetainedTypes, Subprograms, GlobalVariables,
302   - ImportedEntities, Macros};
  299 + Metadata *Ops[] = {
  300 + File, Producer, Flags, SplitDebugFilename,
  301 + EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
  302 + Macros};
303 303 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
304 304 Context, Storage, SourceLanguage, IsOptimized,
305 305 RuntimeVersion, EmissionKind, DWOId, Ops),
... ... @@ -335,7 +335,7 @@ DISubprogram *DISubprogram::getImpl(
335 335 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
336 336 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
337 337 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
338   - unsigned Flags, bool IsOptimized, Metadata *TemplateParams,
  338 + unsigned Flags, bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
339 339 Metadata *Declaration, Metadata *Variables, StorageType Storage,
340 340 bool ShouldCreate) {
341 341 assert(isCanonical(Name) && "Expected canonical MDString");
... ... @@ -343,11 +343,11 @@ DISubprogram *DISubprogram::getImpl(
343 343 DEFINE_GETIMPL_LOOKUP(DISubprogram,
344 344 (Scope, Name, LinkageName, File, Line, Type,
345 345 IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
346   - Virtuality, VirtualIndex, Flags, IsOptimized,
  346 + Virtuality, VirtualIndex, Flags, IsOptimized, Unit,
347 347 TemplateParams, Declaration, Variables));
348   - Metadata *Ops[] = {File, Scope, Name, Name,
349   - LinkageName, Type, ContainingType, TemplateParams,
350   - Declaration, Variables};
  348 + Metadata *Ops[] = {File, Scope, Name, Name,
  349 + LinkageName, Type, ContainingType, Unit,
  350 + TemplateParams, Declaration, Variables};
351 351 DEFINE_GETIMPL_STORE(DISubprogram,
352 352 (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
353 353 IsLocalToUnit, IsDefinition, IsOptimized),
... ...
... ... @@ -480,6 +480,7 @@ template &lt;&gt; struct MDNodeKeyImpl&lt;DISubprogram&gt; {
480 480 unsigned VirtualIndex;
481 481 unsigned Flags;
482 482 bool IsOptimized;
  483 + Metadata *Unit;
483 484 Metadata *TemplateParams;
484 485 Metadata *Declaration;
485 486 Metadata *Variables;
... ... @@ -489,14 +490,14 @@ template &lt;&gt; struct MDNodeKeyImpl&lt;DISubprogram&gt; {
489 490 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
490 491 Metadata *ContainingType, unsigned Virtuality,
491 492 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
492   - Metadata *TemplateParams, Metadata *Declaration,
  493 + Metadata *Unit, Metadata *TemplateParams, Metadata *Declaration,
493 494 Metadata *Variables)
494 495 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
495 496 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
496 497 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
497 498 ContainingType(ContainingType), Virtuality(Virtuality),
498 499 VirtualIndex(VirtualIndex), Flags(Flags), IsOptimized(IsOptimized),
499   - TemplateParams(TemplateParams), Declaration(Declaration),
  500 + Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
500 501 Variables(Variables) {}
501 502 MDNodeKeyImpl(const DISubprogram *N)
502 503 : Scope(N->getRawScope()), Name(N->getRawName()),
... ... @@ -506,7 +507,7 @@ template &lt;&gt; struct MDNodeKeyImpl&lt;DISubprogram&gt; {
506 507 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
507 508 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
508 509 Flags(N->getFlags()), IsOptimized(N->isOptimized()),
509   - TemplateParams(N->getRawTemplateParams()),
  510 + Unit(N->getRawUnit()), TemplateParams(N->getRawTemplateParams()),
510 511 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
511 512  
512 513 bool isKeyOf(const DISubprogram *RHS) const {
... ... @@ -519,7 +520,7 @@ template &lt;&gt; struct MDNodeKeyImpl&lt;DISubprogram&gt; {
519 520 ContainingType == RHS->getRawContainingType() &&
520 521 Virtuality == RHS->getVirtuality() &&
521 522 VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() &&
522   - IsOptimized == RHS->isOptimized() &&
  523 + IsOptimized == RHS->isOptimized() && Unit == RHS->getUnit() &&
523 524 TemplateParams == RHS->getRawTemplateParams() &&
524 525 Declaration == RHS->getRawDeclaration() &&
525 526 Variables == RHS->getRawVariables();
... ...
... ... @@ -951,13 +951,10 @@ void Verifier::visitDICompileUnit(const DICompileUnit &amp;N) {
951 951 if (auto *Array = N.getRawRetainedTypes()) {
952 952 Assert(isa<MDTuple>(Array), "invalid retained type list", &N, Array);
953 953 for (Metadata *Op : N.getRetainedTypes()->operands()) {
954   - Assert(Op && isa<DIType>(Op), "invalid retained type", &N, Op);
955   - }
956   - }
957   - if (auto *Array = N.getRawSubprograms()) {
958   - Assert(isa<MDTuple>(Array), "invalid subprogram list", &N, Array);
959   - for (Metadata *Op : N.getSubprograms()->operands()) {
960   - Assert(Op && isa<DISubprogram>(Op), "invalid subprogram ref", &N, Op);
  954 + Assert(Op && (isa<DIType>(Op) ||
  955 + (isa<DISubprogram>(Op) &&
  956 + cast<DISubprogram>(Op)->isDefinition() == false)),
  957 + "invalid retained type", &N, Op);
961 958 }
962 959 }
963 960 if (auto *Array = N.getRawGlobalVariables()) {
... ... @@ -994,10 +991,9 @@ void Verifier::visitDISubprogram(const DISubprogram &amp;N) {
994 991 N.getRawContainingType());
995 992 if (auto *Params = N.getRawTemplateParams())
996 993 visitTemplateParams(N, *Params);
997   - if (auto *S = N.getRawDeclaration()) {
  994 + if (auto *S = N.getRawDeclaration())
998 995 Assert(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
999 996 "invalid subprogram declaration", &N, S);
1000   - }
1001 997 if (auto *RawVars = N.getRawVariables()) {
1002 998 auto *Vars = dyn_cast<MDTuple>(RawVars);
1003 999 Assert(Vars, "invalid variable list", &N, RawVars);
... ... @@ -1009,8 +1005,16 @@ void Verifier::visitDISubprogram(const DISubprogram &amp;N) {
1009 1005 Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",
1010 1006 &N);
1011 1007  
1012   - if (N.isDefinition())
  1008 + auto *Unit = N.getRawUnit();
  1009 + if (N.isDefinition()) {
  1010 + // Subprogram definitions (not part of the type hierarchy).
1013 1011 Assert(N.isDistinct(), "subprogram definitions must be distinct", &N);
  1012 + Assert(Unit, "subprogram definitions must have a compile unit", &N);
  1013 + Assert(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit);
  1014 + } else {
  1015 + // Subprogram declarations (part of the type hierarchy).
  1016 + Assert(!Unit, "subprogram declarations must not have a compile unit", &N);
  1017 + }
1014 1018 }
1015 1019  
1016 1020 void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) {
... ... @@ -2023,6 +2027,8 @@ void Verifier::visitFunction(const Function &amp;F) {
2023 2027 if (!N)
2024 2028 return;
2025 2029  
  2030 + visitDISubprogram(*N);
  2031 +
2026 2032 // Check that all !dbg attachments lead to back to N (or, at least, another
2027 2033 // subprogram that describes the same function).
2028 2034 //
... ... @@ -4419,7 +4425,7 @@ void Verifier::verifyTypeRefs() {
4419 4425 auto *Array = CU->getRawRetainedTypes();
4420 4426 if (!Array || !isa<MDTuple>(Array))
4421 4427 continue;
4422   - for (DIType *Op : CU->getRetainedTypes())
  4428 + for (DIScope *Op : CU->getRetainedTypes())
4423 4429 if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
4424 4430 if (auto *S = T->getRawIdentifier()) {
4425 4431 UnresolvedTypeRefs.erase(S);
... ...
... ... @@ -400,11 +400,6 @@ class IRLinker {
400 400 /// Flags to pass to value mapper invocations.
401 401 RemapFlags ValueMapperFlags = RF_MoveDistinctMDs | RF_IgnoreMissingLocals;
402 402  
403   - /// Set of subprogram metadata that does not need to be linked into the
404   - /// destination module, because the functions were not imported directly
405   - /// or via an inlined body in an imported function.
406   - bool HasUnneededSPs = false;
407   -
408 403 /// Handles cloning of a global values from the source module into
409 404 /// the destination module, including setting the attributes and visibility.
410 405 GlobalValue *copyGlobalValueProto(const GlobalValue *SGV, bool ForDefinition);
... ... @@ -470,15 +465,6 @@ class IRLinker {
470 465  
471 466 void linkNamedMDNodes();
472 467  
473   - /// Look for subprograms referenced from !llvm.dbg.cu that we don't want to
474   - /// link in and map it to nullptr.
475   - ///
476   - /// \post HasUnneededSPs is true iff any unneeded subprograms were found.
477   - void mapUnneededSubprograms();
478   -
479   - /// Remove null subprograms from !llvm.dbg.cu.
480   - void stripNullSubprograms(DICompileUnit *CU);
481   -
482 468 public:
483 469 IRLinker(Module &DstM, IRMover::IdentifiedStructTypeSet &Set,
484 470 std::unique_ptr<Module> SrcM, ArrayRef<GlobalValue *> ValuesToLink,
... ... @@ -1004,60 +990,8 @@ bool IRLinker::linkGlobalValueBody(GlobalValue &amp;Dst, GlobalValue &amp;Src) {
1004 990 return false;
1005 991 }
1006 992  
1007   -void IRLinker::mapUnneededSubprograms() {
1008   - // Track unneeded nodes to make it simpler to handle the case
1009   - // where we are checking if an already-mapped SP is needed.
1010   - NamedMDNode *CompileUnits = SrcM->getNamedMetadata("llvm.dbg.cu");
1011   - if (!CompileUnits)
1012   - return;
1013   -
1014   - // Seed the ValueMap with the imported entities, in case they reference new
1015   - // subprograms.
1016   - // FIXME: The DISubprogram for functions not linked in but kept due to
1017   - // being referenced by a DIImportedEntity should also get their
1018   - // IsDefinition flag is unset.
1019   - for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
1020   - if (MDTuple *IEs = cast<DICompileUnit>(CompileUnits->getOperand(I))
1021   - ->getImportedEntities()
1022   - .get())
1023   - (void)MapMetadata(IEs, ValueMap,
1024   - ValueMapperFlags | RF_NullMapMissingGlobalValues,
1025   - &TypeMap, &GValMaterializer);
1026   - }
1027   -
1028   - // Try to insert nullptr into the map for any SP not already mapped. If
1029   - // the insertion succeeds, we don't need this subprogram.
1030   - for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
1031   - for (auto *Op :
1032   - cast<DICompileUnit>(CompileUnits->getOperand(I))->getSubprograms())
1033   - if (ValueMap.MD().insert(std::make_pair(Op, TrackingMDRef())).second)
1034   - HasUnneededSPs = true;
1035   - }
1036   -}
1037   -
1038   -// Squash null subprograms from the given compile unit's subprogram list.
1039   -void IRLinker::stripNullSubprograms(DICompileUnit *CU) {
1040   - // There won't be any nulls if we didn't have any subprograms marked
1041   - // as unneeded.
1042   - if (!HasUnneededSPs)
1043   - return;
1044   - SmallVector<Metadata *, 16> NewSPs;
1045   - NewSPs.reserve(CU->getSubprograms().size());
1046   - bool FoundNull = false;
1047   - for (DISubprogram *SP : CU->getSubprograms()) {
1048   - if (!SP) {
1049   - FoundNull = true;
1050   - continue;
1051   - }
1052   - NewSPs.push_back(SP);
1053   - }
1054   - if (FoundNull)
1055   - CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
1056   -}
1057   -
1058 993 /// Insert all of the named MDNodes in Src into the Dest module.
1059 994 void IRLinker::linkNamedMDNodes() {
1060   - mapUnneededSubprograms();
1061 995 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1062 996 for (const NamedMDNode &NMD : SrcM->named_metadata()) {
1063 997 // Don't link module flags here. Do them separately.
... ... @@ -1069,11 +1003,6 @@ void IRLinker::linkNamedMDNodes() {
1069 1003 MDNode *DestMD = MapMetadata(
1070 1004 op, ValueMap, ValueMapperFlags | RF_NullMapMissingGlobalValues,
1071 1005 &TypeMap, &GValMaterializer);
1072   - // For each newly mapped compile unit remove any null subprograms,
1073   - // which occur when mapUnneededSubprograms identified any as unneeded
1074   - // in the dest module.
1075   - if (auto *CU = dyn_cast<DICompileUnit>(DestMD))
1076   - stripNullSubprograms(CU);
1077 1006 DestNMD->addOperand(DestMD);
1078 1007 }
1079 1008 }
... ...
... ... @@ -312,20 +312,6 @@ bool StripDeadDebugInfo::runOnModule(Module &amp;M) {
312 312 }
313 313  
314 314 for (DICompileUnit *DIC : F.compile_units()) {
315   - // Create our live subprogram list.
316   - bool SubprogramChange = false;
317   - for (DISubprogram *DISP : DIC->getSubprograms()) {
318   - // Make sure we visit each subprogram only once.
319   - if (!VisitedSet.insert(DISP).second)
320   - continue;
321   -
322   - // If the function referenced by DISP is not null, the function is live.
323   - if (LiveSPs.count(DISP))
324   - LiveSubprograms.push_back(DISP);
325   - else
326   - SubprogramChange = true;
327   - }
328   -
329 315 // Create our live global variable list.
330 316 bool GlobalVariableChange = false;
331 317 for (DIGlobalVariable *DIG : DIC->getGlobalVariables()) {
... ... @@ -341,14 +327,8 @@ bool StripDeadDebugInfo::runOnModule(Module &amp;M) {
341 327 GlobalVariableChange = true;
342 328 }
343 329  
344   - // If we found dead subprograms or global variables, replace the current
345   - // subprogram list/global variable list with our new live subprogram/global
346   - // variable list.
347   - if (SubprogramChange) {
348   - DIC->replaceSubprograms(MDTuple::get(C, LiveSubprograms));
349   - Changed = true;
350   - }
351   -
  330 + // If we found dead global variables, replace the current global
  331 + // variable list with our new live global variable list.
352 332 if (GlobalVariableChange) {
353 333 DIC->replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
354 334 Changed = true;
... ...
... ... @@ -138,7 +138,6 @@ namespace {
138 138 Module *M;
139 139 LLVMContext *Ctx;
140 140 SmallVector<std::unique_ptr<GCOVFunction>, 16> Funcs;
141   - DenseMap<DISubprogram *, Function *> FnMap;
142 141 };
143 142 }
144 143  
... ... @@ -450,28 +449,21 @@ bool GCOVProfiler::runOnModule(Module &amp;M) {
450 449 this->M = &M;
451 450 Ctx = &M.getContext();
452 451  
453   - FnMap.clear();
454   - for (Function &F : M) {
455   - if (DISubprogram *SP = F.getSubprogram())
456   - FnMap[SP] = &F;
457   - }
458   -
459 452 if (Options.EmitNotes) emitProfileNotes();
460 453 if (Options.EmitData) return emitProfileArcs();
461 454 return false;
462 455 }
463 456  
464   -static bool functionHasLines(Function *F) {
  457 +static bool functionHasLines(Function &F) {
465 458 // Check whether this function actually has any source lines. Not only
466 459 // do these waste space, they also can crash gcov.
467   - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
468   - for (BasicBlock::iterator I = BB->begin(), IE = BB->end();
469   - I != IE; ++I) {
  460 + for (auto &BB : F) {
  461 + for (auto &I : BB) {
470 462 // Debug intrinsic locations correspond to the location of the
471 463 // declaration, not necessarily any statements or expressions.
472   - if (isa<DbgInfoIntrinsic>(I)) continue;
  464 + if (isa<DbgInfoIntrinsic>(&I)) continue;
473 465  
474   - const DebugLoc &Loc = I->getDebugLoc();
  466 + const DebugLoc &Loc = I.getDebugLoc();
475 467 if (!Loc)
476 468 continue;
477 469  
... ... @@ -504,27 +496,27 @@ void GCOVProfiler::emitProfileNotes() {
504 496 std::string EdgeDestinations;
505 497  
506 498 unsigned FunctionIdent = 0;
507   - for (auto *SP : CU->getSubprograms()) {
508   - Function *F = FnMap[SP];
509   - if (!F) continue;
  499 + for (auto &F : M->functions()) {
  500 + DISubprogram *SP = F.getSubprogram();
  501 + if (!SP) continue;
510 502 if (!functionHasLines(F)) continue;
511 503  
512 504 // gcov expects every function to start with an entry block that has a
513 505 // single successor, so split the entry block to make sure of that.
514   - BasicBlock &EntryBlock = F->getEntryBlock();
  506 + BasicBlock &EntryBlock = F.getEntryBlock();
515 507 BasicBlock::iterator It = EntryBlock.begin();
516 508 while (isa<AllocaInst>(*It) || isa<DbgInfoIntrinsic>(*It))
517 509 ++It;
518 510 EntryBlock.splitBasicBlock(It);
519 511  
520   - Funcs.push_back(make_unique<GCOVFunction>(SP, F, &out, FunctionIdent++,
  512 + Funcs.push_back(make_unique<GCOVFunction>(SP, &F, &out, FunctionIdent++,
521 513 Options.UseCfgChecksum,
522 514 Options.ExitBlockBeforeBody));
523 515 GCOVFunction &Func = *Funcs.back();
524 516  
525   - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
526   - GCOVBlock &Block = Func.getBlock(&*BB);
527   - TerminatorInst *TI = BB->getTerminator();
  517 + for (auto &BB : F) {
  518 + GCOVBlock &Block = Func.getBlock(&BB);
  519 + TerminatorInst *TI = BB.getTerminator();
528 520 if (int successors = TI->getNumSuccessors()) {
529 521 for (int i = 0; i != successors; ++i) {
530 522 Block.addEdge(Func.getBlock(TI->getSuccessor(i)));
... ... @@ -534,13 +526,12 @@ void GCOVProfiler::emitProfileNotes() {
534 526 }
535 527  
536 528 uint32_t Line = 0;
537   - for (BasicBlock::iterator I = BB->begin(), IE = BB->end();
538   - I != IE; ++I) {
  529 + for (auto &I : BB) {
539 530 // Debug intrinsic locations correspond to the location of the
540 531 // declaration, not necessarily any statements or expressions.
541   - if (isa<DbgInfoIntrinsic>(I)) continue;
  532 + if (isa<DbgInfoIntrinsic>(&I)) continue;
542 533  
543   - const DebugLoc &Loc = I->getDebugLoc();
  534 + const DebugLoc &Loc = I.getDebugLoc();
544 535 if (!Loc)
545 536 continue;
546 537  
... ... @@ -581,16 +572,15 @@ bool GCOVProfiler::emitProfileArcs() {
581 572 bool Result = false;
582 573 bool InsertIndCounterIncrCode = false;
583 574 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
584   - auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(i));
585 575 SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
586   - for (auto *SP : CU->getSubprograms()) {
587   - Function *F = FnMap[SP];
588   - if (!F) continue;
  576 + for (auto &F : M->functions()) {
  577 + DISubprogram *SP = F.getSubprogram();
  578 + if (!SP) continue;
589 579 if (!functionHasLines(F)) continue;
590 580 if (!Result) Result = true;
591 581 unsigned Edges = 0;
592   - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
593   - TerminatorInst *TI = BB->getTerminator();
  582 + for (auto &BB : F) {
  583 + TerminatorInst *TI = BB.getTerminator();
594 584 if (isa<ReturnInst>(TI))
595 585 ++Edges;
596 586 else
... ... @@ -610,12 +600,12 @@ bool GCOVProfiler::emitProfileArcs() {
610 600 UniqueVector<BasicBlock *> ComplexEdgeSuccs;
611 601  
612 602 unsigned Edge = 0;
613   - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
614   - TerminatorInst *TI = BB->getTerminator();
  603 + for (auto &BB : F) {
  604 + TerminatorInst *TI = BB.getTerminator();
615 605 int Successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors();
616 606 if (Successors) {
617 607 if (Successors == 1) {
618   - IRBuilder<> Builder(&*BB->getFirstInsertionPt());
  608 + IRBuilder<> Builder(&*BB.getFirstInsertionPt());
619 609 Value *Counter = Builder.CreateConstInBoundsGEP2_64(Counters, 0,
620 610 Edge);
621 611 Value *Count = Builder.CreateLoad(Counter);
... ... @@ -635,7 +625,7 @@ bool GCOVProfiler::emitProfileArcs() {
635 625 Count = Builder.CreateAdd(Count, Builder.getInt64(1));
636 626 Builder.CreateStore(Count, Counter);
637 627 } else {
638   - ComplexEdgePreds.insert(&*BB);
  628 + ComplexEdgePreds.insert(&BB);
639 629 for (int i = 0; i != Successors; ++i)
640 630 ComplexEdgeSuccs.insert(TI->getSuccessor(i));
641 631 }
... ... @@ -646,7 +636,7 @@ bool GCOVProfiler::emitProfileArcs() {
646 636  
647 637 if (!ComplexEdgePreds.empty()) {
648 638 GlobalVariable *EdgeTable =
649   - buildEdgeLookupTable(F, Counters,
  639 + buildEdgeLookupTable(&F, Counters,
650 640 ComplexEdgePreds, ComplexEdgeSuccs);
651 641 GlobalVariable *EdgeState = getEdgeStateValue();
652 642  
... ...
... ... @@ -172,52 +172,17 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
172 172 TypeMapper, Materializer);
173 173 }
174 174  
175   -// Find the MDNode which corresponds to the subprogram data that described F.
176   -static DISubprogram *FindSubprogram(const Function *F,
177   - DebugInfoFinder &Finder) {
178   - for (DISubprogram *Subprogram : Finder.subprograms()) {
179   - if (Subprogram->describes(F))
180   - return Subprogram;
181   - }
182   - return nullptr;
183   -}
184   -
185   -// Add an operand to an existing MDNode. The new operand will be added at the
186   -// back of the operand list.
187   -static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
188   - Metadata *NewSP) {
189   - SmallVector<Metadata *, 16> NewSPs;
190   - NewSPs.reserve(SPs.size() + 1);
191   - for (auto *SP : SPs)
192   - NewSPs.push_back(SP);
193   - NewSPs.push_back(NewSP);
194   - CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
195   -}
196   -
197 175 // Clone the module-level debug info associated with OldFunc. The cloned data
198 176 // will point to NewFunc instead.
199 177 static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
200 178 ValueToValueMapTy &VMap) {
201   - DebugInfoFinder Finder;
202   - Finder.processModule(*OldFunc->getParent());
203   -
204   - const DISubprogram *OldSubprogramMDNode = FindSubprogram(OldFunc, Finder);
205   - if (!OldSubprogramMDNode) return;
206   -
207   - auto *NewSubprogram =
208   - cast<DISubprogram>(MapMetadata(OldSubprogramMDNode, VMap));
209   - NewFunc->setSubprogram(NewSubprogram);
210   -
211   - for (auto *CU : Finder.compile_units()) {
212   - auto Subprograms = CU->getSubprograms();
213   - // If the compile unit's function list contains the old function, it should
214   - // also contain the new one.
215   - for (auto *SP : Subprograms) {
216   - if (SP == OldSubprogramMDNode) {
217   - AddOperand(CU, Subprograms, NewSubprogram);
218   - break;
219   - }
220   - }
  179 + if (const DISubprogram *OldSP = OldFunc->getSubprogram()) {
  180 + auto *NewSP = cast<DISubprogram>(MapMetadata(OldSP, VMap));
  181 + // FIXME: There ought to be a better way to do this: ValueMapper
  182 + // will clone the distinct DICompileUnit. Use the original one
  183 + // instead.
  184 + NewSP->replaceUnit(OldSP->getUnit());
  185 + NewFunc->setSubprogram(NewSP);
221 186 }
222 187 }
223 188  
... ...
... ... @@ -27,9 +27,9 @@ define i32 @main() nounwind readonly !dbg !1 {
27 27 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
28 28  
29 29 !7 = !{!1}
30   -!6 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk 131941)", isOptimized: true, emissionKind: FullDebug, file: !8, enums: !9, retainedTypes: !9, subprograms: !7)
  30 +!6 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk 131941)", isOptimized: true, emissionKind: FullDebug, file: !8, enums: !9, retainedTypes: !9)
31 31 !0 = !DILocalVariable(name: "c", line: 2, scope: !1, file: !2, type: !5)
32   -!1 = distinct !DISubprogram(name: "main", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 1, file: !8, scope: !2, type: !3)
  32 +!1 = distinct !DISubprogram(name: "main", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !6, scopeLine: 1, file: !8, scope: !2, type: !3)
33 33 !2 = !DIFile(filename: "/d/j/debug-test.c", directory: "/Volumes/Data/b")
34 34 !3 = !DISubroutineType(types: !4)
35 35 !4 = !{!5}
... ...
... ... @@ -16,12 +16,12 @@
16 16 !6 = distinct !{}
17 17 !7 = distinct !{}
18 18  
19   -; CHECK: !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: FullDebug, enums: !2, retainedTypes: !3, subprograms: !4, globals: !5, imports: !6, macros: !7, dwoId: 42)
  19 +; CHECK: !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !5, imports: !6, macros: !7, dwoId: 42)
20 20 !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
21 21 isOptimized: true, flags: "-O2", runtimeVersion: 2,
22 22 splitDebugFilename: "abc.debug",
23 23 emissionKind: FullDebug,
24   - enums: !2, retainedTypes: !3, subprograms: !4,
  24 + enums: !2, retainedTypes: !3,
25 25 globals: !5, imports: !6, macros: !7, dwoId: 42)
26 26  
27 27 ; CHECK: !9 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
... ...
1 1 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
2 2 ; RUN: verify-uselistorder %s
3 3  
4   -; CHECK: !named = !{!0, !1, !2, !3, !3}
5   -!named = !{!0, !1, !2, !3, !4}
  4 +; CHECK: !named = !{!0, !3, !4, !5, !5}
  5 +!named = !{!0, !3, !4, !5, !6}
6 6  
7 7 !llvm.module.flags = !{!7}
8   -!llvm.dbg.cu = !{!5}
  8 +!llvm.dbg.cu = !{!1}
9 9  
10 10 ; CHECK: !0 = distinct !DISubprogram({{.*}})
11   -; CHECK-NEXT: !1 = !DICompositeType({{.*}})
12   -!0 = distinct !DISubprogram(name: "foo")
13   -!1 = !DICompositeType(tag: DW_TAG_structure_type, name: "Class", size: 32, align: 32)
  11 +!0 = distinct !DISubprogram(name: "foo", isDefinition: true, unit: !1)
14 12  
15   -; CHECK-NEXT: !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, entity: !1, line: 7)
16   -!2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
  13 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  14 + file: !2,
  15 + isOptimized: true, flags: "-O2",
  16 + splitDebugFilename: "abc.debug", emissionKind: 2)
  17 +!2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
  18 +; CHECK: !3 = !DICompositeType({{.*}})
  19 +!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "Class", size: 32, align: 32)
  20 +
  21 +; CHECK-NEXT: !4 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, entity: !1, line: 7)
  22 +!4 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
17 23 entity: !1, line: 7)
18 24  
19   -; CHECK-NEXT: !3 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0)
20   -!3 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0)
21   -!4 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "", scope: !0, entity: null,
  25 +; CHECK-NEXT: !5 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0)
  26 +!5 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0)
  27 +!6 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "", scope: !0, entity: null,
22 28 line: 0)
23   -
24   -!5 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
25   - file: !6,
26   - isOptimized: true, flags: "-O2",
27   - splitDebugFilename: "abc.debug", emissionKind: 2,
28   - subprograms: !{!0})
29   -!6 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
30 29 !7 = !{i32 2, !"Debug Info Version", i32 3}
... ...
1 1 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
2 2 ; RUN: verify-uselistorder %s
3 3  
4   -; CHECK: !named = !{!0, !1, !2, !3, !4, !4, !5, !6, !7, !7}
5   -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
  4 +; CHECK: !named = !{!0, !1, !2, !3, !4, !4, !5, !6, !7, !7, !8}
  5 +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
6 6  
7 7 !llvm.module.flags = !{!11}
8   -!llvm.dbg.cu = !{!10}
  8 +!llvm.dbg.cu = !{!0}
9 9  
10   -!0 = distinct !{}
11   -!1 = distinct !DISubprogram(name: "foo", scope: !2)
12   -!2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
  10 +!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  11 + file: !1,
  12 + isOptimized: true, flags: "-O2",
  13 + splitDebugFilename: "abc.debug", emissionKind: 2)
  14 +!1 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
  15 +!2 = distinct !DISubprogram(name: "foo", scope: !1, unit: !0)
13 16  
14   -; CHECK: !3 = !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
15   -!3 = !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
  17 +; CHECK: !3 = !DILexicalBlock(scope: !2, file: !1, line: 7, column: 35)
  18 +!3 = !DILexicalBlock(scope: !2, file: !1, line: 7, column: 35)
16 19  
17   -; CHECK: !4 = !DILexicalBlock(scope: !1)
18   -!4 = !DILexicalBlock(scope: !1)
19   -!5 = !DILexicalBlock(scope: !1, file: null, line: 0, column: 0)
  20 +; CHECK: !4 = !DILexicalBlock(scope: !2)
  21 +!4 = !DILexicalBlock(scope: !2)
  22 +!5 = !DILexicalBlock(scope: !2, file: null, line: 0, column: 0)
20 23  
21   -; CHECK: !5 = !DILexicalBlockFile(scope: !3, file: !2, discriminator: 0)
22   -; CHECK: !6 = !DILexicalBlockFile(scope: !3, file: !2, discriminator: 1)
23   -!6 = !DILexicalBlockFile(scope: !3, file: !2, discriminator: 0)
24   -!7 = !DILexicalBlockFile(scope: !3, file: !2, discriminator: 1)
  24 +; CHECK: !5 = !DILexicalBlockFile(scope: !3, file: !1, discriminator: 0)
  25 +; CHECK: !6 = !DILexicalBlockFile(scope: !3, file: !1, discriminator: 1)
  26 +!6 = !DILexicalBlockFile(scope: !3, file: !1, discriminator: 0)
  27 +!7 = !DILexicalBlockFile(scope: !3, file: !1, discriminator: 1)
25 28  
26 29 ; CHECK: !7 = !DILexicalBlockFile(scope: !3, discriminator: 7)
27 30 !8 = !DILexicalBlockFile(scope: !3, discriminator: 7)
28 31 !9 = !DILexicalBlockFile(scope: !3, file: null, discriminator: 7)
  32 +!10 = distinct !{}
29 33  
30   -!10 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
31   - file: !2,
32   - isOptimized: true, flags: "-O2",
33   - splitDebugFilename: "abc.debug", emissionKind: 2,
34   - subprograms: !{!1})
35 34 !11 = !{i32 2, !"Debug Info Version", i32 3}
... ...
1 1 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
2 2 ; RUN: verify-uselistorder %s
3 3  
4   -; CHECK: !named = !{!0, !1}
5   -!named = !{!0, !1}
  4 +; CHECK: !named = !{!0, !3}
  5 +!named = !{!0, !3}
6 6  
7 7 !llvm.module.flags = !{!4}
8   -!llvm.dbg.cu = !{!2}
  8 +!llvm.dbg.cu = !{!1}
9 9  
10   -!0 = distinct !DISubprogram()
  10 +!0 = distinct !DISubprogram(unit: !1)
  11 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  12 + file: !2,
  13 + isOptimized: true, flags: "-O2",
  14 + splitDebugFilename: "abc.debug", emissionKind: 2)
  15 +!2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
11 16  
12   -; CHECK: !1 = !DILocalVariable(name: "foo", arg: 65535, scope: !0)
13   -!1 = !DILocalVariable(name: "foo", arg: 65535, scope: !0)
  17 +; CHECK: !3 = !DILocalVariable(name: "foo", arg: 65535, scope: !0)
  18 +!3 = !DILocalVariable(name: "foo", arg: 65535, scope: !0)
14 19  
15   -!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
16   - file: !3,
17   - isOptimized: true, flags: "-O2",
18   - splitDebugFilename: "abc.debug", emissionKind: 2,
19   - subprograms: !{!0})
20   -!3 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
21 20 !4 = !{i32 2, !"Debug Info Version", i32 3}
... ...
... ... @@ -3,14 +3,17 @@
3 3  
4 4 @foo = global i32 0
5 5  
6   -; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
7   -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
  6 +; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
  7 +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
8 8  
9 9 !llvm.module.flags = !{!10}
10   -!llvm.dbg.cu = !{!9}
  10 +!llvm.dbg.cu = !{!1}
11 11  
12   -!0 = distinct !DISubprogram()
13   -!1 = distinct !{}
  12 +!0 = distinct !DISubprogram(unit: !1)
  13 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  14 + file: !2,
  15 + isOptimized: true, flags: "-O2",
  16 + splitDebugFilename: "abc.debug", emissionKind: 2)
14 17 !2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
15 18 !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
16 19 !4 = !DILocation(scope: !0)
... ... @@ -27,10 +30,6 @@
27 30 ; CHECK: !8 = !DILocalVariable(scope: !0)
28 31 !7 = !DILocalVariable(scope: !0, arg: 1)
29 32 !8 = !DILocalVariable(scope: !0)
  33 +!9 = distinct !{}
30 34  
31   -!9 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
32   - file: !2,
33   - isOptimized: true, flags: "-O2",
34   - splitDebugFilename: "abc.debug", emissionKind: 2,
35   - subprograms: !{!0})
36 35 !10 = !{i32 2, !"Debug Info Version", i32 3}
... ...
1 1 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
2 2 ; RUN: verify-uselistorder %s
3 3  
4   -; CHECK: !named = !{!0, !1, !1, !2, !2, !3, !3, !4}
5   -!named = !{!0, !1, !2, !3, !4, !5, !6, !7}
  4 +; CHECK: !named = !{!0, !2, !3, !3, !4, !4, !5, !5, !6}
  5 +!named = !{!0, !2, !3, !4, !5, !6, !7, !8, !9}
6 6  
7 7 !llvm.module.flags = !{!10}
8   -!llvm.dbg.cu = !{!8}
  8 +!llvm.dbg.cu = !{!1}
9 9  
10 10 ; CHECK: !0 = distinct !DISubprogram(
11   -!0 = distinct !DISubprogram()
  11 +!0 = distinct !DISubprogram(unit: !1)
  12 +; CHECK: !1 = distinct !DICompileUnit
  13 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  14 + file: !2,
  15 + isOptimized: true, flags: "-O2",
  16 + splitDebugFilename: "abc.debug", emissionKind: 2)
  17 +; CHECK: !2 = !DIFile
  18 +!2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
12 19  
13   -; CHECK-NEXT: !1 = !DILocation(line: 3, column: 7, scope: !0)
14   -!1 = !DILocation(line: 3, column: 7, scope: !0)
15   -!2 = !DILocation(scope: !0, column: 7, line: 3)
  20 +; CHECK-NEXT: !3 = !DILocation(line: 3, column: 7, scope: !0)
  21 +!3 = !DILocation(line: 3, column: 7, scope: !0)
  22 +!4 = !DILocation(scope: !0, column: 7, line: 3)
16 23  
17   -; CHECK-NEXT: !2 = !DILocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
18   -!3 = !DILocation(scope: !0, inlinedAt: !1, column: 7, line: 3)
19   -!4 = !DILocation(column: 7, line: 3, scope: !0, inlinedAt: !1)
  24 +; CHECK-NEXT: !4 = !DILocation(line: 3, column: 7, scope: !0, inlinedAt: !3)
  25 +!5 = !DILocation(scope: !0, inlinedAt: !3, column: 7, line: 3)
  26 +!6 = !DILocation(column: 7, line: 3, scope: !0, inlinedAt: !3)
20 27  
21   -; CHECK-NEXT: !3 = !DILocation(line: 0, scope: !0)
22   -!5 = !DILocation(scope: !0)
23   -!6 = !DILocation(scope: !0, column: 0, line: 0)
  28 +; CHECK-NEXT: !5 = !DILocation(line: 0, scope: !0)
  29 +!7 = !DILocation(scope: !0)
  30 +!8 = !DILocation(scope: !0, column: 0, line: 0)
24 31  
25   -; CHECK-NEXT: !4 = !DILocation(line: 4294967295, column: 65535, scope: !0)
26   -!7 = !DILocation(line: 4294967295, column: 65535, scope: !0)
  32 +; CHECK-NEXT: !6 = !DILocation(line: 4294967295, column: 65535, scope: !0)
  33 +!9 = !DILocation(line: 4294967295, column: 65535, scope: !0)
27 34  
28   -!8 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
29   - file: !9,
30   - isOptimized: true, flags: "-O2",
31   - splitDebugFilename: "abc.debug", emissionKind: 2,
32   - subprograms: !{!0})
33   -!9 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
34 35 !10 = !{i32 2, !"Debug Info Version", i32 3}
... ...
... ... @@ -6,8 +6,8 @@ define void @_Z3foov() !dbg !9 {
6 6 ret void
7 7 }
8 8  
9   -; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
10   -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
  9 +; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12}
  10 +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12}
11 11  
12 12 !0 = !{null}
13 13 !1 = distinct !DICompositeType(tag: DW_TAG_structure_type)
... ... @@ -17,44 +17,50 @@ define void @_Z3foov() !dbg !9 {
17 17 !5 = distinct !{}
18 18 !6 = distinct !{}
19 19  
20   -; CHECK: !7 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false)
21   -!7 = distinct !DISubprogram()
  20 +; CHECK: !7 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !8)
  21 +!7 = distinct !DISubprogram(unit: !8)
22 22  
23   -; CHECK: !8 = !DISubprogram(scope: null, isLocal: false, isDefinition: false, isOptimized: false)
24   -!8 = !DISubprogram(isDefinition: false)
  23 +!8 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
  24 + file: !2,
  25 + isOptimized: true, flags: "-O2",
  26 + splitDebugFilename: "abc.debug", emissionKind: 2)
25 27  
26   -; CHECK: !9 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, file: !2, line: 7, type: !3, isLocal: true, isDefinition: true, scopeLine: 8, containingType: !4, virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10, flags: DIFlagPrototyped, isOptimized: true, templateParams: !5, declaration: !8, variables: !6)
27   -!9 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  28 +; CHECK: !9 = !DISubprogram(scope: null, isLocal: false, isDefinition: false, isOptimized: false)
  29 +!9 = !DISubprogram(isDefinition: false)
  30 +
  31 +; CHECK: !10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, file: !2, line: 7, type: !3, isLocal: true, isDefinition: true, scopeLine: 8, containingType: !4, virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10, flags: DIFlagPrototyped, isOptimized: true, unit: !8, templateParams: !5, declaration: !9, variables: !6)
  32 +!10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
28 33 file: !2, line: 7, type: !3, isLocal: true,
29   - isDefinition: true, scopeLine: 8, containingType: !4,
30   - virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
31   - flags: DIFlagPrototyped, isOptimized: true,
32   - templateParams: !5, declaration: !8, variables: !6)
  34 + isDefinition: true, scopeLine: 8,
  35 + containingType: !4,
  36 + virtuality: DW_VIRTUALITY_pure_virtual,
  37 + virtualIndex: 10, flags: DIFlagPrototyped,
  38 + isOptimized: true, unit: !8, templateParams: !5,
  39 + declaration: !9, variables: !6)
33 40  
34   -; CHECK: !10 = distinct !DISubprogram
  41 +; CHECK: !11 = distinct !DISubprogram
35 42 ; CHECK-SAME: virtualIndex: 0,
36   -!10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  43 +!11 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
37 44 file: !2, line: 7, type: !3, isLocal: true,
38   - isDefinition: true, scopeLine: 8, containingType: !4,
39   - virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 0,
  45 + isDefinition: true, scopeLine: 8,
  46 + containingType: !4,
  47 + virtuality: DW_VIRTUALITY_pure_virtual,
  48 + virtualIndex: 0,
40 49 flags: DIFlagPrototyped, isOptimized: true,
41   - templateParams: !5, declaration: !8, variables: !6)
  50 + unit: !8, templateParams: !5, declaration: !9,
  51 + variables: !6)
42 52  
43   -; CHECK: !11 = distinct !DISubprogram
  53 +; CHECK: !12 = distinct !DISubprogram
44 54 ; CHECK-NOT: virtualIndex
45   -!11 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
  55 +!12 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
46 56 file: !2, line: 7, type: !3, isLocal: true,
47   - isDefinition: true, scopeLine: 8, containingType: !4,
  57 + isDefinition: true, scopeLine: 8,
  58 + containingType: !4,
48 59 virtuality: DW_VIRTUALITY_none,
49 60 flags: DIFlagPrototyped, isOptimized: true,
50   - templateParams: !5, declaration: !8, variables: !6)
  61 + unit: !8,
  62 + templateParams: !5, declaration: !9, variables: !6)
51 63  
52   -!12 = !{i32 1, !"Debug Info Version", i32 3}
53   -!llvm.module.flags = !{!12}
54   -!llvm.dbg.cu = !{!13}
55   -
56   -!13 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
57   - file: !2,
58   - isOptimized: true, flags: "-O2",
59   - splitDebugFilename: "abc.debug", emissionKind: 2,
60   - subprograms: !{!7, !9, !10, !11})
  64 +!13 = !{i32 1, !"Debug Info Version", i32 3}
  65 +!llvm.module.flags = !{!13}
  66 +!llvm.dbg.cu = !{!8}
... ...
... ... @@ -12,11 +12,10 @@ entry:
12 12 !llvm.dbg.cu = !{!0}
13 13 !llvm.module.flags = !{!9}
14 14  
15   -!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 (trunk 195495) (llvm/trunk 195495:195504M)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
  15 +!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 (trunk 195495) (llvm/trunk 195495:195504M)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
16 16 !1 = !DIFile(filename: "../llvm/tools/clang/test/CodeGen/debug-info-version.c", directory: "/Users/manmanren/llvm_gmail/release")
17 17 !2 = !{i32 0}
18   -!3 = !{!4}
19   -!4 = distinct !DISubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !1, scope: !5, type: !6, variables: !2)
  18 +!4 = distinct !DISubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, variables: !2)
20 19 !5 = !DIFile(filename: "../llvm/tools/clang/test/CodeGen/debug-info-version.c", directory: "/Users/manmanren/llvm_gmail/release")
21 20 !6 = !DISubroutineType(types: !7)
22 21 !7 = !{!8}
... ...
... ... @@ -2,8 +2,8 @@
2 2 ; RUN: verify-uselistorder %s
3 3  
4 4 ; CHECK-LABEL: @test
5   -; CHECK: ret void, !bar !4, !foo !5
6   -define void @test() {
  5 +; CHECK: ret void, !bar !4, !foo !3
  6 +define void @test() !dbg !1 {
7 7 add i32 2, 1, !bar !0
8 8 add i32 1, 2, !foo !1
9 9 call void @llvm.dbg.func.start(metadata !"foo")
... ... @@ -11,19 +11,19 @@ define void @test() {
11 11 ret void, !foo !0, !bar !1
12 12 }
13 13  
14   -; CHECK-LABEL: define void @test2() !foo !6 !baz !7
  14 +; CHECK-LABEL: define void @test2() !foo !5 !baz !6
15 15 define void @test2() !foo !2 !baz !3 {
16 16 unreachable
17 17 }
18 18  
19   -; CHECK-LABEL: define void @test3() !bar !7
20   -; CHECK: unreachable, !bar !8
  19 +; CHECK-LABEL: define void @test3() !bar !6
  20 +; CHECK: unreachable, !bar !7
21 21 define void @test3() !bar !3 {
22 22 unreachable, !bar !4
23 23 }
24 24  
25 25 ; CHECK-LABEL: define void @test_attachment_name() {
26   -; CHECK: unreachable, !\342abc !8
  26 +; CHECK: unreachable, !\342abc !7
27 27 define void @test_attachment_name() {
28 28 ;; Escape the first character when printing text IR, since it's a digit
29 29 unreachable, !\34\32abc !4
... ... @@ -32,15 +32,14 @@ define void @test_attachment_name() {
32 32 !llvm.module.flags = !{!7}
33 33 !llvm.dbg.cu = !{!5}
34 34 !0 = !DILocation(line: 662302, column: 26, scope: !1)
35   -!1 = distinct !DISubprogram(name: "foo")
  35 +!1 = distinct !DISubprogram(name: "foo", isDefinition: true, unit: !5)
36 36 !2 = distinct !{}
37 37 !3 = distinct !{}
38 38 !4 = distinct !{}
39 39 !5 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
40 40 file: !6,
41 41 isOptimized: true, flags: "-O2",
42   - splitDebugFilename: "abc.debug", emissionKind: 2,
43   - subprograms: !{!1})
  42 + splitDebugFilename: "abc.debug", emissionKind: 2)
44 43 !6 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
45 44 !7 = !{i32 2, !"Debug Info Version", i32 3}
46 45  
... ...
1 1 ; RUN: llvm-dis < %s.bc | FileCheck %s
2 2 ; Check that subprogram definitions are correctly upgraded to 'distinct'.
3   -; Bitcode compiled from r245235 of the 3.7 release branch.
  3 +; Bitcode compiled with llvm-as version 3.7.
4 4  
5   -!named = !{!0}
6   -!0 = distinct !DICompileUnit(language: 12, file: !1, subprograms: !2)
  5 +define void @f() !dbg !3 { ret void }
  6 +
  7 +!llvm.module.flags = !{!4}
  8 +!llvm.dbg.cu = !{!0}
  9 +!0 = distinct !DICompileUnit(language: 12, file: !1, subprograms: !{!3})
7 10 !1 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
8   -!2 = !{!3}
9 11  
10 12 ; CHECK: = distinct !DISubprogram({{.*}}, isDefinition: true
11 13 !3 = !DISubprogram(name: "foo", isDefinition: true)
  14 +!4 = !{i32 2, !"Debug Info Version", i32 3}
... ...
... ... @@ -30,8 +30,7 @@ entry:
30 30 !llvm.dbg.cu = !{!1}
31 31  
32 32 !0 = !{i32 2, !"Debug Info Version", i32 3}
33   -!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !DIFile(filename: "f", directory: "/d"),
34   - subprograms: !{!2})
35   -!2 = distinct !DISubprogram(name: "foo")
  33 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !DIFile(filename: "f", directory: "/d"))
  34 +!2 = distinct !DISubprogram(name: "foo", unit: !1)
36 35 !3 = !DILocation(line: 1, scope: !2)
37 36 !4 = !DILocation(line: 2, scope: !2)
... ...
... ... @@ -10,7 +10,7 @@ define void @foo() {
10 10 !0 = !{i32 2, !"Debug Info Version", i32 3}
11 11  
12 12 !llvm.dbg.cu = !{!1}
13   -!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3}, emissionKind: FullDebug)
  13 +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
14 14 !2 = !DIFile(filename: "foo.c", directory: "/path/to/dir")
15 15 ; CHECK: [[SP]] = distinct !DISubprogram
16 16 !3 = distinct !DISubprogram(file: !2, scope: !2, line: 51, name: "foo", function: void ()* @foo, type: !4)
... ...
... ... @@ -31,8 +31,8 @@ declare void @foo()
31 31 !3 = !{!"noise"}
32 32 !4 = !{!"filler"}
33 33  
34   -!8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !15, subprograms: !{!9})
35   -!9 = distinct !DISubprogram(name: "test", file: !15)
  34 +!8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !15)
  35 +!9 = distinct !DISubprogram(name: "test", file: !15, unit: !8)
36 36 !10 = !DILocation(line: 100, column: 101, scope: !9)
37 37 !11 = !DILocation(line: 102, column: 103, scope: !9)
38 38 !12 = !DILocation(line: 104, column: 105, scope: !9)
... ...
... ... @@ -44,11 +44,10 @@ attributes #1 = { nounwind readnone }
44 44 !llvm.module.flags = !{!36, !37}
45 45 !llvm.ident = !{!38}
46 46  
47   -!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 ", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
  47 +!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 ", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
48 48 !1 = !DIFile(filename: "test.c", directory: "")
49 49 !2 = !{}
50   -!3 = !{!4}
51   -!4 = distinct !DISubp