1ef860a24SChandler Carruth //===-- LLVMContext.cpp - Implement LLVMContext ---------------------------===//
2ef860a24SChandler Carruth //
3ef860a24SChandler Carruth //                     The LLVM Compiler Infrastructure
4ef860a24SChandler Carruth //
5ef860a24SChandler Carruth // This file is distributed under the University of Illinois Open Source
6ef860a24SChandler Carruth // License. See LICENSE.TXT for details.
7ef860a24SChandler Carruth //
8ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
9ef860a24SChandler Carruth //
10ef860a24SChandler Carruth //  This file implements LLVMContext, as a wrapper around the opaque
11ef860a24SChandler Carruth //  class LLVMContextImpl.
12ef860a24SChandler Carruth //
13ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
14ef860a24SChandler Carruth 
159fb823bbSChandler Carruth #include "llvm/IR/LLVMContext.h"
166bda14b3SChandler Carruth #include "LLVMContextImpl.h"
175354a8aaSEugene Zelenko #include "llvm/ADT/SmallVector.h"
185354a8aaSEugene Zelenko #include "llvm/ADT/StringMap.h"
195354a8aaSEugene Zelenko #include "llvm/ADT/StringRef.h"
205354a8aaSEugene Zelenko #include "llvm/ADT/Twine.h"
21b4c44d23SQuentin Colombet #include "llvm/IR/DiagnosticInfo.h"
22b4c44d23SQuentin Colombet #include "llvm/IR/DiagnosticPrinter.h"
239fb823bbSChandler Carruth #include "llvm/IR/Metadata.h"
245354a8aaSEugene Zelenko #include "llvm/IR/Module.h"
255354a8aaSEugene Zelenko #include "llvm/Support/Casting.h"
265354a8aaSEugene Zelenko #include "llvm/Support/ErrorHandling.h"
275354a8aaSEugene Zelenko #include "llvm/Support/raw_ostream.h"
285354a8aaSEugene Zelenko #include <cassert>
295354a8aaSEugene Zelenko #include <cstdlib>
305354a8aaSEugene Zelenko #include <string>
315354a8aaSEugene Zelenko #include <utility>
325354a8aaSEugene Zelenko 
33ef860a24SChandler Carruth using namespace llvm;
34ef860a24SChandler Carruth 
35ef860a24SChandler Carruth LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) {
36ef860a24SChandler Carruth   // Create the fixed metadata kinds. This is done in the same order as the
37ef860a24SChandler Carruth   // MD_* enum values so that they correspond.
386f0b4f2eSPeter Collingbourne   std::pair<unsigned, StringRef> MDKinds[] = {
396f0b4f2eSPeter Collingbourne     {MD_dbg, "dbg"},
406f0b4f2eSPeter Collingbourne     {MD_tbaa, "tbaa"},
416f0b4f2eSPeter Collingbourne     {MD_prof, "prof"},
426f0b4f2eSPeter Collingbourne     {MD_fpmath, "fpmath"},
436f0b4f2eSPeter Collingbourne     {MD_range, "range"},
446f0b4f2eSPeter Collingbourne     {MD_tbaa_struct, "tbaa.struct"},
456f0b4f2eSPeter Collingbourne     {MD_invariant_load, "invariant.load"},
466f0b4f2eSPeter Collingbourne     {MD_alias_scope, "alias.scope"},
476f0b4f2eSPeter Collingbourne     {MD_noalias, "noalias"},
486f0b4f2eSPeter Collingbourne     {MD_nontemporal, "nontemporal"},
496f0b4f2eSPeter Collingbourne     {MD_mem_parallel_loop_access, "llvm.mem.parallel_loop_access"},
506f0b4f2eSPeter Collingbourne     {MD_nonnull, "nonnull"},
516f0b4f2eSPeter Collingbourne     {MD_dereferenceable, "dereferenceable"},
526f0b4f2eSPeter Collingbourne     {MD_dereferenceable_or_null, "dereferenceable_or_null"},
536f0b4f2eSPeter Collingbourne     {MD_make_implicit, "make.implicit"},
546f0b4f2eSPeter Collingbourne     {MD_unpredictable, "unpredictable"},
556f0b4f2eSPeter Collingbourne     {MD_invariant_group, "invariant.group"},
566f0b4f2eSPeter Collingbourne     {MD_align, "align"},
576f0b4f2eSPeter Collingbourne     {MD_loop, "llvm.loop"},
586f0b4f2eSPeter Collingbourne     {MD_type, "type"},
596f0b4f2eSPeter Collingbourne     {MD_section_prefix, "section_prefix"},
60235c275bSPeter Collingbourne     {MD_absolute_symbol, "absolute_symbol"},
6151c962f7SEvgeniy Stepanov     {MD_associated, "associated"},
6236bbc8ceSMatthew Simpson     {MD_callees, "callees"},
63*dce9def3SHiroshi Yamauchi     {MD_irr_loop, "irr_loop"},
646f0b4f2eSPeter Collingbourne   };
65ef860a24SChandler Carruth 
666f0b4f2eSPeter Collingbourne   for (auto &MDKind : MDKinds) {
676f0b4f2eSPeter Collingbourne     unsigned ID = getMDKindID(MDKind.second);
686f0b4f2eSPeter Collingbourne     assert(ID == MDKind.first && "metadata kind id drifted");
696f0b4f2eSPeter Collingbourne     (void)ID;
706f0b4f2eSPeter Collingbourne   }
71302b69c9SDehao Chen 
72cdafd849SSanjoy Das   auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt");
73cdafd849SSanjoy Das   assert(DeoptEntry->second == LLVMContext::OB_deopt &&
74cdafd849SSanjoy Das          "deopt operand bundle id drifted!");
75cdafd849SSanjoy Das   (void)DeoptEntry;
763bb88c02SDavid Majnemer 
773bb88c02SDavid Majnemer   auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet");
783bb88c02SDavid Majnemer   assert(FuncletEntry->second == LLVMContext::OB_funclet &&
793bb88c02SDavid Majnemer          "funclet operand bundle id drifted!");
803bb88c02SDavid Majnemer   (void)FuncletEntry;
81a34ce95bSSanjoy Das 
82a34ce95bSSanjoy Das   auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition");
83a34ce95bSSanjoy Das   assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition &&
84a34ce95bSSanjoy Das          "gc-transition operand bundle id drifted!");
85a34ce95bSSanjoy Das   (void)GCTransitionEntry;
86bb80d3e1SKonstantin Zhuravlyov 
87bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SingleThreadSSID =
88bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("singlethread");
89bb80d3e1SKonstantin Zhuravlyov   assert(SingleThreadSSID == SyncScope::SingleThread &&
90bb80d3e1SKonstantin Zhuravlyov          "singlethread synchronization scope ID drifted!");
91878fdee0SKonstantin Zhuravlyov   (void)SingleThreadSSID;
92bb80d3e1SKonstantin Zhuravlyov 
93bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SystemSSID =
94bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("");
95bb80d3e1SKonstantin Zhuravlyov   assert(SystemSSID == SyncScope::System &&
96bb80d3e1SKonstantin Zhuravlyov          "system synchronization scope ID drifted!");
97878fdee0SKonstantin Zhuravlyov   (void)SystemSSID;
98ef860a24SChandler Carruth }
995354a8aaSEugene Zelenko 
100ef860a24SChandler Carruth LLVMContext::~LLVMContext() { delete pImpl; }
101ef860a24SChandler Carruth 
102ef860a24SChandler Carruth void LLVMContext::addModule(Module *M) {
103ef860a24SChandler Carruth   pImpl->OwnedModules.insert(M);
104ef860a24SChandler Carruth }
105ef860a24SChandler Carruth 
106ef860a24SChandler Carruth void LLVMContext::removeModule(Module *M) {
107ef860a24SChandler Carruth   pImpl->OwnedModules.erase(M);
108ef860a24SChandler Carruth }
109ef860a24SChandler Carruth 
110ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
111ef860a24SChandler Carruth // Recoverable Backend Errors
112ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
113ef860a24SChandler Carruth 
114a594fab4SBob Wilson void LLVMContext::
115a594fab4SBob Wilson setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
116ef860a24SChandler Carruth                               void *DiagContext) {
117a594fab4SBob Wilson   pImpl->InlineAsmDiagHandler = DiagHandler;
118a594fab4SBob Wilson   pImpl->InlineAsmDiagContext = DiagContext;
119ef860a24SChandler Carruth }
120ef860a24SChandler Carruth 
121a594fab4SBob Wilson /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
122a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
123a594fab4SBob Wilson LLVMContext::InlineAsmDiagHandlerTy
124a594fab4SBob Wilson LLVMContext::getInlineAsmDiagnosticHandler() const {
125a594fab4SBob Wilson   return pImpl->InlineAsmDiagHandler;
126ef860a24SChandler Carruth }
127ef860a24SChandler Carruth 
128a594fab4SBob Wilson /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
129a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
130a594fab4SBob Wilson void *LLVMContext::getInlineAsmDiagnosticContext() const {
131a594fab4SBob Wilson   return pImpl->InlineAsmDiagContext;
132ef860a24SChandler Carruth }
133ef860a24SChandler Carruth 
134b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandlerCallBack(
135b5ab895eSVivek Pandya     DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler,
136b5ab895eSVivek Pandya     void *DiagnosticContext, bool RespectFilters) {
137b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler;
138b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
139b5ab895eSVivek Pandya   pImpl->RespectDiagnosticFilters = RespectFilters;
140b5ab895eSVivek Pandya }
141b5ab895eSVivek Pandya 
142b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
14330c9242cSDuncan P. N. Exon Smith                                       bool RespectFilters) {
144b5ab895eSVivek Pandya   pImpl->DiagHandler = std::move(DH);
14530c9242cSDuncan P. N. Exon Smith   pImpl->RespectDiagnosticFilters = RespectFilters;
146b4c44d23SQuentin Colombet }
147b4c44d23SQuentin Colombet 
14844e5f6c4SBrian Gesiak void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) {
14944e5f6c4SBrian Gesiak   pImpl->DiagnosticsHotnessRequested = Requested;
15044e5f6c4SBrian Gesiak }
15144e5f6c4SBrian Gesiak bool LLVMContext::getDiagnosticsHotnessRequested() const {
15244e5f6c4SBrian Gesiak   return pImpl->DiagnosticsHotnessRequested;
153aad81608SAdam Nemet }
154aad81608SAdam Nemet 
1554ef3daafSBrian Gesiak void LLVMContext::setDiagnosticsHotnessThreshold(uint64_t Threshold) {
1564ef3daafSBrian Gesiak   pImpl->DiagnosticsHotnessThreshold = Threshold;
1574ef3daafSBrian Gesiak }
1584ef3daafSBrian Gesiak uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
1594ef3daafSBrian Gesiak   return pImpl->DiagnosticsHotnessThreshold;
1604ef3daafSBrian Gesiak }
1614ef3daafSBrian Gesiak 
162a62b7e1aSAdam Nemet yaml::Output *LLVMContext::getDiagnosticsOutputFile() {
163a62b7e1aSAdam Nemet   return pImpl->DiagnosticsOutputFile.get();
164a62b7e1aSAdam Nemet }
165a62b7e1aSAdam Nemet 
1666f408368SMehdi Amini void LLVMContext::setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F) {
1676f408368SMehdi Amini   pImpl->DiagnosticsOutputFile = std::move(F);
168a62b7e1aSAdam Nemet }
169a62b7e1aSAdam Nemet 
170b5ab895eSVivek Pandya DiagnosticHandler::DiagnosticHandlerTy
171b5ab895eSVivek Pandya LLVMContext::getDiagnosticHandlerCallBack() const {
172b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagHandlerCallback;
173b4c44d23SQuentin Colombet }
174b4c44d23SQuentin Colombet 
175b4c44d23SQuentin Colombet void *LLVMContext::getDiagnosticContext() const {
176b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagnosticContext;
177b4c44d23SQuentin Colombet }
178b4c44d23SQuentin Colombet 
17934390c70SJuergen Ributzka void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
18034390c70SJuergen Ributzka {
18134390c70SJuergen Ributzka   pImpl->YieldCallback = Callback;
18234390c70SJuergen Ributzka   pImpl->YieldOpaqueHandle = OpaqueHandle;
18334390c70SJuergen Ributzka }
18434390c70SJuergen Ributzka 
18534390c70SJuergen Ributzka void LLVMContext::yield() {
18634390c70SJuergen Ributzka   if (pImpl->YieldCallback)
18734390c70SJuergen Ributzka     pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle);
18834390c70SJuergen Ributzka }
18934390c70SJuergen Ributzka 
190ef860a24SChandler Carruth void LLVMContext::emitError(const Twine &ErrorStr) {
191dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(ErrorStr));
192ef860a24SChandler Carruth }
193ef860a24SChandler Carruth 
194bfb44ef9SBob Wilson void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
195dec8d55bSQuentin Colombet   assert (I && "Invalid instruction");
196dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr));
197ef860a24SChandler Carruth }
198ef860a24SChandler Carruth 
19930c9242cSDuncan P. N. Exon Smith static bool isDiagnosticEnabled(const DiagnosticInfo &DI) {
2007f8af8bfSDiego Novillo   // Optimization remarks are selective. They need to check whether the regexp
2017f8af8bfSDiego Novillo   // pattern, passed via one of the -pass-remarks* flags, matches the name of
2027f8af8bfSDiego Novillo   // the pass that is emitting the diagnostic. If there is no match, ignore the
2037f8af8bfSDiego Novillo   // diagnostic and return.
204f31b1f31SAdam Nemet   //
205f31b1f31SAdam Nemet   // Also noisy remarks are only enabled if we have hotness information to sort
206f31b1f31SAdam Nemet   // them.
207e9148dd6SAkira Hatanaka   if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
208f31b1f31SAdam Nemet     return Remark->isEnabled() &&
209f31b1f31SAdam Nemet            (!Remark->isVerbose() || Remark->getHotness());
210e9148dd6SAkira Hatanaka 
21130c9242cSDuncan P. N. Exon Smith   return true;
21230c9242cSDuncan P. N. Exon Smith }
21330c9242cSDuncan P. N. Exon Smith 
2144b9c0d4dSRenato Golin const char *
2154b9c0d4dSRenato Golin LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
216735c47ecSAlex Lorenz   switch (Severity) {
217735c47ecSAlex Lorenz   case DS_Error:
218735c47ecSAlex Lorenz     return "error";
219735c47ecSAlex Lorenz   case DS_Warning:
220735c47ecSAlex Lorenz     return "warning";
221735c47ecSAlex Lorenz   case DS_Remark:
222735c47ecSAlex Lorenz     return "remark";
223735c47ecSAlex Lorenz   case DS_Note:
224735c47ecSAlex Lorenz     return "note";
225735c47ecSAlex Lorenz   }
2265220476aSAaron Ballman   llvm_unreachable("Unknown DiagnosticSeverity");
227735c47ecSAlex Lorenz }
228735c47ecSAlex Lorenz 
22930c9242cSDuncan P. N. Exon Smith void LLVMContext::diagnose(const DiagnosticInfo &DI) {
2306c381b7aSAdam Nemet   if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
2316c381b7aSAdam Nemet     yaml::Output *Out = getDiagnosticsOutputFile();
2326c381b7aSAdam Nemet     if (Out) {
2336c381b7aSAdam Nemet       // For remarks the << operator takes a reference to a pointer.
2346c381b7aSAdam Nemet       auto *P = const_cast<DiagnosticInfoOptimizationBase *>(OptDiagBase);
2356c381b7aSAdam Nemet       *Out << P;
2366c381b7aSAdam Nemet     }
2376c381b7aSAdam Nemet   }
23830c9242cSDuncan P. N. Exon Smith   // If there is a report handler, use it.
239b5ab895eSVivek Pandya   if (pImpl->DiagHandler &&
240b5ab895eSVivek Pandya       (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
241b5ab895eSVivek Pandya       pImpl->DiagHandler->handleDiagnostics(DI))
24230c9242cSDuncan P. N. Exon Smith     return;
24330c9242cSDuncan P. N. Exon Smith 
24430c9242cSDuncan P. N. Exon Smith   if (!isDiagnosticEnabled(DI))
24530c9242cSDuncan P. N. Exon Smith     return;
246df655013SDiego Novillo 
247b4c44d23SQuentin Colombet   // Otherwise, print the message with a prefix based on the severity.
248735c47ecSAlex Lorenz   DiagnosticPrinterRawOStream DP(errs());
249735c47ecSAlex Lorenz   errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
250b4c44d23SQuentin Colombet   DI.print(DP);
251735c47ecSAlex Lorenz   errs() << "\n";
252735c47ecSAlex Lorenz   if (DI.getSeverity() == DS_Error)
253b4c44d23SQuentin Colombet     exit(1);
254b4c44d23SQuentin Colombet }
255b4c44d23SQuentin Colombet 
256ef860a24SChandler Carruth void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
257dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
258ef860a24SChandler Carruth }
259ef860a24SChandler Carruth 
260ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
261ef860a24SChandler Carruth // Metadata Kind Uniquing
262ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
263ef860a24SChandler Carruth 
2641ac0d2deSFilipe Cabecinhas /// Return a unique non-zero ID for the specified metadata kind.
265ef860a24SChandler Carruth unsigned LLVMContext::getMDKindID(StringRef Name) const {
266ef860a24SChandler Carruth   // If this is new, assign it its ID.
2671ac0d2deSFilipe Cabecinhas   return pImpl->CustomMDKindNames.insert(
2681ac0d2deSFilipe Cabecinhas                                      std::make_pair(
2691ac0d2deSFilipe Cabecinhas                                          Name, pImpl->CustomMDKindNames.size()))
2705106ce78SDavid Blaikie       .first->second;
271ef860a24SChandler Carruth }
272ef860a24SChandler Carruth 
2734104337dSSanjay Patel /// getHandlerNames - Populate client-supplied smallvector using custom
274ef860a24SChandler Carruth /// metadata name and ID.
275ef860a24SChandler Carruth void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
276ef860a24SChandler Carruth   Names.resize(pImpl->CustomMDKindNames.size());
277ef860a24SChandler Carruth   for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
278ef860a24SChandler Carruth        E = pImpl->CustomMDKindNames.end(); I != E; ++I)
279ef860a24SChandler Carruth     Names[I->second] = I->first();
280ef860a24SChandler Carruth }
2819303c246SSanjoy Das 
2829303c246SSanjoy Das void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
2839303c246SSanjoy Das   pImpl->getOperandBundleTags(Tags);
2849303c246SSanjoy Das }
2859303c246SSanjoy Das 
2869303c246SSanjoy Das uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
2879303c246SSanjoy Das   return pImpl->getOperandBundleTagID(Tag);
2889303c246SSanjoy Das }
289599ebf27SMehdi Amini 
290bb80d3e1SKonstantin Zhuravlyov SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) {
291bb80d3e1SKonstantin Zhuravlyov   return pImpl->getOrInsertSyncScopeID(SSN);
292bb80d3e1SKonstantin Zhuravlyov }
293bb80d3e1SKonstantin Zhuravlyov 
294bb80d3e1SKonstantin Zhuravlyov void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
295bb80d3e1SKonstantin Zhuravlyov   pImpl->getSyncScopeNames(SSNs);
296bb80d3e1SKonstantin Zhuravlyov }
297bb80d3e1SKonstantin Zhuravlyov 
298599ebf27SMehdi Amini void LLVMContext::setGC(const Function &Fn, std::string GCName) {
299599ebf27SMehdi Amini   auto It = pImpl->GCNames.find(&Fn);
300599ebf27SMehdi Amini 
301599ebf27SMehdi Amini   if (It == pImpl->GCNames.end()) {
302599ebf27SMehdi Amini     pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName)));
303599ebf27SMehdi Amini     return;
304599ebf27SMehdi Amini   }
305599ebf27SMehdi Amini   It->second = std::move(GCName);
306599ebf27SMehdi Amini }
3075354a8aaSEugene Zelenko 
308599ebf27SMehdi Amini const std::string &LLVMContext::getGC(const Function &Fn) {
309599ebf27SMehdi Amini   return pImpl->GCNames[&Fn];
310599ebf27SMehdi Amini }
3115354a8aaSEugene Zelenko 
312599ebf27SMehdi Amini void LLVMContext::deleteGC(const Function &Fn) {
313599ebf27SMehdi Amini   pImpl->GCNames.erase(&Fn);
314599ebf27SMehdi Amini }
31509b4a8daSMehdi Amini 
316e7090155SMehdi Amini bool LLVMContext::shouldDiscardValueNames() const {
317e7090155SMehdi Amini   return pImpl->DiscardValueNames;
318e7090155SMehdi Amini }
31909b4a8daSMehdi Amini 
320ed8fdb2aSDuncan P. N. Exon Smith bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; }
3215ab2be09SDuncan P. N. Exon Smith 
322ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::enableDebugTypeODRUniquing() {
3235ab2be09SDuncan P. N. Exon Smith   if (pImpl->DITypeMap)
3245ab2be09SDuncan P. N. Exon Smith     return;
3255ab2be09SDuncan P. N. Exon Smith 
326e8b555c6SDuncan P. N. Exon Smith   pImpl->DITypeMap.emplace();
3275ab2be09SDuncan P. N. Exon Smith }
3285ab2be09SDuncan P. N. Exon Smith 
329ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
3305ab2be09SDuncan P. N. Exon Smith 
33109b4a8daSMehdi Amini void LLVMContext::setDiscardValueNames(bool Discard) {
33209b4a8daSMehdi Amini   pImpl->DiscardValueNames = Discard;
33309b4a8daSMehdi Amini }
334aa641a51SAndrew Kaylor 
335aa641a51SAndrew Kaylor OptBisect &LLVMContext::getOptBisect() {
336aa641a51SAndrew Kaylor   return pImpl->getOptBisect();
337aa641a51SAndrew Kaylor }
338b5ab895eSVivek Pandya 
339b5ab895eSVivek Pandya const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
340b5ab895eSVivek Pandya   return pImpl->DiagHandler.get();
341b5ab895eSVivek Pandya }
342b5ab895eSVivek Pandya 
343b5ab895eSVivek Pandya std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
344b5ab895eSVivek Pandya   return std::move(pImpl->DiagHandler);
345b5ab895eSVivek Pandya }
346