+ // Note that we only generate this when the caller wants to actually
+ // emit debug information. When we are only interested in tracking
+ // source line locations throughout the backend, we prevent codegen from
+ // emitting debug info in the final output by not generating llvm.dbg.cu.
+ if (EmitDebugInfo) {
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
+ NMD->addOperand(CUNode);
+ }
+
+ return DICompileUnit(CUNode);
+}
+
+static DIImportedEntity
+createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
+ Value *NS, unsigned Line, StringRef Name,
+ SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
+ const MDNode *R;
+ if (Name.empty()) {
+ Value *Elts[] = {
+ GetTagConstant(C, Tag),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ };
+ R = MDNode::get(C, Elts);
+ } else {
+ Value *Elts[] = {
+ GetTagConstant(C, Tag),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ MDString::get(C, Name)
+ };
+ R = MDNode::get(C, Elts);
+ }
+ DIImportedEntity M(R);
+ assert(M.Verify() && "Imported module should be valid");
+ AllImportedModules.push_back(TrackingVH<MDNode>(M));
+ return M;
+}
+
+DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
+ DINameSpace NS,
+ unsigned Line) {
+ return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
+ Context, NS, Line, StringRef(), AllImportedModules);
+}
+
+DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
+ DIImportedEntity NS,
+ unsigned Line) {
+ return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
+ Context, NS, Line, StringRef(), AllImportedModules);
+}
+
+DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
+ DIScope Decl,
+ unsigned Line, StringRef Name) {
+ return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
+ Context, Decl.getRef(), Line, Name,
+ AllImportedModules);
+}
+
+DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
+ DIImportedEntity Imp,
+ unsigned Line, StringRef Name) {
+ return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
+ Context, Imp, Line, Name, AllImportedModules);