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"
227531a503SFrancis Visoiu Mistrih #include "llvm/IR/LLVMRemarkStreamer.h"
239fb823bbSChandler Carruth #include "llvm/IR/Metadata.h"
245354a8aaSEugene Zelenko #include "llvm/IR/Module.h"
257531a503SFrancis Visoiu Mistrih #include "llvm/Remarks/RemarkStreamer.h"
265354a8aaSEugene Zelenko #include "llvm/Support/Casting.h"
275354a8aaSEugene Zelenko #include "llvm/Support/ErrorHandling.h"
285354a8aaSEugene Zelenko #include "llvm/Support/raw_ostream.h"
295354a8aaSEugene Zelenko #include <cassert>
305354a8aaSEugene Zelenko #include <cstdlib>
315354a8aaSEugene Zelenko #include <string>
325354a8aaSEugene Zelenko #include <utility>
335354a8aaSEugene Zelenko 
34ef860a24SChandler Carruth using namespace llvm;
35ef860a24SChandler Carruth 
36ef860a24SChandler Carruth LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) {
37ef860a24SChandler Carruth   // Create the fixed metadata kinds. This is done in the same order as the
38ef860a24SChandler Carruth   // MD_* enum values so that they correspond.
396f0b4f2eSPeter Collingbourne   std::pair<unsigned, StringRef> MDKinds[] = {
40d01ae675SVedant Kumar #define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name},
41d01ae675SVedant Kumar #include "llvm/IR/FixedMetadataKinds.def"
42d01ae675SVedant Kumar #undef LLVM_FIXED_MD_KIND
436f0b4f2eSPeter Collingbourne   };
44ef860a24SChandler Carruth 
456f0b4f2eSPeter Collingbourne   for (auto &MDKind : MDKinds) {
466f0b4f2eSPeter Collingbourne     unsigned ID = getMDKindID(MDKind.second);
476f0b4f2eSPeter Collingbourne     assert(ID == MDKind.first && "metadata kind id drifted");
486f0b4f2eSPeter Collingbourne     (void)ID;
496f0b4f2eSPeter Collingbourne   }
50302b69c9SDehao Chen 
51cdafd849SSanjoy Das   auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt");
52cdafd849SSanjoy Das   assert(DeoptEntry->second == LLVMContext::OB_deopt &&
53cdafd849SSanjoy Das          "deopt operand bundle id drifted!");
54cdafd849SSanjoy Das   (void)DeoptEntry;
553bb88c02SDavid Majnemer 
563bb88c02SDavid Majnemer   auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet");
573bb88c02SDavid Majnemer   assert(FuncletEntry->second == LLVMContext::OB_funclet &&
583bb88c02SDavid Majnemer          "funclet operand bundle id drifted!");
593bb88c02SDavid Majnemer   (void)FuncletEntry;
60a34ce95bSSanjoy Das 
61a34ce95bSSanjoy Das   auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition");
62a34ce95bSSanjoy Das   assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition &&
63a34ce95bSSanjoy Das          "gc-transition operand bundle id drifted!");
64a34ce95bSSanjoy Das   (void)GCTransitionEntry;
65bb80d3e1SKonstantin Zhuravlyov 
66d157a9bcSAndrew Paverd   auto *CFGuardTargetEntry = pImpl->getOrInsertBundleTag("cfguardtarget");
67d157a9bcSAndrew Paverd   assert(CFGuardTargetEntry->second == LLVMContext::OB_cfguardtarget &&
68d157a9bcSAndrew Paverd          "cfguardtarget operand bundle id drifted!");
69d157a9bcSAndrew Paverd   (void)CFGuardTargetEntry;
70d157a9bcSAndrew Paverd 
713b0450acSArthur Eubanks   auto *PreallocatedEntry = pImpl->getOrInsertBundleTag("preallocated");
723b0450acSArthur Eubanks   assert(PreallocatedEntry->second == LLVMContext::OB_preallocated &&
733b0450acSArthur Eubanks          "preallocated operand bundle id drifted!");
743b0450acSArthur Eubanks   (void)PreallocatedEntry;
753b0450acSArthur Eubanks 
760e7c7705SPhilip Reames   auto *GCLiveEntry = pImpl->getOrInsertBundleTag("gc-live");
770e7c7705SPhilip Reames   assert(GCLiveEntry->second == LLVMContext::OB_gc_live &&
780e7c7705SPhilip Reames          "gc-transition operand bundle id drifted!");
790e7c7705SPhilip Reames   (void)GCLiveEntry;
800e7c7705SPhilip Reames 
81bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SingleThreadSSID =
82bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("singlethread");
83bb80d3e1SKonstantin Zhuravlyov   assert(SingleThreadSSID == SyncScope::SingleThread &&
84bb80d3e1SKonstantin Zhuravlyov          "singlethread synchronization scope ID drifted!");
85878fdee0SKonstantin Zhuravlyov   (void)SingleThreadSSID;
86bb80d3e1SKonstantin Zhuravlyov 
87bb80d3e1SKonstantin Zhuravlyov   SyncScope::ID SystemSSID =
88bb80d3e1SKonstantin Zhuravlyov       pImpl->getOrInsertSyncScopeID("");
89bb80d3e1SKonstantin Zhuravlyov   assert(SystemSSID == SyncScope::System &&
90bb80d3e1SKonstantin Zhuravlyov          "system synchronization scope ID drifted!");
91878fdee0SKonstantin Zhuravlyov   (void)SystemSSID;
92ef860a24SChandler Carruth }
935354a8aaSEugene Zelenko 
94ef860a24SChandler Carruth LLVMContext::~LLVMContext() { delete pImpl; }
95ef860a24SChandler Carruth 
96ef860a24SChandler Carruth void LLVMContext::addModule(Module *M) {
97ef860a24SChandler Carruth   pImpl->OwnedModules.insert(M);
98ef860a24SChandler Carruth }
99ef860a24SChandler Carruth 
100ef860a24SChandler Carruth void LLVMContext::removeModule(Module *M) {
101ef860a24SChandler Carruth   pImpl->OwnedModules.erase(M);
102ef860a24SChandler Carruth }
103ef860a24SChandler Carruth 
104ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
105ef860a24SChandler Carruth // Recoverable Backend Errors
106ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
107ef860a24SChandler Carruth 
108a594fab4SBob Wilson void LLVMContext::
109a594fab4SBob Wilson setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
110ef860a24SChandler Carruth                               void *DiagContext) {
111a594fab4SBob Wilson   pImpl->InlineAsmDiagHandler = DiagHandler;
112a594fab4SBob Wilson   pImpl->InlineAsmDiagContext = DiagContext;
113ef860a24SChandler Carruth }
114ef860a24SChandler Carruth 
115a594fab4SBob Wilson /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
116a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
117a594fab4SBob Wilson LLVMContext::InlineAsmDiagHandlerTy
118a594fab4SBob Wilson LLVMContext::getInlineAsmDiagnosticHandler() const {
119a594fab4SBob Wilson   return pImpl->InlineAsmDiagHandler;
120ef860a24SChandler Carruth }
121ef860a24SChandler Carruth 
122a594fab4SBob Wilson /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
123a594fab4SBob Wilson /// setInlineAsmDiagnosticHandler.
124a594fab4SBob Wilson void *LLVMContext::getInlineAsmDiagnosticContext() const {
125a594fab4SBob Wilson   return pImpl->InlineAsmDiagContext;
126ef860a24SChandler Carruth }
127ef860a24SChandler Carruth 
128b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandlerCallBack(
129b5ab895eSVivek Pandya     DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler,
130b5ab895eSVivek Pandya     void *DiagnosticContext, bool RespectFilters) {
131b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler;
132b5ab895eSVivek Pandya   pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
133b5ab895eSVivek Pandya   pImpl->RespectDiagnosticFilters = RespectFilters;
134b5ab895eSVivek Pandya }
135b5ab895eSVivek Pandya 
136b5ab895eSVivek Pandya void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
13730c9242cSDuncan P. N. Exon Smith                                       bool RespectFilters) {
138b5ab895eSVivek Pandya   pImpl->DiagHandler = std::move(DH);
13930c9242cSDuncan P. N. Exon Smith   pImpl->RespectDiagnosticFilters = RespectFilters;
140b4c44d23SQuentin Colombet }
141b4c44d23SQuentin Colombet 
14244e5f6c4SBrian Gesiak void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) {
14344e5f6c4SBrian Gesiak   pImpl->DiagnosticsHotnessRequested = Requested;
14444e5f6c4SBrian Gesiak }
14544e5f6c4SBrian Gesiak bool LLVMContext::getDiagnosticsHotnessRequested() const {
14644e5f6c4SBrian Gesiak   return pImpl->DiagnosticsHotnessRequested;
147aad81608SAdam Nemet }
148aad81608SAdam Nemet 
149*3acda917SWei Wang void LLVMContext::setDiagnosticsHotnessThreshold(Optional<uint64_t> Threshold) {
1504ef3daafSBrian Gesiak   pImpl->DiagnosticsHotnessThreshold = Threshold;
1514ef3daafSBrian Gesiak }
1524ef3daafSBrian Gesiak uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
153*3acda917SWei Wang   return pImpl->DiagnosticsHotnessThreshold.getValueOr(UINT64_MAX);
1544ef3daafSBrian Gesiak }
1554ef3daafSBrian Gesiak 
1567531a503SFrancis Visoiu Mistrih remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() {
1577531a503SFrancis Visoiu Mistrih   return pImpl->MainRemarkStreamer.get();
158a62b7e1aSAdam Nemet }
1597531a503SFrancis Visoiu Mistrih const remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() const {
1607531a503SFrancis Visoiu Mistrih   return const_cast<LLVMContext *>(this)->getMainRemarkStreamer();
161b8a847c0SFrancis Visoiu Mistrih }
1627531a503SFrancis Visoiu Mistrih void LLVMContext::setMainRemarkStreamer(
1637531a503SFrancis Visoiu Mistrih     std::unique_ptr<remarks::RemarkStreamer> RemarkStreamer) {
1647531a503SFrancis Visoiu Mistrih   pImpl->MainRemarkStreamer = std::move(RemarkStreamer);
1657531a503SFrancis Visoiu Mistrih }
1667531a503SFrancis Visoiu Mistrih 
1677531a503SFrancis Visoiu Mistrih LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() {
16831258878SFrancis Visoiu Mistrih   return pImpl->LLVMRS.get();
1697531a503SFrancis Visoiu Mistrih }
1707531a503SFrancis Visoiu Mistrih const LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() const {
1717531a503SFrancis Visoiu Mistrih   return const_cast<LLVMContext *>(this)->getLLVMRemarkStreamer();
1727531a503SFrancis Visoiu Mistrih }
1737531a503SFrancis Visoiu Mistrih void LLVMContext::setLLVMRemarkStreamer(
1747531a503SFrancis Visoiu Mistrih     std::unique_ptr<LLVMRemarkStreamer> RemarkStreamer) {
17531258878SFrancis Visoiu Mistrih   pImpl->LLVMRS = std::move(RemarkStreamer);
176a62b7e1aSAdam Nemet }
177a62b7e1aSAdam Nemet 
178b5ab895eSVivek Pandya DiagnosticHandler::DiagnosticHandlerTy
179b5ab895eSVivek Pandya LLVMContext::getDiagnosticHandlerCallBack() const {
180b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagHandlerCallback;
181b4c44d23SQuentin Colombet }
182b4c44d23SQuentin Colombet 
183b4c44d23SQuentin Colombet void *LLVMContext::getDiagnosticContext() const {
184b5ab895eSVivek Pandya   return pImpl->DiagHandler->DiagnosticContext;
185b4c44d23SQuentin Colombet }
186b4c44d23SQuentin Colombet 
18734390c70SJuergen Ributzka void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
18834390c70SJuergen Ributzka {
18934390c70SJuergen Ributzka   pImpl->YieldCallback = Callback;
19034390c70SJuergen Ributzka   pImpl->YieldOpaqueHandle = OpaqueHandle;
19134390c70SJuergen Ributzka }
19234390c70SJuergen Ributzka 
19334390c70SJuergen Ributzka void LLVMContext::yield() {
19434390c70SJuergen Ributzka   if (pImpl->YieldCallback)
19534390c70SJuergen Ributzka     pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle);
19634390c70SJuergen Ributzka }
19734390c70SJuergen Ributzka 
198ef860a24SChandler Carruth void LLVMContext::emitError(const Twine &ErrorStr) {
199dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(ErrorStr));
200ef860a24SChandler Carruth }
201ef860a24SChandler Carruth 
202bfb44ef9SBob Wilson void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
203dec8d55bSQuentin Colombet   assert (I && "Invalid instruction");
204dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr));
205ef860a24SChandler Carruth }
206ef860a24SChandler Carruth 
20730c9242cSDuncan P. N. Exon Smith static bool isDiagnosticEnabled(const DiagnosticInfo &DI) {
2087f8af8bfSDiego Novillo   // Optimization remarks are selective. They need to check whether the regexp
2097f8af8bfSDiego Novillo   // pattern, passed via one of the -pass-remarks* flags, matches the name of
2107f8af8bfSDiego Novillo   // the pass that is emitting the diagnostic. If there is no match, ignore the
2117f8af8bfSDiego Novillo   // diagnostic and return.
212f31b1f31SAdam Nemet   //
213f31b1f31SAdam Nemet   // Also noisy remarks are only enabled if we have hotness information to sort
214f31b1f31SAdam Nemet   // them.
215e9148dd6SAkira Hatanaka   if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
216f31b1f31SAdam Nemet     return Remark->isEnabled() &&
217f31b1f31SAdam Nemet            (!Remark->isVerbose() || Remark->getHotness());
218e9148dd6SAkira Hatanaka 
21930c9242cSDuncan P. N. Exon Smith   return true;
22030c9242cSDuncan P. N. Exon Smith }
22130c9242cSDuncan P. N. Exon Smith 
2224b9c0d4dSRenato Golin const char *
2234b9c0d4dSRenato Golin LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
224735c47ecSAlex Lorenz   switch (Severity) {
225735c47ecSAlex Lorenz   case DS_Error:
226735c47ecSAlex Lorenz     return "error";
227735c47ecSAlex Lorenz   case DS_Warning:
228735c47ecSAlex Lorenz     return "warning";
229735c47ecSAlex Lorenz   case DS_Remark:
230735c47ecSAlex Lorenz     return "remark";
231735c47ecSAlex Lorenz   case DS_Note:
232735c47ecSAlex Lorenz     return "note";
233735c47ecSAlex Lorenz   }
2345220476aSAaron Ballman   llvm_unreachable("Unknown DiagnosticSeverity");
235735c47ecSAlex Lorenz }
236735c47ecSAlex Lorenz 
23730c9242cSDuncan P. N. Exon Smith void LLVMContext::diagnose(const DiagnosticInfo &DI) {
238b8a847c0SFrancis Visoiu Mistrih   if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
2397531a503SFrancis Visoiu Mistrih     if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer())
240b8a847c0SFrancis Visoiu Mistrih       RS->emit(*OptDiagBase);
241b8a847c0SFrancis Visoiu Mistrih 
24230c9242cSDuncan P. N. Exon Smith   // If there is a report handler, use it.
243b5ab895eSVivek Pandya   if (pImpl->DiagHandler &&
244b5ab895eSVivek Pandya       (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
245b5ab895eSVivek Pandya       pImpl->DiagHandler->handleDiagnostics(DI))
24630c9242cSDuncan P. N. Exon Smith     return;
24730c9242cSDuncan P. N. Exon Smith 
24830c9242cSDuncan P. N. Exon Smith   if (!isDiagnosticEnabled(DI))
24930c9242cSDuncan P. N. Exon Smith     return;
250df655013SDiego Novillo 
251b4c44d23SQuentin Colombet   // Otherwise, print the message with a prefix based on the severity.
252735c47ecSAlex Lorenz   DiagnosticPrinterRawOStream DP(errs());
253735c47ecSAlex Lorenz   errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
254b4c44d23SQuentin Colombet   DI.print(DP);
255735c47ecSAlex Lorenz   errs() << "\n";
256735c47ecSAlex Lorenz   if (DI.getSeverity() == DS_Error)
257b4c44d23SQuentin Colombet     exit(1);
258b4c44d23SQuentin Colombet }
259b4c44d23SQuentin Colombet 
260ef860a24SChandler Carruth void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
261dec8d55bSQuentin Colombet   diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
262ef860a24SChandler Carruth }
263ef860a24SChandler Carruth 
264ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
265ef860a24SChandler Carruth // Metadata Kind Uniquing
266ef860a24SChandler Carruth //===----------------------------------------------------------------------===//
267ef860a24SChandler Carruth 
2681ac0d2deSFilipe Cabecinhas /// Return a unique non-zero ID for the specified metadata kind.
269ef860a24SChandler Carruth unsigned LLVMContext::getMDKindID(StringRef Name) const {
270ef860a24SChandler Carruth   // If this is new, assign it its ID.
2711ac0d2deSFilipe Cabecinhas   return pImpl->CustomMDKindNames.insert(
2721ac0d2deSFilipe Cabecinhas                                      std::make_pair(
2731ac0d2deSFilipe Cabecinhas                                          Name, pImpl->CustomMDKindNames.size()))
2745106ce78SDavid Blaikie       .first->second;
275ef860a24SChandler Carruth }
276ef860a24SChandler Carruth 
2774104337dSSanjay Patel /// getHandlerNames - Populate client-supplied smallvector using custom
278ef860a24SChandler Carruth /// metadata name and ID.
279ef860a24SChandler Carruth void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
280ef860a24SChandler Carruth   Names.resize(pImpl->CustomMDKindNames.size());
281ef860a24SChandler Carruth   for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
282ef860a24SChandler Carruth        E = pImpl->CustomMDKindNames.end(); I != E; ++I)
283ef860a24SChandler Carruth     Names[I->second] = I->first();
284ef860a24SChandler Carruth }
2859303c246SSanjoy Das 
2869303c246SSanjoy Das void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
2879303c246SSanjoy Das   pImpl->getOperandBundleTags(Tags);
2889303c246SSanjoy Das }
2899303c246SSanjoy Das 
290da100de0SOCHyams StringMapEntry<uint32_t> *
291da100de0SOCHyams LLVMContext::getOrInsertBundleTag(StringRef TagName) const {
292da100de0SOCHyams   return pImpl->getOrInsertBundleTag(TagName);
293da100de0SOCHyams }
294da100de0SOCHyams 
2959303c246SSanjoy Das uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
2969303c246SSanjoy Das   return pImpl->getOperandBundleTagID(Tag);
2979303c246SSanjoy Das }
298599ebf27SMehdi Amini 
299bb80d3e1SKonstantin Zhuravlyov SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) {
300bb80d3e1SKonstantin Zhuravlyov   return pImpl->getOrInsertSyncScopeID(SSN);
301bb80d3e1SKonstantin Zhuravlyov }
302bb80d3e1SKonstantin Zhuravlyov 
303bb80d3e1SKonstantin Zhuravlyov void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
304bb80d3e1SKonstantin Zhuravlyov   pImpl->getSyncScopeNames(SSNs);
305bb80d3e1SKonstantin Zhuravlyov }
306bb80d3e1SKonstantin Zhuravlyov 
307599ebf27SMehdi Amini void LLVMContext::setGC(const Function &Fn, std::string GCName) {
308599ebf27SMehdi Amini   auto It = pImpl->GCNames.find(&Fn);
309599ebf27SMehdi Amini 
310599ebf27SMehdi Amini   if (It == pImpl->GCNames.end()) {
311599ebf27SMehdi Amini     pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName)));
312599ebf27SMehdi Amini     return;
313599ebf27SMehdi Amini   }
314599ebf27SMehdi Amini   It->second = std::move(GCName);
315599ebf27SMehdi Amini }
3165354a8aaSEugene Zelenko 
317599ebf27SMehdi Amini const std::string &LLVMContext::getGC(const Function &Fn) {
318599ebf27SMehdi Amini   return pImpl->GCNames[&Fn];
319599ebf27SMehdi Amini }
3205354a8aaSEugene Zelenko 
321599ebf27SMehdi Amini void LLVMContext::deleteGC(const Function &Fn) {
322599ebf27SMehdi Amini   pImpl->GCNames.erase(&Fn);
323599ebf27SMehdi Amini }
32409b4a8daSMehdi Amini 
325e7090155SMehdi Amini bool LLVMContext::shouldDiscardValueNames() const {
326e7090155SMehdi Amini   return pImpl->DiscardValueNames;
327e7090155SMehdi Amini }
32809b4a8daSMehdi Amini 
329ed8fdb2aSDuncan P. N. Exon Smith bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; }
3305ab2be09SDuncan P. N. Exon Smith 
331ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::enableDebugTypeODRUniquing() {
3325ab2be09SDuncan P. N. Exon Smith   if (pImpl->DITypeMap)
3335ab2be09SDuncan P. N. Exon Smith     return;
3345ab2be09SDuncan P. N. Exon Smith 
335e8b555c6SDuncan P. N. Exon Smith   pImpl->DITypeMap.emplace();
3365ab2be09SDuncan P. N. Exon Smith }
3375ab2be09SDuncan P. N. Exon Smith 
338ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
3395ab2be09SDuncan P. N. Exon Smith 
34009b4a8daSMehdi Amini void LLVMContext::setDiscardValueNames(bool Discard) {
34109b4a8daSMehdi Amini   pImpl->DiscardValueNames = Discard;
34209b4a8daSMehdi Amini }
343aa641a51SAndrew Kaylor 
344d29884c7SFedor Sergeev OptPassGate &LLVMContext::getOptPassGate() const {
34598014e43SFedor Sergeev   return pImpl->getOptPassGate();
346aa641a51SAndrew Kaylor }
347b5ab895eSVivek Pandya 
348d29884c7SFedor Sergeev void LLVMContext::setOptPassGate(OptPassGate& OPG) {
349d29884c7SFedor Sergeev   pImpl->setOptPassGate(OPG);
350d29884c7SFedor Sergeev }
351d29884c7SFedor Sergeev 
352b5ab895eSVivek Pandya const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
353b5ab895eSVivek Pandya   return pImpl->DiagHandler.get();
354b5ab895eSVivek Pandya }
355b5ab895eSVivek Pandya 
356b5ab895eSVivek Pandya std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
357b5ab895eSVivek Pandya   return std::move(pImpl->DiagHandler);
358b5ab895eSVivek Pandya }
359