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 } 141*964398ccSPaul Kirth 1424ef3daafSBrian Gesiak uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const { 1433acda917SWei Wang return pImpl->DiagnosticsHotnessThreshold.getValueOr(UINT64_MAX); 1444ef3daafSBrian Gesiak } 1454ef3daafSBrian Gesiak 14693dc1b5bSWei Wang bool LLVMContext::isDiagnosticsHotnessThresholdSetFromPSI() const { 14793dc1b5bSWei Wang return !pImpl->DiagnosticsHotnessThreshold.hasValue(); 14893dc1b5bSWei Wang } 14993dc1b5bSWei Wang 1507531a503SFrancis Visoiu Mistrih remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() { 1517531a503SFrancis Visoiu Mistrih return pImpl->MainRemarkStreamer.get(); 152a62b7e1aSAdam Nemet } 1537531a503SFrancis Visoiu Mistrih const remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() const { 1547531a503SFrancis Visoiu Mistrih return const_cast<LLVMContext *>(this)->getMainRemarkStreamer(); 155b8a847c0SFrancis Visoiu Mistrih } 1567531a503SFrancis Visoiu Mistrih void LLVMContext::setMainRemarkStreamer( 1577531a503SFrancis Visoiu Mistrih std::unique_ptr<remarks::RemarkStreamer> RemarkStreamer) { 1587531a503SFrancis Visoiu Mistrih pImpl->MainRemarkStreamer = std::move(RemarkStreamer); 1597531a503SFrancis Visoiu Mistrih } 1607531a503SFrancis Visoiu Mistrih 1617531a503SFrancis Visoiu Mistrih LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() { 16231258878SFrancis Visoiu Mistrih return pImpl->LLVMRS.get(); 1637531a503SFrancis Visoiu Mistrih } 1647531a503SFrancis Visoiu Mistrih const LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() const { 1657531a503SFrancis Visoiu Mistrih return const_cast<LLVMContext *>(this)->getLLVMRemarkStreamer(); 1667531a503SFrancis Visoiu Mistrih } 1677531a503SFrancis Visoiu Mistrih void LLVMContext::setLLVMRemarkStreamer( 1687531a503SFrancis Visoiu Mistrih std::unique_ptr<LLVMRemarkStreamer> RemarkStreamer) { 16931258878SFrancis Visoiu Mistrih pImpl->LLVMRS = std::move(RemarkStreamer); 170a62b7e1aSAdam Nemet } 171a62b7e1aSAdam Nemet 172b5ab895eSVivek Pandya DiagnosticHandler::DiagnosticHandlerTy 173b5ab895eSVivek Pandya LLVMContext::getDiagnosticHandlerCallBack() const { 174b5ab895eSVivek Pandya return pImpl->DiagHandler->DiagHandlerCallback; 175b4c44d23SQuentin Colombet } 176b4c44d23SQuentin Colombet 177b4c44d23SQuentin Colombet void *LLVMContext::getDiagnosticContext() const { 178b5ab895eSVivek Pandya return pImpl->DiagHandler->DiagnosticContext; 179b4c44d23SQuentin Colombet } 180b4c44d23SQuentin Colombet 18134390c70SJuergen Ributzka void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle) 18234390c70SJuergen Ributzka { 18334390c70SJuergen Ributzka pImpl->YieldCallback = Callback; 18434390c70SJuergen Ributzka pImpl->YieldOpaqueHandle = OpaqueHandle; 18534390c70SJuergen Ributzka } 18634390c70SJuergen Ributzka 18734390c70SJuergen Ributzka void LLVMContext::yield() { 18834390c70SJuergen Ributzka if (pImpl->YieldCallback) 18934390c70SJuergen Ributzka pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle); 19034390c70SJuergen Ributzka } 19134390c70SJuergen Ributzka 192ef860a24SChandler Carruth void LLVMContext::emitError(const Twine &ErrorStr) { 193dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(ErrorStr)); 194ef860a24SChandler Carruth } 195ef860a24SChandler Carruth 196bfb44ef9SBob Wilson void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { 197dec8d55bSQuentin Colombet assert (I && "Invalid instruction"); 198dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); 199ef860a24SChandler Carruth } 200ef860a24SChandler Carruth 20130c9242cSDuncan P. N. Exon Smith static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { 2027f8af8bfSDiego Novillo // Optimization remarks are selective. They need to check whether the regexp 2037f8af8bfSDiego Novillo // pattern, passed via one of the -pass-remarks* flags, matches the name of 2047f8af8bfSDiego Novillo // the pass that is emitting the diagnostic. If there is no match, ignore the 2057f8af8bfSDiego Novillo // diagnostic and return. 206f31b1f31SAdam Nemet // 207f31b1f31SAdam Nemet // Also noisy remarks are only enabled if we have hotness information to sort 208f31b1f31SAdam Nemet // them. 209e9148dd6SAkira Hatanaka if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) 210f31b1f31SAdam Nemet return Remark->isEnabled() && 211f31b1f31SAdam Nemet (!Remark->isVerbose() || Remark->getHotness()); 212e9148dd6SAkira Hatanaka 21330c9242cSDuncan P. N. Exon Smith return true; 21430c9242cSDuncan P. N. Exon Smith } 21530c9242cSDuncan P. N. Exon Smith 2164b9c0d4dSRenato Golin const char * 2174b9c0d4dSRenato Golin LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { 218735c47ecSAlex Lorenz switch (Severity) { 219735c47ecSAlex Lorenz case DS_Error: 220735c47ecSAlex Lorenz return "error"; 221735c47ecSAlex Lorenz case DS_Warning: 222735c47ecSAlex Lorenz return "warning"; 223735c47ecSAlex Lorenz case DS_Remark: 224735c47ecSAlex Lorenz return "remark"; 225735c47ecSAlex Lorenz case DS_Note: 226735c47ecSAlex Lorenz return "note"; 227735c47ecSAlex Lorenz } 2285220476aSAaron Ballman llvm_unreachable("Unknown DiagnosticSeverity"); 229735c47ecSAlex Lorenz } 230735c47ecSAlex Lorenz 23130c9242cSDuncan P. N. Exon Smith void LLVMContext::diagnose(const DiagnosticInfo &DI) { 232b8a847c0SFrancis Visoiu Mistrih if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) 2337531a503SFrancis Visoiu Mistrih if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer()) 234b8a847c0SFrancis Visoiu Mistrih RS->emit(*OptDiagBase); 235b8a847c0SFrancis Visoiu Mistrih 23630c9242cSDuncan P. N. Exon Smith // If there is a report handler, use it. 237b5ab895eSVivek Pandya if (pImpl->DiagHandler && 238b5ab895eSVivek Pandya (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) && 239b5ab895eSVivek Pandya pImpl->DiagHandler->handleDiagnostics(DI)) 24030c9242cSDuncan P. N. Exon Smith return; 24130c9242cSDuncan P. N. Exon Smith 24230c9242cSDuncan P. N. Exon Smith if (!isDiagnosticEnabled(DI)) 24330c9242cSDuncan P. N. Exon Smith return; 244df655013SDiego Novillo 245b4c44d23SQuentin Colombet // Otherwise, print the message with a prefix based on the severity. 246735c47ecSAlex Lorenz DiagnosticPrinterRawOStream DP(errs()); 247735c47ecSAlex Lorenz errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; 248b4c44d23SQuentin Colombet DI.print(DP); 249735c47ecSAlex Lorenz errs() << "\n"; 250735c47ecSAlex Lorenz if (DI.getSeverity() == DS_Error) 251b4c44d23SQuentin Colombet exit(1); 252b4c44d23SQuentin Colombet } 253b4c44d23SQuentin Colombet 254bd411367SSimon Tatham void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { 255dec8d55bSQuentin Colombet diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); 256ef860a24SChandler Carruth } 257ef860a24SChandler Carruth 258ef860a24SChandler Carruth //===----------------------------------------------------------------------===// 259ef860a24SChandler Carruth // Metadata Kind Uniquing 260ef860a24SChandler Carruth //===----------------------------------------------------------------------===// 261ef860a24SChandler Carruth 2621ac0d2deSFilipe Cabecinhas /// Return a unique non-zero ID for the specified metadata kind. 263ef860a24SChandler Carruth unsigned LLVMContext::getMDKindID(StringRef Name) const { 264ef860a24SChandler Carruth // If this is new, assign it its ID. 2651ac0d2deSFilipe Cabecinhas return pImpl->CustomMDKindNames.insert( 2661ac0d2deSFilipe Cabecinhas std::make_pair( 2671ac0d2deSFilipe Cabecinhas Name, pImpl->CustomMDKindNames.size())) 2685106ce78SDavid Blaikie .first->second; 269ef860a24SChandler Carruth } 270ef860a24SChandler Carruth 2714104337dSSanjay Patel /// getHandlerNames - Populate client-supplied smallvector using custom 272ef860a24SChandler Carruth /// metadata name and ID. 273ef860a24SChandler Carruth void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const { 274ef860a24SChandler Carruth Names.resize(pImpl->CustomMDKindNames.size()); 275ef860a24SChandler Carruth for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(), 276ef860a24SChandler Carruth E = pImpl->CustomMDKindNames.end(); I != E; ++I) 277ef860a24SChandler Carruth Names[I->second] = I->first(); 278ef860a24SChandler Carruth } 2799303c246SSanjoy Das 2809303c246SSanjoy Das void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const { 2819303c246SSanjoy Das pImpl->getOperandBundleTags(Tags); 2829303c246SSanjoy Das } 2839303c246SSanjoy Das 284da100de0SOCHyams StringMapEntry<uint32_t> * 285da100de0SOCHyams LLVMContext::getOrInsertBundleTag(StringRef TagName) const { 286da100de0SOCHyams return pImpl->getOrInsertBundleTag(TagName); 287da100de0SOCHyams } 288da100de0SOCHyams 2899303c246SSanjoy Das uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const { 2909303c246SSanjoy Das return pImpl->getOperandBundleTagID(Tag); 2919303c246SSanjoy Das } 292599ebf27SMehdi Amini 293bb80d3e1SKonstantin Zhuravlyov SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) { 294bb80d3e1SKonstantin Zhuravlyov return pImpl->getOrInsertSyncScopeID(SSN); 295bb80d3e1SKonstantin Zhuravlyov } 296bb80d3e1SKonstantin Zhuravlyov 297bb80d3e1SKonstantin Zhuravlyov void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const { 298bb80d3e1SKonstantin Zhuravlyov pImpl->getSyncScopeNames(SSNs); 299bb80d3e1SKonstantin Zhuravlyov } 300bb80d3e1SKonstantin Zhuravlyov 301599ebf27SMehdi Amini void LLVMContext::setGC(const Function &Fn, std::string GCName) { 302599ebf27SMehdi Amini auto It = pImpl->GCNames.find(&Fn); 303599ebf27SMehdi Amini 304599ebf27SMehdi Amini if (It == pImpl->GCNames.end()) { 305599ebf27SMehdi Amini pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName))); 306599ebf27SMehdi Amini return; 307599ebf27SMehdi Amini } 308599ebf27SMehdi Amini It->second = std::move(GCName); 309599ebf27SMehdi Amini } 3105354a8aaSEugene Zelenko 311599ebf27SMehdi Amini const std::string &LLVMContext::getGC(const Function &Fn) { 312599ebf27SMehdi Amini return pImpl->GCNames[&Fn]; 313599ebf27SMehdi Amini } 3145354a8aaSEugene Zelenko 315599ebf27SMehdi Amini void LLVMContext::deleteGC(const Function &Fn) { 316599ebf27SMehdi Amini pImpl->GCNames.erase(&Fn); 317599ebf27SMehdi Amini } 31809b4a8daSMehdi Amini 319e7090155SMehdi Amini bool LLVMContext::shouldDiscardValueNames() const { 320e7090155SMehdi Amini return pImpl->DiscardValueNames; 321e7090155SMehdi Amini } 32209b4a8daSMehdi Amini 323ed8fdb2aSDuncan P. N. Exon Smith bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; } 3245ab2be09SDuncan P. N. Exon Smith 325ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::enableDebugTypeODRUniquing() { 3265ab2be09SDuncan P. N. Exon Smith if (pImpl->DITypeMap) 3275ab2be09SDuncan P. N. Exon Smith return; 3285ab2be09SDuncan P. N. Exon Smith 329e8b555c6SDuncan P. N. Exon Smith pImpl->DITypeMap.emplace(); 3305ab2be09SDuncan P. N. Exon Smith } 3315ab2be09SDuncan P. N. Exon Smith 332ed8fdb2aSDuncan P. N. Exon Smith void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } 3335ab2be09SDuncan P. N. Exon Smith 33409b4a8daSMehdi Amini void LLVMContext::setDiscardValueNames(bool Discard) { 33509b4a8daSMehdi Amini pImpl->DiscardValueNames = Discard; 33609b4a8daSMehdi Amini } 337aa641a51SAndrew Kaylor 338d29884c7SFedor Sergeev OptPassGate &LLVMContext::getOptPassGate() const { 33998014e43SFedor Sergeev return pImpl->getOptPassGate(); 340aa641a51SAndrew Kaylor } 341b5ab895eSVivek Pandya 342d29884c7SFedor Sergeev void LLVMContext::setOptPassGate(OptPassGate& OPG) { 343d29884c7SFedor Sergeev pImpl->setOptPassGate(OPG); 344d29884c7SFedor Sergeev } 345d29884c7SFedor Sergeev 346b5ab895eSVivek Pandya const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const { 347b5ab895eSVivek Pandya return pImpl->DiagHandler.get(); 348b5ab895eSVivek Pandya } 349b5ab895eSVivek Pandya 350b5ab895eSVivek Pandya std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() { 351b5ab895eSVivek Pandya return std::move(pImpl->DiagHandler); 352b5ab895eSVivek Pandya } 3538c7349b3SNikita Popov 354295172efSArthur Eubanks bool LLVMContext::hasSetOpaquePointersValue() const { 355295172efSArthur Eubanks return pImpl->hasOpaquePointersValue(); 356295172efSArthur Eubanks } 357295172efSArthur Eubanks 35890ec6dffSNikita Popov void LLVMContext::enableOpaquePointers() const { 35990ec6dffSNikita Popov assert(pImpl->PointerTypes.empty() && pImpl->ASPointerTypes.empty() && 36090ec6dffSNikita Popov "Must be called before creating any pointer types"); 3611caabbefSVitaly Buka pImpl->setOpaquePointers(true); 36290ec6dffSNikita Popov } 36390ec6dffSNikita Popov 3648c7349b3SNikita Popov bool LLVMContext::supportsTypedPointers() const { 3651caabbefSVitaly Buka return !pImpl->getOpaquePointers(); 3668c7349b3SNikita Popov } 367