Nick Lewycky | fca2acb | 2012-12-26 22:00:49 +0000 | [diff] [blame] | 1 | //===-- LLVMContext.cpp - Implement LLVMContext ---------------------------===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +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 | //===----------------------------------------------------------------------===// |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements LLVMContext, as a wrapper around the opaque |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 11 | // class LLVMContextImpl. |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 14 | |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 15 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "LLVMContextImpl.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Constants.h" |
Diego Novillo | a9298b2 | 2014-04-08 16:42:34 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DebugLoc.h" |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 19 | #include "llvm/IR/DiagnosticInfo.h" |
| 20 | #include "llvm/IR/DiagnosticPrinter.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Instruction.h" |
| 22 | #include "llvm/IR/Metadata.h" |
Owen Anderson | 1938fb1 | 2009-06-30 23:39:59 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ManagedStatic.h" |
Chris Lattner | 1e45789 | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 24 | #include "llvm/Support/SourceMgr.h" |
Nick Lewycky | 0de20af | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 25 | #include <cctype> |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Owen Anderson | 1938fb1 | 2009-06-30 23:39:59 +0000 | [diff] [blame] | 28 | static ManagedStatic<LLVMContext> GlobalContext; |
| 29 | |
Owen Anderson | 2a15443 | 2009-07-01 23:13:44 +0000 | [diff] [blame] | 30 | LLVMContext& llvm::getGlobalContext() { |
Owen Anderson | 1cf085d | 2009-07-01 21:22:36 +0000 | [diff] [blame] | 31 | return *GlobalContext; |
Owen Anderson | 1938fb1 | 2009-06-30 23:39:59 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | c263b42 | 2010-03-30 23:03:27 +0000 | [diff] [blame] | 34 | LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { |
Dan Gohman | 41f14cf | 2010-09-14 21:25:10 +0000 | [diff] [blame] | 35 | // Create the fixed metadata kinds. This is done in the same order as the |
| 36 | // MD_* enum values so that they correspond. |
| 37 | |
Bob Wilson | ec3ff9c | 2010-12-17 23:06:32 +0000 | [diff] [blame] | 38 | // Create the 'dbg' metadata kind. |
Chris Lattner | c263b42 | 2010-03-30 23:03:27 +0000 | [diff] [blame] | 39 | unsigned DbgID = getMDKindID("dbg"); |
| 40 | assert(DbgID == MD_dbg && "dbg kind id drifted"); (void)DbgID; |
Dan Gohman | 41f14cf | 2010-09-14 21:25:10 +0000 | [diff] [blame] | 41 | |
| 42 | // Create the 'tbaa' metadata kind. |
| 43 | unsigned TBAAID = getMDKindID("tbaa"); |
| 44 | assert(TBAAID == MD_tbaa && "tbaa kind id drifted"); (void)TBAAID; |
Jakub Staszak | 3f158fd | 2011-07-06 18:22:43 +0000 | [diff] [blame] | 45 | |
| 46 | // Create the 'prof' metadata kind. |
| 47 | unsigned ProfID = getMDKindID("prof"); |
| 48 | assert(ProfID == MD_prof && "prof kind id drifted"); (void)ProfID; |
Peter Collingbourne | f7d1e7b | 2011-10-27 19:19:14 +0000 | [diff] [blame] | 49 | |
Duncan Sands | 34bd91a | 2012-04-14 12:36:06 +0000 | [diff] [blame] | 50 | // Create the 'fpmath' metadata kind. |
| 51 | unsigned FPAccuracyID = getMDKindID("fpmath"); |
| 52 | assert(FPAccuracyID == MD_fpmath && "fpmath kind id drifted"); |
Peter Collingbourne | f7d1e7b | 2011-10-27 19:19:14 +0000 | [diff] [blame] | 53 | (void)FPAccuracyID; |
Rafael Espindola | ef9f550 | 2012-03-24 00:14:51 +0000 | [diff] [blame] | 54 | |
| 55 | // Create the 'range' metadata kind. |
| 56 | unsigned RangeID = getMDKindID("range"); |
| 57 | assert(RangeID == MD_range && "range kind id drifted"); |
| 58 | (void)RangeID; |
Dan Gohman | 3effe81 | 2012-09-13 17:56:17 +0000 | [diff] [blame] | 59 | |
| 60 | // Create the 'tbaa.struct' metadata kind. |
| 61 | unsigned TBAAStructID = getMDKindID("tbaa.struct"); |
| 62 | assert(TBAAStructID == MD_tbaa_struct && "tbaa.struct kind id drifted"); |
| 63 | (void)TBAAStructID; |
Shuxin Yang | 408bdad | 2013-03-06 17:48:48 +0000 | [diff] [blame] | 64 | |
| 65 | // Create the 'invariant.load' metadata kind. |
| 66 | unsigned InvariantLdId = getMDKindID("invariant.load"); |
| 67 | assert(InvariantLdId == MD_invariant_load && "invariant.load kind id drifted"); |
| 68 | (void)InvariantLdId; |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 69 | |
| 70 | // Create the 'alias.scope' metadata kind. |
| 71 | unsigned AliasScopeID = getMDKindID("alias.scope"); |
| 72 | assert(AliasScopeID == MD_alias_scope && "alias.scope kind id drifted"); |
| 73 | (void)AliasScopeID; |
| 74 | |
| 75 | // Create the 'noalias' metadata kind. |
| 76 | unsigned NoAliasID = getMDKindID("noalias"); |
| 77 | assert(NoAliasID == MD_noalias && "noalias kind id drifted"); |
| 78 | (void)NoAliasID; |
Philip Reames | 5a3f5f7 | 2014-10-21 00:13:20 +0000 | [diff] [blame] | 79 | |
| 80 | // Create the 'nontemporal' metadata kind. |
| 81 | unsigned NonTemporalID = getMDKindID("nontemporal"); |
| 82 | assert(NonTemporalID == MD_nontemporal && "nontemporal kind id drifted"); |
| 83 | (void)NonTemporalID; |
| 84 | |
| 85 | // Create the 'llvm.mem.parallel_loop_access' metadata kind. |
| 86 | unsigned MemParallelLoopAccessID = getMDKindID("llvm.mem.parallel_loop_access"); |
| 87 | assert(MemParallelLoopAccessID == MD_mem_parallel_loop_access && |
| 88 | "mem_parallel_loop_access kind id drifted"); |
| 89 | (void)MemParallelLoopAccessID; |
| 90 | |
Philip Reames | 5a3f5f7 | 2014-10-21 00:13:20 +0000 | [diff] [blame] | 91 | // Create the 'nonnull' metadata kind. |
| 92 | unsigned NonNullID = getMDKindID("nonnull"); |
| 93 | assert(NonNullID == MD_nonnull && "nonnull kind id drifted"); |
| 94 | (void)NonNullID; |
Sanjoy Das | f999547 | 2015-05-19 20:10:19 +0000 | [diff] [blame] | 95 | |
| 96 | // Create the 'dereferenceable' metadata kind. |
| 97 | unsigned DereferenceableID = getMDKindID("dereferenceable"); |
| 98 | assert(DereferenceableID == MD_dereferenceable && |
| 99 | "dereferenceable kind id drifted"); |
| 100 | (void)DereferenceableID; |
| 101 | |
| 102 | // Create the 'dereferenceable_or_null' metadata kind. |
| 103 | unsigned DereferenceableOrNullID = getMDKindID("dereferenceable_or_null"); |
| 104 | assert(DereferenceableOrNullID == MD_dereferenceable_or_null && |
| 105 | "dereferenceable_or_null kind id drifted"); |
| 106 | (void)DereferenceableOrNullID; |
Chen Li | 0003878 | 2015-08-04 04:41:34 +0000 | [diff] [blame] | 107 | |
| 108 | // Create the 'make.implicit' metadata kind. |
| 109 | unsigned MakeImplicitID = getMDKindID("make.implicit"); |
| 110 | assert(MakeImplicitID == MD_make_implicit && |
| 111 | "make.implicit kind id drifted"); |
| 112 | (void)MakeImplicitID; |
Sanjay Patel | a99ab1f | 2015-09-02 19:06:43 +0000 | [diff] [blame] | 113 | |
| 114 | // Create the 'unpredictable' metadata kind. |
| 115 | unsigned UnpredictableID = getMDKindID("unpredictable"); |
| 116 | assert(UnpredictableID == MD_unpredictable && |
| 117 | "unpredictable kind id drifted"); |
| 118 | (void)UnpredictableID; |
Piotr Padlewski | ea09288 | 2015-09-17 20:25:07 +0000 | [diff] [blame] | 119 | |
| 120 | // Create the 'invariant.group' metadata kind. |
| 121 | unsigned InvariantGroupId = getMDKindID("invariant.group"); |
| 122 | assert(InvariantGroupId == MD_invariant_group && |
| 123 | "invariant.group kind id drifted"); |
| 124 | (void)InvariantGroupId; |
| 125 | |
Artur Pilipenko | b4d0090 | 2015-09-28 17:41:08 +0000 | [diff] [blame] | 126 | // Create the 'align' metadata kind. |
| 127 | unsigned AlignID = getMDKindID("align"); |
| 128 | assert(AlignID == MD_align && "align kind id drifted"); |
| 129 | (void)AlignID; |
Sanjoy Das | cdafd84 | 2015-11-11 21:38:02 +0000 | [diff] [blame] | 130 | |
| 131 | auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt"); |
| 132 | assert(DeoptEntry->second == LLVMContext::OB_deopt && |
| 133 | "deopt operand bundle id drifted!"); |
| 134 | (void)DeoptEntry; |
Chris Lattner | c263b42 | 2010-03-30 23:03:27 +0000 | [diff] [blame] | 135 | } |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 136 | LLVMContext::~LLVMContext() { delete pImpl; } |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 137 | |
Owen Anderson | 8e89e41 | 2010-09-08 18:03:32 +0000 | [diff] [blame] | 138 | void LLVMContext::addModule(Module *M) { |
| 139 | pImpl->OwnedModules.insert(M); |
| 140 | } |
| 141 | |
| 142 | void LLVMContext::removeModule(Module *M) { |
| 143 | pImpl->OwnedModules.erase(M); |
| 144 | } |
| 145 | |
Chris Lattner | 1e45789 | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 146 | //===----------------------------------------------------------------------===// |
| 147 | // Recoverable Backend Errors |
| 148 | //===----------------------------------------------------------------------===// |
| 149 | |
Bob Wilson | a594fab | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 150 | void LLVMContext:: |
| 151 | setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler, |
| 152 | void *DiagContext) { |
| 153 | pImpl->InlineAsmDiagHandler = DiagHandler; |
| 154 | pImpl->InlineAsmDiagContext = DiagContext; |
Chris Lattner | 60955d4 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Bob Wilson | a594fab | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 157 | /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by |
| 158 | /// setInlineAsmDiagnosticHandler. |
| 159 | LLVMContext::InlineAsmDiagHandlerTy |
| 160 | LLVMContext::getInlineAsmDiagnosticHandler() const { |
| 161 | return pImpl->InlineAsmDiagHandler; |
Chris Lattner | 60955d4 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Bob Wilson | a594fab | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 164 | /// getInlineAsmDiagnosticContext - Return the diagnostic context set by |
| 165 | /// setInlineAsmDiagnosticHandler. |
| 166 | void *LLVMContext::getInlineAsmDiagnosticContext() const { |
| 167 | return pImpl->InlineAsmDiagContext; |
Chris Lattner | 60955d4 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 168 | } |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 169 | |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 170 | void LLVMContext::setDiagnosticHandler(DiagnosticHandlerTy DiagnosticHandler, |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 171 | void *DiagnosticContext, |
| 172 | bool RespectFilters) { |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 173 | pImpl->DiagnosticHandler = DiagnosticHandler; |
| 174 | pImpl->DiagnosticContext = DiagnosticContext; |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 175 | pImpl->RespectDiagnosticFilters = RespectFilters; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | LLVMContext::DiagnosticHandlerTy LLVMContext::getDiagnosticHandler() const { |
| 179 | return pImpl->DiagnosticHandler; |
| 180 | } |
| 181 | |
| 182 | void *LLVMContext::getDiagnosticContext() const { |
| 183 | return pImpl->DiagnosticContext; |
| 184 | } |
| 185 | |
Juergen Ributzka | 34390c7 | 2014-05-16 02:33:15 +0000 | [diff] [blame] | 186 | void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle) |
| 187 | { |
| 188 | pImpl->YieldCallback = Callback; |
| 189 | pImpl->YieldOpaqueHandle = OpaqueHandle; |
| 190 | } |
| 191 | |
| 192 | void LLVMContext::yield() { |
| 193 | if (pImpl->YieldCallback) |
| 194 | pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle); |
| 195 | } |
| 196 | |
Chris Lattner | e22e613 | 2012-01-03 23:47:05 +0000 | [diff] [blame] | 197 | void LLVMContext::emitError(const Twine &ErrorStr) { |
Quentin Colombet | dec8d55 | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 198 | diagnose(DiagnosticInfoInlineAsm(ErrorStr)); |
Chris Lattner | 1e45789 | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Bob Wilson | bfb44ef | 2013-02-08 21:48:29 +0000 | [diff] [blame] | 201 | void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { |
Quentin Colombet | dec8d55 | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 202 | assert (I && "Invalid instruction"); |
| 203 | diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); |
Chris Lattner | 1e45789 | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 206 | static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 207 | // Optimization remarks are selective. They need to check whether the regexp |
| 208 | // pattern, passed via one of the -pass-remarks* flags, matches the name of |
| 209 | // the pass that is emitting the diagnostic. If there is no match, ignore the |
| 210 | // diagnostic and return. |
| 211 | switch (DI.getKind()) { |
| 212 | case llvm::DK_OptimizationRemark: |
Diego Novillo | 0b761a4 | 2014-05-22 17:19:01 +0000 | [diff] [blame] | 213 | if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled()) |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 214 | return false; |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 215 | break; |
| 216 | case llvm::DK_OptimizationRemarkMissed: |
Diego Novillo | 0b761a4 | 2014-05-22 17:19:01 +0000 | [diff] [blame] | 217 | if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled()) |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 218 | return false; |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 219 | break; |
| 220 | case llvm::DK_OptimizationRemarkAnalysis: |
Diego Novillo | 0b761a4 | 2014-05-22 17:19:01 +0000 | [diff] [blame] | 221 | if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled()) |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 222 | return false; |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 223 | break; |
Tyler Nowicki | c1a86f5 | 2015-08-10 19:51:46 +0000 | [diff] [blame] | 224 | case llvm::DK_OptimizationRemarkAnalysisFPCommute: |
| 225 | if (!cast<DiagnosticInfoOptimizationRemarkAnalysisFPCommute>(DI) |
| 226 | .isEnabled()) |
| 227 | return false; |
| 228 | break; |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 229 | default: |
| 230 | break; |
| 231 | } |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 232 | return true; |
| 233 | } |
| 234 | |
Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 235 | static const char *getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { |
| 236 | switch (Severity) { |
| 237 | case DS_Error: |
| 238 | return "error"; |
| 239 | case DS_Warning: |
| 240 | return "warning"; |
| 241 | case DS_Remark: |
| 242 | return "remark"; |
| 243 | case DS_Note: |
| 244 | return "note"; |
| 245 | } |
Aaron Ballman | 5220476 | 2015-06-16 13:14:59 +0000 | [diff] [blame] | 246 | llvm_unreachable("Unknown DiagnosticSeverity"); |
Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 249 | void LLVMContext::diagnose(const DiagnosticInfo &DI) { |
| 250 | // If there is a report handler, use it. |
| 251 | if (pImpl->DiagnosticHandler) { |
| 252 | if (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) |
| 253 | pImpl->DiagnosticHandler(DI, pImpl->DiagnosticContext); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | if (!isDiagnosticEnabled(DI)) |
| 258 | return; |
Diego Novillo | df65501 | 2014-04-16 16:53:41 +0000 | [diff] [blame] | 259 | |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 260 | // Otherwise, print the message with a prefix based on the severity. |
Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 261 | DiagnosticPrinterRawOStream DP(errs()); |
| 262 | errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 263 | DI.print(DP); |
Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 264 | errs() << "\n"; |
| 265 | if (DI.getSeverity() == DS_Error) |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 266 | exit(1); |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Chris Lattner | e22e613 | 2012-01-03 23:47:05 +0000 | [diff] [blame] | 269 | void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) { |
Quentin Colombet | dec8d55 | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 270 | diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); |
Chris Lattner | 1e45789 | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | //===----------------------------------------------------------------------===// |
| 274 | // Metadata Kind Uniquing |
| 275 | //===----------------------------------------------------------------------===// |
| 276 | |
Filipe Cabecinhas | 1ac0d2d | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 277 | /// Return a unique non-zero ID for the specified metadata kind. |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 278 | unsigned LLVMContext::getMDKindID(StringRef Name) const { |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 279 | // If this is new, assign it its ID. |
Filipe Cabecinhas | 1ac0d2d | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 280 | return pImpl->CustomMDKindNames.insert( |
| 281 | std::make_pair( |
| 282 | Name, pImpl->CustomMDKindNames.size())) |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 283 | .first->second; |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Sanjay Patel | 4104337 | 2015-08-24 23:20:16 +0000 | [diff] [blame] | 286 | /// getHandlerNames - Populate client-supplied smallvector using custom |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 287 | /// metadata name and ID. |
| 288 | void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const { |
Dan Gohman | 43aa8f0 | 2010-07-20 21:42:28 +0000 | [diff] [blame] | 289 | Names.resize(pImpl->CustomMDKindNames.size()); |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 290 | for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(), |
| 291 | E = pImpl->CustomMDKindNames.end(); I != E; ++I) |
Chris Lattner | a3b94ba | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 292 | Names[I->second] = I->first(); |
| 293 | } |
Sanjoy Das | 9303c24 | 2015-09-24 19:14:18 +0000 | [diff] [blame] | 294 | |
| 295 | void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const { |
| 296 | pImpl->getOperandBundleTags(Tags); |
| 297 | } |
| 298 | |
| 299 | uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const { |
| 300 | return pImpl->getOperandBundleTagID(Tag); |
| 301 | } |