1ef860a24SChandler Carruth //===-- LLVMContext.cpp - Implement LLVMContext ---------------------------===//
2ef860a24SChandler Carruth //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ef860a24SChandler Carruth //
7ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
8ef860a24SChandler Carruth //
9ef860a24SChandler Carruth //  This file implements LLVMContext, as a wrapper around the opaque
10ef860a24SChandler Carruth //  class LLVMContextImpl.
11ef860a24SChandler Carruth //
12ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
13ef860a24SChandler Carruth 
149fb823bbSChandler Carruth #include "llvm/IR/LLVMContext.h"
156bda14b3SChandler Carruth #include "LLVMContextImpl.h"
165354a8aaSEugene Zelenko #include "llvm/ADT/SmallVector.h"
175354a8aaSEugene Zelenko #include "llvm/ADT/StringMap.h"
185354a8aaSEugene Zelenko #include "llvm/ADT/StringRef.h"
195354a8aaSEugene Zelenko #include "llvm/ADT/Twine.h"
20b4c44d23SQuentin Colombet #include "llvm/IR/DiagnosticInfo.h"
21b4c44d23SQuentin Colombet #include "llvm/IR/DiagnosticPrinter.h"
229fb823bbSChandler Carruth #include "llvm/IR/Metadata.h"
235354a8aaSEugene Zelenko #include "llvm/IR/Module.h"
24b8a847c0SFrancis Visoiu Mistrih #include "llvm/IR/RemarkStreamer.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[] = {
39d01ae675SVedant Kumar #define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name},
40d01ae675SVedant Kumar #include "llvm/IR/FixedMetadataKinds.def"
41d01ae675SVedant Kumar #undef LLVM_FIXED_MD_KIND
426f0b4f2eSPeter Collingbourne   };
43ef860a24SChandler Carruth 
446f0b4f2eSPeter Collingbourne   for (auto &MDKind : MDKinds) {
456f0b4f2eSPeter Collingbourne     unsigned ID = getMDKindID(MDKind.second);
466f0b4f2eSPeter Collingbourne     assert(ID == MDKind.first && "metadata kind id drifted");
476f0b4f2eSPeter Collingbourne     (void)ID;
486f0b4f2eSPeter Collingbourne   }
49302b69c9SDehao Chen 
50cdafd849SSanjoy Das   auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt");
51cdafd849SSanjoy Das   assert(DeoptEntry->second == LLVMContext::OB_deopt &&
52cdafd849SSanjoy Das          "deopt operand bundle id drifted!");
53cdafd849SSanjoy Das   (void)DeoptEntry;
543bb88c02SDavid Majnemer 
553bb88c02SDavid Majnemer   auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet");
563bb88c02SDavid Majnemer   assert(FuncletEntry->second == LLVMContext::OB_funclet &&
573bb88c02SDavid Majnemer          "funclet operand bundle id drifted!");
583bb88c02SDavid Majnemer   (void)FuncletEntry;
59a34ce95bSSanjoy Das 
60a34ce95bSSanjoy Das   auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition");
61a34ce95bSSanjoy Das   assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition &&
62a34ce95bSSanjoy Das          "gc-transition operand bundle id drifted!");
63a34ce95bSSanjoy Das   (void)GCTransitionEntry;
64bb80d3e1SKonstantin Zhuravlyov 
65*d157a9bcSAndrew Paverd   auto *CFGuardTargetEntry = pImpl->getOrInsertBundleTag("cfguardtarget");
66*d157a9bcSAndrew Paverd   assert(CFGuardTargetEntry->second == LLVMContext::OB_cfguardtarget &&
67*d157a9bcSAndrew Paverd          "cfguardtarget operand bundle id drifted!");
68*d157a9bcSAndrew Paverd   (void)CFGuardTargetEntry;
69*d157a9bcSAndrew Paverd 
70bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SingleThreadSSID =
71bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("singlethread");
72bb80d3e1SKonstantin Zhuravlyov   assert(SingleThreadSSID == SyncScope::SingleThread &&
73bb80d3e1SKonstantin Zhuravlyov          "singlethread synchronization scope ID drifted!");
74878fdee0SKonstantin Zhuravlyov   (void)SingleThreadSSID;
75bb80d3e1SKonstantin Zhuravlyov 
76bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SystemSSID =
77bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("");
78bb80d3e1SKonstantin Zhuravlyov   assert(SystemSSID == SyncScope::System &&
79bb80d3e1SKonstantin Zhuravlyov          "system synchronization scope ID drifted!");
80878fdee0SKonstantin Zhuravlyov   (void)SystemSSID;
81ef860a24SChandler Carruth }
825354a8aaSEugene Zelenko 
83ef860a24SChandler Carruth LLVMContext::~LLVMContext() { delete pImpl; }
84ef860a24SChandler Carruth 
85ef860a24SChandler Carruth void LLVMContext::addModule(Module *M) {
86ef860a24SChandler Carruth   pImpl->OwnedModules.insert(M);
87ef860a24SChandler Carruth }
88ef860a24SChandler Carruth 
89ef860a24SChandler Carruth void LLVMContext::removeModule(Module *M) {
90ef860a24SChandler Carruth   pImpl->OwnedModules.erase(M);
91ef860a24SChandler Carruth }
92ef860a24SChandler Carruth 
93ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
94ef860a24SChandler Carruth // Recoverable Backend Errors
95ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
96ef860a24SChandler Carruth 
97a594fab4SBob Wilson void LLVMContext::
98a594fab4SBob Wilson setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
99ef860a24SChandler Carruth                               void *DiagContext) {
100a594fab4SBob Wilson   pImpl->InlineAsmDiagHandler = DiagHandler;
101a594fab4SBob Wilson   pImpl->InlineAsmDiagContext = DiagContext;
102ef860a24SChandler Carruth }
103ef860a24SChandler Carruth 
104a594fab4SBob Wilson /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
105a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
106a594fab4SBob Wilson LLVMContext::InlineAsmDiagHandlerTy
107a594fab4SBob Wilson LLVMContext::getInlineAsmDiagnosticHandler() const {
108a594fab4SBob Wilson   return pImpl->InlineAsmDiagHandler;
109ef860a24SChandler Carruth }
110ef860a24SChandler Carruth 
111a594fab4SBob Wilson /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
112a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
113a594fab4SBob Wilson void *LLVMContext::getInlineAsmDiagnosticContext() const {
114a594fab4SBob Wilson   return pImpl->InlineAsmDiagContext;
115ef860a24SChandler Carruth }
116ef860a24SChandler Carruth 
117b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandlerCallBack(
118b5ab895eSVivek Pandya     DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler,
119b5ab895eSVivek Pandya     void *DiagnosticContext, bool RespectFilters) {
120b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler;
121b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
122b5ab895eSVivek Pandya   pImpl->RespectDiagnosticFilters = RespectFilters;
123b5ab895eSVivek Pandya }
124b5ab895eSVivek Pandya 
125b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
12630c9242cSDuncan P. N. Exon Smith                                       bool RespectFilters) {
127b5ab895eSVivek Pandya   pImpl->DiagHandler = std::move(DH);
12830c9242cSDuncan P. N. Exon Smith   pImpl->RespectDiagnosticFilters = RespectFilters;
129b4c44d23SQuentin Colombet }
130b4c44d23SQuentin Colombet 
13144e5f6c4SBrian Gesiak void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) {
13244e5f6c4SBrian Gesiak   pImpl->DiagnosticsHotnessRequested = Requested;
13344e5f6c4SBrian Gesiak }
13444e5f6c4SBrian Gesiak bool LLVMContext::getDiagnosticsHotnessRequested() const {
13544e5f6c4SBrian Gesiak   return pImpl->DiagnosticsHotnessRequested;
136aad81608SAdam Nemet }
137aad81608SAdam Nemet 
1384ef3daafSBrian Gesiak void LLVMContext::setDiagnosticsHotnessThreshold(uint64_t Threshold) {
1394ef3daafSBrian Gesiak   pImpl->DiagnosticsHotnessThreshold = Threshold;
1404ef3daafSBrian Gesiak }
1414ef3daafSBrian Gesiak uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
1424ef3daafSBrian Gesiak   return pImpl->DiagnosticsHotnessThreshold;
1434ef3daafSBrian Gesiak }
1444ef3daafSBrian Gesiak 
145b8a847c0SFrancis Visoiu Mistrih RemarkStreamer *LLVMContext::getRemarkStreamer() {
146b8a847c0SFrancis Visoiu Mistrih   return pImpl->RemarkDiagStreamer.get();
147a62b7e1aSAdam Nemet }
148b8a847c0SFrancis Visoiu Mistrih const RemarkStreamer *LLVMContext::getRemarkStreamer() const {
149b8a847c0SFrancis Visoiu Mistrih   return const_cast<LLVMContext *>(this)->getRemarkStreamer();
150b8a847c0SFrancis Visoiu Mistrih }
151b8a847c0SFrancis Visoiu Mistrih void LLVMContext::setRemarkStreamer(
152b8a847c0SFrancis Visoiu Mistrih     std::unique_ptr<RemarkStreamer> RemarkStreamer) {
153b8a847c0SFrancis Visoiu Mistrih   pImpl->RemarkDiagStreamer = std::move(RemarkStreamer);
154a62b7e1aSAdam Nemet }
155a62b7e1aSAdam Nemet 
156b5ab895eSVivek Pandya DiagnosticHandler::DiagnosticHandlerTy
157b5ab895eSVivek Pandya LLVMContext::getDiagnosticHandlerCallBack() const {
158b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagHandlerCallback;
159b4c44d23SQuentin Colombet }
160b4c44d23SQuentin Colombet 
161b4c44d23SQuentin Colombet void *LLVMContext::getDiagnosticContext() const {
162b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagnosticContext;
163b4c44d23SQuentin Colombet }
164b4c44d23SQuentin Colombet 
16534390c70SJuergen Ributzka void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
16634390c70SJuergen Ributzka {
16734390c70SJuergen Ributzka   pImpl->YieldCallback = Callback;
16834390c70SJuergen Ributzka   pImpl->YieldOpaqueHandle = OpaqueHandle;
16934390c70SJuergen Ributzka }
17034390c70SJuergen Ributzka 
17134390c70SJuergen Ributzka void LLVMContext::yield() {
17234390c70SJuergen Ributzka   if (pImpl->YieldCallback)
17334390c70SJuergen Ributzka     pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle);
17434390c70SJuergen Ributzka }
17534390c70SJuergen Ributzka 
176ef860a24SChandler Carruth void LLVMContext::emitError(const Twine &ErrorStr) {
177dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(ErrorStr));
178ef860a24SChandler Carruth }
179ef860a24SChandler Carruth 
180bfb44ef9SBob Wilson void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
181dec8d55bSQuentin Colombet   assert (I && "Invalid instruction");
182dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr));
183ef860a24SChandler Carruth }
184ef860a24SChandler Carruth 
18530c9242cSDuncan P. N. Exon Smith static bool isDiagnosticEnabled(const DiagnosticInfo &DI) {
1867f8af8bfSDiego Novillo   // Optimization remarks are selective. They need to check whether the regexp
1877f8af8bfSDiego Novillo   // pattern, passed via one of the -pass-remarks* flags, matches the name of
1887f8af8bfSDiego Novillo   // the pass that is emitting the diagnostic. If there is no match, ignore the
1897f8af8bfSDiego Novillo   // diagnostic and return.
190f31b1f31SAdam Nemet   //
191f31b1f31SAdam Nemet   // Also noisy remarks are only enabled if we have hotness information to sort
192f31b1f31SAdam Nemet   // them.
193e9148dd6SAkira Hatanaka   if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
194f31b1f31SAdam Nemet     return Remark->isEnabled() &&
195f31b1f31SAdam Nemet            (!Remark->isVerbose() || Remark->getHotness());
196e9148dd6SAkira Hatanaka 
19730c9242cSDuncan P. N. Exon Smith   return true;
19830c9242cSDuncan P. N. Exon Smith }
19930c9242cSDuncan P. N. Exon Smith 
2004b9c0d4dSRenato Golin const char *
2014b9c0d4dSRenato Golin LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
202735c47ecSAlex Lorenz   switch (Severity) {
203735c47ecSAlex Lorenz   case DS_Error:
204735c47ecSAlex Lorenz     return "error";
205735c47ecSAlex Lorenz   case DS_Warning:
206735c47ecSAlex Lorenz     return "warning";
207735c47ecSAlex Lorenz   case DS_Remark:
208735c47ecSAlex Lorenz     return "remark";
209735c47ecSAlex Lorenz   case DS_Note:
210735c47ecSAlex Lorenz     return "note";
211735c47ecSAlex Lorenz   }
2125220476aSAaron Ballman   llvm_unreachable("Unknown DiagnosticSeverity");
213735c47ecSAlex Lorenz }
214735c47ecSAlex Lorenz 
21530c9242cSDuncan P. N. Exon Smith void LLVMContext::diagnose(const DiagnosticInfo &DI) {
216b8a847c0SFrancis Visoiu Mistrih   if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
217b8a847c0SFrancis Visoiu Mistrih     if (RemarkStreamer *RS = getRemarkStreamer())
218b8a847c0SFrancis Visoiu Mistrih       RS->emit(*OptDiagBase);
219b8a847c0SFrancis Visoiu Mistrih 
22030c9242cSDuncan P. N. Exon Smith   // If there is a report handler, use it.
221b5ab895eSVivek Pandya   if (pImpl->DiagHandler &&
222b5ab895eSVivek Pandya       (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
223b5ab895eSVivek Pandya       pImpl->DiagHandler->handleDiagnostics(DI))
22430c9242cSDuncan P. N. Exon Smith     return;
22530c9242cSDuncan P. N. Exon Smith 
22630c9242cSDuncan P. N. Exon Smith   if (!isDiagnosticEnabled(DI))
22730c9242cSDuncan P. N. Exon Smith     return;
228df655013SDiego Novillo 
229b4c44d23SQuentin Colombet   // Otherwise, print the message with a prefix based on the severity.
230735c47ecSAlex Lorenz   DiagnosticPrinterRawOStream DP(errs());
231735c47ecSAlex Lorenz   errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
232b4c44d23SQuentin Colombet   DI.print(DP);
233735c47ecSAlex Lorenz   errs() << "\n";
234735c47ecSAlex Lorenz   if (DI.getSeverity() == DS_Error)
235b4c44d23SQuentin Colombet     exit(1);
236b4c44d23SQuentin Colombet }
237b4c44d23SQuentin Colombet 
238ef860a24SChandler Carruth void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
239dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
240ef860a24SChandler Carruth }
241ef860a24SChandler Carruth 
242ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
243ef860a24SChandler Carruth // Metadata Kind Uniquing
244ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
245ef860a24SChandler Carruth 
2461ac0d2deSFilipe Cabecinhas /// Return a unique non-zero ID for the specified metadata kind.
247ef860a24SChandler Carruth unsigned LLVMContext::getMDKindID(StringRef Name) const {
248ef860a24SChandler Carruth   // If this is new, assign it its ID.
2491ac0d2deSFilipe Cabecinhas   return pImpl->CustomMDKindNames.insert(
2501ac0d2deSFilipe Cabecinhas                                      std::make_pair(
2511ac0d2deSFilipe Cabecinhas                                          Name, pImpl->CustomMDKindNames.size()))
2525106ce78SDavid Blaikie       .first->second;
253ef860a24SChandler Carruth }
254ef860a24SChandler Carruth 
2554104337dSSanjay Patel /// getHandlerNames - Populate client-supplied smallvector using custom
256ef860a24SChandler Carruth /// metadata name and ID.
257ef860a24SChandler Carruth void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
258ef860a24SChandler Carruth   Names.resize(pImpl->CustomMDKindNames.size());
259ef860a24SChandler Carruth   for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
260ef860a24SChandler Carruth        E = pImpl->CustomMDKindNames.end(); I != E; ++I)
261ef860a24SChandler Carruth     Names[I->second] = I->first();
262ef860a24SChandler Carruth }
2639303c246SSanjoy Das 
2649303c246SSanjoy Das void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
2659303c246SSanjoy Das   pImpl->getOperandBundleTags(Tags);
2669303c246SSanjoy Das }
2679303c246SSanjoy Das 
2689303c246SSanjoy Das uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
2699303c246SSanjoy Das   return pImpl->getOperandBundleTagID(Tag);
2709303c246SSanjoy Das }
271599ebf27SMehdi Amini 
272bb80d3e1SKonstantin Zhuravlyov SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) {
273bb80d3e1SKonstantin Zhuravlyov   return pImpl->getOrInsertSyncScopeID(SSN);
274bb80d3e1SKonstantin Zhuravlyov }
275bb80d3e1SKonstantin Zhuravlyov 
276bb80d3e1SKonstantin Zhuravlyov void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
277bb80d3e1SKonstantin Zhuravlyov   pImpl->getSyncScopeNames(SSNs);
278bb80d3e1SKonstantin Zhuravlyov }
279bb80d3e1SKonstantin Zhuravlyov 
280599ebf27SMehdi Amini void LLVMContext::setGC(const Function &Fn, std::string GCName) {
281599ebf27SMehdi Amini   auto It = pImpl->GCNames.find(&Fn);
282599ebf27SMehdi Amini 
283599ebf27SMehdi Amini   if (It == pImpl->GCNames.end()) {
284599ebf27SMehdi Amini     pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName)));
285599ebf27SMehdi Amini     return;
286599ebf27SMehdi Amini   }
287599ebf27SMehdi Amini   It->second = std::move(GCName);
288599ebf27SMehdi Amini }
2895354a8aaSEugene Zelenko 
290599ebf27SMehdi Amini const std::string &LLVMContext::getGC(const Function &Fn) {
291599ebf27SMehdi Amini   return pImpl->GCNames[&Fn];
292599ebf27SMehdi Amini }
2935354a8aaSEugene Zelenko 
294599ebf27SMehdi Amini void LLVMContext::deleteGC(const Function &Fn) {
295599ebf27SMehdi Amini   pImpl->GCNames.erase(&Fn);
296599ebf27SMehdi Amini }
29709b4a8daSMehdi Amini 
298e7090155SMehdi Amini bool LLVMContext::shouldDiscardValueNames() const {
299e7090155SMehdi Amini   return pImpl->DiscardValueNames;
300e7090155SMehdi Amini }
30109b4a8daSMehdi Amini 
302ed8fdb2aSDuncan P. N. Exon Smith bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; }
3035ab2be09SDuncan P. N. Exon Smith 
304ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::enableDebugTypeODRUniquing() {
3055ab2be09SDuncan P. N. Exon Smith   if (pImpl->DITypeMap)
3065ab2be09SDuncan P. N. Exon Smith     return;
3075ab2be09SDuncan P. N. Exon Smith 
308e8b555c6SDuncan P. N. Exon Smith   pImpl->DITypeMap.emplace();
3095ab2be09SDuncan P. N. Exon Smith }
3105ab2be09SDuncan P. N. Exon Smith 
311ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
3125ab2be09SDuncan P. N. Exon Smith 
31309b4a8daSMehdi Amini void LLVMContext::setDiscardValueNames(bool Discard) {
31409b4a8daSMehdi Amini   pImpl->DiscardValueNames = Discard;
31509b4a8daSMehdi Amini }
316aa641a51SAndrew Kaylor 
317d29884c7SFedor Sergeev OptPassGate &LLVMContext::getOptPassGate() const {
31898014e43SFedor Sergeev   return pImpl->getOptPassGate();
319aa641a51SAndrew Kaylor }
320b5ab895eSVivek Pandya 
321d29884c7SFedor Sergeev void LLVMContext::setOptPassGate(OptPassGate& OPG) {
322d29884c7SFedor Sergeev   pImpl->setOptPassGate(OPG);
323d29884c7SFedor Sergeev }
324d29884c7SFedor Sergeev 
325b5ab895eSVivek Pandya const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
326b5ab895eSVivek Pandya   return pImpl->DiagHandler.get();
327b5ab895eSVivek Pandya }
328b5ab895eSVivek Pandya 
329b5ab895eSVivek Pandya std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
330b5ab895eSVivek Pandya   return std::move(pImpl->DiagHandler);
331b5ab895eSVivek Pandya }
332