llvm.org GIT mirror llvm / 7177647
Add a DIModule metadata node to the IR. It is meant to be used to record modules @imported by the current compile unit, so a debugger an import the same modules to replicate this environment before dropping into the expression evaluator. DIModule is a sibling to DINamespace and behaves quite similarly. In addition to the name of the module it also records the module configuration details that are necessary to uniquely identify the module. This includes the configuration macros (e.g., -DNDEBUG), the include path where the module.map file is to be found, and the isysroot. The idea is that the backend will turn this into a DW_TAG_module. http://reviews.llvm.org/D9614 rdar://problem/20965932 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241017 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 4 years ago
16 changed file(s) with 261 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
166166 METADATA_EXPRESSION = 29, // [distinct, n x element]
167167 METADATA_OBJC_PROPERTY = 30, // [distinct, name, file, line, ...]
168168 METADATA_IMPORTED_ENTITY=31, // [distinct, tag, scope, entity, line, name]
169 METADATA_MODULE=32, // [distinct, scope, name, ...]
169170 };
170171
171172 // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
565565 DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
566566 unsigned LineNo);
567567
568 /// createModule - This creates new descriptor for a module
569 /// with the specified parent scope.
570 /// @param Scope Parent scope
571 /// @param Name Name of this module
572 /// @param ConfigurationMacros
573 /// A space-separated shell-quoted list of -D macro
574 /// definitions as they would appear on a command line.
575 /// @param IncludePath The path to the module map file.
576 /// @param ISysRoot The clang system root (value of -isysroot).
577 DIModule *createModule(DIScope *Scope, StringRef Name,
578 StringRef ConfigurationMacros,
579 StringRef IncludePath,
580 StringRef ISysRoot);
581
568582 /// createLexicalBlockFile - This creates a descriptor for a lexical
569583 /// block with a new file attached. This merely extends the existing
570584 /// lexical block as it crosses a file.
596610 /// @param Line Line number
597611 DIImportedEntity *createImportedModule(DIScope *Context,
598612 DIImportedEntity *NS, unsigned Line);
613
614 /// \brief Create a descriptor for an imported module.
615 /// @param Context The scope this module is imported into
616 /// @param M The module being imported here
617 /// @param Line Line number
618 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M,
619 unsigned Line);
599620
600621 /// \brief Create a descriptor for an imported function.
601622 /// @param Context The scope this module is imported into
217217 case DILocalVariableKind:
218218 case DIObjCPropertyKind:
219219 case DIImportedEntityKind:
220 case DIModuleKind:
220221 return true;
221222 }
222223 }
442443 case DILexicalBlockKind:
443444 case DILexicalBlockFileKind:
444445 case DINamespaceKind:
446 case DIModuleKind:
445447 return true;
446448 }
447449 }
16221624 }
16231625 };
16241626
1627 /// \brief A (clang) module that has been imported by the compile unit.
1628 ///
1629 class DIModule : public DIScope {
1630 friend class LLVMContextImpl;
1631 friend class MDNode;
1632
1633 DIModule(LLVMContext &Context, StorageType Storage, ArrayRef Ops)
1634 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
1635 ~DIModule() {}
1636
1637 static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
1638 StringRef Name, StringRef ConfigurationMacros,
1639 StringRef IncludePath, StringRef ISysRoot,
1640 StorageType Storage, bool ShouldCreate = true) {
1641 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1642 getCanonicalMDString(Context, ConfigurationMacros),
1643 getCanonicalMDString(Context, IncludePath),
1644 getCanonicalMDString(Context, ISysRoot),
1645 Storage, ShouldCreate);
1646 }
1647 static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
1648 MDString *Name, MDString *ConfigurationMacros,
1649 MDString *IncludePath, MDString *ISysRoot,
1650 StorageType Storage, bool ShouldCreate = true);
1651
1652 TempDIModule cloneImpl() const {
1653 return getTemporary(getContext(), getScope(), getName(),
1654 getConfigurationMacros(), getIncludePath(),
1655 getISysRoot());
1656 }
1657
1658 public:
1659 DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
1660 StringRef ConfigurationMacros, StringRef IncludePath,
1661 StringRef ISysRoot),
1662 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1663 DEFINE_MDNODE_GET(DIModule,
1664 (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
1665 MDString *IncludePath, MDString *ISysRoot),
1666 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1667
1668 TempDIModule clone() const { return cloneImpl(); }
1669
1670 DIScope *getScope() const { return cast_or_null(getRawScope()); }
1671 StringRef getName() const { return getStringOperand(1); }
1672 StringRef getConfigurationMacros() const { return getStringOperand(2); }
1673 StringRef getIncludePath() const { return getStringOperand(3); }
1674 StringRef getISysRoot() const { return getStringOperand(4); }
1675
1676 Metadata *getRawScope() const { return getOperand(0); }
1677 MDString *getRawName() const { return getOperandAs(1); }
1678 MDString *getRawConfigurationMacros() const { return getOperandAs(2); }
1679 MDString *getRawIncludePath() const { return getOperandAs(3); }
1680 MDString *getRawISysRoot() const { return getOperandAs(4); }
1681
1682 static bool classof(const Metadata *MD) {
1683 return MD->getMetadataID() == DIModuleKind;
1684 }
1685 };
1686
16251687 /// \brief Base class for template parameters.
16261688 class DITemplateParameter : public DINode {
16271689 protected:
8181 HANDLE_SPECIALIZED_MDNODE_LEAF(DILexicalBlock)
8282 HANDLE_SPECIALIZED_MDNODE_LEAF(DILexicalBlockFile)
8383 HANDLE_SPECIALIZED_MDNODE_LEAF(DINamespace)
84 HANDLE_SPECIALIZED_MDNODE_LEAF(DIModule)
8485 HANDLE_SPECIALIZED_MDNODE_BRANCH(DITemplateParameter)
8586 HANDLE_SPECIALIZED_MDNODE_LEAF(DITemplateTypeParameter)
8687 HANDLE_SPECIALIZED_MDNODE_LEAF(DITemplateValueParameter)
7575 DILexicalBlockKind,
7676 DILexicalBlockFileKind,
7777 DINamespaceKind,
78 DIModuleKind,
7879 DITemplateTypeParameterKind,
7980 DITemplateValueParameterKind,
8081 DIGlobalVariableKind,
36753675 return false;
36763676 }
36773677
3678 /// ParseDIModule:
3679 /// ::= !DIModule(scope: !0, name: "SomeModule", configMacros: "-DNDEBUG",
3680 /// includePath: "/usr/include", isysroot: "/")
3681 bool LLParser::ParseDIModule(MDNode *&Result, bool IsDistinct) {
3682 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3683 REQUIRED(scope, MDField, ); \
3684 REQUIRED(name, MDStringField, ); \
3685 OPTIONAL(configMacros, MDStringField, ); \
3686 OPTIONAL(includePath, MDStringField, ); \
3687 OPTIONAL(isysroot, MDStringField, );
3688 PARSE_MD_FIELDS();
3689 #undef VISIT_MD_FIELDS
3690
3691 Result = GET_OR_DISTINCT(DIModule, (Context, scope.Val, name.Val,
3692 configMacros.Val, includePath.Val, isysroot.Val));
3693 return false;
3694 }
3695
36783696 /// ParseDITemplateTypeParameter:
36793697 /// ::= !DITemplateTypeParameter(name: "Ty", type: !1)
36803698 bool LLParser::ParseDITemplateTypeParameter(MDNode *&Result, bool IsDistinct) {
18261826 NextMDValueNo++);
18271827 break;
18281828 }
1829
1830 case bitc::METADATA_MODULE: {
1831 if (Record.size() != 6)
1832 return error("Invalid record");
1833
1834 MDValueList.assignValue(
1835 GET_OR_DISTINCT(DIModule, Record[0],
1836 (Context, getMDOrNull(Record[1]),
1837 getMDString(Record[2]), getMDString(Record[3]),
1838 getMDString(Record[4]), getMDString(Record[5]))),
1839 NextMDValueNo++);
1840 break;
1841 }
1842
18291843 case bitc::METADATA_FILE: {
18301844 if (Record.size() != 3)
18311845 return error("Invalid record");
10281028 Record.push_back(N->getLine());
10291029
10301030 Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev);
1031 Record.clear();
1032 }
1033
1034 static void WriteDIModule(const DIModule *N, const ValueEnumerator &VE,
1035 BitstreamWriter &Stream,
1036 SmallVectorImpl &Record, unsigned Abbrev) {
1037 Record.push_back(N->isDistinct());
1038 for (auto &I : N->operands())
1039 Record.push_back(VE.getMetadataOrNullID(I));
1040
1041 Stream.EmitRecord(bitc::METADATA_MODULE, Record, Abbrev);
10311042 Record.clear();
10321043 }
10331044
17221722 Out << ")";
17231723 }
17241724
1725 static void writeDIModule(raw_ostream &Out, const DIModule *N,
1726 TypePrinting *TypePrinter, SlotTracker *Machine,
1727 const Module *Context) {
1728 Out << "!DIModule(";
1729 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1730 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1731 Printer.printString("name", N->getName());
1732 Printer.printString("configMacros", N->getConfigurationMacros());
1733 Printer.printString("includePath", N->getIncludePath());
1734 Printer.printString("isysroot", N->getISysRoot());
1735 Out << ")";
1736 }
1737
1738
17251739 static void writeDITemplateTypeParameter(raw_ostream &Out,
17261740 const DITemplateTypeParameter *N,
17271741 TypePrinting *TypePrinter,
183183 unsigned Line) {
184184 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
185185 Context, NS, Line, StringRef(), AllImportedModules);
186 }
187
188 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M,
189 unsigned Line) {
190 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
191 Context, M, Line, StringRef(), AllImportedModules);
186192 }
187193
188194 DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
702708 LineNo);
703709 }
704710
711 DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
712 StringRef ConfigurationMacros,
713 StringRef IncludePath,
714 StringRef ISysRoot) {
715 return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
716 ConfigurationMacros, IncludePath, ISysRoot);
717 }
718
705719 DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
706720 DIFile *File,
707721 unsigned Discriminator) {
144144 processSubprogram(SP);
145145 else if (auto *NS = dyn_cast(Entity))
146146 processScope(NS->getScope());
147 else if (auto *M = dyn_cast(Entity))
148 processScope(M->getScope());
147149 }
148150 }
149151 }
200202 processScope(LB->getScope());
201203 } else if (auto *NS = dyn_cast(Scope)) {
202204 processScope(NS->getScope());
205 } else if (auto *M = dyn_cast(Scope)) {
206 processScope(M->getScope());
203207 }
204208 }
205209
137137 if (auto *NS = dyn_cast(this))
138138 return DIScopeRef(NS->getScope());
139139
140 if (auto *M = dyn_cast(this))
141 return DIScopeRef(M->getScope());
142
140143 assert((isa(this) || isa(this)) &&
141144 "Unhandled type of scope.");
142145 return nullptr;
149152 return SP->getName();
150153 if (auto *NS = dyn_cast(this))
151154 return NS->getName();
155 if (auto *M = dyn_cast(this))
156 return M->getName();
152157 assert((isa(this) || isa(this) ||
153158 isa(this)) &&
154159 "Unhandled type of scope.");
409414 DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
410415 }
411416
417 DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
418 MDString *Name, MDString *ConfigurationMacros,
419 MDString *IncludePath, MDString *ISysRoot,
420 StorageType Storage, bool ShouldCreate) {
421 assert(isCanonical(Name) && "Expected canonical MDString");
422 DEFINE_GETIMPL_LOOKUP(DIModule,
423 (Scope, getString(Name), getString(ConfigurationMacros),
424 getString(IncludePath), getString(ISysRoot)));
425 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
426 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
427 }
428
412429 DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
413430 MDString *Name,
414431 Metadata *Type,
650650 }
651651 };
652652
653 template <> struct MDNodeKeyImpl {
654 Metadata *Scope;
655 StringRef Name;
656 StringRef ConfigurationMacros;
657 StringRef IncludePath;
658 StringRef ISysRoot;
659 MDNodeKeyImpl(Metadata *Scope, StringRef Name,
660 StringRef ConfigurationMacros,
661 StringRef IncludePath,
662 StringRef ISysRoot)
663 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
664 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
665 MDNodeKeyImpl(const DIModule *N)
666 : Scope(N->getRawScope()), Name(N->getName()),
667 ConfigurationMacros(N->getConfigurationMacros()),
668 IncludePath(N->getIncludePath()), ISysRoot(N->getISysRoot()) {}
669
670 bool isKeyOf(const DIModule *RHS) const {
671 return Scope == RHS->getRawScope() && Name == RHS->getName() &&
672 ConfigurationMacros == RHS->getConfigurationMacros() &&
673 IncludePath == RHS->getIncludePath() &&
674 ISysRoot == RHS->getISysRoot();
675 }
676 unsigned getHashValue() const {
677 return hash_combine(Scope, Name,
678 ConfigurationMacros, IncludePath, ISysRoot);
679 }
680 };
681
653682 template <> struct MDNodeKeyImpl {
654683 StringRef Name;
655684 Metadata *Type;
10141014 Assert(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N);
10151015 if (auto *S = N.getRawScope())
10161016 Assert(isa(S), "invalid scope ref", &N, S);
1017 }
1018
1019 void Verifier::visitDIModule(const DIModule &N) {
1020 Assert(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N);
1021 Assert(!N.getName().empty(), "anonymous module", &N);
10171022 }
10181023
10191024 void Verifier::visitDITemplateParameter(const DITemplateParameter &N) {
0 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
1 ; RUN: verify-uselistorder %s
2
3 ; CHECK: !named = !{!0, !1, !2, !1}
4 !named = !{!0, !1, !2, !3}
5
6 !0 = distinct !{}
7
8 ; CHECK: !1 = !DIModule(scope: !0, name: "Module")
9 !1 = !DIModule(scope: !0, name: "Module")
10
11 ; CHECK: !2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include", isysroot: "/")
12 !2 = !DIModule(scope: !0, name: "Module", configMacros: "-DNDEBUG", includePath: "/usr/include", isysroot: "/")
13
14 !3 = !DIModule(scope: !0, name: "Module", configMacros: "")
17031703 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
17041704 }
17051705
1706 typedef MetadataTest DIModuleTest;
1707
1708 TEST_F(DIModuleTest, get) {
1709 DIScope *Scope = getFile();
1710 StringRef Name = "module";
1711 StringRef ConfigMacro = "-DNDEBUG";
1712 StringRef Includes = "-I.";
1713 StringRef Sysroot = "/";
1714
1715 auto *N = DIModule::get(Context, Scope, Name, ConfigMacro, Includes, Sysroot);
1716
1717 EXPECT_EQ(dwarf::DW_TAG_module, N->getTag());
1718 EXPECT_EQ(Scope, N->getScope());
1719 EXPECT_EQ(Name, N->getName());
1720 EXPECT_EQ(ConfigMacro, N->getConfigurationMacros());
1721 EXPECT_EQ(Includes, N->getIncludePath());
1722 EXPECT_EQ(Sysroot, N->getISysRoot());
1723 EXPECT_EQ(N, DIModule::get(Context, Scope, Name,
1724 ConfigMacro, Includes, Sysroot));
1725 EXPECT_NE(N, DIModule::get(Context, getFile(), Name,
1726 ConfigMacro, Includes, Sysroot));
1727 EXPECT_NE(N, DIModule::get(Context, Scope, "other",
1728 ConfigMacro, Includes, Sysroot));
1729 EXPECT_NE(N, DIModule::get(Context, Scope, Name,
1730 "other", Includes, Sysroot));
1731 EXPECT_NE(N, DIModule::get(Context, Scope, Name,
1732 ConfigMacro, "other", Sysroot));
1733 EXPECT_NE(N, DIModule::get(Context, Scope, Name,
1734 ConfigMacro, Includes, "other"));
1735
1736 TempDIModule Temp = N->clone();
1737 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
1738 }
1739
17061740 typedef MetadataTest DITemplateTypeParameterTest;
17071741
17081742 TEST_F(DITemplateTypeParameterTest, get) {