Nick Lewycky | dbf5081 | 2012-12-26 22:00:49 +0000 | [diff] [blame] | 1 | //===-- LLVMContext.cpp - Implement LLVMContext ---------------------------===// |
Owen Anderson | 2bc29dc | 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 | 5217007 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements LLVMContext, as a wrapper around the opaque |
Benjamin Kramer | 12ddd40 | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 11 | // class LLVMContextImpl. |
Owen Anderson | 5217007 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Owen Anderson | 2bc29dc | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 14 | |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 15 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "LLVMContextImpl.h" |
Eugene Zelenko | aaf3f04 | 2016-04-28 18:04:41 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | #include "llvm/ADT/StringMap.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/ADT/Twine.h" |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DiagnosticInfo.h" |
| 22 | #include "llvm/IR/DiagnosticPrinter.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Metadata.h" |
Eugene Zelenko | aaf3f04 | 2016-04-28 18:04:41 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Module.h" |
| 25 | #include "llvm/Support/Casting.h" |
| 26 | #include "llvm/Support/ErrorHandling.h" |
| 27 | #include "llvm/Support/raw_ostream.h" |
| 28 | #include <cassert> |
| 29 | #include <cstdlib> |
| 30 | #include <string> |
| 31 | #include <utility> |
| 32 | |
Owen Anderson | 2bc29dc | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Chris Lattner | ec39f09 | 2010-03-30 23:03:27 +0000 | [diff] [blame] | 35 | LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { |
Dan Gohman | b2143b6 | 2010-09-14 21:25:10 +0000 | [diff] [blame] | 36 | // Create the fixed metadata kinds. This is done in the same order as the |
| 37 | // MD_* enum values so that they correspond. |
Peter Collingbourne | 2af93f1 | 2016-12-06 23:53:01 +0000 | [diff] [blame] | 38 | std::pair<unsigned, StringRef> MDKinds[] = { |
| 39 | {MD_dbg, "dbg"}, |
| 40 | {MD_tbaa, "tbaa"}, |
| 41 | {MD_prof, "prof"}, |
| 42 | {MD_fpmath, "fpmath"}, |
| 43 | {MD_range, "range"}, |
| 44 | {MD_tbaa_struct, "tbaa.struct"}, |
| 45 | {MD_invariant_load, "invariant.load"}, |
| 46 | {MD_alias_scope, "alias.scope"}, |
| 47 | {MD_noalias, "noalias"}, |
| 48 | {MD_nontemporal, "nontemporal"}, |
| 49 | {MD_mem_parallel_loop_access, "llvm.mem.parallel_loop_access"}, |
| 50 | {MD_nonnull, "nonnull"}, |
| 51 | {MD_dereferenceable, "dereferenceable"}, |
| 52 | {MD_dereferenceable_or_null, "dereferenceable_or_null"}, |
| 53 | {MD_make_implicit, "make.implicit"}, |
| 54 | {MD_unpredictable, "unpredictable"}, |
| 55 | {MD_invariant_group, "invariant.group"}, |
| 56 | {MD_align, "align"}, |
| 57 | {MD_loop, "llvm.loop"}, |
| 58 | {MD_type, "type"}, |
| 59 | {MD_section_prefix, "section_prefix"}, |
Peter Collingbourne | b29976c | 2016-12-08 19:01:00 +0000 | [diff] [blame] | 60 | {MD_absolute_symbol, "absolute_symbol"}, |
Evgeniy Stepanov | df808fe | 2017-03-17 22:17:24 +0000 | [diff] [blame] | 61 | {MD_associated, "associated"}, |
Matthew Simpson | 9f219e8d | 2017-10-16 22:22:11 +0000 | [diff] [blame] | 62 | {MD_callees, "callees"}, |
Hiroshi Yamauchi | dd33e17 | 2017-11-02 22:26:51 +0000 | [diff] [blame] | 63 | {MD_irr_loop, "irr_loop"}, |
Michael Kruse | 42a382c | 2018-12-20 04:58:07 +0000 | [diff] [blame] | 64 | {MD_access_group, "llvm.access.group"}, |
Peter Collingbourne | 2af93f1 | 2016-12-06 23:53:01 +0000 | [diff] [blame] | 65 | }; |
Dan Gohman | b2143b6 | 2010-09-14 21:25:10 +0000 | [diff] [blame] | 66 | |
Peter Collingbourne | 2af93f1 | 2016-12-06 23:53:01 +0000 | [diff] [blame] | 67 | for (auto &MDKind : MDKinds) { |
| 68 | unsigned ID = getMDKindID(MDKind.second); |
| 69 | assert(ID == MDKind.first && "metadata kind id drifted"); |
| 70 | (void)ID; |
| 71 | } |
Dehao Chen | 977fc82 | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 72 | |
Sanjoy Das | b4b58ba | 2015-11-11 21:38:02 +0000 | [diff] [blame] | 73 | auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt"); |
| 74 | assert(DeoptEntry->second == LLVMContext::OB_deopt && |
| 75 | "deopt operand bundle id drifted!"); |
| 76 | (void)DeoptEntry; |
David Majnemer | b46bb54 | 2015-12-15 21:27:27 +0000 | [diff] [blame] | 77 | |
| 78 | auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet"); |
| 79 | assert(FuncletEntry->second == LLVMContext::OB_funclet && |
| 80 | "funclet operand bundle id drifted!"); |
| 81 | (void)FuncletEntry; |
Sanjoy Das | e6a9ed7 | 2016-01-20 19:50:25 +0000 | [diff] [blame] | 82 | |
| 83 | auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition"); |
| 84 | assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition && |
| 85 | "gc-transition operand bundle id drifted!"); |
| 86 | (void)GCTransitionEntry; |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 87 | |
| 88 | SyncScope::ID SingleThreadSSID = |
| 89 | pImpl->getOrInsertSyncScopeID("singlethread"); |
| 90 | assert(SingleThreadSSID == SyncScope::SingleThread && |
| 91 | "singlethread synchronization scope ID drifted!"); |
Konstantin Zhuravlyov | 4cdc883 | 2017-07-12 00:15:53 +0000 | [diff] [blame] | 92 | (void)SingleThreadSSID; |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 93 | |
| 94 | SyncScope::ID SystemSSID = |
| 95 | pImpl->getOrInsertSyncScopeID(""); |
| 96 | assert(SystemSSID == SyncScope::System && |
| 97 | "system synchronization scope ID drifted!"); |
Konstantin Zhuravlyov | 4cdc883 | 2017-07-12 00:15:53 +0000 | [diff] [blame] | 98 | (void)SystemSSID; |
Chris Lattner | ec39f09 | 2010-03-30 23:03:27 +0000 | [diff] [blame] | 99 | } |
Eugene Zelenko | aaf3f04 | 2016-04-28 18:04:41 +0000 | [diff] [blame] | 100 | |
Owen Anderson | 2bc29dc | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 101 | LLVMContext::~LLVMContext() { delete pImpl; } |
Owen Anderson | 48b2f3e | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 102 | |
Owen Anderson | 30268be | 2010-09-08 18:03:32 +0000 | [diff] [blame] | 103 | void LLVMContext::addModule(Module *M) { |
| 104 | pImpl->OwnedModules.insert(M); |
| 105 | } |
| 106 | |
| 107 | void LLVMContext::removeModule(Module *M) { |
| 108 | pImpl->OwnedModules.erase(M); |
| 109 | } |
| 110 | |
Chris Lattner | 38686bd | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 111 | //===----------------------------------------------------------------------===// |
| 112 | // Recoverable Backend Errors |
| 113 | //===----------------------------------------------------------------------===// |
| 114 | |
Bob Wilson | f64c889 | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 115 | void LLVMContext:: |
| 116 | setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler, |
| 117 | void *DiagContext) { |
| 118 | pImpl->InlineAsmDiagHandler = DiagHandler; |
| 119 | pImpl->InlineAsmDiagContext = DiagContext; |
Chris Lattner | 42a4ee0 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Bob Wilson | f64c889 | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 122 | /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by |
| 123 | /// setInlineAsmDiagnosticHandler. |
| 124 | LLVMContext::InlineAsmDiagHandlerTy |
| 125 | LLVMContext::getInlineAsmDiagnosticHandler() const { |
| 126 | return pImpl->InlineAsmDiagHandler; |
Chris Lattner | 42a4ee0 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Bob Wilson | f64c889 | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 129 | /// getInlineAsmDiagnosticContext - Return the diagnostic context set by |
| 130 | /// setInlineAsmDiagnosticHandler. |
| 131 | void *LLVMContext::getInlineAsmDiagnosticContext() const { |
| 132 | return pImpl->InlineAsmDiagContext; |
Chris Lattner | 42a4ee0 | 2010-04-06 00:44:45 +0000 | [diff] [blame] | 133 | } |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 134 | |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 135 | void LLVMContext::setDiagnosticHandlerCallBack( |
| 136 | DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler, |
| 137 | void *DiagnosticContext, bool RespectFilters) { |
| 138 | pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler; |
| 139 | pImpl->DiagHandler->DiagnosticContext = DiagnosticContext; |
| 140 | pImpl->RespectDiagnosticFilters = RespectFilters; |
| 141 | } |
| 142 | |
| 143 | void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH, |
| 144 | bool RespectFilters) { |
| 145 | pImpl->DiagHandler = std::move(DH); |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 146 | pImpl->RespectDiagnosticFilters = RespectFilters; |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Brian Gesiak | 8e8ec78 | 2017-06-30 18:13:59 +0000 | [diff] [blame] | 149 | void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) { |
| 150 | pImpl->DiagnosticsHotnessRequested = Requested; |
| 151 | } |
| 152 | bool LLVMContext::getDiagnosticsHotnessRequested() const { |
| 153 | return pImpl->DiagnosticsHotnessRequested; |
Adam Nemet | f8cec99 | 2016-07-15 17:23:20 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Brian Gesiak | e330528 | 2017-06-30 23:14:53 +0000 | [diff] [blame] | 156 | void LLVMContext::setDiagnosticsHotnessThreshold(uint64_t Threshold) { |
| 157 | pImpl->DiagnosticsHotnessThreshold = Threshold; |
| 158 | } |
| 159 | uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const { |
| 160 | return pImpl->DiagnosticsHotnessThreshold; |
| 161 | } |
| 162 | |
Adam Nemet | 47c0d49 | 2016-09-27 20:55:07 +0000 | [diff] [blame] | 163 | yaml::Output *LLVMContext::getDiagnosticsOutputFile() { |
| 164 | return pImpl->DiagnosticsOutputFile.get(); |
| 165 | } |
| 166 | |
Mehdi Amini | 1bb4b12 | 2016-11-19 18:19:41 +0000 | [diff] [blame] | 167 | void LLVMContext::setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F) { |
| 168 | pImpl->DiagnosticsOutputFile = std::move(F); |
Adam Nemet | 47c0d49 | 2016-09-27 20:55:07 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 171 | DiagnosticHandler::DiagnosticHandlerTy |
| 172 | LLVMContext::getDiagnosticHandlerCallBack() const { |
| 173 | return pImpl->DiagHandler->DiagHandlerCallback; |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void *LLVMContext::getDiagnosticContext() const { |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 177 | return pImpl->DiagHandler->DiagnosticContext; |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Juergen Ributzka | 9bc1b73 | 2014-05-16 02:33:15 +0000 | [diff] [blame] | 180 | void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle) |
| 181 | { |
| 182 | pImpl->YieldCallback = Callback; |
| 183 | pImpl->YieldOpaqueHandle = OpaqueHandle; |
| 184 | } |
| 185 | |
| 186 | void LLVMContext::yield() { |
| 187 | if (pImpl->YieldCallback) |
| 188 | pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle); |
| 189 | } |
| 190 | |
Chris Lattner | 3a4c60c | 2012-01-03 23:47:05 +0000 | [diff] [blame] | 191 | void LLVMContext::emitError(const Twine &ErrorStr) { |
Quentin Colombet | 341149a | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 192 | diagnose(DiagnosticInfoInlineAsm(ErrorStr)); |
Chris Lattner | 38686bd | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Bob Wilson | 5844691 | 2013-02-08 21:48:29 +0000 | [diff] [blame] | 195 | void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { |
Quentin Colombet | 341149a | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 196 | assert (I && "Invalid instruction"); |
| 197 | diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); |
Chris Lattner | 38686bd | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 200 | static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { |
Diego Novillo | d16404a | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 201 | // Optimization remarks are selective. They need to check whether the regexp |
| 202 | // pattern, passed via one of the -pass-remarks* flags, matches the name of |
| 203 | // the pass that is emitting the diagnostic. If there is no match, ignore the |
| 204 | // diagnostic and return. |
Adam Nemet | 138faec | 2017-10-04 04:26:23 +0000 | [diff] [blame] | 205 | // |
| 206 | // Also noisy remarks are only enabled if we have hotness information to sort |
| 207 | // them. |
Akira Hatanaka | 5fe8a3c | 2016-04-01 00:34:39 +0000 | [diff] [blame] | 208 | if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) |
Adam Nemet | 138faec | 2017-10-04 04:26:23 +0000 | [diff] [blame] | 209 | return Remark->isEnabled() && |
| 210 | (!Remark->isVerbose() || Remark->getHotness()); |
Akira Hatanaka | 5fe8a3c | 2016-04-01 00:34:39 +0000 | [diff] [blame] | 211 | |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 212 | return true; |
| 213 | } |
| 214 | |
Renato Golin | 3b0d377 | 2016-05-16 14:28:02 +0000 | [diff] [blame] | 215 | const char * |
| 216 | LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 217 | switch (Severity) { |
| 218 | case DS_Error: |
| 219 | return "error"; |
| 220 | case DS_Warning: |
| 221 | return "warning"; |
| 222 | case DS_Remark: |
| 223 | return "remark"; |
| 224 | case DS_Note: |
| 225 | return "note"; |
| 226 | } |
Aaron Ballman | db8ece3 | 2015-06-16 13:14:59 +0000 | [diff] [blame] | 227 | llvm_unreachable("Unknown DiagnosticSeverity"); |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 230 | void LLVMContext::diagnose(const DiagnosticInfo &DI) { |
Adam Nemet | c5599f6 | 2017-10-04 15:18:11 +0000 | [diff] [blame] | 231 | if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) { |
| 232 | yaml::Output *Out = getDiagnosticsOutputFile(); |
| 233 | if (Out) { |
| 234 | // For remarks the << operator takes a reference to a pointer. |
| 235 | auto *P = const_cast<DiagnosticInfoOptimizationBase *>(OptDiagBase); |
| 236 | *Out << P; |
| 237 | } |
| 238 | } |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 239 | // If there is a report handler, use it. |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 240 | if (pImpl->DiagHandler && |
| 241 | (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) && |
| 242 | pImpl->DiagHandler->handleDiagnostics(DI)) |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 243 | return; |
Duncan P. N. Exon Smith | 04d2186 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 244 | |
| 245 | if (!isDiagnosticEnabled(DI)) |
| 246 | return; |
Diego Novillo | b902acb | 2014-04-16 16:53:41 +0000 | [diff] [blame] | 247 | |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 248 | // Otherwise, print the message with a prefix based on the severity. |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 249 | DiagnosticPrinterRawOStream DP(errs()); |
| 250 | errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 251 | DI.print(DP); |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 252 | errs() << "\n"; |
| 253 | if (DI.getSeverity() == DS_Error) |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 254 | exit(1); |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Chris Lattner | 3a4c60c | 2012-01-03 23:47:05 +0000 | [diff] [blame] | 257 | void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) { |
Quentin Colombet | 341149a | 2014-02-22 00:34:11 +0000 | [diff] [blame] | 258 | diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); |
Chris Lattner | 38686bd | 2010-04-07 23:40:44 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | //===----------------------------------------------------------------------===// |
| 262 | // Metadata Kind Uniquing |
| 263 | //===----------------------------------------------------------------------===// |
| 264 | |
Filipe Cabecinhas | 581e255 | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 265 | /// Return a unique non-zero ID for the specified metadata kind. |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 266 | unsigned LLVMContext::getMDKindID(StringRef Name) const { |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 267 | // If this is new, assign it its ID. |
Filipe Cabecinhas | 581e255 | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 268 | return pImpl->CustomMDKindNames.insert( |
| 269 | std::make_pair( |
| 270 | Name, pImpl->CustomMDKindNames.size())) |
David Blaikie | 1d4f28c | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 271 | .first->second; |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Sanjay Patel | 002f836 | 2015-08-24 23:20:16 +0000 | [diff] [blame] | 274 | /// getHandlerNames - Populate client-supplied smallvector using custom |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 275 | /// metadata name and ID. |
| 276 | void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const { |
Dan Gohman | 19538d1 | 2010-07-20 21:42:28 +0000 | [diff] [blame] | 277 | Names.resize(pImpl->CustomMDKindNames.size()); |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 278 | for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(), |
| 279 | E = pImpl->CustomMDKindNames.end(); I != E; ++I) |
Chris Lattner | 04e3b1e | 2010-03-30 20:48:48 +0000 | [diff] [blame] | 280 | Names[I->second] = I->first(); |
| 281 | } |
Sanjoy Das | 5b674c0 | 2015-09-24 19:14:18 +0000 | [diff] [blame] | 282 | |
| 283 | void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const { |
| 284 | pImpl->getOperandBundleTags(Tags); |
| 285 | } |
| 286 | |
| 287 | uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const { |
| 288 | return pImpl->getOperandBundleTagID(Tag); |
| 289 | } |
Mehdi Amini | 3569d3c | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 290 | |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 291 | SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) { |
| 292 | return pImpl->getOrInsertSyncScopeID(SSN); |
| 293 | } |
| 294 | |
| 295 | void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const { |
| 296 | pImpl->getSyncScopeNames(SSNs); |
| 297 | } |
| 298 | |
Mehdi Amini | 3569d3c | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 299 | void LLVMContext::setGC(const Function &Fn, std::string GCName) { |
| 300 | auto It = pImpl->GCNames.find(&Fn); |
| 301 | |
| 302 | if (It == pImpl->GCNames.end()) { |
| 303 | pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName))); |
| 304 | return; |
| 305 | } |
| 306 | It->second = std::move(GCName); |
| 307 | } |
Eugene Zelenko | aaf3f04 | 2016-04-28 18:04:41 +0000 | [diff] [blame] | 308 | |
Mehdi Amini | 3569d3c | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 309 | const std::string &LLVMContext::getGC(const Function &Fn) { |
| 310 | return pImpl->GCNames[&Fn]; |
| 311 | } |
Eugene Zelenko | aaf3f04 | 2016-04-28 18:04:41 +0000 | [diff] [blame] | 312 | |
Mehdi Amini | 3569d3c | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 313 | void LLVMContext::deleteGC(const Function &Fn) { |
| 314 | pImpl->GCNames.erase(&Fn); |
| 315 | } |
Mehdi Amini | 2de9927 | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 316 | |
Mehdi Amini | b3cb9bc | 2016-04-02 03:59:58 +0000 | [diff] [blame] | 317 | bool LLVMContext::shouldDiscardValueNames() const { |
| 318 | return pImpl->DiscardValueNames; |
| 319 | } |
Mehdi Amini | 2de9927 | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 320 | |
Duncan P. N. Exon Smith | 2663f35 | 2016-04-19 04:55:25 +0000 | [diff] [blame] | 321 | bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; } |
Duncan P. N. Exon Smith | 9bb5d5d | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 322 | |
Duncan P. N. Exon Smith | 2663f35 | 2016-04-19 04:55:25 +0000 | [diff] [blame] | 323 | void LLVMContext::enableDebugTypeODRUniquing() { |
Duncan P. N. Exon Smith | 9bb5d5d | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 324 | if (pImpl->DITypeMap) |
| 325 | return; |
| 326 | |
Duncan P. N. Exon Smith | 75cc051 | 2016-04-19 16:06:50 +0000 | [diff] [blame] | 327 | pImpl->DITypeMap.emplace(); |
Duncan P. N. Exon Smith | 9bb5d5d | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Duncan P. N. Exon Smith | 2663f35 | 2016-04-19 04:55:25 +0000 | [diff] [blame] | 330 | void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } |
Duncan P. N. Exon Smith | 9bb5d5d | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 331 | |
Mehdi Amini | 2de9927 | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 332 | void LLVMContext::setDiscardValueNames(bool Discard) { |
| 333 | pImpl->DiscardValueNames = Discard; |
| 334 | } |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 335 | |
Fedor Sergeev | 46d5e2b | 2018-04-05 10:29:37 +0000 | [diff] [blame] | 336 | OptPassGate &LLVMContext::getOptPassGate() const { |
Fedor Sergeev | 558f76f | 2018-03-27 16:57:20 +0000 | [diff] [blame] | 337 | return pImpl->getOptPassGate(); |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 338 | } |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 339 | |
Fedor Sergeev | 46d5e2b | 2018-04-05 10:29:37 +0000 | [diff] [blame] | 340 | void LLVMContext::setOptPassGate(OptPassGate& OPG) { |
| 341 | pImpl->setOptPassGate(OPG); |
| 342 | } |
| 343 | |
Vivek Pandya | 18b4c37 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 344 | const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const { |
| 345 | return pImpl->DiagHandler.get(); |
| 346 | } |
| 347 | |
| 348 | std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() { |
| 349 | return std::move(pImpl->DiagHandler); |
| 350 | } |