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" 237531a503SFrancis Visoiu Mistrih #include "llvm/Remarks/RemarkStreamer.h" 245354a8aaSEugene Zelenko #include "llvm/Support/Casting.h" 255354a8aaSEugene Zelenko #include "llvm/Support/ErrorHandling.h" 265354a8aaSEugene Zelenko #include "llvm/Support/raw_ostream.h" 275354a8aaSEugene Zelenko #include <cassert> 285354a8aaSEugene Zelenko #include <cstdlib> 295354a8aaSEugene Zelenko #include <string> 305354a8aaSEugene Zelenko #include <utility> 315354a8aaSEugene Zelenko 32ef860a24SChandler Carruth using namespace llvm; 33ef860a24SChandler Carruth 34ef860a24SChandler Carruth LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { 35ef860a24SChandler Carruth // Create the fixed metadata kinds. This is done in the same order as the 36ef860a24SChandler Carruth // MD_* enum values so that they correspond. 376f0b4f2eSPeter Collingbourne std::pair<unsigned, StringRef> MDKinds[] = { 38d01ae675SVedant Kumar #define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name}, 39d01ae675SVedant Kumar #include "llvm/IR/FixedMetadataKinds.def" 40d01ae675SVedant Kumar #undef LLVM_FIXED_MD_KIND 416f0b4f2eSPeter Collingbourne }; 42ef860a24SChandler Carruth 436f0b4f2eSPeter Collingbourne for (auto &MDKind : MDKinds) { 446f0b4f2eSPeter Collingbourne unsigned ID = getMDKindID(MDKind.second); 456f0b4f2eSPeter Collingbourne assert(ID == MDKind.first && "metadata kind id drifted"); 466f0b4f2eSPeter Collingbourne (void)ID; 476f0b4f2eSPeter Collingbourne } 48302b69c9SDehao Chen 49cdafd849SSanjoy Das auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt"); 50cdafd849SSanjoy Das assert(DeoptEntry->second == LLVMContext::OB_deopt && 51cdafd849SSanjoy Das "deopt operand bundle id drifted!"); 52cdafd849SSanjoy Das (void)DeoptEntry; 533bb88c02SDavid Majnemer 543bb88c02SDavid Majnemer auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet"); 553bb88c02SDavid Majnemer assert(FuncletEntry->second == LLVMContext::OB_funclet && 563bb88c02SDavid Majnemer "funclet operand bundle id drifted!"); 573bb88c02SDavid Majnemer (void)FuncletEntry; 58a34ce95bSSanjoy Das 59a34ce95bSSanjoy Das auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition"); 60a34ce95bSSanjoy Das assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition && 61a34ce95bSSanjoy Das "gc-transition operand bundle id drifted!"); 62a34ce95bSSanjoy Das (void)GCTransitionEntry; 63bb80d3e1SKonstantin Zhuravlyov 64d157a9bcSAndrew Paverd auto *CFGuardTargetEntry = pImpl->getOrInsertBundleTag("cfguardtarget"); 65d157a9bcSAndrew Paverd assert(CFGuardTargetEntry->second == LLVMContext::OB_cfguardtarget && 66d157a9bcSAndrew Paverd "cfguardtarget operand bundle id drifted!"); 67d157a9bcSAndrew Paverd (void)CFGuardTargetEntry; 68d157a9bcSAndrew Paverd 693b0450acSArthur Eubanks auto *PreallocatedEntry = pImpl->getOrInsertBundleTag("preallocated"); 703b0450acSArthur Eubanks assert(PreallocatedEntry->second == LLVMContext::OB_preallocated && 713b0450acSArthur Eubanks "preallocated operand bundle id drifted!"); 723b0450acSArthur Eubanks (void)PreallocatedEntry; 733b0450acSArthur Eubanks 740e7c7705SPhilip Reames auto *GCLiveEntry = pImpl->getOrInsertBundleTag("gc-live"); 750e7c7705SPhilip Reames assert(GCLiveEntry->second == LLVMContext::OB_gc_live && 760e7c7705SPhilip Reames "gc-transition operand bundle id drifted!"); 770e7c7705SPhilip Reames (void)GCLiveEntry; 780e7c7705SPhilip Reames 7919005035SAkira Hatanaka auto *ClangAttachedCall = 8019005035SAkira Hatanaka pImpl->getOrInsertBundleTag("clang.arc.attachedcall"); 8119005035SAkira Hatanaka assert(ClangAttachedCall->second == LLVMContext::OB_clang_arc_attachedcall && 8219005035SAkira Hatanaka "clang.arc.attachedcall operand bundle id drifted!"); 8319005035SAkira Hatanaka (void)ClangAttachedCall; 8419005035SAkira Hatanaka 85c703f852SAhmed Bougacha auto *PtrauthEntry = pImpl->getOrInsertBundleTag("ptrauth"); 86c703f852SAhmed Bougacha assert(PtrauthEntry->second == LLVMContext::OB_ptrauth && 87c703f852SAhmed Bougacha "ptrauth operand bundle id drifted!"); 88c703f852SAhmed Bougacha (void)PtrauthEntry; 89c703f852SAhmed Bougacha 90bb80d3e1SKonstantin Zhuravlyov SyncScope::ID SingleThreadSSID = 91bb80d3e1SKonstantin Zhuravlyov pImpl->getOrInsertSyncScopeID("singlethread"); 92bb80d3e1SKonstantin Zhuravlyov assert(SingleThreadSSID == SyncScope::SingleThread && 93bb80d3e1SKonstantin Zhuravlyov "singlethread synchronization scope ID drifted!"); 94878fdee0SKonstantin Zhuravlyov (void)SingleThreadSSID; 95bb80d3e1SKonstantin Zhuravlyov 96bb80d3e1SKonstantin Zhuravlyov SyncScope::ID SystemSSID = 97bb80d3e1SKonstantin Zhuravlyov pImpl->getOrInsertSyncScopeID(""); 98bb80d3e1SKonstantin Zhuravlyov assert(SystemSSID == SyncScope::System && 99bb80d3e1SKonstantin Zhuravlyov "system synchronization scope ID drifted!"); 100878fdee0SKonstantin Zhuravlyov (void)SystemSSID; 101ef860a24SChandler Carruth } 1025354a8aaSEugene Zelenko 103ef860a24SChandler Carruth LLVMContext::~LLVMContext() { delete pImpl; } 104ef860a24SChandler Carruth 105ef860a24SChandler Carruth void LLVMContext::addModule(Module *M) { 106ef860a24SChandler Carruth pImpl->OwnedModules.insert(M); 107ef860a24SChandler Carruth } 108ef860a24SChandler Carruth 109ef860a24SChandler Carruth void LLVMContext::removeModule(Module *M) { 110ef860a24SChandler Carruth pImpl->OwnedModules.erase(M); 111ef860a24SChandler Carruth } 112ef860a24SChandler Carruth 113ef860a24SChandler Carruth //===----------------------------------------------------------------------===// 114ef860a24SChandler Carruth // Recoverable Backend Errors 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 1383acda917SWei Wang void LLVMContext::setDiagnosticsHotnessThreshold(Optional<uint64_t> Threshold) { 1394ef3daafSBrian Gesiak pImpl->DiagnosticsHotnessThreshold = Threshold; 1404ef3daafSBrian Gesiak } 141bac6cd5bSPaul Kirth void LLVMContext::setMisExpectWarningRequested(bool Requested) { 142bac6cd5bSPaul Kirth pImpl->MisExpectWarningRequested = Requested; 143bac6cd5bSPaul Kirth } 144bac6cd5bSPaul Kirth bool LLVMContext::getMisExpectWarningRequested() const { 145bac6cd5bSPaul Kirth return pImpl->MisExpectWarningRequested; 146bac6cd5bSPaul Kirth } 1474ef3daafSBrian Gesiak uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const { 148*129b531cSKazu Hirata return pImpl->DiagnosticsHotnessThreshold.value_or(UINT64_MAX); 1494ef3daafSBrian Gesiak } 150bac6cd5bSPaul Kirth void LLVMContext::setDiagnosticsMisExpectTolerance( 151bac6cd5bSPaul Kirth Optional<uint64_t> Tolerance) { 152bac6cd5bSPaul Kirth pImpl->DiagnosticsMisExpectTolerance = Tolerance; 153bac6cd5bSPaul Kirth } 154bac6cd5bSPaul Kirth uint64_t LLVMContext::getDiagnosticsMisExpectTolerance() const { 155*129b531cSKazu Hirata return pImpl->DiagnosticsMisExpectTolerance.value_or(0); 156bac6cd5bSPaul Kirth } 1574ef3daafSBrian Gesiak 15893dc1b5bSWei Wang bool LLVMContext::isDiagnosticsHotnessThresholdSetFromPSI() const { 15993dc1b5bSWei Wang return !pImpl->DiagnosticsHotnessThreshold.hasValue(); 16093dc1b5bSWei Wang } 16193dc1b5bSWei Wang 1627531a503SFrancis Visoiu Mistrih remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() { 1637531a503SFrancis Visoiu Mistrih return pImpl->MainRemarkStreamer.get(); 164a62b7e1aSAdam Nemet } 1657531a503SFrancis Visoiu Mistrih const remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() const { 1667531a503SFrancis Visoiu Mistrih return const_cast<LLVMContext *>(this)->getMainRemarkStreamer(); 167b8a847c0SFrancis Visoiu Mistrih } 1687531a503SFrancis Visoiu Mistrih void LLVMContext::setMainRemarkStreamer( 1697531a503SFrancis Visoiu Mistrih std::unique_ptr<remarks::RemarkStreamer> RemarkStreamer) { 1707531a503SFrancis Visoiu Mistrih pImpl->MainRemarkStreamer = std::move(RemarkStreamer); 1717531a503SFrancis Visoiu Mistrih } 1727531a503SFrancis Visoiu Mistrih 1737531a503SFrancis Visoiu Mistrih LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() { 17431258878SFrancis Visoiu Mistrih return pImpl->LLVMRS.get(); 1757531a503SFrancis Visoiu Mistrih } 1767531a503SFrancis Visoiu Mistrih const LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() const { 1777531a503SFrancis Visoiu Mistrih return const_cast<LLVMContext *>(this)->getLLVMRemarkStreamer(); 1787531a503SFrancis Visoiu Mistrih } 1797531a503SFrancis Visoiu Mistrih void LLVMContext::setLLVMRemarkStreamer( 1807531a503SFrancis Visoiu Mistrih std::unique_ptr<LLVMRemarkStreamer> RemarkStreamer) { 18131258878SFrancis Visoiu Mistrih pImpl->LLVMRS = std::move(RemarkStreamer); 182a62b7e1aSAdam Nemet } 183a62b7e1aSAdam Nemet 184b5ab895eSVivek Pandya DiagnosticHandler::DiagnosticHandlerTy 185b5ab895eSVivek Pandya LLVMContext::getDiagnosticHandlerCallBack() const { 186b5ab895eSVivek Pandya return pImpl->DiagHandler->DiagHandlerCallback; 187b4c44d23SQuentin Colombet } 188b4c44d23SQuentin Colombet 189b4c44d23SQuentin Colombet void *LLVMContext::getDiagnosticContext() const { 190b5ab895eSVivek Pandya return pImpl->DiagHandler->DiagnosticContext; 191b4c44d23SQuentin Colombet } 192b4c44d23SQuentin Colombet 19334390c70SJuergen Ributzka void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle) 19434390c70SJuergen Ributzka { 19534390c70SJuergen Ributzka pImpl->YieldCallback = Callback; 19634390c70SJuergen Ributzka pImpl->YieldOpaqueHandle = OpaqueHandle; 19734390c70SJuergen Ributzka } 19834390c70SJuergen Ributzka 19934390c70SJuergen Ributzka void LLVMContext::yield() { 20034390c70SJuergen Ributzka if (pImpl->YieldCallback) 20134390c70SJuergen Ributzka pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle); 20234390c70SJuergen Ributzka } 20334390c70SJuergen Ributzka 204ef860a24SChandler Carruth void LLVMContext::emitError(const Twine &ErrorStr) { 205dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(ErrorStr)); 206ef860a24SChandler Carruth } 207ef860a24SChandler Carruth 208bfb44ef9SBob Wilson void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { 209dec8d55bSQuentin Colombet assert (I && "Invalid instruction"); 210dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); 211ef860a24SChandler Carruth } 212ef860a24SChandler Carruth 21330c9242cSDuncan P. N. Exon Smith static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { 2147f8af8bfSDiego Novillo // Optimization remarks are selective. They need to check whether the regexp 2157f8af8bfSDiego Novillo // pattern, passed via one of the -pass-remarks* flags, matches the name of 2167f8af8bfSDiego Novillo // the pass that is emitting the diagnostic. If there is no match, ignore the 2177f8af8bfSDiego Novillo // diagnostic and return. 218f31b1f31SAdam Nemet // 219f31b1f31SAdam Nemet // Also noisy remarks are only enabled if we have hotness information to sort 220f31b1f31SAdam Nemet // them. 221e9148dd6SAkira Hatanaka if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) 222f31b1f31SAdam Nemet return Remark->isEnabled() && 223f31b1f31SAdam Nemet (!Remark->isVerbose() || Remark->getHotness()); 224e9148dd6SAkira Hatanaka 22530c9242cSDuncan P. N. Exon Smith return true; 22630c9242cSDuncan P. N. Exon Smith } 22730c9242cSDuncan P. N. Exon Smith 2284b9c0d4dSRenato Golin const char * 2294b9c0d4dSRenato Golin LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { 230735c47ecSAlex Lorenz switch (Severity) { 231735c47ecSAlex Lorenz case DS_Error: 232735c47ecSAlex Lorenz return "error"; 233735c47ecSAlex Lorenz case DS_Warning: 234735c47ecSAlex Lorenz return "warning"; 235735c47ecSAlex Lorenz case DS_Remark: 236735c47ecSAlex Lorenz return "remark"; 237735c47ecSAlex Lorenz case DS_Note: 238735c47ecSAlex Lorenz return "note"; 239735c47ecSAlex Lorenz } 2405220476aSAaron Ballman llvm_unreachable("Unknown DiagnosticSeverity"); 241735c47ecSAlex Lorenz } 242735c47ecSAlex Lorenz 24330c9242cSDuncan P. N. Exon Smith void LLVMContext::diagnose(const DiagnosticInfo &DI) { 244b8a847c0SFrancis Visoiu Mistrih if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) 2457531a503SFrancis Visoiu Mistrih if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer()) 246b8a847c0SFrancis Visoiu Mistrih RS->emit(*OptDiagBase); 247b8a847c0SFrancis Visoiu Mistrih 24830c9242cSDuncan P. N. Exon Smith // If there is a report handler, use it. 249b5ab895eSVivek Pandya if (pImpl->DiagHandler && 250b5ab895eSVivek Pandya (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) && 251b5ab895eSVivek Pandya pImpl->DiagHandler->handleDiagnostics(DI)) 25230c9242cSDuncan P. N. Exon Smith return; 25330c9242cSDuncan P. N. Exon Smith 25430c9242cSDuncan P. N. Exon Smith if (!isDiagnosticEnabled(DI)) 25530c9242cSDuncan P. N. Exon Smith return; 256df655013SDiego Novillo 257b4c44d23SQuentin Colombet // Otherwise, print the message with a prefix based on the severity. 258735c47ecSAlex Lorenz DiagnosticPrinterRawOStream DP(errs()); 259735c47ecSAlex Lorenz errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; 260b4c44d23SQuentin Colombet DI.print(DP); 261735c47ecSAlex Lorenz errs() << "\n"; 262735c47ecSAlex Lorenz if (DI.getSeverity() == DS_Error) 263b4c44d23SQuentin Colombet exit(1); 264b4c44d23SQuentin Colombet } 265b4c44d23SQuentin Colombet 266bd411367SSimon Tatham void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { 267dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); 268ef860a24SChandler Carruth } 269ef860a24SChandler Carruth 270ef860a24SChandler Carruth //===----------------------------------------------------------------------===// 271ef860a24SChandler Carruth // Metadata Kind Uniquing 272ef860a24SChandler Carruth //===----------------------------------------------------------------------===// 273ef860a24SChandler Carruth 2741ac0d2deSFilipe Cabecinhas /// Return a unique non-zero ID for the specified metadata kind. 275ef860a24SChandler Carruth unsigned LLVMContext::getMDKindID(StringRef Name) const { 276ef860a24SChandler Carruth // If this is new, assign it its ID. 2771ac0d2deSFilipe Cabecinhas return pImpl->CustomMDKindNames.insert( 2781ac0d2deSFilipe Cabecinhas std::make_pair( 2791ac0d2deSFilipe Cabecinhas Name, pImpl->CustomMDKindNames.size())) 2805106ce78SDavid Blaikie .first->second; 281ef860a24SChandler Carruth } 282ef860a24SChandler Carruth 2834104337dSSanjay Patel /// getHandlerNames - Populate client-supplied smallvector using custom 284ef860a24SChandler Carruth /// metadata name and ID. 285ef860a24SChandler Carruth void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const { 286ef860a24SChandler Carruth Names.resize(pImpl->CustomMDKindNames.size()); 287ef860a24SChandler Carruth for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(), 288ef860a24SChandler Carruth E = pImpl->CustomMDKindNames.end(); I != E; ++I) 289ef860a24SChandler Carruth Names[I->second] = I->first(); 290ef860a24SChandler Carruth } 2919303c246SSanjoy Das 2929303c246SSanjoy Das void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const { 2939303c246SSanjoy Das pImpl->getOperandBundleTags(Tags); 2949303c246SSanjoy Das } 2959303c246SSanjoy Das 296da100de0SOCHyams StringMapEntry<uint32_t> * 297da100de0SOCHyams LLVMContext::getOrInsertBundleTag(StringRef TagName) const { 298da100de0SOCHyams return pImpl->getOrInsertBundleTag(TagName); 299da100de0SOCHyams } 300da100de0SOCHyams 3019303c246SSanjoy Das uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const { 3029303c246SSanjoy Das return pImpl->getOperandBundleTagID(Tag); 3039303c246SSanjoy Das } 304599ebf27SMehdi Amini 305bb80d3e1SKonstantin Zhuravlyov SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) { 306bb80d3e1SKonstantin Zhuravlyov return pImpl->getOrInsertSyncScopeID(SSN); 307bb80d3e1SKonstantin Zhuravlyov } 308bb80d3e1SKonstantin Zhuravlyov 309bb80d3e1SKonstantin Zhuravlyov void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const { 310bb80d3e1SKonstantin Zhuravlyov pImpl->getSyncScopeNames(SSNs); 311bb80d3e1SKonstantin Zhuravlyov } 312bb80d3e1SKonstantin Zhuravlyov 313599ebf27SMehdi Amini void LLVMContext::setGC(const Function &Fn, std::string GCName) { 314599ebf27SMehdi Amini auto It = pImpl->GCNames.find(&Fn); 315599ebf27SMehdi Amini 316599ebf27SMehdi Amini if (It == pImpl->GCNames.end()) { 317599ebf27SMehdi Amini pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName))); 318599ebf27SMehdi Amini return; 319599ebf27SMehdi Amini } 320599ebf27SMehdi Amini It->second = std::move(GCName); 321599ebf27SMehdi Amini } 3225354a8aaSEugene Zelenko 323599ebf27SMehdi Amini const std::string &LLVMContext::getGC(const Function &Fn) { 324599ebf27SMehdi Amini return pImpl->GCNames[&Fn]; 325599ebf27SMehdi Amini } 3265354a8aaSEugene Zelenko 327599ebf27SMehdi Amini void LLVMContext::deleteGC(const Function &Fn) { 328599ebf27SMehdi Amini pImpl->GCNames.erase(&Fn); 329599ebf27SMehdi Amini } 33009b4a8daSMehdi Amini 331e7090155SMehdi Amini bool LLVMContext::shouldDiscardValueNames() const { 332e7090155SMehdi Amini return pImpl->DiscardValueNames; 333e7090155SMehdi Amini } 33409b4a8daSMehdi Amini 335ed8fdb2aSDuncan P. N. Exon Smith bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; } 3365ab2be09SDuncan P. N. Exon Smith 337ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::enableDebugTypeODRUniquing() { 3385ab2be09SDuncan P. N. Exon Smith if (pImpl->DITypeMap) 3395ab2be09SDuncan P. N. Exon Smith return; 3405ab2be09SDuncan P. N. Exon Smith 341e8b555c6SDuncan P. N. Exon Smith pImpl->DITypeMap.emplace(); 3425ab2be09SDuncan P. N. Exon Smith } 3435ab2be09SDuncan P. N. Exon Smith 344ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } 3455ab2be09SDuncan P. N. Exon Smith 34609b4a8daSMehdi Amini void LLVMContext::setDiscardValueNames(bool Discard) { 34709b4a8daSMehdi Amini pImpl->DiscardValueNames = Discard; 34809b4a8daSMehdi Amini } 349aa641a51SAndrew Kaylor 350d29884c7SFedor Sergeev OptPassGate &LLVMContext::getOptPassGate() const { 35198014e43SFedor Sergeev return pImpl->getOptPassGate(); 352aa641a51SAndrew Kaylor } 353b5ab895eSVivek Pandya 354d29884c7SFedor Sergeev void LLVMContext::setOptPassGate(OptPassGate& OPG) { 355d29884c7SFedor Sergeev pImpl->setOptPassGate(OPG); 356d29884c7SFedor Sergeev } 357d29884c7SFedor Sergeev 358b5ab895eSVivek Pandya const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const { 359b5ab895eSVivek Pandya return pImpl->DiagHandler.get(); 360b5ab895eSVivek Pandya } 361b5ab895eSVivek Pandya 362b5ab895eSVivek Pandya std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() { 363b5ab895eSVivek Pandya return std::move(pImpl->DiagHandler); 364b5ab895eSVivek Pandya } 3658c7349b3SNikita Popov 3662362c4ecSArthur Eubanks bool LLVMContext::hasSetOpaquePointersValue() const { 3672362c4ecSArthur Eubanks return pImpl->hasOpaquePointersValue(); 3682362c4ecSArthur Eubanks } 3692362c4ecSArthur Eubanks 37046cfbe56SNikita Popov void LLVMContext::setOpaquePointers(bool Enable) const { 37146cfbe56SNikita Popov pImpl->setOpaquePointers(Enable); 37290ec6dffSNikita Popov } 37390ec6dffSNikita Popov 3748c7349b3SNikita Popov bool LLVMContext::supportsTypedPointers() const { 3751caabbefSVitaly Buka return !pImpl->getOpaquePointers(); 3768c7349b3SNikita Popov } 377e6f44a3cSChris Bieneman 378e6f44a3cSChris Bieneman Any &LLVMContext::getTargetData() const { 379e6f44a3cSChris Bieneman return pImpl->TargetDataStorage; 380e6f44a3cSChris Bieneman } 381