Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 1 | //===- DebugInfo.cpp - Debug Information Helper Classes -------------------===// |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the helper classes used to build and interpret debug |
| 11 | // information in LLVM IR form. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 15 | #include "llvm-c/DebugInfo.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/ADT/DenseSet.h" |
| 18 | #include "llvm/ADT/None.h" |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
| 23 | #include "llvm/IR/BasicBlock.h" |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Constants.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 25 | #include "llvm/IR/DebugInfoMetadata.h" |
| 26 | #include "llvm/IR/DebugLoc.h" |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 27 | #include "llvm/IR/DebugInfo.h" |
| 28 | #include "llvm/IR/DIBuilder.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Function.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 30 | #include "llvm/IR/GVMaterializer.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 31 | #include "llvm/IR/Instruction.h" |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 32 | #include "llvm/IR/IntrinsicInst.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 33 | #include "llvm/IR/LLVMContext.h" |
| 34 | #include "llvm/IR/Metadata.h" |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 35 | #include "llvm/IR/Module.h" |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Casting.h" |
| 37 | #include <algorithm> |
| 38 | #include <cassert> |
| 39 | #include <utility> |
| 40 | |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 41 | using namespace llvm; |
| 42 | using namespace llvm::dwarf; |
| 43 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 44 | DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { |
| 45 | if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope)) |
Duncan P. N. Exon Smith | dd77af8 | 2015-03-31 02:06:28 +0000 | [diff] [blame] | 46 | return LocalScope->getSubprogram(); |
| 47 | return nullptr; |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 50 | //===----------------------------------------------------------------------===// |
| 51 | // DebugInfoFinder implementations. |
| 52 | //===----------------------------------------------------------------------===// |
| 53 | |
| 54 | void DebugInfoFinder::reset() { |
| 55 | CUs.clear(); |
| 56 | SPs.clear(); |
| 57 | GVs.clear(); |
| 58 | TYs.clear(); |
| 59 | Scopes.clear(); |
| 60 | NodesSeen.clear(); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 63 | void DebugInfoFinder::processModule(const Module &M) { |
Roman Tereshin | dab10b5 | 2018-04-13 21:23:11 +0000 | [diff] [blame] | 64 | for (auto *CU : M.debug_compile_units()) |
| 65 | processCompileUnit(CU); |
Keno Fischer | 3077977 | 2017-04-11 13:32:11 +0000 | [diff] [blame] | 66 | for (auto &F : M.functions()) { |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 67 | if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram())) |
| 68 | processSubprogram(SP); |
Keno Fischer | 3077977 | 2017-04-11 13:32:11 +0000 | [diff] [blame] | 69 | // There could be subprograms from inlined functions referenced from |
| 70 | // instructions only. Walk the function to find them. |
Roman Tereshin | dab10b5 | 2018-04-13 21:23:11 +0000 | [diff] [blame] | 71 | for (const BasicBlock &BB : F) |
| 72 | for (const Instruction &I : BB) |
| 73 | processInstruction(M, I); |
Keno Fischer | 3077977 | 2017-04-11 13:32:11 +0000 | [diff] [blame] | 74 | } |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Roman Tereshin | d769eb3 | 2018-04-13 21:22:24 +0000 | [diff] [blame] | 77 | void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) { |
| 78 | if (!addCompileUnit(CU)) |
| 79 | return; |
| 80 | for (auto DIG : CU->getGlobalVariables()) { |
| 81 | if (!addGlobalVariable(DIG)) |
| 82 | continue; |
| 83 | auto *GV = DIG->getVariable(); |
| 84 | processScope(GV->getScope()); |
| 85 | processType(GV->getType().resolve()); |
| 86 | } |
| 87 | for (auto *ET : CU->getEnumTypes()) |
| 88 | processType(ET); |
| 89 | for (auto *RT : CU->getRetainedTypes()) |
| 90 | if (auto *T = dyn_cast<DIType>(RT)) |
| 91 | processType(T); |
| 92 | else |
| 93 | processSubprogram(cast<DISubprogram>(RT)); |
| 94 | for (auto *Import : CU->getImportedEntities()) { |
| 95 | auto *Entity = Import->getEntity().resolve(); |
| 96 | if (auto *T = dyn_cast<DIType>(Entity)) |
| 97 | processType(T); |
| 98 | else if (auto *SP = dyn_cast<DISubprogram>(Entity)) |
| 99 | processSubprogram(SP); |
| 100 | else if (auto *NS = dyn_cast<DINamespace>(Entity)) |
| 101 | processScope(NS->getScope()); |
| 102 | else if (auto *M = dyn_cast<DIModule>(Entity)) |
| 103 | processScope(M->getScope()); |
Roman Tereshin | d769eb3 | 2018-04-13 21:22:24 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Roman Tereshin | dab10b5 | 2018-04-13 21:23:11 +0000 | [diff] [blame] | 107 | void DebugInfoFinder::processInstruction(const Module &M, |
| 108 | const Instruction &I) { |
| 109 | if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) |
| 110 | processDeclare(M, DDI); |
| 111 | else if (auto *DVI = dyn_cast<DbgValueInst>(&I)) |
| 112 | processValue(M, DVI); |
| 113 | |
| 114 | if (auto DbgLoc = I.getDebugLoc()) |
| 115 | processLocation(M, DbgLoc.get()); |
| 116 | } |
| 117 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 118 | void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 119 | if (!Loc) |
| 120 | return; |
Duncan P. N. Exon Smith | b7e221b | 2015-04-14 01:35:55 +0000 | [diff] [blame] | 121 | processScope(Loc->getScope()); |
| 122 | processLocation(M, Loc->getInlinedAt()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 125 | void DebugInfoFinder::processType(DIType *DT) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 126 | if (!addType(DT)) |
| 127 | return; |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 128 | processScope(DT->getScope().resolve()); |
Duncan P. N. Exon Smith | 260fa8a | 2015-07-24 20:56:10 +0000 | [diff] [blame] | 129 | if (auto *ST = dyn_cast<DISubroutineType>(DT)) { |
| 130 | for (DITypeRef Ref : ST->getTypeArray()) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 131 | processType(Ref.resolve()); |
Duncan P. N. Exon Smith | 260fa8a | 2015-07-24 20:56:10 +0000 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | if (auto *DCT = dyn_cast<DICompositeType>(DT)) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 135 | processType(DCT->getBaseType().resolve()); |
Anders Waldenborg | 1433fd4 | 2015-04-14 09:18:17 +0000 | [diff] [blame] | 136 | for (Metadata *D : DCT->getElements()) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 137 | if (auto *T = dyn_cast<DIType>(D)) |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 138 | processType(T); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 139 | else if (auto *SP = dyn_cast<DISubprogram>(D)) |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 140 | processSubprogram(SP); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 141 | } |
Duncan P. N. Exon Smith | 260fa8a | 2015-07-24 20:56:10 +0000 | [diff] [blame] | 142 | return; |
| 143 | } |
| 144 | if (auto *DDT = dyn_cast<DIDerivedType>(DT)) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 145 | processType(DDT->getBaseType().resolve()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 149 | void DebugInfoFinder::processScope(DIScope *Scope) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 150 | if (!Scope) |
| 151 | return; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 152 | if (auto *Ty = dyn_cast<DIType>(Scope)) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 153 | processType(Ty); |
| 154 | return; |
| 155 | } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 156 | if (auto *CU = dyn_cast<DICompileUnit>(Scope)) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 157 | addCompileUnit(CU); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 158 | return; |
| 159 | } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 160 | if (auto *SP = dyn_cast<DISubprogram>(Scope)) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 161 | processSubprogram(SP); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | if (!addScope(Scope)) |
| 165 | return; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 166 | if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) { |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 167 | processScope(LB->getScope()); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 168 | } else if (auto *NS = dyn_cast<DINamespace>(Scope)) { |
Duncan P. N. Exon Smith | 20caafb | 2015-04-14 03:01:27 +0000 | [diff] [blame] | 169 | processScope(NS->getScope()); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 170 | } else if (auto *M = dyn_cast<DIModule>(Scope)) { |
| 171 | processScope(M->getScope()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 175 | void DebugInfoFinder::processSubprogram(DISubprogram *SP) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 176 | if (!addSubprogram(SP)) |
| 177 | return; |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 178 | processScope(SP->getScope().resolve()); |
Roman Tereshin | d769eb3 | 2018-04-13 21:22:24 +0000 | [diff] [blame] | 179 | // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a |
| 180 | // ValueMap containing identity mappings for all of the DICompileUnit's, not |
| 181 | // just DISubprogram's, referenced from anywhere within the Function being |
| 182 | // cloned prior to calling MapMetadata / RemapInstruction to avoid their |
| 183 | // duplication later as DICompileUnit's are also directly referenced by |
| 184 | // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well. |
| 185 | // Also, DICompileUnit's may reference DISubprogram's too and therefore need |
| 186 | // to be at least looked through. |
| 187 | processCompileUnit(SP->getUnit()); |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 188 | processType(SP->getType()); |
| 189 | for (auto *Element : SP->getTemplateParams()) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 190 | if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 191 | processType(TType->getType().resolve()); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 192 | } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 193 | processType(TVal->getType().resolve()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Manman Ren | 2085ccc | 2013-11-17 18:42:37 +0000 | [diff] [blame] | 198 | void DebugInfoFinder::processDeclare(const Module &M, |
| 199 | const DbgDeclareInst *DDI) { |
Duncan P. N. Exon Smith | ed557b5 | 2015-04-17 23:20:10 +0000 | [diff] [blame] | 200 | auto *N = dyn_cast<MDNode>(DDI->getVariable()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 201 | if (!N) |
| 202 | return; |
| 203 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 204 | auto *DV = dyn_cast<DILocalVariable>(N); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 205 | if (!DV) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 206 | return; |
| 207 | |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 208 | if (!NodesSeen.insert(DV).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 209 | return; |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 210 | processScope(DV->getScope()); |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 211 | processType(DV->getType().resolve()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Manman Ren | 2085ccc | 2013-11-17 18:42:37 +0000 | [diff] [blame] | 214 | void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { |
Duncan P. N. Exon Smith | ed557b5 | 2015-04-17 23:20:10 +0000 | [diff] [blame] | 215 | auto *N = dyn_cast<MDNode>(DVI->getVariable()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 216 | if (!N) |
| 217 | return; |
| 218 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 219 | auto *DV = dyn_cast<DILocalVariable>(N); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 220 | if (!DV) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 221 | return; |
| 222 | |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 223 | if (!NodesSeen.insert(DV).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 224 | return; |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 225 | processScope(DV->getScope()); |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 226 | processType(DV->getType().resolve()); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 229 | bool DebugInfoFinder::addType(DIType *DT) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 230 | if (!DT) |
| 231 | return false; |
| 232 | |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 233 | if (!NodesSeen.insert(DT).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 234 | return false; |
| 235 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 236 | TYs.push_back(const_cast<DIType *>(DT)); |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 237 | return true; |
| 238 | } |
| 239 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 240 | bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 241 | if (!CU) |
| 242 | return false; |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 243 | if (!NodesSeen.insert(CU).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 244 | return false; |
| 245 | |
| 246 | CUs.push_back(CU); |
| 247 | return true; |
| 248 | } |
| 249 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 250 | bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) { |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 251 | if (!NodesSeen.insert(DIG).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 252 | return false; |
| 253 | |
| 254 | GVs.push_back(DIG); |
| 255 | return true; |
| 256 | } |
| 257 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 258 | bool DebugInfoFinder::addSubprogram(DISubprogram *SP) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 259 | if (!SP) |
| 260 | return false; |
| 261 | |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 262 | if (!NodesSeen.insert(SP).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 263 | return false; |
| 264 | |
| 265 | SPs.push_back(SP); |
| 266 | return true; |
| 267 | } |
| 268 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 269 | bool DebugInfoFinder::addScope(DIScope *Scope) { |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 270 | if (!Scope) |
| 271 | return false; |
| 272 | // FIXME: Ocaml binding generates a scope with no content, we treat it |
| 273 | // as null for now. |
| 274 | if (Scope->getNumOperands() == 0) |
| 275 | return false; |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 276 | if (!NodesSeen.insert(Scope).second) |
Bill Wendling | 523bea8 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 277 | return false; |
| 278 | Scopes.push_back(Scope); |
| 279 | return true; |
| 280 | } |
| 281 | |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 282 | static MDNode *stripDebugLocFromLoopID(MDNode *N) { |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 283 | assert(N->op_begin() != N->op_end() && "Missing self reference?"); |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 284 | |
Teresa Johnson | 9b4b8c8 | 2017-03-19 13:54:57 +0000 | [diff] [blame] | 285 | // if there is no debug location, we do not have to rewrite this MDNode. |
| 286 | if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { |
| 287 | return isa<DILocation>(Op.get()); |
| 288 | })) |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 289 | return N; |
| 290 | |
Teresa Johnson | 9b4b8c8 | 2017-03-19 13:54:57 +0000 | [diff] [blame] | 291 | // If there is only the debug location without any actual loop metadata, we |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 292 | // can remove the metadata. |
Teresa Johnson | 9b4b8c8 | 2017-03-19 13:54:57 +0000 | [diff] [blame] | 293 | if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { |
| 294 | return !isa<DILocation>(Op.get()); |
| 295 | })) |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 296 | return nullptr; |
| 297 | |
| 298 | SmallVector<Metadata *, 4> Args; |
| 299 | // Reserve operand 0 for loop id self reference. |
| 300 | auto TempNode = MDNode::getTemporary(N->getContext(), None); |
| 301 | Args.push_back(TempNode.get()); |
Teresa Johnson | 9b4b8c8 | 2017-03-19 13:54:57 +0000 | [diff] [blame] | 302 | // Add all non-debug location operands back. |
| 303 | for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) { |
| 304 | if (!isa<DILocation>(*Op)) |
| 305 | Args.push_back(*Op); |
| 306 | } |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 307 | |
| 308 | // Set the first operand to itself. |
| 309 | MDNode *LoopID = MDNode::get(N->getContext(), Args); |
| 310 | LoopID->replaceOperandWith(0, LoopID); |
| 311 | return LoopID; |
| 312 | } |
| 313 | |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 314 | bool llvm::stripDebugInfo(Function &F) { |
| 315 | bool Changed = false; |
Benjamin Kramer | 0deb9a9 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 316 | if (F.hasMetadata(LLVMContext::MD_dbg)) { |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 317 | Changed = true; |
| 318 | F.setSubprogram(nullptr); |
| 319 | } |
Mehdi Amini | 581f0e1 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 320 | |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 321 | DenseMap<MDNode*, MDNode*> LoopIDsMap; |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 322 | for (BasicBlock &BB : F) { |
Mehdi Amini | 581f0e1 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 323 | for (auto II = BB.begin(), End = BB.end(); II != End;) { |
| 324 | Instruction &I = *II++; // We may delete the instruction, increment now. |
Mehdi Amini | db8dd55 | 2016-05-14 04:58:35 +0000 | [diff] [blame] | 325 | if (isa<DbgInfoIntrinsic>(&I)) { |
| 326 | I.eraseFromParent(); |
Mehdi Amini | 581f0e1 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 327 | Changed = true; |
Mehdi Amini | bbedb14 | 2016-05-07 05:07:47 +0000 | [diff] [blame] | 328 | continue; |
Mehdi Amini | 581f0e1 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 329 | } |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 330 | if (I.getDebugLoc()) { |
| 331 | Changed = true; |
| 332 | I.setDebugLoc(DebugLoc()); |
| 333 | } |
| 334 | } |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 335 | |
| 336 | auto *TermInst = BB.getTerminator(); |
Justin Bogner | b29bebe | 2017-08-18 21:38:03 +0000 | [diff] [blame] | 337 | if (!TermInst) |
| 338 | // This is invalid IR, but we may not have run the verifier yet |
| 339 | continue; |
Daniel Sanders | b96a945 | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 340 | if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) { |
| 341 | auto *NewLoopID = LoopIDsMap.lookup(LoopID); |
| 342 | if (!NewLoopID) |
| 343 | NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID); |
| 344 | if (NewLoopID != LoopID) |
| 345 | TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID); |
| 346 | } |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 347 | } |
| 348 | return Changed; |
| 349 | } |
| 350 | |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 351 | bool llvm::StripDebugInfo(Module &M) { |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 352 | bool Changed = false; |
| 353 | |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 354 | for (Module::named_metadata_iterator NMI = M.named_metadata_begin(), |
| 355 | NME = M.named_metadata_end(); NMI != NME;) { |
Duncan P. N. Exon Smith | 52888a6 | 2015-10-08 23:49:46 +0000 | [diff] [blame] | 356 | NamedMDNode *NMD = &*NMI; |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 357 | ++NMI; |
Davide Italiano | 84bd58e | 2016-10-17 20:05:35 +0000 | [diff] [blame] | 358 | |
| 359 | // We're stripping debug info, and without them, coverage information |
| 360 | // doesn't quite make sense. |
| 361 | if (NMD->getName().startswith("llvm.dbg.") || |
| 362 | NMD->getName() == "llvm.gcov") { |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 363 | NMD->eraseFromParent(); |
| 364 | Changed = true; |
| 365 | } |
| 366 | } |
| 367 | |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 368 | for (Function &F : M) |
| 369 | Changed |= stripDebugInfo(F); |
| 370 | |
Adrian Prantl | 3bfe109 | 2016-10-10 17:53:33 +0000 | [diff] [blame] | 371 | for (auto &GV : M.globals()) { |
Benjamin Kramer | 0deb9a9 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 372 | Changed |= GV.eraseMetadata(LLVMContext::MD_dbg); |
Adrian Prantl | 3bfe109 | 2016-10-10 17:53:33 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Rafael Espindola | 468b868 | 2015-04-01 14:44:59 +0000 | [diff] [blame] | 375 | if (GVMaterializer *Materializer = M.getMaterializer()) |
Rafael Espindola | 0d68b4c | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 376 | Materializer->setStripDebugInfo(); |
Manman Ren | cb14bbc | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 377 | |
| 378 | return Changed; |
| 379 | } |
Manman Ren | 8b4306c | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 380 | |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 381 | namespace { |
| 382 | |
| 383 | /// Helper class to downgrade -g metadata to -gline-tables-only metadata. |
| 384 | class DebugTypeInfoRemoval { |
| 385 | DenseMap<Metadata *, Metadata *> Replacements; |
| 386 | |
| 387 | public: |
| 388 | /// The (void)() type. |
| 389 | MDNode *EmptySubroutineType; |
| 390 | |
| 391 | private: |
| 392 | /// Remember what linkage name we originally had before stripping. If we end |
| 393 | /// up making two subprograms identical who originally had different linkage |
| 394 | /// names, then we need to make one of them distinct, to avoid them getting |
| 395 | /// uniqued. Maps the new node to the old linkage name. |
| 396 | DenseMap<DISubprogram *, StringRef> NewToLinkageName; |
| 397 | |
| 398 | // TODO: Remember the distinct subprogram we created for a given linkage name, |
| 399 | // so that we can continue to unique whenever possible. Map <newly created |
| 400 | // node, old linkage name> to the first (possibly distinct) mdsubprogram |
| 401 | // created for that combination. This is not strictly needed for correctness, |
| 402 | // but can cut down on the number of MDNodes and let us diff cleanly with the |
| 403 | // output of -gline-tables-only. |
| 404 | |
| 405 | public: |
| 406 | DebugTypeInfoRemoval(LLVMContext &C) |
| 407 | : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0, |
| 408 | MDNode::get(C, {}))) {} |
| 409 | |
| 410 | Metadata *map(Metadata *M) { |
| 411 | if (!M) |
| 412 | return nullptr; |
| 413 | auto Replacement = Replacements.find(M); |
| 414 | if (Replacement != Replacements.end()) |
| 415 | return Replacement->second; |
| 416 | |
| 417 | return M; |
| 418 | } |
| 419 | MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); } |
| 420 | |
| 421 | /// Recursively remap N and all its referenced children. Does a DF post-order |
| 422 | /// traversal, so as to remap bottoms up. |
| 423 | void traverseAndRemap(MDNode *N) { traverse(N); } |
| 424 | |
| 425 | private: |
| 426 | // Create a new DISubprogram, to replace the one given. |
| 427 | DISubprogram *getReplacementSubprogram(DISubprogram *MDS) { |
| 428 | auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile())); |
| 429 | StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : ""; |
| 430 | DISubprogram *Declaration = nullptr; |
| 431 | auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType())); |
| 432 | DITypeRef ContainingType(map(MDS->getContainingType())); |
| 433 | auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit())); |
| 434 | auto Variables = nullptr; |
| 435 | auto TemplateParams = nullptr; |
| 436 | |
| 437 | // Make a distinct DISubprogram, for situations that warrent it. |
| 438 | auto distinctMDSubprogram = [&]() { |
| 439 | return DISubprogram::getDistinct( |
| 440 | MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, |
| 441 | FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(), |
| 442 | MDS->isDefinition(), MDS->getScopeLine(), ContainingType, |
| 443 | MDS->getVirtuality(), MDS->getVirtualIndex(), |
| 444 | MDS->getThisAdjustment(), MDS->getFlags(), MDS->isOptimized(), Unit, |
| 445 | TemplateParams, Declaration, Variables); |
| 446 | }; |
| 447 | |
| 448 | if (MDS->isDistinct()) |
| 449 | return distinctMDSubprogram(); |
| 450 | |
| 451 | auto *NewMDS = DISubprogram::get( |
| 452 | MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, |
| 453 | FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(), |
| 454 | MDS->isDefinition(), MDS->getScopeLine(), ContainingType, |
| 455 | MDS->getVirtuality(), MDS->getVirtualIndex(), MDS->getThisAdjustment(), |
| 456 | MDS->getFlags(), MDS->isOptimized(), Unit, TemplateParams, Declaration, |
| 457 | Variables); |
| 458 | |
| 459 | StringRef OldLinkageName = MDS->getLinkageName(); |
| 460 | |
| 461 | // See if we need to make a distinct one. |
| 462 | auto OrigLinkage = NewToLinkageName.find(NewMDS); |
| 463 | if (OrigLinkage != NewToLinkageName.end()) { |
| 464 | if (OrigLinkage->second == OldLinkageName) |
| 465 | // We're good. |
| 466 | return NewMDS; |
| 467 | |
| 468 | // Otherwise, need to make a distinct one. |
| 469 | // TODO: Query the map to see if we already have one. |
| 470 | return distinctMDSubprogram(); |
| 471 | } |
| 472 | |
| 473 | NewToLinkageName.insert({NewMDS, MDS->getLinkageName()}); |
| 474 | return NewMDS; |
| 475 | } |
| 476 | |
| 477 | /// Create a new compile unit, to replace the one given |
| 478 | DICompileUnit *getReplacementCU(DICompileUnit *CU) { |
| 479 | // Drop skeleton CUs. |
| 480 | if (CU->getDWOId()) |
| 481 | return nullptr; |
| 482 | |
| 483 | auto *File = cast_or_null<DIFile>(map(CU->getFile())); |
| 484 | MDTuple *EnumTypes = nullptr; |
| 485 | MDTuple *RetainedTypes = nullptr; |
| 486 | MDTuple *GlobalVariables = nullptr; |
| 487 | MDTuple *ImportedEntities = nullptr; |
| 488 | return DICompileUnit::getDistinct( |
| 489 | CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(), |
| 490 | CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(), |
| 491 | CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes, |
| 492 | RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(), |
Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 493 | CU->getDWOId(), CU->getSplitDebugInlining(), |
David Blaikie | 66cf14d | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 494 | CU->getDebugInfoForProfiling(), CU->getNameTableKind()); |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | DILocation *getReplacementMDLocation(DILocation *MLD) { |
| 498 | auto *Scope = map(MLD->getScope()); |
| 499 | auto *InlinedAt = map(MLD->getInlinedAt()); |
| 500 | if (MLD->isDistinct()) |
| 501 | return DILocation::getDistinct(MLD->getContext(), MLD->getLine(), |
| 502 | MLD->getColumn(), Scope, InlinedAt); |
| 503 | return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(), |
| 504 | Scope, InlinedAt); |
| 505 | } |
| 506 | |
| 507 | /// Create a new generic MDNode, to replace the one given |
| 508 | MDNode *getReplacementMDNode(MDNode *N) { |
| 509 | SmallVector<Metadata *, 8> Ops; |
| 510 | Ops.reserve(N->getNumOperands()); |
| 511 | for (auto &I : N->operands()) |
| 512 | if (I) |
| 513 | Ops.push_back(map(I)); |
| 514 | auto *Ret = MDNode::get(N->getContext(), Ops); |
| 515 | return Ret; |
| 516 | } |
| 517 | |
| 518 | /// Attempt to re-map N to a newly created node. |
| 519 | void remap(MDNode *N) { |
| 520 | if (Replacements.count(N)) |
| 521 | return; |
| 522 | |
| 523 | auto doRemap = [&](MDNode *N) -> MDNode * { |
| 524 | if (!N) |
| 525 | return nullptr; |
| 526 | if (auto *MDSub = dyn_cast<DISubprogram>(N)) { |
| 527 | remap(MDSub->getUnit()); |
| 528 | return getReplacementSubprogram(MDSub); |
| 529 | } |
| 530 | if (isa<DISubroutineType>(N)) |
| 531 | return EmptySubroutineType; |
| 532 | if (auto *CU = dyn_cast<DICompileUnit>(N)) |
| 533 | return getReplacementCU(CU); |
| 534 | if (isa<DIFile>(N)) |
| 535 | return N; |
| 536 | if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N)) |
| 537 | // Remap to our referenced scope (recursively). |
| 538 | return mapNode(MDLB->getScope()); |
| 539 | if (auto *MLD = dyn_cast<DILocation>(N)) |
| 540 | return getReplacementMDLocation(MLD); |
| 541 | |
| 542 | // Otherwise, if we see these, just drop them now. Not strictly necessary, |
| 543 | // but this speeds things up a little. |
| 544 | if (isa<DINode>(N)) |
| 545 | return nullptr; |
| 546 | |
| 547 | return getReplacementMDNode(N); |
| 548 | }; |
| 549 | Replacements[N] = doRemap(N); |
| 550 | } |
| 551 | |
| 552 | /// Do the remapping traversal. |
| 553 | void traverse(MDNode *); |
| 554 | }; |
| 555 | |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 556 | } // end anonymous namespace |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 557 | |
| 558 | void DebugTypeInfoRemoval::traverse(MDNode *N) { |
| 559 | if (!N || Replacements.count(N)) |
| 560 | return; |
| 561 | |
| 562 | // To avoid cycles, as well as for efficiency sake, we will sometimes prune |
| 563 | // parts of the graph. |
| 564 | auto prune = [](MDNode *Parent, MDNode *Child) { |
| 565 | if (auto *MDS = dyn_cast<DISubprogram>(Parent)) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 566 | return Child == MDS->getRetainedNodes().get(); |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 567 | return false; |
| 568 | }; |
| 569 | |
| 570 | SmallVector<MDNode *, 16> ToVisit; |
| 571 | DenseSet<MDNode *> Opened; |
| 572 | |
| 573 | // Visit each node starting at N in post order, and map them. |
| 574 | ToVisit.push_back(N); |
| 575 | while (!ToVisit.empty()) { |
| 576 | auto *N = ToVisit.back(); |
| 577 | if (!Opened.insert(N).second) { |
| 578 | // Close it. |
| 579 | remap(N); |
| 580 | ToVisit.pop_back(); |
| 581 | continue; |
| 582 | } |
| 583 | for (auto &I : N->operands()) |
| 584 | if (auto *MDN = dyn_cast_or_null<MDNode>(I)) |
| 585 | if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) && |
| 586 | !isa<DICompileUnit>(MDN)) |
| 587 | ToVisit.push_back(MDN); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | bool llvm::stripNonLineTableDebugInfo(Module &M) { |
| 592 | bool Changed = false; |
| 593 | |
| 594 | // First off, delete the debug intrinsics. |
| 595 | auto RemoveUses = [&](StringRef Name) { |
| 596 | if (auto *DbgVal = M.getFunction(Name)) { |
| 597 | while (!DbgVal->use_empty()) |
| 598 | cast<Instruction>(DbgVal->user_back())->eraseFromParent(); |
| 599 | DbgVal->eraseFromParent(); |
| 600 | Changed = true; |
| 601 | } |
| 602 | }; |
| 603 | RemoveUses("llvm.dbg.declare"); |
| 604 | RemoveUses("llvm.dbg.value"); |
| 605 | |
| 606 | // Delete non-CU debug info named metadata nodes. |
| 607 | for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end(); |
| 608 | NMI != NME;) { |
| 609 | NamedMDNode *NMD = &*NMI; |
| 610 | ++NMI; |
| 611 | // Specifically keep dbg.cu around. |
| 612 | if (NMD->getName() == "llvm.dbg.cu") |
| 613 | continue; |
| 614 | } |
| 615 | |
| 616 | // Drop all dbg attachments from global variables. |
| 617 | for (auto &GV : M.globals()) |
| 618 | GV.eraseMetadata(LLVMContext::MD_dbg); |
| 619 | |
| 620 | DebugTypeInfoRemoval Mapper(M.getContext()); |
Eugene Zelenko | f53a7b4 | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 621 | auto remap = [&](MDNode *Node) -> MDNode * { |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 622 | if (!Node) |
| 623 | return nullptr; |
| 624 | Mapper.traverseAndRemap(Node); |
| 625 | auto *NewNode = Mapper.mapNode(Node); |
| 626 | Changed |= Node != NewNode; |
| 627 | Node = NewNode; |
| 628 | return NewNode; |
| 629 | }; |
| 630 | |
| 631 | // Rewrite the DebugLocs to be equivalent to what |
| 632 | // -gline-tables-only would have created. |
| 633 | for (auto &F : M) { |
| 634 | if (auto *SP = F.getSubprogram()) { |
| 635 | Mapper.traverseAndRemap(SP); |
| 636 | auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP)); |
| 637 | Changed |= SP != NewSP; |
| 638 | F.setSubprogram(NewSP); |
| 639 | } |
| 640 | for (auto &BB : F) { |
| 641 | for (auto &I : BB) { |
Adrian Prantl | 346dcaf | 2017-03-30 20:10:56 +0000 | [diff] [blame] | 642 | auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc { |
| 643 | auto *Scope = DL.getScope(); |
| 644 | MDNode *InlinedAt = DL.getInlinedAt(); |
| 645 | Scope = remap(Scope); |
| 646 | InlinedAt = remap(InlinedAt); |
| 647 | return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt); |
| 648 | }; |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 649 | |
Adrian Prantl | 346dcaf | 2017-03-30 20:10:56 +0000 | [diff] [blame] | 650 | if (I.getDebugLoc() != DebugLoc()) |
| 651 | I.setDebugLoc(remapDebugLoc(I.getDebugLoc())); |
| 652 | |
| 653 | // Remap DILocations in untyped MDNodes (e.g., llvm.loop). |
| 654 | SmallVector<std::pair<unsigned, MDNode *>, 2> MDs; |
| 655 | I.getAllMetadata(MDs); |
| 656 | for (auto Attachment : MDs) |
| 657 | if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second)) |
| 658 | for (unsigned N = 0; N < T->getNumOperands(); ++N) |
| 659 | if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N))) |
| 660 | if (Loc != DebugLoc()) |
| 661 | T->replaceOperandWith(N, remapDebugLoc(Loc)); |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | // Create a new llvm.dbg.cu, which is equivalent to the one |
| 667 | // -gline-tables-only would have created. |
| 668 | for (auto &NMD : M.getNamedMDList()) { |
| 669 | SmallVector<MDNode *, 8> Ops; |
| 670 | for (MDNode *Op : NMD.operands()) |
| 671 | Ops.push_back(remap(Op)); |
Bjorn Pettersson | aa02580 | 2018-07-03 12:39:52 +0000 | [diff] [blame] | 672 | |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 673 | if (!Changed) |
| 674 | continue; |
Bjorn Pettersson | aa02580 | 2018-07-03 12:39:52 +0000 | [diff] [blame] | 675 | |
Michael Ilseman | e542804 | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 676 | NMD.clearOperands(); |
| 677 | for (auto *Op : Ops) |
| 678 | if (Op) |
| 679 | NMD.addOperand(Op); |
| 680 | } |
| 681 | return Changed; |
| 682 | } |
| 683 | |
Manman Ren | bd4daf8 | 2013-12-03 00:12:14 +0000 | [diff] [blame] | 684 | unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) { |
David Majnemer | e7a9cdb | 2015-02-16 06:04:53 +0000 | [diff] [blame] | 685 | if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>( |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 686 | M.getModuleFlag("Debug Info Version"))) |
| 687 | return Val->getZExtValue(); |
| 688 | return 0; |
Manman Ren | 8b4306c | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 689 | } |
Dehao Chen | f464627 | 2017-10-02 18:13:14 +0000 | [diff] [blame] | 690 | |
| 691 | void Instruction::applyMergedLocation(const DILocation *LocA, |
| 692 | const DILocation *LocB) { |
David Blaikie | 2a813ef | 2018-08-23 22:35:58 +0000 | [diff] [blame] | 693 | setDebugLoc(DILocation::getMergedLocation(LocA, LocB)); |
Dehao Chen | f464627 | 2017-10-02 18:13:14 +0000 | [diff] [blame] | 694 | } |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 695 | |
| 696 | //===----------------------------------------------------------------------===// |
| 697 | // LLVM C API implementations. |
| 698 | //===----------------------------------------------------------------------===// |
| 699 | |
| 700 | static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang) { |
| 701 | switch (lang) { |
| 702 | #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \ |
| 703 | case LLVMDWARFSourceLanguage##NAME: return ID; |
| 704 | #include "llvm/BinaryFormat/Dwarf.def" |
| 705 | #undef HANDLE_DW_LANG |
| 706 | } |
| 707 | llvm_unreachable("Unhandled Tag"); |
| 708 | } |
| 709 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 710 | template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) { |
| 711 | return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr); |
| 712 | } |
| 713 | |
| 714 | static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) { |
| 715 | return static_cast<DINode::DIFlags>(Flags); |
| 716 | } |
| 717 | |
Robert Widmann | 260b581 | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 718 | static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) { |
| 719 | return static_cast<LLVMDIFlags>(Flags); |
| 720 | } |
| 721 | |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 722 | unsigned LLVMDebugMetadataVersion() { |
| 723 | return DEBUG_METADATA_VERSION; |
| 724 | } |
| 725 | |
| 726 | LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M) { |
| 727 | return wrap(new DIBuilder(*unwrap(M), false)); |
| 728 | } |
| 729 | |
| 730 | LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M) { |
| 731 | return wrap(new DIBuilder(*unwrap(M))); |
| 732 | } |
| 733 | |
| 734 | unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M) { |
| 735 | return getDebugMetadataVersionFromModule(*unwrap(M)); |
| 736 | } |
| 737 | |
| 738 | LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M) { |
| 739 | return StripDebugInfo(*unwrap(M)); |
| 740 | } |
| 741 | |
| 742 | void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder) { |
| 743 | delete unwrap(Builder); |
| 744 | } |
| 745 | |
| 746 | void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder) { |
| 747 | unwrap(Builder)->finalize(); |
| 748 | } |
| 749 | |
| 750 | LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( |
| 751 | LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, |
| 752 | LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, |
| 753 | LLVMBool isOptimized, const char *Flags, size_t FlagsLen, |
| 754 | unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, |
| 755 | LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, |
| 756 | LLVMBool DebugInfoForProfiling) { |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 757 | auto File = unwrapDI<DIFile>(FileRef); |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 758 | |
| 759 | return wrap(unwrap(Builder)->createCompileUnit( |
| 760 | map_from_llvmDWARFsourcelanguage(Lang), File, |
| 761 | StringRef(Producer, ProducerLen), isOptimized, |
| 762 | StringRef(Flags, FlagsLen), RuntimeVer, |
| 763 | StringRef(SplitName, SplitNameLen), |
| 764 | static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId, |
| 765 | SplitDebugInlining, DebugInfoForProfiling)); |
| 766 | } |
| 767 | |
| 768 | LLVMMetadataRef |
| 769 | LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, |
| 770 | size_t FilenameLen, const char *Directory, |
| 771 | size_t DirectoryLen) { |
| 772 | return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen), |
| 773 | StringRef(Directory, DirectoryLen))); |
| 774 | } |
| 775 | |
Robert Widmann | b02fe64 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 776 | LLVMMetadataRef |
| 777 | LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, |
| 778 | const char *Name, size_t NameLen, |
| 779 | const char *ConfigMacros, size_t ConfigMacrosLen, |
| 780 | const char *IncludePath, size_t IncludePathLen, |
| 781 | const char *ISysRoot, size_t ISysRootLen) { |
| 782 | return wrap(unwrap(Builder)->createModule( |
| 783 | unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), |
| 784 | StringRef(ConfigMacros, ConfigMacrosLen), |
| 785 | StringRef(IncludePath, IncludePathLen), |
| 786 | StringRef(ISysRoot, ISysRootLen))); |
| 787 | } |
| 788 | |
| 789 | LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, |
| 790 | LLVMMetadataRef ParentScope, |
| 791 | const char *Name, size_t NameLen, |
| 792 | LLVMBool ExportSymbols) { |
| 793 | return wrap(unwrap(Builder)->createNameSpace( |
| 794 | unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols)); |
| 795 | } |
| 796 | |
Robert Widmann | f53050f | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 797 | LLVMMetadataRef LLVMDIBuilderCreateFunction( |
| 798 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 799 | size_t NameLen, const char *LinkageName, size_t LinkageNameLen, |
| 800 | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 801 | LLVMBool IsLocalToUnit, LLVMBool IsDefinition, |
| 802 | unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) { |
| 803 | return wrap(unwrap(Builder)->createFunction( |
| 804 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen}, |
| 805 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), |
| 806 | IsLocalToUnit, IsDefinition, ScopeLine, map_from_llvmDIFlags(Flags), |
| 807 | IsOptimized, nullptr, nullptr, nullptr)); |
| 808 | } |
| 809 | |
| 810 | |
| 811 | LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( |
| 812 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 813 | LLVMMetadataRef File, unsigned Line, unsigned Col) { |
| 814 | return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope), |
| 815 | unwrapDI<DIFile>(File), |
| 816 | Line, Col)); |
| 817 | } |
| 818 | |
| 819 | LLVMMetadataRef |
| 820 | LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, |
| 821 | LLVMMetadataRef Scope, |
| 822 | LLVMMetadataRef File, |
| 823 | unsigned Discriminator) { |
| 824 | return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope), |
| 825 | unwrapDI<DIFile>(File), |
| 826 | Discriminator)); |
| 827 | } |
| 828 | |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 829 | LLVMMetadataRef |
Robert Widmann | aec494f3 | 2018-04-28 22:32:07 +0000 | [diff] [blame] | 830 | LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, |
| 831 | LLVMMetadataRef Scope, |
| 832 | LLVMMetadataRef NS, |
| 833 | LLVMMetadataRef File, |
| 834 | unsigned Line) { |
| 835 | return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope), |
| 836 | unwrapDI<DINamespace>(NS), |
| 837 | unwrapDI<DIFile>(File), |
| 838 | Line)); |
| 839 | } |
| 840 | |
| 841 | LLVMMetadataRef |
| 842 | LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, |
| 843 | LLVMMetadataRef Scope, |
| 844 | LLVMMetadataRef ImportedEntity, |
| 845 | LLVMMetadataRef File, |
| 846 | unsigned Line) { |
| 847 | return wrap(unwrap(Builder)->createImportedModule( |
| 848 | unwrapDI<DIScope>(Scope), |
| 849 | unwrapDI<DIImportedEntity>(ImportedEntity), |
| 850 | unwrapDI<DIFile>(File), Line)); |
| 851 | } |
| 852 | |
| 853 | LLVMMetadataRef |
| 854 | LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, |
| 855 | LLVMMetadataRef Scope, |
| 856 | LLVMMetadataRef M, |
| 857 | LLVMMetadataRef File, |
| 858 | unsigned Line) { |
| 859 | return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope), |
| 860 | unwrapDI<DIModule>(M), |
| 861 | unwrapDI<DIFile>(File), |
| 862 | Line)); |
| 863 | } |
| 864 | |
| 865 | LLVMMetadataRef |
| 866 | LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, |
| 867 | LLVMMetadataRef Scope, |
| 868 | LLVMMetadataRef Decl, |
| 869 | LLVMMetadataRef File, |
| 870 | unsigned Line, |
| 871 | const char *Name, size_t NameLen) { |
| 872 | return wrap(unwrap(Builder)->createImportedDeclaration( |
| 873 | unwrapDI<DIScope>(Scope), |
| 874 | unwrapDI<DINode>(Decl), |
| 875 | unwrapDI<DIFile>(File), Line, {Name, NameLen})); |
| 876 | } |
| 877 | |
| 878 | LLVMMetadataRef |
whitequark | 789164d | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 879 | LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, |
| 880 | unsigned Column, LLVMMetadataRef Scope, |
| 881 | LLVMMetadataRef InlinedAt) { |
| 882 | return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope), |
| 883 | unwrap(InlinedAt))); |
| 884 | } |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 885 | |
Robert Widmann | 260b581 | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 886 | unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) { |
| 887 | return unwrapDI<DILocation>(Location)->getLine(); |
| 888 | } |
| 889 | |
| 890 | unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) { |
| 891 | return unwrapDI<DILocation>(Location)->getColumn(); |
| 892 | } |
| 893 | |
| 894 | LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) { |
| 895 | return wrap(unwrapDI<DILocation>(Location)->getScope()); |
| 896 | } |
| 897 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 898 | LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( |
| 899 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 900 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 901 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 902 | unsigned NumElements, LLVMMetadataRef ClassTy) { |
| 903 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 904 | NumElements}); |
| 905 | return wrap(unwrap(Builder)->createEnumerationType( |
| 906 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 907 | LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy))); |
| 908 | } |
| 909 | |
| 910 | LLVMMetadataRef LLVMDIBuilderCreateUnionType( |
| 911 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 912 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 913 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 914 | LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, |
| 915 | const char *UniqueId, size_t UniqueIdLen) { |
| 916 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 917 | NumElements}); |
| 918 | return wrap(unwrap(Builder)->createUnionType( |
| 919 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 920 | LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), |
| 921 | Elts, RunTimeLang, {UniqueId, UniqueIdLen})); |
| 922 | } |
| 923 | |
| 924 | |
| 925 | LLVMMetadataRef |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 926 | LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, |
| 927 | uint32_t AlignInBits, LLVMMetadataRef Ty, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 928 | LLVMMetadataRef *Subscripts, |
| 929 | unsigned NumSubscripts) { |
| 930 | auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), |
| 931 | NumSubscripts}); |
| 932 | return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits, |
| 933 | unwrapDI<DIType>(Ty), Subs)); |
| 934 | } |
| 935 | |
| 936 | LLVMMetadataRef |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 937 | LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, |
| 938 | uint32_t AlignInBits, LLVMMetadataRef Ty, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 939 | LLVMMetadataRef *Subscripts, |
| 940 | unsigned NumSubscripts) { |
| 941 | auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), |
| 942 | NumSubscripts}); |
| 943 | return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits, |
| 944 | unwrapDI<DIType>(Ty), Subs)); |
| 945 | } |
| 946 | |
| 947 | LLVMMetadataRef |
| 948 | LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 949 | size_t NameLen, uint64_t SizeInBits, |
whitequark | b56a4d3 | 2018-08-19 23:39:47 +0000 | [diff] [blame] | 950 | LLVMDWARFTypeEncoding Encoding, |
| 951 | LLVMDIFlags Flags) { |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 952 | return wrap(unwrap(Builder)->createBasicType({Name, NameLen}, |
whitequark | b56a4d3 | 2018-08-19 23:39:47 +0000 | [diff] [blame] | 953 | SizeInBits, Encoding, |
| 954 | map_from_llvmDIFlags(Flags))); |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | LLVMMetadataRef LLVMDIBuilderCreatePointerType( |
| 958 | LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 959 | uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 960 | const char *Name, size_t NameLen) { |
| 961 | return wrap(unwrap(Builder)->createPointerType(unwrapDI<DIType>(PointeeTy), |
| 962 | SizeInBits, AlignInBits, |
| 963 | AddressSpace, {Name, NameLen})); |
| 964 | } |
| 965 | |
| 966 | LLVMMetadataRef LLVMDIBuilderCreateStructType( |
| 967 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 968 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 969 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 970 | LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, |
| 971 | unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, |
| 972 | const char *UniqueId, size_t UniqueIdLen) { |
| 973 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 974 | NumElements}); |
| 975 | return wrap(unwrap(Builder)->createStructType( |
| 976 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 977 | LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), |
| 978 | unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang, |
| 979 | unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen})); |
| 980 | } |
| 981 | |
| 982 | LLVMMetadataRef LLVMDIBuilderCreateMemberType( |
| 983 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 984 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, |
| 985 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 986 | LLVMMetadataRef Ty) { |
| 987 | return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope), |
| 988 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, |
| 989 | OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty))); |
| 990 | } |
| 991 | |
| 992 | LLVMMetadataRef |
| 993 | LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, |
| 994 | size_t NameLen) { |
| 995 | return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen})); |
| 996 | } |
| 997 | |
| 998 | LLVMMetadataRef |
| 999 | LLVMDIBuilderCreateStaticMemberType( |
| 1000 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1001 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 1002 | LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1003 | uint32_t AlignInBits) { |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1004 | return wrap(unwrap(Builder)->createStaticMemberType( |
| 1005 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1006 | unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type), |
| 1007 | map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal), |
| 1008 | AlignInBits)); |
| 1009 | } |
| 1010 | |
| 1011 | LLVMMetadataRef |
Robert Widmann | 38fa750 | 2018-05-21 16:27:35 +0000 | [diff] [blame] | 1012 | LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, |
| 1013 | const char *Name, size_t NameLen, |
| 1014 | LLVMMetadataRef File, unsigned LineNo, |
| 1015 | uint64_t SizeInBits, uint32_t AlignInBits, |
| 1016 | uint64_t OffsetInBits, LLVMDIFlags Flags, |
| 1017 | LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) { |
| 1018 | return wrap(unwrap(Builder)->createObjCIVar( |
| 1019 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, |
| 1020 | SizeInBits, AlignInBits, OffsetInBits, |
| 1021 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty), |
| 1022 | unwrapDI<MDNode>(PropertyNode))); |
| 1023 | } |
| 1024 | |
| 1025 | LLVMMetadataRef |
| 1026 | LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, |
| 1027 | const char *Name, size_t NameLen, |
| 1028 | LLVMMetadataRef File, unsigned LineNo, |
| 1029 | const char *GetterName, size_t GetterNameLen, |
| 1030 | const char *SetterName, size_t SetterNameLen, |
| 1031 | unsigned PropertyAttributes, |
| 1032 | LLVMMetadataRef Ty) { |
| 1033 | return wrap(unwrap(Builder)->createObjCProperty( |
| 1034 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, |
| 1035 | {GetterName, GetterNameLen}, {SetterName, SetterNameLen}, |
| 1036 | PropertyAttributes, unwrapDI<DIType>(Ty))); |
| 1037 | } |
| 1038 | |
| 1039 | LLVMMetadataRef |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1040 | LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, |
| 1041 | LLVMMetadataRef Type) { |
| 1042 | return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type))); |
| 1043 | } |
| 1044 | |
| 1045 | LLVMMetadataRef |
Robert Widmann | 4b0084b | 2018-05-10 21:10:06 +0000 | [diff] [blame] | 1046 | LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, |
| 1047 | const char *Name, size_t NameLen, |
| 1048 | LLVMMetadataRef File, unsigned LineNo, |
| 1049 | LLVMMetadataRef Scope) { |
| 1050 | return wrap(unwrap(Builder)->createTypedef( |
| 1051 | unwrapDI<DIType>(Type), {Name, NameLen}, |
| 1052 | unwrapDI<DIFile>(File), LineNo, |
| 1053 | unwrapDI<DIScope>(Scope))); |
| 1054 | } |
| 1055 | |
| 1056 | LLVMMetadataRef |
Robert Widmann | 38fa750 | 2018-05-21 16:27:35 +0000 | [diff] [blame] | 1057 | LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, |
| 1058 | LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, |
| 1059 | uint64_t BaseOffset, uint32_t VBPtrOffset, |
| 1060 | LLVMDIFlags Flags) { |
| 1061 | return wrap(unwrap(Builder)->createInheritance( |
| 1062 | unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy), |
| 1063 | BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags))); |
| 1064 | } |
| 1065 | |
| 1066 | LLVMMetadataRef |
Robert Widmann | b02fe64 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 1067 | LLVMDIBuilderCreateForwardDecl( |
| 1068 | LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, |
| 1069 | size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1070 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
Robert Widmann | b02fe64 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 1071 | const char *UniqueIdentifier, size_t UniqueIdentifierLen) { |
| 1072 | return wrap(unwrap(Builder)->createForwardDecl( |
| 1073 | Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope), |
| 1074 | unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits, |
| 1075 | AlignInBits, {UniqueIdentifier, UniqueIdentifierLen})); |
| 1076 | } |
| 1077 | |
| 1078 | LLVMMetadataRef |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1079 | LLVMDIBuilderCreateReplaceableCompositeType( |
Harlan Haskins | bee4b58 | 2018-04-02 19:11:44 +0000 | [diff] [blame] | 1080 | LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, |
| 1081 | size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1082 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1083 | LLVMDIFlags Flags, const char *UniqueIdentifier, |
Harlan Haskins | bee4b58 | 2018-04-02 19:11:44 +0000 | [diff] [blame] | 1084 | size_t UniqueIdentifierLen) { |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1085 | return wrap(unwrap(Builder)->createReplaceableCompositeType( |
| 1086 | Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope), |
| 1087 | unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits, |
| 1088 | AlignInBits, map_from_llvmDIFlags(Flags), |
| 1089 | {UniqueIdentifier, UniqueIdentifierLen})); |
| 1090 | } |
| 1091 | |
| 1092 | LLVMMetadataRef |
| 1093 | LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, |
| 1094 | LLVMMetadataRef Type) { |
| 1095 | return wrap(unwrap(Builder)->createQualifiedType(Tag, |
| 1096 | unwrapDI<DIType>(Type))); |
| 1097 | } |
| 1098 | |
| 1099 | LLVMMetadataRef |
| 1100 | LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, |
| 1101 | LLVMMetadataRef Type) { |
| 1102 | return wrap(unwrap(Builder)->createReferenceType(Tag, |
| 1103 | unwrapDI<DIType>(Type))); |
| 1104 | } |
| 1105 | |
| 1106 | LLVMMetadataRef |
| 1107 | LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) { |
| 1108 | return wrap(unwrap(Builder)->createNullPtrType()); |
| 1109 | } |
| 1110 | |
| 1111 | LLVMMetadataRef |
| 1112 | LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, |
| 1113 | LLVMMetadataRef PointeeType, |
| 1114 | LLVMMetadataRef ClassType, |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1115 | uint64_t SizeInBits, |
| 1116 | uint32_t AlignInBits, |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1117 | LLVMDIFlags Flags) { |
| 1118 | return wrap(unwrap(Builder)->createMemberPointerType( |
| 1119 | unwrapDI<DIType>(PointeeType), |
| 1120 | unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits, |
| 1121 | map_from_llvmDIFlags(Flags))); |
| 1122 | } |
| 1123 | |
| 1124 | LLVMMetadataRef |
Robert Widmann | 2d2698c | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1125 | LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, |
| 1126 | LLVMMetadataRef Scope, |
| 1127 | const char *Name, size_t NameLen, |
| 1128 | LLVMMetadataRef File, unsigned LineNumber, |
| 1129 | uint64_t SizeInBits, |
| 1130 | uint64_t OffsetInBits, |
| 1131 | uint64_t StorageOffsetInBits, |
| 1132 | LLVMDIFlags Flags, LLVMMetadataRef Type) { |
| 1133 | return wrap(unwrap(Builder)->createBitFieldMemberType( |
| 1134 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1135 | unwrapDI<DIFile>(File), LineNumber, |
| 1136 | SizeInBits, OffsetInBits, StorageOffsetInBits, |
| 1137 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type))); |
| 1138 | } |
| 1139 | |
| 1140 | LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, |
| 1141 | LLVMMetadataRef Scope, const char *Name, size_t NameLen, |
| 1142 | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 1143 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, |
| 1144 | LLVMMetadataRef DerivedFrom, |
| 1145 | LLVMMetadataRef *Elements, unsigned NumElements, |
| 1146 | LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, |
| 1147 | const char *UniqueIdentifier, size_t UniqueIdentifierLen) { |
| 1148 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 1149 | NumElements}); |
| 1150 | return wrap(unwrap(Builder)->createClassType( |
| 1151 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1152 | unwrapDI<DIFile>(File), LineNumber, |
| 1153 | SizeInBits, AlignInBits, OffsetInBits, |
| 1154 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), |
| 1155 | Elts, unwrapDI<DIType>(VTableHolder), |
| 1156 | unwrapDI<MDNode>(TemplateParamsNode), |
| 1157 | {UniqueIdentifier, UniqueIdentifierLen})); |
| 1158 | } |
| 1159 | |
| 1160 | LLVMMetadataRef |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1161 | LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, |
| 1162 | LLVMMetadataRef Type) { |
| 1163 | return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type))); |
| 1164 | } |
| 1165 | |
Robert Widmann | 260b581 | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 1166 | const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) { |
| 1167 | StringRef Str = unwrap<DIType>(DType)->getName(); |
| 1168 | *Length = Str.size(); |
| 1169 | return Str.data(); |
| 1170 | } |
| 1171 | |
| 1172 | uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) { |
| 1173 | return unwrapDI<DIType>(DType)->getSizeInBits(); |
| 1174 | } |
| 1175 | |
| 1176 | uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) { |
| 1177 | return unwrapDI<DIType>(DType)->getOffsetInBits(); |
| 1178 | } |
| 1179 | |
| 1180 | uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) { |
| 1181 | return unwrapDI<DIType>(DType)->getAlignInBits(); |
| 1182 | } |
| 1183 | |
| 1184 | unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) { |
| 1185 | return unwrapDI<DIType>(DType)->getLine(); |
| 1186 | } |
| 1187 | |
| 1188 | LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) { |
| 1189 | return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags()); |
| 1190 | } |
| 1191 | |
Robert Widmann | 6978db7 | 2018-04-23 14:29:33 +0000 | [diff] [blame] | 1192 | LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, |
| 1193 | LLVMMetadataRef *Types, |
| 1194 | size_t Length) { |
| 1195 | return wrap( |
| 1196 | unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get()); |
| 1197 | } |
| 1198 | |
Harlan Haskins | b7881bb | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1199 | LLVMMetadataRef |
| 1200 | LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, |
| 1201 | LLVMMetadataRef File, |
| 1202 | LLVMMetadataRef *ParameterTypes, |
| 1203 | unsigned NumParameterTypes, |
| 1204 | LLVMDIFlags Flags) { |
| 1205 | auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes), |
| 1206 | NumParameterTypes}); |
| 1207 | return wrap(unwrap(Builder)->createSubroutineType( |
| 1208 | Elts, map_from_llvmDIFlags(Flags))); |
| 1209 | } |
Robert Widmann | f53050f | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 1210 | |
Robert Widmann | 12e367b | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1211 | LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, |
| 1212 | int64_t *Addr, size_t Length) { |
| 1213 | return wrap(unwrap(Builder)->createExpression(ArrayRef<int64_t>(Addr, |
| 1214 | Length))); |
| 1215 | } |
| 1216 | |
Robert Widmann | 21fc15d | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1217 | LLVMMetadataRef |
| 1218 | LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, |
| 1219 | int64_t Value) { |
| 1220 | return wrap(unwrap(Builder)->createConstantValueExpression(Value)); |
| 1221 | } |
| 1222 | |
| 1223 | LLVMMetadataRef |
| 1224 | LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder, |
| 1225 | LLVMMetadataRef Scope, |
| 1226 | const char *Name, size_t NameLen, |
| 1227 | const char *Linkage, size_t LinkLen, |
| 1228 | LLVMMetadataRef File, |
| 1229 | unsigned LineNo, |
| 1230 | LLVMMetadataRef Ty, |
| 1231 | LLVMBool LocalToUnit, |
| 1232 | LLVMMetadataRef Expr, |
| 1233 | LLVMMetadataRef Decl, |
| 1234 | uint32_t AlignInBits) { |
| 1235 | return wrap(unwrap(Builder)->createGlobalVariableExpression( |
| 1236 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen}, |
| 1237 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), |
| 1238 | LocalToUnit, unwrap<DIExpression>(Expr), |
| 1239 | unwrapDI<MDNode>(Decl), AlignInBits)); |
| 1240 | } |
| 1241 | |
Robert Widmann | a428eba | 2018-05-10 18:09:53 +0000 | [diff] [blame] | 1242 | LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, |
| 1243 | size_t Count) { |
| 1244 | return wrap( |
| 1245 | MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release()); |
| 1246 | } |
| 1247 | |
| 1248 | void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) { |
| 1249 | MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode)); |
| 1250 | } |
| 1251 | |
| 1252 | void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata, |
| 1253 | LLVMMetadataRef Replacement) { |
| 1254 | auto *Node = unwrapDI<MDNode>(TargetMetadata); |
| 1255 | Node->replaceAllUsesWith(unwrap<Metadata>(Replacement)); |
| 1256 | MDNode::deleteTemporary(Node); |
| 1257 | } |
| 1258 | |
Robert Widmann | 21fc15d | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1259 | LLVMMetadataRef |
| 1260 | LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder, |
| 1261 | LLVMMetadataRef Scope, |
| 1262 | const char *Name, size_t NameLen, |
| 1263 | const char *Linkage, size_t LnkLen, |
| 1264 | LLVMMetadataRef File, |
| 1265 | unsigned LineNo, |
| 1266 | LLVMMetadataRef Ty, |
| 1267 | LLVMBool LocalToUnit, |
| 1268 | LLVMMetadataRef Decl, |
| 1269 | uint32_t AlignInBits) { |
| 1270 | return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl( |
| 1271 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen}, |
| 1272 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), |
| 1273 | LocalToUnit, unwrapDI<MDNode>(Decl), AlignInBits)); |
| 1274 | } |
| 1275 | |
Robert Widmann | 12e367b | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1276 | LLVMValueRef LLVMDIBuilderInsertDeclareBefore( |
| 1277 | LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, |
| 1278 | LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) { |
| 1279 | return wrap(unwrap(Builder)->insertDeclare( |
| 1280 | unwrap(Storage), unwrap<DILocalVariable>(VarInfo), |
| 1281 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), |
| 1282 | unwrap<Instruction>(Instr))); |
| 1283 | } |
| 1284 | |
| 1285 | LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( |
| 1286 | LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, |
| 1287 | LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) { |
| 1288 | return wrap(unwrap(Builder)->insertDeclare( |
| 1289 | unwrap(Storage), unwrap<DILocalVariable>(VarInfo), |
| 1290 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), |
| 1291 | unwrap(Block))); |
| 1292 | } |
| 1293 | |
Robert Widmann | 21fc15d | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1294 | LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, |
| 1295 | LLVMValueRef Val, |
| 1296 | LLVMMetadataRef VarInfo, |
| 1297 | LLVMMetadataRef Expr, |
| 1298 | LLVMMetadataRef DebugLoc, |
| 1299 | LLVMValueRef Instr) { |
| 1300 | return wrap(unwrap(Builder)->insertDbgValueIntrinsic( |
| 1301 | unwrap(Val), unwrap<DILocalVariable>(VarInfo), |
| 1302 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), |
| 1303 | unwrap<Instruction>(Instr))); |
| 1304 | } |
| 1305 | |
| 1306 | LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, |
| 1307 | LLVMValueRef Val, |
| 1308 | LLVMMetadataRef VarInfo, |
| 1309 | LLVMMetadataRef Expr, |
| 1310 | LLVMMetadataRef DebugLoc, |
| 1311 | LLVMBasicBlockRef Block) { |
| 1312 | return wrap(unwrap(Builder)->insertDbgValueIntrinsic( |
| 1313 | unwrap(Val), unwrap<DILocalVariable>(VarInfo), |
| 1314 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), |
| 1315 | unwrap(Block))); |
| 1316 | } |
| 1317 | |
Robert Widmann | 12e367b | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1318 | LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( |
| 1319 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1320 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 1321 | LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) { |
| 1322 | return wrap(unwrap(Builder)->createAutoVariable( |
| 1323 | unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File), |
| 1324 | LineNo, unwrap<DIType>(Ty), AlwaysPreserve, |
| 1325 | map_from_llvmDIFlags(Flags), AlignInBits)); |
| 1326 | } |
| 1327 | |
| 1328 | LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( |
| 1329 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1330 | size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, |
| 1331 | LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) { |
| 1332 | return wrap(unwrap(Builder)->createParameterVariable( |
Robert Widmann | 106eab0 | 2018-08-25 19:54:39 +0000 | [diff] [blame] | 1333 | unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File), |
Robert Widmann | 12e367b | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1334 | LineNo, unwrap<DIType>(Ty), AlwaysPreserve, |
| 1335 | map_from_llvmDIFlags(Flags))); |
| 1336 | } |
| 1337 | |
Robert Widmann | 6978db7 | 2018-04-23 14:29:33 +0000 | [diff] [blame] | 1338 | LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, |
| 1339 | int64_t Lo, int64_t Count) { |
| 1340 | return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count)); |
| 1341 | } |
| 1342 | |
| 1343 | LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, |
| 1344 | LLVMMetadataRef *Data, |
| 1345 | size_t Length) { |
| 1346 | Metadata **DataValue = unwrap(Data); |
| 1347 | return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get()); |
| 1348 | } |
| 1349 | |
Robert Widmann | f53050f | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 1350 | LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) { |
| 1351 | return wrap(unwrap<Function>(Func)->getSubprogram()); |
| 1352 | } |
| 1353 | |
| 1354 | void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { |
| 1355 | unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP)); |
| 1356 | } |
Robert Widmann | abda7ee | 2018-10-01 13:15:09 +0000 | [diff] [blame] | 1357 | |
| 1358 | LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) { |
| 1359 | switch(unwrap(Metadata)->getMetadataID()) { |
| 1360 | #define HANDLE_METADATA_LEAF(CLASS) \ |
| 1361 | case Metadata::CLASS##Kind: \ |
| 1362 | return (LLVMMetadataKind)LLVM##CLASS##MetadataKind; |
| 1363 | #include "llvm/IR/Metadata.def" |
| 1364 | default: |
| 1365 | return (LLVMMetadataKind)LLVMGenericDINodeMetadataKind; |
| 1366 | } |
| 1367 | } |