Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 1 | //===- DebugInfo.cpp - Debug Information Helper Classes -------------------===// |
Bill Wendling | 5f72591 | 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 | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 15 | #include "llvm-c/DebugInfo.h" |
Eugene Zelenko | e5dc33d | 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 | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | e5dc33d | 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 | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Constants.h" |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 25 | #include "llvm/IR/DebugInfoMetadata.h" |
| 26 | #include "llvm/IR/DebugLoc.h" |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 27 | #include "llvm/IR/DebugInfo.h" |
| 28 | #include "llvm/IR/DIBuilder.h" |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Function.h" |
Mehdi Amini | f6071e1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 30 | #include "llvm/IR/GVMaterializer.h" |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 31 | #include "llvm/IR/Instruction.h" |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 32 | #include "llvm/IR/IntrinsicInst.h" |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 33 | #include "llvm/IR/LLVMContext.h" |
| 34 | #include "llvm/IR/Metadata.h" |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 35 | #include "llvm/IR/Module.h" |
Eugene Zelenko | e5dc33d | 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 | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 41 | using namespace llvm; |
| 42 | using namespace llvm::dwarf; |
| 43 | |
Duncan P. N. Exon Smith | e56023a | 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 | 81a8d62 | 2015-03-31 02:06:28 +0000 | [diff] [blame] | 46 | return LocalScope->getSubprogram(); |
| 47 | return nullptr; |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Bill Wendling | 5f72591 | 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 | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 63 | void DebugInfoFinder::processModule(const Module &M) { |
Roman Tereshin | 9899cf0 | 2018-04-13 21:23:11 +0000 | [diff] [blame] | 64 | for (auto *CU : M.debug_compile_units()) |
| 65 | processCompileUnit(CU); |
Keno Fischer | 1a17357 | 2017-04-11 13:32:11 +0000 | [diff] [blame] | 66 | for (auto &F : M.functions()) { |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 67 | if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram())) |
| 68 | processSubprogram(SP); |
Keno Fischer | 1a17357 | 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 | 9899cf0 | 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 | 1a17357 | 2017-04-11 13:32:11 +0000 | [diff] [blame] | 74 | } |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Roman Tereshin | 883750c | 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 | 883750c | 2018-04-13 21:22:24 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Roman Tereshin | 9899cf0 | 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 | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 118 | void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 119 | if (!Loc) |
| 120 | return; |
Duncan P. N. Exon Smith | d59e30d | 2015-04-14 01:35:55 +0000 | [diff] [blame] | 121 | processScope(Loc->getScope()); |
| 122 | processLocation(M, Loc->getInlinedAt()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 125 | void DebugInfoFinder::processType(DIType *DT) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 126 | if (!addType(DT)) |
| 127 | return; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 128 | processScope(DT->getScope().resolve()); |
Duncan P. N. Exon Smith | 24b6acf | 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 | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 131 | processType(Ref.resolve()); |
Duncan P. N. Exon Smith | 24b6acf | 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 | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 135 | processType(DCT->getBaseType().resolve()); |
Anders Waldenborg | 6ee1030 | 2015-04-14 09:18:17 +0000 | [diff] [blame] | 136 | for (Metadata *D : DCT->getElements()) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 137 | if (auto *T = dyn_cast<DIType>(D)) |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 138 | processType(T); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 139 | else if (auto *SP = dyn_cast<DISubprogram>(D)) |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 140 | processSubprogram(SP); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 141 | } |
Duncan P. N. Exon Smith | 24b6acf | 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 | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 145 | processType(DDT->getBaseType().resolve()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 149 | void DebugInfoFinder::processScope(DIScope *Scope) { |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 150 | if (!Scope) |
| 151 | return; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 152 | if (auto *Ty = dyn_cast<DIType>(Scope)) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 153 | processType(Ty); |
| 154 | return; |
| 155 | } |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 156 | if (auto *CU = dyn_cast<DICompileUnit>(Scope)) { |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 157 | addCompileUnit(CU); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 158 | return; |
| 159 | } |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 160 | if (auto *SP = dyn_cast<DISubprogram>(Scope)) { |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 161 | processSubprogram(SP); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | if (!addScope(Scope)) |
| 165 | return; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 166 | if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) { |
Duncan P. N. Exon Smith | 125e3d3 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 167 | processScope(LB->getScope()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 168 | } else if (auto *NS = dyn_cast<DINamespace>(Scope)) { |
Duncan P. N. Exon Smith | 41ed493 | 2015-04-14 03:01:27 +0000 | [diff] [blame] | 169 | processScope(NS->getScope()); |
Adrian Prantl | 7177647 | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 170 | } else if (auto *M = dyn_cast<DIModule>(Scope)) { |
| 171 | processScope(M->getScope()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 175 | void DebugInfoFinder::processSubprogram(DISubprogram *SP) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 176 | if (!addSubprogram(SP)) |
| 177 | return; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 178 | processScope(SP->getScope().resolve()); |
Roman Tereshin | 883750c | 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 | 125e3d3 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 188 | processType(SP->getType()); |
| 189 | for (auto *Element : SP->getTemplateParams()) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 190 | if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) { |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 191 | processType(TType->getType().resolve()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 192 | } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) { |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 193 | processType(TVal->getType().resolve()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Manman Ren | 2b31b82 | 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 | 5d801364 | 2015-04-17 23:20:10 +0000 | [diff] [blame] | 200 | auto *N = dyn_cast<MDNode>(DDI->getVariable()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 201 | if (!N) |
| 202 | return; |
| 203 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 204 | auto *DV = dyn_cast<DILocalVariable>(N); |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 205 | if (!DV) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 206 | return; |
| 207 | |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 208 | if (!NodesSeen.insert(DV).second) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 209 | return; |
Duncan P. N. Exon Smith | 355ec00 | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 210 | processScope(DV->getScope()); |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 211 | processType(DV->getType().resolve()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Manman Ren | 2b31b82 | 2013-11-17 18:42:37 +0000 | [diff] [blame] | 214 | void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { |
Duncan P. N. Exon Smith | 5d801364 | 2015-04-17 23:20:10 +0000 | [diff] [blame] | 215 | auto *N = dyn_cast<MDNode>(DVI->getVariable()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 216 | if (!N) |
| 217 | return; |
| 218 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 219 | auto *DV = dyn_cast<DILocalVariable>(N); |
Duncan P. N. Exon Smith | 1545953 | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 220 | if (!DV) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 221 | return; |
| 222 | |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 223 | if (!NodesSeen.insert(DV).second) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 224 | return; |
Duncan P. N. Exon Smith | 355ec00 | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 225 | processScope(DV->getScope()); |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 226 | processType(DV->getType().resolve()); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 229 | bool DebugInfoFinder::addType(DIType *DT) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 230 | if (!DT) |
| 231 | return false; |
| 232 | |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 233 | if (!NodesSeen.insert(DT).second) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 234 | return false; |
| 235 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 236 | TYs.push_back(const_cast<DIType *>(DT)); |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 237 | return true; |
| 238 | } |
| 239 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 240 | bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 241 | if (!CU) |
| 242 | return false; |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 243 | if (!NodesSeen.insert(CU).second) |
Bill Wendling | 5f72591 | 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 | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 250 | bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) { |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 251 | if (!NodesSeen.insert(DIG).second) |
Bill Wendling | 5f72591 | 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 | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 258 | bool DebugInfoFinder::addSubprogram(DISubprogram *SP) { |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 259 | if (!SP) |
| 260 | return false; |
| 261 | |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 262 | if (!NodesSeen.insert(SP).second) |
Bill Wendling | 5f72591 | 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 | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 269 | bool DebugInfoFinder::addScope(DIScope *Scope) { |
Bill Wendling | 5f72591 | 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 | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 276 | if (!NodesSeen.insert(Scope).second) |
Bill Wendling | 5f72591 | 2013-11-08 08:13:15 +0000 | [diff] [blame] | 277 | return false; |
| 278 | Scopes.push_back(Scope); |
| 279 | return true; |
| 280 | } |
| 281 | |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 282 | static MDNode *stripDebugLocFromLoopID(MDNode *N) { |
Matthias Braun | b3bc958 | 2018-10-31 00:23:23 +0000 | [diff] [blame] | 283 | assert(!empty(N->operands()) && "Missing self reference?"); |
Daniel Sanders | 0028bf5b | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 284 | |
Teresa Johnson | ad346a2 | 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 | 0028bf5b | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 289 | return N; |
| 290 | |
Teresa Johnson | ad346a2 | 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 | 0028bf5b | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 292 | // can remove the metadata. |
Teresa Johnson | ad346a2 | 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 | 0028bf5b | 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 | ad346a2 | 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 | 0028bf5b | 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 | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 314 | bool llvm::stripDebugInfo(Function &F) { |
| 315 | bool Changed = false; |
Benjamin Kramer | f4eac50 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 316 | if (F.hasMetadata(LLVMContext::MD_dbg)) { |
Peter Collingbourne | 5f220be | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 317 | Changed = true; |
| 318 | F.setSubprogram(nullptr); |
| 319 | } |
Mehdi Amini | 7994118 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 320 | |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 321 | DenseMap<MDNode*, MDNode*> LoopIDsMap; |
Rafael Espindola | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 322 | for (BasicBlock &BB : F) { |
Mehdi Amini | 7994118 | 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 | 77d5aec | 2016-05-14 04:58:35 +0000 | [diff] [blame] | 325 | if (isa<DbgInfoIntrinsic>(&I)) { |
| 326 | I.eraseFromParent(); |
Mehdi Amini | 7994118 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 327 | Changed = true; |
Mehdi Amini | 0c3421d | 2016-05-07 05:07:47 +0000 | [diff] [blame] | 328 | continue; |
Mehdi Amini | 7994118 | 2016-05-07 04:10:52 +0000 | [diff] [blame] | 329 | } |
Rafael Espindola | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 330 | if (I.getDebugLoc()) { |
| 331 | Changed = true; |
| 332 | I.setDebugLoc(DebugLoc()); |
| 333 | } |
| 334 | } |
Daniel Sanders | 0028bf5b | 2017-01-28 11:22:05 +0000 | [diff] [blame] | 335 | |
| 336 | auto *TermInst = BB.getTerminator(); |
Justin Bogner | b251a75 | 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 | 0028bf5b | 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 | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 347 | } |
| 348 | return Changed; |
| 349 | } |
| 350 | |
Manman Ren | e6c749a | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 351 | bool llvm::StripDebugInfo(Module &M) { |
Manman Ren | e6c749a | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 352 | bool Changed = false; |
| 353 | |
Manman Ren | e6c749a | 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 | eac3095 | 2015-10-08 23:49:46 +0000 | [diff] [blame] | 356 | NamedMDNode *NMD = &*NMI; |
Manman Ren | e6c749a | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 357 | ++NMI; |
Davide Italiano | ac38a64 | 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 | e6c749a | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 363 | NMD->eraseFromParent(); |
| 364 | Changed = true; |
| 365 | } |
| 366 | } |
| 367 | |
Rafael Espindola | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 368 | for (Function &F : M) |
| 369 | Changed |= stripDebugInfo(F); |
| 370 | |
Adrian Prantl | 4970f01 | 2016-10-10 17:53:33 +0000 | [diff] [blame] | 371 | for (auto &GV : M.globals()) { |
Benjamin Kramer | f4eac50 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 372 | Changed |= GV.eraseMetadata(LLVMContext::MD_dbg); |
Adrian Prantl | 4970f01 | 2016-10-10 17:53:33 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Rafael Espindola | 4eeb5e9 | 2015-04-01 14:44:59 +0000 | [diff] [blame] | 375 | if (GVMaterializer *Materializer = M.getMaterializer()) |
Rafael Espindola | a55ae07 | 2015-03-30 21:36:43 +0000 | [diff] [blame] | 376 | Materializer->setStripDebugInfo(); |
Manman Ren | e6c749a | 2013-11-22 22:06:31 +0000 | [diff] [blame] | 377 | |
| 378 | return Changed; |
| 379 | } |
Manman Ren | 7d318bd | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 380 | |
Michael Ilseman | 5bd98bf | 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, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 441 | FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), |
| 442 | ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(), |
| 443 | MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration, |
| 444 | Variables); |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | if (MDS->isDistinct()) |
| 448 | return distinctMDSubprogram(); |
| 449 | |
| 450 | auto *NewMDS = DISubprogram::get( |
| 451 | MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 452 | FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType, |
| 453 | MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(), |
| 454 | MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables); |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 455 | |
| 456 | StringRef OldLinkageName = MDS->getLinkageName(); |
| 457 | |
| 458 | // See if we need to make a distinct one. |
| 459 | auto OrigLinkage = NewToLinkageName.find(NewMDS); |
| 460 | if (OrigLinkage != NewToLinkageName.end()) { |
| 461 | if (OrigLinkage->second == OldLinkageName) |
| 462 | // We're good. |
| 463 | return NewMDS; |
| 464 | |
| 465 | // Otherwise, need to make a distinct one. |
| 466 | // TODO: Query the map to see if we already have one. |
| 467 | return distinctMDSubprogram(); |
| 468 | } |
| 469 | |
| 470 | NewToLinkageName.insert({NewMDS, MDS->getLinkageName()}); |
| 471 | return NewMDS; |
| 472 | } |
| 473 | |
| 474 | /// Create a new compile unit, to replace the one given |
| 475 | DICompileUnit *getReplacementCU(DICompileUnit *CU) { |
| 476 | // Drop skeleton CUs. |
| 477 | if (CU->getDWOId()) |
| 478 | return nullptr; |
| 479 | |
| 480 | auto *File = cast_or_null<DIFile>(map(CU->getFile())); |
| 481 | MDTuple *EnumTypes = nullptr; |
| 482 | MDTuple *RetainedTypes = nullptr; |
| 483 | MDTuple *GlobalVariables = nullptr; |
| 484 | MDTuple *ImportedEntities = nullptr; |
| 485 | return DICompileUnit::getDistinct( |
| 486 | CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(), |
| 487 | CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(), |
| 488 | CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes, |
| 489 | RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(), |
Dehao Chen | fe46230 | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 490 | CU->getDWOId(), CU->getSplitDebugInlining(), |
David Blaikie | ecc582a | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 491 | CU->getDebugInfoForProfiling(), CU->getNameTableKind(), |
| 492 | CU->getRangesBaseAddress()); |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | DILocation *getReplacementMDLocation(DILocation *MLD) { |
| 496 | auto *Scope = map(MLD->getScope()); |
| 497 | auto *InlinedAt = map(MLD->getInlinedAt()); |
| 498 | if (MLD->isDistinct()) |
| 499 | return DILocation::getDistinct(MLD->getContext(), MLD->getLine(), |
| 500 | MLD->getColumn(), Scope, InlinedAt); |
| 501 | return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(), |
| 502 | Scope, InlinedAt); |
| 503 | } |
| 504 | |
| 505 | /// Create a new generic MDNode, to replace the one given |
| 506 | MDNode *getReplacementMDNode(MDNode *N) { |
| 507 | SmallVector<Metadata *, 8> Ops; |
| 508 | Ops.reserve(N->getNumOperands()); |
| 509 | for (auto &I : N->operands()) |
| 510 | if (I) |
| 511 | Ops.push_back(map(I)); |
| 512 | auto *Ret = MDNode::get(N->getContext(), Ops); |
| 513 | return Ret; |
| 514 | } |
| 515 | |
| 516 | /// Attempt to re-map N to a newly created node. |
| 517 | void remap(MDNode *N) { |
| 518 | if (Replacements.count(N)) |
| 519 | return; |
| 520 | |
| 521 | auto doRemap = [&](MDNode *N) -> MDNode * { |
| 522 | if (!N) |
| 523 | return nullptr; |
| 524 | if (auto *MDSub = dyn_cast<DISubprogram>(N)) { |
| 525 | remap(MDSub->getUnit()); |
| 526 | return getReplacementSubprogram(MDSub); |
| 527 | } |
| 528 | if (isa<DISubroutineType>(N)) |
| 529 | return EmptySubroutineType; |
| 530 | if (auto *CU = dyn_cast<DICompileUnit>(N)) |
| 531 | return getReplacementCU(CU); |
| 532 | if (isa<DIFile>(N)) |
| 533 | return N; |
| 534 | if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N)) |
| 535 | // Remap to our referenced scope (recursively). |
| 536 | return mapNode(MDLB->getScope()); |
| 537 | if (auto *MLD = dyn_cast<DILocation>(N)) |
| 538 | return getReplacementMDLocation(MLD); |
| 539 | |
| 540 | // Otherwise, if we see these, just drop them now. Not strictly necessary, |
| 541 | // but this speeds things up a little. |
| 542 | if (isa<DINode>(N)) |
| 543 | return nullptr; |
| 544 | |
| 545 | return getReplacementMDNode(N); |
| 546 | }; |
| 547 | Replacements[N] = doRemap(N); |
| 548 | } |
| 549 | |
| 550 | /// Do the remapping traversal. |
| 551 | void traverse(MDNode *); |
| 552 | }; |
| 553 | |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 554 | } // end anonymous namespace |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 555 | |
| 556 | void DebugTypeInfoRemoval::traverse(MDNode *N) { |
| 557 | if (!N || Replacements.count(N)) |
| 558 | return; |
| 559 | |
| 560 | // To avoid cycles, as well as for efficiency sake, we will sometimes prune |
| 561 | // parts of the graph. |
| 562 | auto prune = [](MDNode *Parent, MDNode *Child) { |
| 563 | if (auto *MDS = dyn_cast<DISubprogram>(Parent)) |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 564 | return Child == MDS->getRetainedNodes().get(); |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 565 | return false; |
| 566 | }; |
| 567 | |
| 568 | SmallVector<MDNode *, 16> ToVisit; |
| 569 | DenseSet<MDNode *> Opened; |
| 570 | |
| 571 | // Visit each node starting at N in post order, and map them. |
| 572 | ToVisit.push_back(N); |
| 573 | while (!ToVisit.empty()) { |
| 574 | auto *N = ToVisit.back(); |
| 575 | if (!Opened.insert(N).second) { |
| 576 | // Close it. |
| 577 | remap(N); |
| 578 | ToVisit.pop_back(); |
| 579 | continue; |
| 580 | } |
| 581 | for (auto &I : N->operands()) |
| 582 | if (auto *MDN = dyn_cast_or_null<MDNode>(I)) |
| 583 | if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) && |
| 584 | !isa<DICompileUnit>(MDN)) |
| 585 | ToVisit.push_back(MDN); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | bool llvm::stripNonLineTableDebugInfo(Module &M) { |
| 590 | bool Changed = false; |
| 591 | |
| 592 | // First off, delete the debug intrinsics. |
| 593 | auto RemoveUses = [&](StringRef Name) { |
| 594 | if (auto *DbgVal = M.getFunction(Name)) { |
| 595 | while (!DbgVal->use_empty()) |
| 596 | cast<Instruction>(DbgVal->user_back())->eraseFromParent(); |
| 597 | DbgVal->eraseFromParent(); |
| 598 | Changed = true; |
| 599 | } |
| 600 | }; |
| 601 | RemoveUses("llvm.dbg.declare"); |
| 602 | RemoveUses("llvm.dbg.value"); |
| 603 | |
| 604 | // Delete non-CU debug info named metadata nodes. |
| 605 | for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end(); |
| 606 | NMI != NME;) { |
| 607 | NamedMDNode *NMD = &*NMI; |
| 608 | ++NMI; |
| 609 | // Specifically keep dbg.cu around. |
| 610 | if (NMD->getName() == "llvm.dbg.cu") |
| 611 | continue; |
| 612 | } |
| 613 | |
| 614 | // Drop all dbg attachments from global variables. |
| 615 | for (auto &GV : M.globals()) |
| 616 | GV.eraseMetadata(LLVMContext::MD_dbg); |
| 617 | |
| 618 | DebugTypeInfoRemoval Mapper(M.getContext()); |
Eugene Zelenko | e5dc33d | 2017-05-05 22:30:37 +0000 | [diff] [blame] | 619 | auto remap = [&](MDNode *Node) -> MDNode * { |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 620 | if (!Node) |
| 621 | return nullptr; |
| 622 | Mapper.traverseAndRemap(Node); |
| 623 | auto *NewNode = Mapper.mapNode(Node); |
| 624 | Changed |= Node != NewNode; |
| 625 | Node = NewNode; |
| 626 | return NewNode; |
| 627 | }; |
| 628 | |
| 629 | // Rewrite the DebugLocs to be equivalent to what |
| 630 | // -gline-tables-only would have created. |
| 631 | for (auto &F : M) { |
| 632 | if (auto *SP = F.getSubprogram()) { |
| 633 | Mapper.traverseAndRemap(SP); |
| 634 | auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP)); |
| 635 | Changed |= SP != NewSP; |
| 636 | F.setSubprogram(NewSP); |
| 637 | } |
| 638 | for (auto &BB : F) { |
| 639 | for (auto &I : BB) { |
Adrian Prantl | 70eccef | 2017-03-30 20:10:56 +0000 | [diff] [blame] | 640 | auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc { |
| 641 | auto *Scope = DL.getScope(); |
| 642 | MDNode *InlinedAt = DL.getInlinedAt(); |
| 643 | Scope = remap(Scope); |
| 644 | InlinedAt = remap(InlinedAt); |
| 645 | return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt); |
| 646 | }; |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 647 | |
Adrian Prantl | 70eccef | 2017-03-30 20:10:56 +0000 | [diff] [blame] | 648 | if (I.getDebugLoc() != DebugLoc()) |
| 649 | I.setDebugLoc(remapDebugLoc(I.getDebugLoc())); |
| 650 | |
| 651 | // Remap DILocations in untyped MDNodes (e.g., llvm.loop). |
| 652 | SmallVector<std::pair<unsigned, MDNode *>, 2> MDs; |
| 653 | I.getAllMetadata(MDs); |
| 654 | for (auto Attachment : MDs) |
| 655 | if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second)) |
| 656 | for (unsigned N = 0; N < T->getNumOperands(); ++N) |
| 657 | if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N))) |
| 658 | if (Loc != DebugLoc()) |
| 659 | T->replaceOperandWith(N, remapDebugLoc(Loc)); |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // Create a new llvm.dbg.cu, which is equivalent to the one |
| 665 | // -gline-tables-only would have created. |
| 666 | for (auto &NMD : M.getNamedMDList()) { |
| 667 | SmallVector<MDNode *, 8> Ops; |
| 668 | for (MDNode *Op : NMD.operands()) |
| 669 | Ops.push_back(remap(Op)); |
Bjorn Pettersson | a1ff84e | 2018-07-03 12:39:52 +0000 | [diff] [blame] | 670 | |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 671 | if (!Changed) |
| 672 | continue; |
Bjorn Pettersson | a1ff84e | 2018-07-03 12:39:52 +0000 | [diff] [blame] | 673 | |
Michael Ilseman | 5bd98bf | 2016-10-25 18:44:13 +0000 | [diff] [blame] | 674 | NMD.clearOperands(); |
| 675 | for (auto *Op : Ops) |
| 676 | if (Op) |
| 677 | NMD.addOperand(Op); |
| 678 | } |
| 679 | return Changed; |
| 680 | } |
| 681 | |
Manman Ren | 44de223 | 2013-12-03 00:12:14 +0000 | [diff] [blame] | 682 | unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) { |
David Majnemer | 3f58e9b | 2015-02-16 06:04:53 +0000 | [diff] [blame] | 683 | if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>( |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 684 | M.getModuleFlag("Debug Info Version"))) |
| 685 | return Val->getZExtValue(); |
| 686 | return 0; |
Manman Ren | 7d318bd | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 687 | } |
Dehao Chen | 50b210a | 2017-10-02 18:13:14 +0000 | [diff] [blame] | 688 | |
| 689 | void Instruction::applyMergedLocation(const DILocation *LocA, |
| 690 | const DILocation *LocB) { |
David Blaikie | 4976f0e | 2018-08-23 22:35:58 +0000 | [diff] [blame] | 691 | setDebugLoc(DILocation::getMergedLocation(LocA, LocB)); |
Dehao Chen | 50b210a | 2017-10-02 18:13:14 +0000 | [diff] [blame] | 692 | } |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 693 | |
| 694 | //===----------------------------------------------------------------------===// |
| 695 | // LLVM C API implementations. |
| 696 | //===----------------------------------------------------------------------===// |
| 697 | |
| 698 | static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang) { |
| 699 | switch (lang) { |
David Blaikie | 838b95b5 | 2018-12-19 19:34:24 +0000 | [diff] [blame] | 700 | #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ |
| 701 | case LLVMDWARFSourceLanguage##NAME: \ |
| 702 | return ID; |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 703 | #include "llvm/BinaryFormat/Dwarf.def" |
| 704 | #undef HANDLE_DW_LANG |
| 705 | } |
| 706 | llvm_unreachable("Unhandled Tag"); |
| 707 | } |
| 708 | |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 709 | template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) { |
| 710 | return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr); |
| 711 | } |
| 712 | |
| 713 | static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) { |
| 714 | return static_cast<DINode::DIFlags>(Flags); |
| 715 | } |
| 716 | |
Robert Widmann | aaea1bf | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 717 | static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) { |
| 718 | return static_cast<LLVMDIFlags>(Flags); |
| 719 | } |
| 720 | |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 721 | static DISubprogram::DISPFlags |
| 722 | pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) { |
| 723 | return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized); |
| 724 | } |
| 725 | |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 726 | unsigned LLVMDebugMetadataVersion() { |
| 727 | return DEBUG_METADATA_VERSION; |
| 728 | } |
| 729 | |
| 730 | LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M) { |
| 731 | return wrap(new DIBuilder(*unwrap(M), false)); |
| 732 | } |
| 733 | |
| 734 | LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M) { |
| 735 | return wrap(new DIBuilder(*unwrap(M))); |
| 736 | } |
| 737 | |
| 738 | unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M) { |
| 739 | return getDebugMetadataVersionFromModule(*unwrap(M)); |
| 740 | } |
| 741 | |
| 742 | LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M) { |
| 743 | return StripDebugInfo(*unwrap(M)); |
| 744 | } |
| 745 | |
| 746 | void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder) { |
| 747 | delete unwrap(Builder); |
| 748 | } |
| 749 | |
| 750 | void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder) { |
| 751 | unwrap(Builder)->finalize(); |
| 752 | } |
| 753 | |
| 754 | LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( |
| 755 | LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, |
| 756 | LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, |
| 757 | LLVMBool isOptimized, const char *Flags, size_t FlagsLen, |
| 758 | unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, |
| 759 | LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, |
| 760 | LLVMBool DebugInfoForProfiling) { |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 761 | auto File = unwrapDI<DIFile>(FileRef); |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 762 | |
| 763 | return wrap(unwrap(Builder)->createCompileUnit( |
| 764 | map_from_llvmDWARFsourcelanguage(Lang), File, |
| 765 | StringRef(Producer, ProducerLen), isOptimized, |
| 766 | StringRef(Flags, FlagsLen), RuntimeVer, |
| 767 | StringRef(SplitName, SplitNameLen), |
| 768 | static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId, |
| 769 | SplitDebugInlining, DebugInfoForProfiling)); |
| 770 | } |
| 771 | |
| 772 | LLVMMetadataRef |
| 773 | LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, |
| 774 | size_t FilenameLen, const char *Directory, |
| 775 | size_t DirectoryLen) { |
| 776 | return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen), |
| 777 | StringRef(Directory, DirectoryLen))); |
| 778 | } |
| 779 | |
Robert Widmann | 2fbfc40 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 780 | LLVMMetadataRef |
| 781 | LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, |
| 782 | const char *Name, size_t NameLen, |
| 783 | const char *ConfigMacros, size_t ConfigMacrosLen, |
| 784 | const char *IncludePath, size_t IncludePathLen, |
| 785 | const char *ISysRoot, size_t ISysRootLen) { |
| 786 | return wrap(unwrap(Builder)->createModule( |
| 787 | unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), |
| 788 | StringRef(ConfigMacros, ConfigMacrosLen), |
| 789 | StringRef(IncludePath, IncludePathLen), |
| 790 | StringRef(ISysRoot, ISysRootLen))); |
| 791 | } |
| 792 | |
| 793 | LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, |
| 794 | LLVMMetadataRef ParentScope, |
| 795 | const char *Name, size_t NameLen, |
| 796 | LLVMBool ExportSymbols) { |
| 797 | return wrap(unwrap(Builder)->createNameSpace( |
| 798 | unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols)); |
| 799 | } |
| 800 | |
Robert Widmann | bc866fe | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 801 | LLVMMetadataRef LLVMDIBuilderCreateFunction( |
| 802 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 803 | size_t NameLen, const char *LinkageName, size_t LinkageNameLen, |
| 804 | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 805 | LLVMBool IsLocalToUnit, LLVMBool IsDefinition, |
| 806 | unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) { |
| 807 | return wrap(unwrap(Builder)->createFunction( |
| 808 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen}, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 809 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine, |
| 810 | map_from_llvmDIFlags(Flags), |
| 811 | pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr, |
| 812 | nullptr, nullptr)); |
Robert Widmann | bc866fe | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | |
| 816 | LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( |
| 817 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 818 | LLVMMetadataRef File, unsigned Line, unsigned Col) { |
| 819 | return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope), |
| 820 | unwrapDI<DIFile>(File), |
| 821 | Line, Col)); |
| 822 | } |
| 823 | |
| 824 | LLVMMetadataRef |
| 825 | LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, |
| 826 | LLVMMetadataRef Scope, |
| 827 | LLVMMetadataRef File, |
| 828 | unsigned Discriminator) { |
| 829 | return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope), |
| 830 | unwrapDI<DIFile>(File), |
| 831 | Discriminator)); |
| 832 | } |
| 833 | |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 834 | LLVMMetadataRef |
Robert Widmann | e2e5efb | 2018-04-28 22:32:07 +0000 | [diff] [blame] | 835 | LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, |
| 836 | LLVMMetadataRef Scope, |
| 837 | LLVMMetadataRef NS, |
| 838 | LLVMMetadataRef File, |
| 839 | unsigned Line) { |
| 840 | return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope), |
| 841 | unwrapDI<DINamespace>(NS), |
| 842 | unwrapDI<DIFile>(File), |
| 843 | Line)); |
| 844 | } |
| 845 | |
| 846 | LLVMMetadataRef |
| 847 | LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, |
| 848 | LLVMMetadataRef Scope, |
| 849 | LLVMMetadataRef ImportedEntity, |
| 850 | LLVMMetadataRef File, |
| 851 | unsigned Line) { |
| 852 | return wrap(unwrap(Builder)->createImportedModule( |
| 853 | unwrapDI<DIScope>(Scope), |
| 854 | unwrapDI<DIImportedEntity>(ImportedEntity), |
| 855 | unwrapDI<DIFile>(File), Line)); |
| 856 | } |
| 857 | |
| 858 | LLVMMetadataRef |
| 859 | LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, |
| 860 | LLVMMetadataRef Scope, |
| 861 | LLVMMetadataRef M, |
| 862 | LLVMMetadataRef File, |
| 863 | unsigned Line) { |
| 864 | return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope), |
| 865 | unwrapDI<DIModule>(M), |
| 866 | unwrapDI<DIFile>(File), |
| 867 | Line)); |
| 868 | } |
| 869 | |
| 870 | LLVMMetadataRef |
| 871 | LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, |
| 872 | LLVMMetadataRef Scope, |
| 873 | LLVMMetadataRef Decl, |
| 874 | LLVMMetadataRef File, |
| 875 | unsigned Line, |
| 876 | const char *Name, size_t NameLen) { |
| 877 | return wrap(unwrap(Builder)->createImportedDeclaration( |
| 878 | unwrapDI<DIScope>(Scope), |
| 879 | unwrapDI<DINode>(Decl), |
| 880 | unwrapDI<DIFile>(File), Line, {Name, NameLen})); |
| 881 | } |
| 882 | |
| 883 | LLVMMetadataRef |
whitequark | 8b4e833 | 2017-11-01 22:18:52 +0000 | [diff] [blame] | 884 | LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, |
| 885 | unsigned Column, LLVMMetadataRef Scope, |
| 886 | LLVMMetadataRef InlinedAt) { |
| 887 | return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope), |
| 888 | unwrap(InlinedAt))); |
| 889 | } |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 890 | |
Robert Widmann | aaea1bf | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 891 | unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) { |
| 892 | return unwrapDI<DILocation>(Location)->getLine(); |
| 893 | } |
| 894 | |
| 895 | unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) { |
| 896 | return unwrapDI<DILocation>(Location)->getColumn(); |
| 897 | } |
| 898 | |
| 899 | LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) { |
| 900 | return wrap(unwrapDI<DILocation>(Location)->getScope()); |
| 901 | } |
| 902 | |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 903 | LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( |
| 904 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 905 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 906 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 907 | unsigned NumElements, LLVMMetadataRef ClassTy) { |
| 908 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 909 | NumElements}); |
| 910 | return wrap(unwrap(Builder)->createEnumerationType( |
| 911 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 912 | LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy))); |
| 913 | } |
| 914 | |
| 915 | LLVMMetadataRef LLVMDIBuilderCreateUnionType( |
| 916 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 917 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 918 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 919 | LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, |
| 920 | const char *UniqueId, size_t UniqueIdLen) { |
| 921 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 922 | NumElements}); |
| 923 | return wrap(unwrap(Builder)->createUnionType( |
| 924 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 925 | LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), |
| 926 | Elts, RunTimeLang, {UniqueId, UniqueIdLen})); |
| 927 | } |
| 928 | |
| 929 | |
| 930 | LLVMMetadataRef |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 931 | LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, |
| 932 | uint32_t AlignInBits, LLVMMetadataRef Ty, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 933 | LLVMMetadataRef *Subscripts, |
| 934 | unsigned NumSubscripts) { |
| 935 | auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), |
| 936 | NumSubscripts}); |
| 937 | return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits, |
| 938 | unwrapDI<DIType>(Ty), Subs)); |
| 939 | } |
| 940 | |
| 941 | LLVMMetadataRef |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 942 | LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, |
| 943 | uint32_t AlignInBits, LLVMMetadataRef Ty, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 944 | LLVMMetadataRef *Subscripts, |
| 945 | unsigned NumSubscripts) { |
| 946 | auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), |
| 947 | NumSubscripts}); |
| 948 | return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits, |
| 949 | unwrapDI<DIType>(Ty), Subs)); |
| 950 | } |
| 951 | |
| 952 | LLVMMetadataRef |
| 953 | LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 954 | size_t NameLen, uint64_t SizeInBits, |
whitequark | 8bf9e9a | 2018-08-19 23:39:47 +0000 | [diff] [blame] | 955 | LLVMDWARFTypeEncoding Encoding, |
| 956 | LLVMDIFlags Flags) { |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 957 | return wrap(unwrap(Builder)->createBasicType({Name, NameLen}, |
whitequark | 8bf9e9a | 2018-08-19 23:39:47 +0000 | [diff] [blame] | 958 | SizeInBits, Encoding, |
| 959 | map_from_llvmDIFlags(Flags))); |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | LLVMMetadataRef LLVMDIBuilderCreatePointerType( |
| 963 | LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 964 | uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 965 | const char *Name, size_t NameLen) { |
| 966 | return wrap(unwrap(Builder)->createPointerType(unwrapDI<DIType>(PointeeTy), |
| 967 | SizeInBits, AlignInBits, |
| 968 | AddressSpace, {Name, NameLen})); |
| 969 | } |
| 970 | |
| 971 | LLVMMetadataRef LLVMDIBuilderCreateStructType( |
| 972 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 973 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 974 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 975 | LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, |
| 976 | unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, |
| 977 | const char *UniqueId, size_t UniqueIdLen) { |
| 978 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 979 | NumElements}); |
| 980 | return wrap(unwrap(Builder)->createStructType( |
| 981 | unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), |
| 982 | LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), |
| 983 | unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang, |
| 984 | unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen})); |
| 985 | } |
| 986 | |
| 987 | LLVMMetadataRef LLVMDIBuilderCreateMemberType( |
| 988 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 989 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, |
| 990 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 991 | LLVMMetadataRef Ty) { |
| 992 | return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope), |
| 993 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, |
| 994 | OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty))); |
| 995 | } |
| 996 | |
| 997 | LLVMMetadataRef |
| 998 | LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, |
| 999 | size_t NameLen) { |
| 1000 | return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen})); |
| 1001 | } |
| 1002 | |
| 1003 | LLVMMetadataRef |
| 1004 | LLVMDIBuilderCreateStaticMemberType( |
| 1005 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1006 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 1007 | LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1008 | uint32_t AlignInBits) { |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1009 | return wrap(unwrap(Builder)->createStaticMemberType( |
| 1010 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1011 | unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type), |
| 1012 | map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal), |
| 1013 | AlignInBits)); |
| 1014 | } |
| 1015 | |
| 1016 | LLVMMetadataRef |
Robert Widmann | e9654fe | 2018-05-21 16:27:35 +0000 | [diff] [blame] | 1017 | LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, |
| 1018 | const char *Name, size_t NameLen, |
| 1019 | LLVMMetadataRef File, unsigned LineNo, |
| 1020 | uint64_t SizeInBits, uint32_t AlignInBits, |
| 1021 | uint64_t OffsetInBits, LLVMDIFlags Flags, |
| 1022 | LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) { |
| 1023 | return wrap(unwrap(Builder)->createObjCIVar( |
| 1024 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, |
| 1025 | SizeInBits, AlignInBits, OffsetInBits, |
| 1026 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty), |
| 1027 | unwrapDI<MDNode>(PropertyNode))); |
| 1028 | } |
| 1029 | |
| 1030 | LLVMMetadataRef |
| 1031 | LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, |
| 1032 | const char *Name, size_t NameLen, |
| 1033 | LLVMMetadataRef File, unsigned LineNo, |
| 1034 | const char *GetterName, size_t GetterNameLen, |
| 1035 | const char *SetterName, size_t SetterNameLen, |
| 1036 | unsigned PropertyAttributes, |
| 1037 | LLVMMetadataRef Ty) { |
| 1038 | return wrap(unwrap(Builder)->createObjCProperty( |
| 1039 | {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, |
| 1040 | {GetterName, GetterNameLen}, {SetterName, SetterNameLen}, |
| 1041 | PropertyAttributes, unwrapDI<DIType>(Ty))); |
| 1042 | } |
| 1043 | |
| 1044 | LLVMMetadataRef |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1045 | LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, |
| 1046 | LLVMMetadataRef Type) { |
| 1047 | return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type))); |
| 1048 | } |
| 1049 | |
| 1050 | LLVMMetadataRef |
Robert Widmann | 07e5114 | 2018-05-10 21:10:06 +0000 | [diff] [blame] | 1051 | LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, |
| 1052 | const char *Name, size_t NameLen, |
| 1053 | LLVMMetadataRef File, unsigned LineNo, |
| 1054 | LLVMMetadataRef Scope) { |
| 1055 | return wrap(unwrap(Builder)->createTypedef( |
| 1056 | unwrapDI<DIType>(Type), {Name, NameLen}, |
| 1057 | unwrapDI<DIFile>(File), LineNo, |
| 1058 | unwrapDI<DIScope>(Scope))); |
| 1059 | } |
| 1060 | |
| 1061 | LLVMMetadataRef |
Robert Widmann | e9654fe | 2018-05-21 16:27:35 +0000 | [diff] [blame] | 1062 | LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, |
| 1063 | LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, |
| 1064 | uint64_t BaseOffset, uint32_t VBPtrOffset, |
| 1065 | LLVMDIFlags Flags) { |
| 1066 | return wrap(unwrap(Builder)->createInheritance( |
| 1067 | unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy), |
| 1068 | BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags))); |
| 1069 | } |
| 1070 | |
| 1071 | LLVMMetadataRef |
Robert Widmann | 2fbfc40 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 1072 | LLVMDIBuilderCreateForwardDecl( |
| 1073 | LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, |
| 1074 | size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1075 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
Robert Widmann | 2fbfc40 | 2018-04-23 13:51:43 +0000 | [diff] [blame] | 1076 | const char *UniqueIdentifier, size_t UniqueIdentifierLen) { |
| 1077 | return wrap(unwrap(Builder)->createForwardDecl( |
| 1078 | Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope), |
| 1079 | unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits, |
| 1080 | AlignInBits, {UniqueIdentifier, UniqueIdentifierLen})); |
| 1081 | } |
| 1082 | |
| 1083 | LLVMMetadataRef |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1084 | LLVMDIBuilderCreateReplaceableCompositeType( |
Harlan Haskins | a21e816 | 2018-04-02 19:11:44 +0000 | [diff] [blame] | 1085 | LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, |
| 1086 | size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1087 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1088 | LLVMDIFlags Flags, const char *UniqueIdentifier, |
Harlan Haskins | a21e816 | 2018-04-02 19:11:44 +0000 | [diff] [blame] | 1089 | size_t UniqueIdentifierLen) { |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1090 | return wrap(unwrap(Builder)->createReplaceableCompositeType( |
| 1091 | Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope), |
| 1092 | unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits, |
| 1093 | AlignInBits, map_from_llvmDIFlags(Flags), |
| 1094 | {UniqueIdentifier, UniqueIdentifierLen})); |
| 1095 | } |
| 1096 | |
| 1097 | LLVMMetadataRef |
| 1098 | LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, |
| 1099 | LLVMMetadataRef Type) { |
| 1100 | return wrap(unwrap(Builder)->createQualifiedType(Tag, |
| 1101 | unwrapDI<DIType>(Type))); |
| 1102 | } |
| 1103 | |
| 1104 | LLVMMetadataRef |
| 1105 | LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, |
| 1106 | LLVMMetadataRef Type) { |
| 1107 | return wrap(unwrap(Builder)->createReferenceType(Tag, |
| 1108 | unwrapDI<DIType>(Type))); |
| 1109 | } |
| 1110 | |
| 1111 | LLVMMetadataRef |
| 1112 | LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) { |
| 1113 | return wrap(unwrap(Builder)->createNullPtrType()); |
| 1114 | } |
| 1115 | |
| 1116 | LLVMMetadataRef |
| 1117 | LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, |
| 1118 | LLVMMetadataRef PointeeType, |
| 1119 | LLVMMetadataRef ClassType, |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1120 | uint64_t SizeInBits, |
| 1121 | uint32_t AlignInBits, |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1122 | LLVMDIFlags Flags) { |
| 1123 | return wrap(unwrap(Builder)->createMemberPointerType( |
| 1124 | unwrapDI<DIType>(PointeeType), |
| 1125 | unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits, |
| 1126 | map_from_llvmDIFlags(Flags))); |
| 1127 | } |
| 1128 | |
| 1129 | LLVMMetadataRef |
Robert Widmann | cb99414 | 2018-04-28 18:13:39 +0000 | [diff] [blame] | 1130 | LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, |
| 1131 | LLVMMetadataRef Scope, |
| 1132 | const char *Name, size_t NameLen, |
| 1133 | LLVMMetadataRef File, unsigned LineNumber, |
| 1134 | uint64_t SizeInBits, |
| 1135 | uint64_t OffsetInBits, |
| 1136 | uint64_t StorageOffsetInBits, |
| 1137 | LLVMDIFlags Flags, LLVMMetadataRef Type) { |
| 1138 | return wrap(unwrap(Builder)->createBitFieldMemberType( |
| 1139 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1140 | unwrapDI<DIFile>(File), LineNumber, |
| 1141 | SizeInBits, OffsetInBits, StorageOffsetInBits, |
| 1142 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type))); |
| 1143 | } |
| 1144 | |
| 1145 | LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, |
| 1146 | LLVMMetadataRef Scope, const char *Name, size_t NameLen, |
| 1147 | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 1148 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, |
| 1149 | LLVMMetadataRef DerivedFrom, |
| 1150 | LLVMMetadataRef *Elements, unsigned NumElements, |
| 1151 | LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, |
| 1152 | const char *UniqueIdentifier, size_t UniqueIdentifierLen) { |
| 1153 | auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), |
| 1154 | NumElements}); |
| 1155 | return wrap(unwrap(Builder)->createClassType( |
| 1156 | unwrapDI<DIScope>(Scope), {Name, NameLen}, |
| 1157 | unwrapDI<DIFile>(File), LineNumber, |
| 1158 | SizeInBits, AlignInBits, OffsetInBits, |
| 1159 | map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), |
| 1160 | Elts, unwrapDI<DIType>(VTableHolder), |
| 1161 | unwrapDI<MDNode>(TemplateParamsNode), |
| 1162 | {UniqueIdentifier, UniqueIdentifierLen})); |
| 1163 | } |
| 1164 | |
| 1165 | LLVMMetadataRef |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1166 | LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, |
| 1167 | LLVMMetadataRef Type) { |
| 1168 | return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type))); |
| 1169 | } |
| 1170 | |
Robert Widmann | aaea1bf | 2018-05-10 18:23:55 +0000 | [diff] [blame] | 1171 | const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) { |
| 1172 | StringRef Str = unwrap<DIType>(DType)->getName(); |
| 1173 | *Length = Str.size(); |
| 1174 | return Str.data(); |
| 1175 | } |
| 1176 | |
| 1177 | uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) { |
| 1178 | return unwrapDI<DIType>(DType)->getSizeInBits(); |
| 1179 | } |
| 1180 | |
| 1181 | uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) { |
| 1182 | return unwrapDI<DIType>(DType)->getOffsetInBits(); |
| 1183 | } |
| 1184 | |
| 1185 | uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) { |
| 1186 | return unwrapDI<DIType>(DType)->getAlignInBits(); |
| 1187 | } |
| 1188 | |
| 1189 | unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) { |
| 1190 | return unwrapDI<DIType>(DType)->getLine(); |
| 1191 | } |
| 1192 | |
| 1193 | LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) { |
| 1194 | return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags()); |
| 1195 | } |
| 1196 | |
Robert Widmann | cd997a7 | 2018-04-23 14:29:33 +0000 | [diff] [blame] | 1197 | LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, |
| 1198 | LLVMMetadataRef *Types, |
| 1199 | size_t Length) { |
| 1200 | return wrap( |
| 1201 | unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get()); |
| 1202 | } |
| 1203 | |
Harlan Haskins | 80548aa | 2018-04-02 00:17:40 +0000 | [diff] [blame] | 1204 | LLVMMetadataRef |
| 1205 | LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, |
| 1206 | LLVMMetadataRef File, |
| 1207 | LLVMMetadataRef *ParameterTypes, |
| 1208 | unsigned NumParameterTypes, |
| 1209 | LLVMDIFlags Flags) { |
| 1210 | auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes), |
| 1211 | NumParameterTypes}); |
| 1212 | return wrap(unwrap(Builder)->createSubroutineType( |
| 1213 | Elts, map_from_llvmDIFlags(Flags))); |
| 1214 | } |
Robert Widmann | bc866fe | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 1215 | |
Robert Widmann | aec0628 | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1216 | LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, |
| 1217 | int64_t *Addr, size_t Length) { |
| 1218 | return wrap(unwrap(Builder)->createExpression(ArrayRef<int64_t>(Addr, |
| 1219 | Length))); |
| 1220 | } |
| 1221 | |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1222 | LLVMMetadataRef |
| 1223 | LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, |
| 1224 | int64_t Value) { |
| 1225 | return wrap(unwrap(Builder)->createConstantValueExpression(Value)); |
| 1226 | } |
| 1227 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 1228 | LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression( |
| 1229 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1230 | size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, |
| 1231 | unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, |
| 1232 | LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) { |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1233 | return wrap(unwrap(Builder)->createGlobalVariableExpression( |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 1234 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen}, |
| 1235 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit, |
| 1236 | unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl), |
| 1237 | nullptr, AlignInBits)); |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Robert Widmann | 4240051 | 2018-05-10 18:09:53 +0000 | [diff] [blame] | 1240 | LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, |
| 1241 | size_t Count) { |
| 1242 | return wrap( |
| 1243 | MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release()); |
| 1244 | } |
| 1245 | |
| 1246 | void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) { |
| 1247 | MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode)); |
| 1248 | } |
| 1249 | |
| 1250 | void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata, |
| 1251 | LLVMMetadataRef Replacement) { |
| 1252 | auto *Node = unwrapDI<MDNode>(TargetMetadata); |
| 1253 | Node->replaceAllUsesWith(unwrap<Metadata>(Replacement)); |
| 1254 | MDNode::deleteTemporary(Node); |
| 1255 | } |
| 1256 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 1257 | LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl( |
| 1258 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1259 | size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, |
| 1260 | unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, |
| 1261 | LLVMMetadataRef Decl, uint32_t AlignInBits) { |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1262 | return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl( |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 1263 | unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen}, |
| 1264 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit, |
| 1265 | unwrapDI<MDNode>(Decl), nullptr, AlignInBits)); |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 1268 | LLVMValueRef |
| 1269 | LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, |
| 1270 | LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, |
| 1271 | LLVMMetadataRef DL, LLVMValueRef Instr) { |
Robert Widmann | aec0628 | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1272 | return wrap(unwrap(Builder)->insertDeclare( |
| 1273 | unwrap(Storage), unwrap<DILocalVariable>(VarInfo), |
| 1274 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), |
| 1275 | unwrap<Instruction>(Instr))); |
| 1276 | } |
| 1277 | |
| 1278 | LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( |
| 1279 | LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, |
| 1280 | LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) { |
| 1281 | return wrap(unwrap(Builder)->insertDeclare( |
| 1282 | unwrap(Storage), unwrap<DILocalVariable>(VarInfo), |
| 1283 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), |
| 1284 | unwrap(Block))); |
| 1285 | } |
| 1286 | |
Robert Widmann | bffba31 | 2018-04-23 22:31:49 +0000 | [diff] [blame] | 1287 | LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, |
| 1288 | LLVMValueRef Val, |
| 1289 | LLVMMetadataRef VarInfo, |
| 1290 | LLVMMetadataRef Expr, |
| 1291 | LLVMMetadataRef DebugLoc, |
| 1292 | LLVMValueRef Instr) { |
| 1293 | return wrap(unwrap(Builder)->insertDbgValueIntrinsic( |
| 1294 | unwrap(Val), unwrap<DILocalVariable>(VarInfo), |
| 1295 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), |
| 1296 | unwrap<Instruction>(Instr))); |
| 1297 | } |
| 1298 | |
| 1299 | LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, |
| 1300 | LLVMValueRef Val, |
| 1301 | LLVMMetadataRef VarInfo, |
| 1302 | LLVMMetadataRef Expr, |
| 1303 | LLVMMetadataRef DebugLoc, |
| 1304 | LLVMBasicBlockRef Block) { |
| 1305 | return wrap(unwrap(Builder)->insertDbgValueIntrinsic( |
| 1306 | unwrap(Val), unwrap<DILocalVariable>(VarInfo), |
| 1307 | unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), |
| 1308 | unwrap(Block))); |
| 1309 | } |
| 1310 | |
Robert Widmann | aec0628 | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1311 | LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( |
| 1312 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1313 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 1314 | LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) { |
| 1315 | return wrap(unwrap(Builder)->createAutoVariable( |
| 1316 | unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File), |
| 1317 | LineNo, unwrap<DIType>(Ty), AlwaysPreserve, |
| 1318 | map_from_llvmDIFlags(Flags), AlignInBits)); |
| 1319 | } |
| 1320 | |
| 1321 | LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( |
| 1322 | LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1323 | size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, |
| 1324 | LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) { |
| 1325 | return wrap(unwrap(Builder)->createParameterVariable( |
Robert Widmann | bffc6e5 | 2018-08-25 19:54:39 +0000 | [diff] [blame] | 1326 | unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File), |
Robert Widmann | aec0628 | 2018-04-22 19:24:44 +0000 | [diff] [blame] | 1327 | LineNo, unwrap<DIType>(Ty), AlwaysPreserve, |
| 1328 | map_from_llvmDIFlags(Flags))); |
| 1329 | } |
| 1330 | |
Robert Widmann | cd997a7 | 2018-04-23 14:29:33 +0000 | [diff] [blame] | 1331 | LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, |
| 1332 | int64_t Lo, int64_t Count) { |
| 1333 | return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count)); |
| 1334 | } |
| 1335 | |
| 1336 | LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, |
| 1337 | LLVMMetadataRef *Data, |
| 1338 | size_t Length) { |
| 1339 | Metadata **DataValue = unwrap(Data); |
| 1340 | return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get()); |
| 1341 | } |
| 1342 | |
Robert Widmann | bc866fe | 2018-04-07 06:07:55 +0000 | [diff] [blame] | 1343 | LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) { |
| 1344 | return wrap(unwrap<Function>(Func)->getSubprogram()); |
| 1345 | } |
| 1346 | |
| 1347 | void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { |
| 1348 | unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP)); |
| 1349 | } |
Robert Widmann | eab58e0 | 2018-10-01 13:15:09 +0000 | [diff] [blame] | 1350 | |
| 1351 | LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) { |
| 1352 | switch(unwrap(Metadata)->getMetadataID()) { |
| 1353 | #define HANDLE_METADATA_LEAF(CLASS) \ |
| 1354 | case Metadata::CLASS##Kind: \ |
| 1355 | return (LLVMMetadataKind)LLVM##CLASS##MetadataKind; |
| 1356 | #include "llvm/IR/Metadata.def" |
| 1357 | default: |
| 1358 | return (LLVMMetadataKind)LLVMGenericDINodeMetadataKind; |
| 1359 | } |
| 1360 | } |