Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 1 | //===--- DIBuilder.cpp - Debug Information Builder ------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the DIBuilder. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Chandler Carruth | 12664a0 | 2014-03-06 00:22:06 +0000 | [diff] [blame] | 13 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 14 | #include "LLVMContextImpl.h" |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 17 | #include "llvm/BinaryFormat/Dwarf.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 19 | #include "llvm/IR/DebugInfo.h" |
Reid Kleckner | 4c1a1d3 | 2019-11-14 15:15:48 -0800 | [diff] [blame] | 20 | #include "llvm/IR/IRBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/IntrinsicInst.h" |
| 22 | #include "llvm/IR/Module.h" |
Reid Kleckner | 4c1a1d3 | 2019-11-14 15:15:48 -0800 | [diff] [blame] | 23 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | 3416419 | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Debug.h" |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | using namespace llvm::dwarf; |
| 28 | |
Benjamin Kramer | dc5f805 | 2019-08-23 19:59:23 +0000 | [diff] [blame] | 29 | static cl::opt<bool> |
Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 30 | UseDbgAddr("use-dbg-addr", |
Zachary Turner | 8065f0b | 2017-12-01 00:53:10 +0000 | [diff] [blame] | 31 | llvm::cl::desc("Use llvm.dbg.addr for all local variables"), |
| 32 | cl::init(false), cl::Hidden); |
Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 33 | |
Jessica Paquette | a499c3c | 2018-01-19 21:21:49 +0000 | [diff] [blame] | 34 | DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) |
| 35 | : M(m), VMContext(M.getContext()), CUNode(CU), |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 36 | DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr), |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 37 | AllowUnresolvedNodes(AllowUnresolvedNodes) {} |
| 38 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 39 | void DIBuilder::trackIfUnresolved(MDNode *N) { |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 40 | if (!N) |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 41 | return; |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 42 | if (N->isResolved()) |
| 43 | return; |
| 44 | |
| 45 | assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); |
| 46 | UnresolvedNodes.emplace_back(N); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 47 | } |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 48 | |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 49 | void DIBuilder::finalizeSubprogram(DISubprogram *SP) { |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 50 | MDTuple *Temp = SP->getRetainedNodes().get(); |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 51 | if (!Temp || !Temp->isTemporary()) |
| 52 | return; |
| 53 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 54 | SmallVector<Metadata *, 16> RetainedNodes; |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 55 | |
| 56 | auto PV = PreservedVariables.find(SP); |
| 57 | if (PV != PreservedVariables.end()) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 58 | RetainedNodes.append(PV->second.begin(), PV->second.end()); |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 59 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 60 | auto PL = PreservedLabels.find(SP); |
| 61 | if (PL != PreservedLabels.end()) |
| 62 | RetainedNodes.append(PL->second.begin(), PL->second.end()); |
| 63 | |
| 64 | DINodeArray Node = getOrCreateArray(RetainedNodes); |
| 65 | |
| 66 | TempMDTuple(Temp)->replaceAllUsesWith(Node.get()); |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 69 | void DIBuilder::finalize() { |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 70 | if (!CUNode) { |
| 71 | assert(!AllowUnresolvedNodes && |
| 72 | "creating type nodes without a CU is not supported"); |
| 73 | return; |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 74 | } |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 75 | |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 76 | CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); |
| 77 | |
| 78 | SmallVector<Metadata *, 16> RetainValues; |
| 79 | // Declarations and definitions of the same type may be retained. Some |
| 80 | // clients RAUW these pairs, leaving duplicates in the retained types |
| 81 | // list. Use a set to remove the duplicates while we transform the |
| 82 | // TrackingVHs back into Values. |
| 83 | SmallPtrSet<Metadata *, 16> RetainSet; |
| 84 | for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) |
| 85 | if (RetainSet.insert(AllRetainTypes[I]).second) |
| 86 | RetainValues.push_back(AllRetainTypes[I]); |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 87 | |
| 88 | if (!RetainValues.empty()) |
| 89 | CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 90 | |
| 91 | DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 92 | for (auto *SP : SPs) |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 93 | finalizeSubprogram(SP); |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 94 | for (auto *N : RetainValues) |
| 95 | if (auto *SP = dyn_cast<DISubprogram>(N)) |
Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 96 | finalizeSubprogram(SP); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 97 | |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 98 | if (!AllGVs.empty()) |
| 99 | CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 100 | |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 101 | if (!AllImportedModules.empty()) |
| 102 | CUNode->replaceImportedEntities(MDTuple::get( |
| 103 | VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), |
| 104 | AllImportedModules.end()))); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 105 | |
Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 106 | for (const auto &I : AllMacrosPerParent) { |
| 107 | // DIMacroNode's with nullptr parent are DICompileUnit direct children. |
| 108 | if (!I.first) { |
| 109 | CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef())); |
| 110 | continue; |
| 111 | } |
| 112 | // Otherwise, it must be a temporary DIMacroFile that need to be resolved. |
| 113 | auto *TMF = cast<DIMacroFile>(I.first); |
| 114 | auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file, |
| 115 | TMF->getLine(), TMF->getFile(), |
| 116 | getOrCreateMacroArray(I.second.getArrayRef())); |
| 117 | replaceTemporary(llvm::TempDIMacroNode(TMF), MF); |
| 118 | } |
| 119 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 120 | // Now that all temp nodes have been replaced or deleted, resolve remaining |
| 121 | // cycles. |
| 122 | for (const auto &N : UnresolvedNodes) |
Duncan P. N. Exon Smith | 2bc00f4 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 123 | if (N && !N->isResolved()) |
| 124 | N->resolveCycles(); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 125 | UnresolvedNodes.clear(); |
| 126 | |
| 127 | // Can't handle unresolved nodes anymore. |
| 128 | AllowUnresolvedNodes = false; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Duncan P. N. Exon Smith | 379e375 | 2014-10-01 21:32:15 +0000 | [diff] [blame] | 131 | /// If N is compile unit return NULL otherwise return N. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 132 | static DIScope *getNonCompileUnitScope(DIScope *N) { |
| 133 | if (!N || isa<DICompileUnit>(N)) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 134 | return nullptr; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 135 | return cast<DIScope>(N); |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 138 | DICompileUnit *DIBuilder::createCompileUnit( |
Amjad Aboud | 43c8b6b | 2016-12-14 20:24:54 +0000 | [diff] [blame] | 139 | unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, |
| 140 | StringRef Flags, unsigned RunTimeVer, StringRef SplitName, |
David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 141 | DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, |
David Blaikie | 66cf14d | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 142 | bool SplitDebugInlining, bool DebugInfoForProfiling, |
Adrian Prantl | 7b30370 | 2020-01-14 13:37:04 -0800 | [diff] [blame] | 143 | DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress, |
Adrian Prantl | e4e7e44 | 2020-03-04 14:12:54 -0800 | [diff] [blame] | 144 | StringRef SysRoot, StringRef SDK) { |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 145 | |
Bruce Mitchener | 7e575ed | 2015-02-07 06:35:30 +0000 | [diff] [blame] | 146 | assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || |
Chandler Carruth | 4c0ee74 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 147 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 148 | "Invalid Language tag"); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 149 | |
Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 150 | assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); |
| 151 | CUNode = DICompileUnit::getDistinct( |
Amjad Aboud | 43c8b6b | 2016-12-14 20:24:54 +0000 | [diff] [blame] | 152 | VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, |
| 153 | SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, |
David Blaikie | bb27911 | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 154 | SplitDebugInlining, DebugInfoForProfiling, NameTableKind, |
Adrian Prantl | e4e7e44 | 2020-03-04 14:12:54 -0800 | [diff] [blame] | 155 | RangesBaseAddress, SysRoot, SDK); |
Devang Patel | 09fa69e | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 156 | |
| 157 | // Create a named metadata so that it is easier to find cu in a module. |
Adrian Prantl | 5992a72 | 2016-04-08 22:43:03 +0000 | [diff] [blame] | 158 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 159 | NMD->addOperand(CUNode); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 160 | trackIfUnresolved(CUNode); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 161 | return CUNode; |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 164 | static DIImportedEntity * |
| 165 | createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 166 | Metadata *NS, DIFile *File, unsigned Line, StringRef Name, |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 167 | SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 168 | if (Line) |
| 169 | assert(File && "Source location has line number but no file"); |
Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame] | 170 | unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); |
Fangrui Song | da82ce9 | 2019-05-07 02:06:37 +0000 | [diff] [blame] | 171 | auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS), |
| 172 | File, Line, Name); |
Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame] | 173 | if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) |
| 174 | // A new Imported Entity was just added to the context. |
| 175 | // Add it to the Imported Modules list. |
| 176 | AllImportedModules.emplace_back(M); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 177 | return M; |
| 178 | } |
| 179 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 180 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 181 | DINamespace *NS, DIFile *File, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 182 | unsigned Line) { |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 183 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 184 | Context, NS, File, Line, StringRef(), |
| 185 | AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 188 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
| 189 | DIImportedEntity *NS, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 190 | DIFile *File, unsigned Line) { |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 191 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 192 | Context, NS, File, Line, StringRef(), |
| 193 | AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 196 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 197 | DIFile *File, unsigned Line) { |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 198 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 199 | Context, M, File, Line, StringRef(), |
| 200 | AllImportedModules); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 203 | DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, |
| 204 | DINode *Decl, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 205 | DIFile *File, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 206 | unsigned Line, |
| 207 | StringRef Name) { |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 208 | // Make sure to use the unique identifier based metadata reference for |
| 209 | // types that have one. |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 210 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 211 | Context, Decl, File, Line, Name, |
| 212 | AllImportedModules); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 215 | DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory, |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 216 | Optional<DIFile::ChecksumInfo<StringRef>> CS, |
| 217 | Optional<StringRef> Source) { |
| 218 | return DIFile::get(VMContext, Filename, Directory, CS, Source); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 221 | DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber, |
| 222 | unsigned MacroType, StringRef Name, |
| 223 | StringRef Value) { |
| 224 | assert(!Name.empty() && "Unable to create macro without name"); |
| 225 | assert((MacroType == dwarf::DW_MACINFO_undef || |
| 226 | MacroType == dwarf::DW_MACINFO_define) && |
| 227 | "Unexpected macro type"); |
| 228 | auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value); |
| 229 | AllMacrosPerParent[Parent].insert(M); |
| 230 | return M; |
| 231 | } |
| 232 | |
| 233 | DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent, |
| 234 | unsigned LineNumber, DIFile *File) { |
| 235 | auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file, |
| 236 | LineNumber, File, DIMacroNodeArray()) |
| 237 | .release(); |
| 238 | AllMacrosPerParent[Parent].insert(MF); |
| 239 | // Add the new temporary DIMacroFile to the macro per parent map as a parent. |
| 240 | // This is needed to assure DIMacroFile with no children to have an entry in |
| 241 | // the map. Otherwise, it will not be resolved in DIBuilder::finalize(). |
| 242 | AllMacrosPerParent.insert({MF, {}}); |
| 243 | return MF; |
| 244 | } |
| 245 | |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 246 | DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val, |
| 247 | bool IsUnsigned) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 248 | assert(!Name.empty() && "Unable to create enumerator without name"); |
LemonBoy | aad3d57 | 2020-04-18 11:31:38 -0700 | [diff] [blame] | 249 | return DIEnumerator::get(VMContext, APInt(64, Val, !IsUnsigned), IsUnsigned, |
| 250 | Name); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 253 | DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) { |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 254 | assert(!Name.empty() && "Unable to create type without name"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 255 | return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 258 | DIBasicType *DIBuilder::createNullPtrType() { |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 259 | return createUnspecifiedType("decltype(nullptr)"); |
| 260 | } |
| 261 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 262 | DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 263 | unsigned Encoding, |
| 264 | DINode::DIFlags Flags) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 265 | assert(!Name.empty() && "Unable to create type without name"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 266 | return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 267 | 0, Encoding, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Sourabh Singh Tomar | f91d18e | 2020-08-20 16:11:22 +0530 | [diff] [blame] | 270 | DIStringType *DIBuilder::createStringType(StringRef Name, uint64_t SizeInBits) { |
| 271 | assert(!Name.empty() && "Unable to create type without name"); |
| 272 | return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, |
| 273 | SizeInBits, 0); |
| 274 | } |
| 275 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 276 | DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 277 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 278 | 0, 0, None, DINode::FlagZero); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 281 | DIDerivedType *DIBuilder::createPointerType( |
| 282 | DIType *PointeeTy, |
| 283 | uint64_t SizeInBits, |
| 284 | uint32_t AlignInBits, |
| 285 | Optional<unsigned> DWARFAddressSpace, |
| 286 | StringRef Name) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 287 | // FIXME: Why is there a name here? |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 288 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 289 | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 290 | AlignInBits, 0, DWARFAddressSpace, |
| 291 | DINode::FlagZero); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 294 | DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, |
| 295 | DIType *Base, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 296 | uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 297 | uint32_t AlignInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 298 | DINode::DIFlags Flags) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 299 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 300 | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 301 | AlignInBits, 0, None, Flags, Base); |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 304 | DIDerivedType *DIBuilder::createReferenceType( |
| 305 | unsigned Tag, DIType *RTy, |
| 306 | uint64_t SizeInBits, |
| 307 | uint32_t AlignInBits, |
| 308 | Optional<unsigned> DWARFAddressSpace) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 309 | assert(RTy && "Unable to create reference type"); |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 310 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 311 | SizeInBits, AlignInBits, 0, DWARFAddressSpace, |
| 312 | DINode::FlagZero); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 315 | DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, |
| 316 | DIFile *File, unsigned LineNo, |
Sourabh Singh Tomar | f1e3988 | 2019-12-03 09:29:54 +0530 | [diff] [blame] | 317 | DIScope *Context, |
| 318 | uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 319 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, |
Sourabh Singh Tomar | f1e3988 | 2019-12-03 09:29:54 +0530 | [diff] [blame] | 320 | LineNo, getNonCompileUnitScope(Context), Ty, 0, |
| 321 | AlignInBits, 0, None, DINode::FlagZero); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 324 | DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 325 | assert(Ty && "Invalid type!"); |
| 326 | assert(FriendTy && "Invalid friend type!"); |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 327 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 328 | FriendTy, 0, 0, 0, None, DINode::FlagZero); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 331 | DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 332 | uint64_t BaseOffset, |
Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 333 | uint32_t VBPtrOffset, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 334 | DINode::DIFlags Flags) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 335 | assert(Ty && "Unable to create inheritance"); |
Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 336 | Metadata *ExtraData = ConstantAsMetadata::get( |
| 337 | ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset)); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 338 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 339 | 0, Ty, BaseTy, 0, 0, BaseOffset, None, |
| 340 | Flags, ExtraData); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 343 | DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, |
| 344 | DIFile *File, unsigned LineNumber, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 345 | uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 346 | uint32_t AlignInBits, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 347 | uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 348 | DINode::DIFlags Flags, DIType *Ty) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 349 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 350 | LineNumber, getNonCompileUnitScope(Scope), Ty, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 351 | SizeInBits, AlignInBits, OffsetInBits, None, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 354 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 355 | if (C) |
| 356 | return ConstantAsMetadata::get(C); |
| 357 | return nullptr; |
| 358 | } |
| 359 | |
Adrian Prantl | 9a45452 | 2018-09-12 22:57:28 +0000 | [diff] [blame] | 360 | DIDerivedType *DIBuilder::createVariantMemberType( |
| 361 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| 362 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
| 363 | Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) { |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 364 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 365 | LineNumber, getNonCompileUnitScope(Scope), Ty, |
| 366 | SizeInBits, AlignInBits, OffsetInBits, None, Flags, |
| 367 | getConstantOrNull(Discriminant)); |
| 368 | } |
| 369 | |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 370 | DIDerivedType *DIBuilder::createBitFieldMemberType( |
| 371 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 372 | uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, |
| 373 | DINode::DIFlags Flags, DIType *Ty) { |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 374 | Flags |= DINode::FlagBitField; |
| 375 | return DIDerivedType::get( |
| 376 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 377 | getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 378 | OffsetInBits, None, Flags, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 379 | ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), |
| 380 | StorageOffsetInBits))); |
David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 383 | DIDerivedType * |
| 384 | DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, |
| 385 | unsigned LineNumber, DIType *Ty, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 386 | DINode::DIFlags Flags, llvm::Constant *Val, |
| 387 | uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 388 | Flags |= DINode::FlagStaticMember; |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 389 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 390 | LineNumber, getNonCompileUnitScope(Scope), Ty, 0, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 391 | AlignInBits, 0, None, Flags, |
| 392 | getConstantOrNull(Val)); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 395 | DIDerivedType * |
| 396 | DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 397 | uint64_t SizeInBits, uint32_t AlignInBits, |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 398 | uint64_t OffsetInBits, DINode::DIFlags Flags, |
| 399 | DIType *Ty, MDNode *PropertyNode) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 400 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 401 | LineNumber, getNonCompileUnitScope(File), Ty, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 402 | SizeInBits, AlignInBits, OffsetInBits, None, Flags, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 403 | PropertyNode); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 406 | DIObjCProperty * |
| 407 | DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 408 | StringRef GetterName, StringRef SetterName, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 409 | unsigned PropertyAttributes, DIType *Ty) { |
| 410 | return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 411 | SetterName, PropertyAttributes, Ty); |
Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 414 | DITemplateTypeParameter * |
| 415 | DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 416 | DIType *Ty, bool isDefault) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 417 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 418 | return DITemplateTypeParameter::get(VMContext, Name, Ty, isDefault); |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 421 | static DITemplateValueParameter * |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 422 | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 423 | DIScope *Context, StringRef Name, DIType *Ty, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 424 | bool IsDefault, Metadata *MD) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 425 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 426 | return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, IsDefault, MD); |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 429 | DITemplateValueParameter * |
| 430 | DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 431 | DIType *Ty, bool isDefault, |
| 432 | Constant *Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 433 | return createTemplateValueParameterHelper( |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 434 | VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 435 | isDefault, getConstantOrNull(Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 438 | DITemplateValueParameter * |
| 439 | DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, |
| 440 | DIType *Ty, StringRef Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 441 | return createTemplateValueParameterHelper( |
| 442 | VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 443 | false, MDString::get(VMContext, Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 446 | DITemplateValueParameter * |
| 447 | DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name, |
| 448 | DIType *Ty, DINodeArray Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 449 | return createTemplateValueParameterHelper( |
| 450 | VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, |
Awanish Pandey | 7a42bab | 2020-03-02 10:52:12 +0530 | [diff] [blame] | 451 | false, Val.get()); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 454 | DICompositeType *DIBuilder::createClassType( |
| 455 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 456 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 457 | DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 458 | DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) { |
| 459 | assert((!Context || isa<DIScope>(Context)) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 460 | "createClassType should be called with a valid Context"); |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 461 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 462 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 463 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 464 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, |
| 465 | OffsetInBits, Flags, Elements, 0, VTableHolder, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 466 | cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 467 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 468 | return R; |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 471 | DICompositeType *DIBuilder::createStructType( |
| 472 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 473 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 474 | DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, |
| 475 | DIType *VTableHolder, StringRef UniqueIdentifier) { |
| 476 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 477 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 478 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, |
| 479 | Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 480 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 481 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 484 | DICompositeType *DIBuilder::createUnionType( |
| 485 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 486 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 487 | DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { |
| 488 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 489 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 490 | getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, |
| 491 | Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 492 | trackIfUnresolved(R); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 493 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 496 | DICompositeType *DIBuilder::createVariantPart( |
| 497 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| 498 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
| 499 | DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) { |
| 500 | auto *R = DICompositeType::get( |
| 501 | VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber, |
| 502 | getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, |
| 503 | Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator); |
| 504 | trackIfUnresolved(R); |
| 505 | return R; |
| 506 | } |
| 507 | |
Eric Christopher | bdafb3c | 2015-10-15 06:56:10 +0000 | [diff] [blame] | 508 | DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 509 | DINode::DIFlags Flags, |
| 510 | unsigned CC) { |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 511 | return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 514 | DICompositeType *DIBuilder::createEnumerationType( |
| 515 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 516 | uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, |
Paul Robinson | 7402fd9 | 2019-01-08 17:52:29 +0000 | [diff] [blame] | 517 | DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsScoped) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 518 | auto *CTy = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 519 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 520 | getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, |
Paul Robinson | 7402fd9 | 2019-01-08 17:52:29 +0000 | [diff] [blame] | 521 | IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr, |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 522 | nullptr, UniqueIdentifier); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 523 | AllEnumTypes.push_back(CTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 524 | trackIfUnresolved(CTy); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 525 | return CTy; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 528 | DICompositeType *DIBuilder::createArrayType(uint64_t Size, |
| 529 | uint32_t AlignInBits, DIType *Ty, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 530 | DINodeArray Subscripts) { |
| 531 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 532 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 533 | DINode::FlagZero, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 534 | trackIfUnresolved(R); |
| 535 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 538 | DICompositeType *DIBuilder::createVectorType(uint64_t Size, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 539 | uint32_t AlignInBits, DIType *Ty, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 540 | DINodeArray Subscripts) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 541 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
| 542 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
| 543 | DINode::FlagVector, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 544 | trackIfUnresolved(R); |
| 545 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 546 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 547 | |
Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 548 | DISubprogram *DIBuilder::createArtificialSubprogram(DISubprogram *SP) { |
| 549 | auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial); |
| 550 | return MDNode::replaceWithDistinct(std::move(NewSP)); |
| 551 | } |
| 552 | |
| 553 | static DIType *createTypeWithFlags(const DIType *Ty, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 554 | DINode::DIFlags FlagsToSet) { |
Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 555 | auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 556 | return MDNode::replaceWithUniqued(std::move(NewTy)); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 559 | DIType *DIBuilder::createArtificialType(DIType *Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 560 | // FIXME: Restrict this to the nodes where it's valid. |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 561 | if (Ty->isArtificial()) |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 562 | return Ty; |
Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 563 | return createTypeWithFlags(Ty, DINode::FlagArtificial); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 564 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 565 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 566 | DIType *DIBuilder::createObjectPointerType(DIType *Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 567 | // FIXME: Restrict this to the nodes where it's valid. |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 568 | if (Ty->isObjectPointer()) |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 569 | return Ty; |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 570 | DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial; |
Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 571 | return createTypeWithFlags(Ty, Flags); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 574 | void DIBuilder::retainType(DIScope *T) { |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 575 | assert(T && "Expected non-null type"); |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 576 | assert((isa<DIType>(T) || (isa<DISubprogram>(T) && |
| 577 | cast<DISubprogram>(T)->isDefinition() == false)) && |
| 578 | "Expected type or subprogram declaration"); |
Duncan P. N. Exon Smith | d9ccfb9 | 2015-03-27 23:00:49 +0000 | [diff] [blame] | 579 | AllRetainTypes.emplace_back(T); |
| 580 | } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 581 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 582 | DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 583 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 584 | DICompositeType * |
| 585 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, |
| 586 | DIFile *F, unsigned Line, unsigned RuntimeLang, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 587 | uint64_t SizeInBits, uint32_t AlignInBits, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 588 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 589 | // FIXME: Define in terms of createReplaceableForwardDecl() by calling |
| 590 | // replaceWithUniqued(). |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 591 | auto *RetTy = DICompositeType::get( |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 592 | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
| 593 | SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, |
| 594 | nullptr, nullptr, UniqueIdentifier); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 595 | trackIfUnresolved(RetTy); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 596 | return RetTy; |
| 597 | } |
| 598 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 599 | DICompositeType *DIBuilder::createReplaceableCompositeType( |
| 600 | unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 601 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 602 | DINode::DIFlags Flags, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 603 | auto *RetTy = |
| 604 | DICompositeType::getTemporary( |
| 605 | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
| 606 | SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, |
| 607 | nullptr, UniqueIdentifier) |
| 608 | .release(); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 609 | trackIfUnresolved(RetTy); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 610 | return RetTy; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 613 | DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 614 | return MDTuple::get(VMContext, Elements); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 617 | DIMacroNodeArray |
| 618 | DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) { |
| 619 | return MDTuple::get(VMContext, Elements); |
| 620 | } |
| 621 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 622 | DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 623 | SmallVector<llvm::Metadata *, 16> Elts; |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 624 | for (unsigned i = 0, e = Elements.size(); i != e; ++i) { |
| 625 | if (Elements[i] && isa<MDNode>(Elements[i])) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 626 | Elts.push_back(cast<DIType>(Elements[i])); |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 627 | else |
| 628 | Elts.push_back(Elements[i]); |
| 629 | } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 630 | return DITypeRefArray(MDNode::get(VMContext, Elts)); |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 633 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
Alok Kumar Sharma | d20bf5a | 2020-05-28 13:31:22 +0530 | [diff] [blame] | 634 | auto *LB = ConstantAsMetadata::get( |
| 635 | ConstantInt::getSigned(Type::getInt64Ty(VMContext), Lo)); |
| 636 | auto *CountNode = ConstantAsMetadata::get( |
| 637 | ConstantInt::getSigned(Type::getInt64Ty(VMContext), Count)); |
| 638 | return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 641 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, Metadata *CountNode) { |
Alok Kumar Sharma | d20bf5a | 2020-05-28 13:31:22 +0530 | [diff] [blame] | 642 | auto *LB = ConstantAsMetadata::get( |
| 643 | ConstantInt::getSigned(Type::getInt64Ty(VMContext), Lo)); |
| 644 | return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr); |
| 645 | } |
| 646 | |
| 647 | DISubrange *DIBuilder::getOrCreateSubrange(Metadata *CountNode, Metadata *LB, |
| 648 | Metadata *UB, Metadata *Stride) { |
| 649 | return DISubrange::get(VMContext, CountNode, LB, UB, Stride); |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 652 | static void checkGlobalVariableScope(DIScope *Context) { |
Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 653 | #ifndef NDEBUG |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 654 | if (auto *CT = |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 655 | dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context))) |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 656 | assert(CT->getIdentifier().empty() && |
Manman Ren | bfd2b829 | 2014-11-21 19:47:48 +0000 | [diff] [blame] | 657 | "Context of a global variable should not be a type with identifier"); |
Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 658 | #endif |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 661 | DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 662 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
Simon Pilgrim | 3654ed2 | 2019-12-23 07:27:05 +0000 | [diff] [blame] | 663 | unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, |
Yonghong Song | e3d8ee3 | 2019-11-22 08:45:37 -0800 | [diff] [blame] | 664 | bool isDefined, DIExpression *Expr, |
Simon Pilgrim | 3654ed2 | 2019-12-23 07:27:05 +0000 | [diff] [blame] | 665 | MDNode *Decl, MDTuple *TemplateParams, uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 666 | checkGlobalVariableScope(Context); |
| 667 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 668 | auto *GV = DIGlobalVariable::getDistinct( |
Duncan P. N. Exon Smith | c5225df | 2016-04-23 22:29:09 +0000 | [diff] [blame] | 669 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
Simon Pilgrim | 3654ed2 | 2019-12-23 07:27:05 +0000 | [diff] [blame] | 670 | LineNumber, Ty, IsLocalToUnit, isDefined, cast_or_null<DIDerivedType>(Decl), |
| 671 | TemplateParams, AlignInBits); |
Adrian Prantl | 0578221 | 2017-08-30 18:06:51 +0000 | [diff] [blame] | 672 | if (!Expr) |
| 673 | Expr = createExpression(); |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 674 | auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 675 | AllGVs.push_back(N); |
| 676 | return N; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 679 | DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( |
| 680 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
Simon Pilgrim | 3654ed2 | 2019-12-23 07:27:05 +0000 | [diff] [blame] | 681 | unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl, |
| 682 | MDTuple *TemplateParams, uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 683 | checkGlobalVariableScope(Context); |
| 684 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 685 | return DIGlobalVariable::getTemporary( |
| 686 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
Simon Pilgrim | 3654ed2 | 2019-12-23 07:27:05 +0000 | [diff] [blame] | 687 | LineNumber, Ty, IsLocalToUnit, false, |
| 688 | cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits) |
Duncan P. N. Exon Smith | b273d06 | 2015-04-16 01:37:00 +0000 | [diff] [blame] | 689 | .release(); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 692 | static DILocalVariable *createLocalVariable( |
| 693 | LLVMContext &VMContext, |
Duncan P. N. Exon Smith | 3c406c2 | 2016-04-20 20:14:09 +0000 | [diff] [blame] | 694 | DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 695 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 696 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, |
| 697 | uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 698 | // FIXME: Why getNonCompileUnitScope()? |
| 699 | // FIXME: Why is "!Context" okay here? |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 700 | // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 701 | // the only valid scopes)? |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 702 | DIScope *Context = getNonCompileUnitScope(Scope); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 703 | |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 704 | auto *Node = |
| 705 | DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 706 | File, LineNo, Ty, ArgNo, Flags, AlignInBits); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 707 | if (AlwaysPreserve) { |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 708 | // The optimizer may remove local variables. If there is an interest |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 709 | // to preserve variable info in such situation then stash it in a |
| 710 | // named mdnode. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 711 | DISubprogram *Fn = getDISubprogram(Scope); |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 712 | assert(Fn && "Missing subprogram for local variable"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 713 | PreservedVariables[Fn].emplace_back(Node); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 714 | } |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 715 | return Node; |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 718 | DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, |
| 719 | DIFile *File, unsigned LineNo, |
| 720 | DIType *Ty, bool AlwaysPreserve, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 721 | DINode::DIFlags Flags, |
| 722 | uint32_t AlignInBits) { |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 723 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, |
| 724 | /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 725 | Flags, AlignInBits); |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | DILocalVariable *DIBuilder::createParameterVariable( |
| 729 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 730 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 731 | assert(ArgNo && "Expected non-zero argument number for parameter"); |
| 732 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 733 | File, LineNo, Ty, AlwaysPreserve, Flags, |
| 734 | /* AlignInBits */0); |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 737 | DILabel *DIBuilder::createLabel( |
| 738 | DIScope *Scope, StringRef Name, DIFile *File, |
| 739 | unsigned LineNo, bool AlwaysPreserve) { |
| 740 | DIScope *Context = getNonCompileUnitScope(Scope); |
| 741 | |
| 742 | auto *Node = |
| 743 | DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
| 744 | File, LineNo); |
| 745 | |
| 746 | if (AlwaysPreserve) { |
| 747 | /// The optimizer may remove labels. If there is an interest |
| 748 | /// to preserve label info in such situation then append it to |
| 749 | /// the list of retained nodes of the DISubprogram. |
| 750 | DISubprogram *Fn = getDISubprogram(Scope); |
| 751 | assert(Fn && "Missing subprogram for label"); |
| 752 | PreservedLabels[Fn].emplace_back(Node); |
| 753 | } |
| 754 | return Node; |
| 755 | } |
| 756 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 757 | DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
| 758 | return DIExpression::get(VMContext, Addr); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 761 | DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 762 | // TODO: Remove the callers of this signed version and delete. |
| 763 | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
| 764 | return createExpression(Addr); |
| 765 | } |
| 766 | |
Duncan P. N. Exon Smith | b2df647 | 2015-08-26 22:50:16 +0000 | [diff] [blame] | 767 | template <class... Ts> |
| 768 | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { |
| 769 | if (IsDistinct) |
| 770 | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); |
| 771 | return DISubprogram::get(std::forward<Ts>(Args)...); |
| 772 | } |
| 773 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 774 | DISubprogram *DIBuilder::createFunction( |
| 775 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 776 | unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, |
| 777 | DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags, |
| 778 | DITemplateParameterArray TParams, DISubprogram *Decl, |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 779 | DITypeArray ThrownTypes) { |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 780 | bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 781 | auto *Node = getSubprogram( |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 782 | /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context), |
| 783 | Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags, |
| 784 | SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 785 | MDTuple::getTemporary(VMContext, None).release(), ThrownTypes); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 786 | |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 787 | if (IsDefinition) |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 788 | AllSubprograms.push_back(Node); |
| 789 | trackIfUnresolved(Node); |
| 790 | return Node; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 793 | DISubprogram *DIBuilder::createTempFunctionFwdDecl( |
| 794 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 795 | unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, |
| 796 | DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags, |
| 797 | DITemplateParameterArray TParams, DISubprogram *Decl, |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 798 | DITypeArray ThrownTypes) { |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 799 | bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; |
| 800 | return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context), |
| 801 | Name, LinkageName, File, LineNo, Ty, |
| 802 | ScopeLine, nullptr, 0, 0, Flags, SPFlags, |
| 803 | IsDefinition ? CUNode : nullptr, TParams, |
| 804 | Decl, nullptr, ThrownTypes) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 805 | .release(); |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 808 | DISubprogram *DIBuilder::createMethod( |
| 809 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 810 | unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment, |
| 811 | DIType *VTableHolder, DINode::DIFlags Flags, |
| 812 | DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams, |
| 813 | DITypeArray ThrownTypes) { |
Eric Christopher | 5cb5632 | 2013-10-15 23:31:36 +0000 | [diff] [blame] | 814 | assert(getNonCompileUnitScope(Context) && |
| 815 | "Methods should have both a Context and a context that isn't " |
| 816 | "the compile unit."); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 817 | // FIXME: Do we want to use different scope/lines? |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 818 | bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 819 | auto *SP = getSubprogram( |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 820 | /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name, |
| 821 | LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment, |
| 822 | Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr, |
| 823 | nullptr, ThrownTypes); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 824 | |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 825 | if (IsDefinition) |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 826 | AllSubprograms.push_back(SP); |
| 827 | trackIfUnresolved(SP); |
| 828 | return SP; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Adrian Prantl | 6ed5706 | 2019-04-08 19:13:55 +0000 | [diff] [blame] | 831 | DICommonBlock *DIBuilder::createCommonBlock( |
| 832 | DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File, |
| 833 | unsigned LineNo) { |
| 834 | return DICommonBlock::get( |
| 835 | VMContext, Scope, Decl, Name, File, LineNo); |
| 836 | } |
| 837 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 838 | DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 839 | bool ExportSymbols) { |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 840 | |
| 841 | // It is okay to *not* make anonymous top-level namespaces distinct, because |
| 842 | // all nodes that have an anonymous namespace as their parent scope are |
| 843 | // guaranteed to be unique and/or are linked to their containing |
| 844 | // DICompileUnit. This decision is an explicit tradeoff of link time versus |
| 845 | // memory usage versus code simplicity and may get revisited in the future. |
| 846 | return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name, |
| 847 | ExportSymbols); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 850 | DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, |
| 851 | StringRef ConfigurationMacros, |
Sourabh Singh Tomar | e59744f | 2020-05-08 11:31:41 +0530 | [diff] [blame] | 852 | StringRef IncludePath, StringRef APINotesFile, |
| 853 | DIFile *File, unsigned LineNo) { |
| 854 | return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name, |
| 855 | ConfigurationMacros, IncludePath, APINotesFile, LineNo); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 858 | DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, |
| 859 | DIFile *File, |
| 860 | unsigned Discriminator) { |
| 861 | return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator); |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 864 | DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File, |
| 865 | unsigned Line, unsigned Col) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 866 | // Make these distinct, to avoid merging two lexical blocks on the same |
| 867 | // file/line/column. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 868 | return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), |
Duncan P. N. Exon Smith | 35ef22c | 2015-04-15 23:19:27 +0000 | [diff] [blame] | 869 | File, Line, Col); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 870 | } |
| 871 | |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 872 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 873 | DIExpression *Expr, const DILocation *DL, |
| 874 | Instruction *InsertBefore) { |
| 875 | return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(), |
| 876 | InsertBefore); |
| 877 | } |
| 878 | |
| 879 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 880 | DIExpression *Expr, const DILocation *DL, |
| 881 | BasicBlock *InsertAtEnd) { |
| 882 | // If this block already has a terminator then insert this intrinsic before |
| 883 | // the terminator. Otherwise, put it at the end of the block. |
| 884 | Instruction *InsertBefore = InsertAtEnd->getTerminator(); |
| 885 | return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore); |
| 886 | } |
| 887 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 888 | Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, |
| 889 | Instruction *InsertBefore) { |
| 890 | return insertLabel( |
| 891 | LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr, |
| 892 | InsertBefore); |
| 893 | } |
| 894 | |
| 895 | Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, |
| 896 | BasicBlock *InsertAtEnd) { |
| 897 | return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr); |
| 898 | } |
| 899 | |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 900 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
| 901 | DILocalVariable *VarInfo, |
| 902 | DIExpression *Expr, |
| 903 | const DILocation *DL, |
| 904 | Instruction *InsertBefore) { |
| 905 | return insertDbgValueIntrinsic( |
| 906 | V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr, |
| 907 | InsertBefore); |
| 908 | } |
| 909 | |
| 910 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
| 911 | DILocalVariable *VarInfo, |
| 912 | DIExpression *Expr, |
| 913 | const DILocation *DL, |
| 914 | BasicBlock *InsertAtEnd) { |
| 915 | return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr); |
| 916 | } |
| 917 | |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 918 | /// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics. |
| 919 | /// This abstracts over the various ways to specify an insert position. |
| 920 | static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL, |
| 921 | BasicBlock *InsertBB, Instruction *InsertBefore) { |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 922 | if (InsertBefore) |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 923 | Builder.SetInsertPoint(InsertBefore); |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 924 | else if (InsertBB) |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 925 | Builder.SetInsertPoint(InsertBB); |
| 926 | Builder.SetCurrentDebugLocation(DL); |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 929 | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
| 930 | assert(V && "no value passed to dbg intrinsic"); |
| 931 | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
| 932 | } |
| 933 | |
Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 934 | static Function *getDeclareIntrin(Module &M) { |
| 935 | return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr |
| 936 | : Intrinsic::dbg_declare); |
| 937 | } |
| 938 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 939 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 940 | DIExpression *Expr, const DILocation *DL, |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 941 | BasicBlock *InsertBB, Instruction *InsertBefore) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 942 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 943 | assert(DL && "Expected debug loc"); |
| 944 | assert(DL->getScope()->getSubprogram() == |
| 945 | VarInfo->getScope()->getSubprogram() && |
| 946 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 947 | if (!DeclareFn) |
Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 948 | DeclareFn = getDeclareIntrin(M); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 949 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 950 | trackIfUnresolved(VarInfo); |
| 951 | trackIfUnresolved(Expr); |
| 952 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 953 | MetadataAsValue::get(VMContext, VarInfo), |
| 954 | MetadataAsValue::get(VMContext, Expr)}; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 955 | |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 956 | IRBuilder<> B(DL->getContext()); |
| 957 | initIRBuilder(B, DL, InsertBB, InsertBefore); |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 958 | return B.CreateCall(DeclareFn, Args); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 961 | Instruction *DIBuilder::insertDbgValueIntrinsic( |
| 962 | Value *V, DILocalVariable *VarInfo, DIExpression *Expr, |
| 963 | const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) { |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 964 | assert(V && "no value passed to dbg.value"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 965 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 966 | assert(DL && "Expected debug loc"); |
| 967 | assert(DL->getScope()->getSubprogram() == |
| 968 | VarInfo->getScope()->getSubprogram() && |
| 969 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 970 | if (!ValueFn) |
| 971 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 972 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 973 | trackIfUnresolved(VarInfo); |
| 974 | trackIfUnresolved(Expr); |
| 975 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 976 | MetadataAsValue::get(VMContext, VarInfo), |
| 977 | MetadataAsValue::get(VMContext, Expr)}; |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 978 | |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 979 | IRBuilder<> B(DL->getContext()); |
| 980 | initIRBuilder(B, DL, InsertBB, InsertBefore); |
Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 981 | return B.CreateCall(ValueFn, Args); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 982 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 983 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 984 | Instruction *DIBuilder::insertLabel( |
| 985 | DILabel *LabelInfo, const DILocation *DL, |
| 986 | BasicBlock *InsertBB, Instruction *InsertBefore) { |
| 987 | assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label"); |
| 988 | assert(DL && "Expected debug loc"); |
| 989 | assert(DL->getScope()->getSubprogram() == |
| 990 | LabelInfo->getScope()->getSubprogram() && |
| 991 | "Expected matching subprograms"); |
| 992 | if (!LabelFn) |
| 993 | LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label); |
| 994 | |
| 995 | trackIfUnresolved(LabelInfo); |
| 996 | Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)}; |
| 997 | |
Nikita Popov | 80397d2 | 2020-02-16 17:46:26 +0100 | [diff] [blame] | 998 | IRBuilder<> B(DL->getContext()); |
| 999 | initIRBuilder(B, DL, InsertBB, InsertBefore); |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1000 | return B.CreateCall(LabelFn, Args); |
| 1001 | } |
| 1002 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1003 | void DIBuilder::replaceVTableHolder(DICompositeType *&T, |
Adrian Prantl | a8e5645 | 2017-11-08 22:04:43 +0000 | [diff] [blame] | 1004 | DIType *VTableHolder) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1005 | { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1006 | TypedTrackingMDRef<DICompositeType> N(T); |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1007 | N->replaceVTableHolder(VTableHolder); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1008 | T = N.get(); |
| 1009 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1010 | |
| 1011 | // If this didn't create a self-reference, just return. |
| 1012 | if (T != VTableHolder) |
| 1013 | return; |
| 1014 | |
Adrian Prantl | 18a25b0 | 2015-02-11 17:45:10 +0000 | [diff] [blame] | 1015 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
| 1016 | // cycles underneath it. |
| 1017 | if (T->isResolved()) |
| 1018 | for (const MDOperand &O : T->operands()) |
| 1019 | if (auto *N = dyn_cast_or_null<MDNode>(O)) |
| 1020 | trackIfUnresolved(N); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1023 | void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements, |
| 1024 | DINodeArray TParams) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1025 | { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1026 | TypedTrackingMDRef<DICompositeType> N(T); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1027 | if (Elements) |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 1028 | N->replaceElements(Elements); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1029 | if (TParams) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1030 | N->replaceTemplateParams(DITemplateParameterArray(TParams)); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1031 | T = N.get(); |
| 1032 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1033 | |
| 1034 | // If T isn't resolved, there's no problem. |
| 1035 | if (!T->isResolved()) |
| 1036 | return; |
| 1037 | |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 1038 | // If T is resolved, it may be due to a self-reference cycle. Track the |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1039 | // arrays explicitly if they're unresolved, or else the cycles will be |
| 1040 | // orphaned. |
| 1041 | if (Elements) |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1042 | trackIfUnresolved(Elements.get()); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1043 | if (TParams) |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1044 | trackIfUnresolved(TParams.get()); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1045 | } |