xref: /freebsd-src/contrib/llvm-project/llvm/lib/IR/LLVMContext.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- LLVMContext.cpp - Implement LLVMContext ---------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric //  This file implements LLVMContext, as a wrapper around the opaque
100b57cec5SDimitry Andric //  class LLVMContextImpl.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "llvm/IR/LLVMContext.h"
150b57cec5SDimitry Andric #include "LLVMContextImpl.h"
160b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
170b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
180b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
190b57cec5SDimitry Andric #include "llvm/ADT/Twine.h"
200b57cec5SDimitry Andric #include "llvm/IR/DiagnosticInfo.h"
210b57cec5SDimitry Andric #include "llvm/IR/DiagnosticPrinter.h"
225ffd83dbSDimitry Andric #include "llvm/IR/LLVMRemarkStreamer.h"
235ffd83dbSDimitry Andric #include "llvm/Remarks/RemarkStreamer.h"
240b57cec5SDimitry Andric #include "llvm/Support/Casting.h"
250b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
260b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
270b57cec5SDimitry Andric #include <cassert>
280b57cec5SDimitry Andric #include <cstdlib>
290b57cec5SDimitry Andric #include <string>
300b57cec5SDimitry Andric #include <utility>
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric using namespace llvm;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) {
350b57cec5SDimitry Andric   // Create the fixed metadata kinds. This is done in the same order as the
360b57cec5SDimitry Andric   // MD_* enum values so that they correspond.
370b57cec5SDimitry Andric   std::pair<unsigned, StringRef> MDKinds[] = {
388bcb0991SDimitry Andric #define LLVM_FIXED_MD_KIND(EnumID, Name, Value) {EnumID, Name},
398bcb0991SDimitry Andric #include "llvm/IR/FixedMetadataKinds.def"
408bcb0991SDimitry Andric #undef LLVM_FIXED_MD_KIND
410b57cec5SDimitry Andric   };
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric   for (auto &MDKind : MDKinds) {
440b57cec5SDimitry Andric     unsigned ID = getMDKindID(MDKind.second);
450b57cec5SDimitry Andric     assert(ID == MDKind.first && "metadata kind id drifted");
460b57cec5SDimitry Andric     (void)ID;
470b57cec5SDimitry Andric   }
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   auto *DeoptEntry = pImpl->getOrInsertBundleTag("deopt");
500b57cec5SDimitry Andric   assert(DeoptEntry->second == LLVMContext::OB_deopt &&
510b57cec5SDimitry Andric          "deopt operand bundle id drifted!");
520b57cec5SDimitry Andric   (void)DeoptEntry;
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   auto *FuncletEntry = pImpl->getOrInsertBundleTag("funclet");
550b57cec5SDimitry Andric   assert(FuncletEntry->second == LLVMContext::OB_funclet &&
560b57cec5SDimitry Andric          "funclet operand bundle id drifted!");
570b57cec5SDimitry Andric   (void)FuncletEntry;
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   auto *GCTransitionEntry = pImpl->getOrInsertBundleTag("gc-transition");
600b57cec5SDimitry Andric   assert(GCTransitionEntry->second == LLVMContext::OB_gc_transition &&
610b57cec5SDimitry Andric          "gc-transition operand bundle id drifted!");
620b57cec5SDimitry Andric   (void)GCTransitionEntry;
630b57cec5SDimitry Andric 
64480093f4SDimitry Andric   auto *CFGuardTargetEntry = pImpl->getOrInsertBundleTag("cfguardtarget");
65480093f4SDimitry Andric   assert(CFGuardTargetEntry->second == LLVMContext::OB_cfguardtarget &&
66480093f4SDimitry Andric          "cfguardtarget operand bundle id drifted!");
67480093f4SDimitry Andric   (void)CFGuardTargetEntry;
68480093f4SDimitry Andric 
695ffd83dbSDimitry Andric   auto *PreallocatedEntry = pImpl->getOrInsertBundleTag("preallocated");
705ffd83dbSDimitry Andric   assert(PreallocatedEntry->second == LLVMContext::OB_preallocated &&
715ffd83dbSDimitry Andric          "preallocated operand bundle id drifted!");
725ffd83dbSDimitry Andric   (void)PreallocatedEntry;
735ffd83dbSDimitry Andric 
745ffd83dbSDimitry Andric   auto *GCLiveEntry = pImpl->getOrInsertBundleTag("gc-live");
755ffd83dbSDimitry Andric   assert(GCLiveEntry->second == LLVMContext::OB_gc_live &&
765ffd83dbSDimitry Andric          "gc-transition operand bundle id drifted!");
775ffd83dbSDimitry Andric   (void)GCLiveEntry;
785ffd83dbSDimitry Andric 
79fe6060f1SDimitry Andric   auto *ClangAttachedCall =
80fe6060f1SDimitry Andric       pImpl->getOrInsertBundleTag("clang.arc.attachedcall");
81fe6060f1SDimitry Andric   assert(ClangAttachedCall->second == LLVMContext::OB_clang_arc_attachedcall &&
82fe6060f1SDimitry Andric          "clang.arc.attachedcall operand bundle id drifted!");
83fe6060f1SDimitry Andric   (void)ClangAttachedCall;
84fe6060f1SDimitry Andric 
8581ad6265SDimitry Andric   auto *PtrauthEntry = pImpl->getOrInsertBundleTag("ptrauth");
8681ad6265SDimitry Andric   assert(PtrauthEntry->second == LLVMContext::OB_ptrauth &&
8781ad6265SDimitry Andric          "ptrauth operand bundle id drifted!");
8881ad6265SDimitry Andric   (void)PtrauthEntry;
8981ad6265SDimitry Andric 
90bdd1243dSDimitry Andric   auto *KCFIEntry = pImpl->getOrInsertBundleTag("kcfi");
91bdd1243dSDimitry Andric   assert(KCFIEntry->second == LLVMContext::OB_kcfi &&
92bdd1243dSDimitry Andric          "kcfi operand bundle id drifted!");
93bdd1243dSDimitry Andric   (void)KCFIEntry;
94bdd1243dSDimitry Andric 
9506c3fb27SDimitry Andric   auto *ConvergenceCtrlEntry = pImpl->getOrInsertBundleTag("convergencectrl");
9606c3fb27SDimitry Andric   assert(ConvergenceCtrlEntry->second == LLVMContext::OB_convergencectrl &&
9706c3fb27SDimitry Andric          "convergencectrl operand bundle id drifted!");
9806c3fb27SDimitry Andric   (void)ConvergenceCtrlEntry;
9906c3fb27SDimitry Andric 
1000b57cec5SDimitry Andric   SyncScope::ID SingleThreadSSID =
1010b57cec5SDimitry Andric       pImpl->getOrInsertSyncScopeID("singlethread");
1020b57cec5SDimitry Andric   assert(SingleThreadSSID == SyncScope::SingleThread &&
1030b57cec5SDimitry Andric          "singlethread synchronization scope ID drifted!");
1040b57cec5SDimitry Andric   (void)SingleThreadSSID;
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   SyncScope::ID SystemSSID =
1070b57cec5SDimitry Andric       pImpl->getOrInsertSyncScopeID("");
1080b57cec5SDimitry Andric   assert(SystemSSID == SyncScope::System &&
1090b57cec5SDimitry Andric          "system synchronization scope ID drifted!");
1100b57cec5SDimitry Andric   (void)SystemSSID;
1110b57cec5SDimitry Andric }
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric LLVMContext::~LLVMContext() { delete pImpl; }
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric void LLVMContext::addModule(Module *M) {
1160b57cec5SDimitry Andric   pImpl->OwnedModules.insert(M);
1170b57cec5SDimitry Andric }
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric void LLVMContext::removeModule(Module *M) {
1200b57cec5SDimitry Andric   pImpl->OwnedModules.erase(M);
121*0fca6ea1SDimitry Andric   pImpl->MachineFunctionNums.erase(M);
122*0fca6ea1SDimitry Andric }
123*0fca6ea1SDimitry Andric 
124*0fca6ea1SDimitry Andric unsigned LLVMContext::generateMachineFunctionNum(Function &F) {
125*0fca6ea1SDimitry Andric   Module *M = F.getParent();
126*0fca6ea1SDimitry Andric   assert(pImpl->OwnedModules.contains(M) && "Unexpected module!");
127*0fca6ea1SDimitry Andric   return pImpl->MachineFunctionNums[M]++;
1280b57cec5SDimitry Andric }
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1310b57cec5SDimitry Andric // Recoverable Backend Errors
1320b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric void LLVMContext::setDiagnosticHandlerCallBack(
1350b57cec5SDimitry Andric     DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler,
1360b57cec5SDimitry Andric     void *DiagnosticContext, bool RespectFilters) {
1370b57cec5SDimitry Andric   pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler;
1380b57cec5SDimitry Andric   pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
1390b57cec5SDimitry Andric   pImpl->RespectDiagnosticFilters = RespectFilters;
1400b57cec5SDimitry Andric }
1410b57cec5SDimitry Andric 
1420b57cec5SDimitry Andric void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
1430b57cec5SDimitry Andric                                       bool RespectFilters) {
1440b57cec5SDimitry Andric   pImpl->DiagHandler = std::move(DH);
1450b57cec5SDimitry Andric   pImpl->RespectDiagnosticFilters = RespectFilters;
1460b57cec5SDimitry Andric }
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric void LLVMContext::setDiagnosticsHotnessRequested(bool Requested) {
1490b57cec5SDimitry Andric   pImpl->DiagnosticsHotnessRequested = Requested;
1500b57cec5SDimitry Andric }
1510b57cec5SDimitry Andric bool LLVMContext::getDiagnosticsHotnessRequested() const {
1520b57cec5SDimitry Andric   return pImpl->DiagnosticsHotnessRequested;
1530b57cec5SDimitry Andric }
1540b57cec5SDimitry Andric 
155bdd1243dSDimitry Andric void LLVMContext::setDiagnosticsHotnessThreshold(std::optional<uint64_t> Threshold) {
1560b57cec5SDimitry Andric   pImpl->DiagnosticsHotnessThreshold = Threshold;
1570b57cec5SDimitry Andric }
15881ad6265SDimitry Andric void LLVMContext::setMisExpectWarningRequested(bool Requested) {
15981ad6265SDimitry Andric   pImpl->MisExpectWarningRequested = Requested;
16081ad6265SDimitry Andric }
16181ad6265SDimitry Andric bool LLVMContext::getMisExpectWarningRequested() const {
16281ad6265SDimitry Andric   return pImpl->MisExpectWarningRequested;
16381ad6265SDimitry Andric }
1640b57cec5SDimitry Andric uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
16581ad6265SDimitry Andric   return pImpl->DiagnosticsHotnessThreshold.value_or(UINT64_MAX);
16681ad6265SDimitry Andric }
16781ad6265SDimitry Andric void LLVMContext::setDiagnosticsMisExpectTolerance(
168bdd1243dSDimitry Andric     std::optional<uint32_t> Tolerance) {
16981ad6265SDimitry Andric   pImpl->DiagnosticsMisExpectTolerance = Tolerance;
17081ad6265SDimitry Andric }
171bdd1243dSDimitry Andric uint32_t LLVMContext::getDiagnosticsMisExpectTolerance() const {
17281ad6265SDimitry Andric   return pImpl->DiagnosticsMisExpectTolerance.value_or(0);
173e8d8bef9SDimitry Andric }
174e8d8bef9SDimitry Andric 
175e8d8bef9SDimitry Andric bool LLVMContext::isDiagnosticsHotnessThresholdSetFromPSI() const {
17681ad6265SDimitry Andric   return !pImpl->DiagnosticsHotnessThreshold.has_value();
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric 
1795ffd83dbSDimitry Andric remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() {
1805ffd83dbSDimitry Andric   return pImpl->MainRemarkStreamer.get();
1810b57cec5SDimitry Andric }
1825ffd83dbSDimitry Andric const remarks::RemarkStreamer *LLVMContext::getMainRemarkStreamer() const {
1835ffd83dbSDimitry Andric   return const_cast<LLVMContext *>(this)->getMainRemarkStreamer();
1840b57cec5SDimitry Andric }
1855ffd83dbSDimitry Andric void LLVMContext::setMainRemarkStreamer(
1865ffd83dbSDimitry Andric     std::unique_ptr<remarks::RemarkStreamer> RemarkStreamer) {
1875ffd83dbSDimitry Andric   pImpl->MainRemarkStreamer = std::move(RemarkStreamer);
1885ffd83dbSDimitry Andric }
1895ffd83dbSDimitry Andric 
1905ffd83dbSDimitry Andric LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() {
1915ffd83dbSDimitry Andric   return pImpl->LLVMRS.get();
1925ffd83dbSDimitry Andric }
1935ffd83dbSDimitry Andric const LLVMRemarkStreamer *LLVMContext::getLLVMRemarkStreamer() const {
1945ffd83dbSDimitry Andric   return const_cast<LLVMContext *>(this)->getLLVMRemarkStreamer();
1955ffd83dbSDimitry Andric }
1965ffd83dbSDimitry Andric void LLVMContext::setLLVMRemarkStreamer(
1975ffd83dbSDimitry Andric     std::unique_ptr<LLVMRemarkStreamer> RemarkStreamer) {
1985ffd83dbSDimitry Andric   pImpl->LLVMRS = std::move(RemarkStreamer);
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric DiagnosticHandler::DiagnosticHandlerTy
2020b57cec5SDimitry Andric LLVMContext::getDiagnosticHandlerCallBack() const {
2030b57cec5SDimitry Andric   return pImpl->DiagHandler->DiagHandlerCallback;
2040b57cec5SDimitry Andric }
2050b57cec5SDimitry Andric 
2060b57cec5SDimitry Andric void *LLVMContext::getDiagnosticContext() const {
2070b57cec5SDimitry Andric   return pImpl->DiagHandler->DiagnosticContext;
2080b57cec5SDimitry Andric }
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
2110b57cec5SDimitry Andric {
2120b57cec5SDimitry Andric   pImpl->YieldCallback = Callback;
2130b57cec5SDimitry Andric   pImpl->YieldOpaqueHandle = OpaqueHandle;
2140b57cec5SDimitry Andric }
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric void LLVMContext::yield() {
2170b57cec5SDimitry Andric   if (pImpl->YieldCallback)
2180b57cec5SDimitry Andric     pImpl->YieldCallback(this, pImpl->YieldOpaqueHandle);
2190b57cec5SDimitry Andric }
2200b57cec5SDimitry Andric 
2210b57cec5SDimitry Andric void LLVMContext::emitError(const Twine &ErrorStr) {
2220b57cec5SDimitry Andric   diagnose(DiagnosticInfoInlineAsm(ErrorStr));
2230b57cec5SDimitry Andric }
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
2260b57cec5SDimitry Andric   assert (I && "Invalid instruction");
2270b57cec5SDimitry Andric   diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr));
2280b57cec5SDimitry Andric }
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric static bool isDiagnosticEnabled(const DiagnosticInfo &DI) {
2310b57cec5SDimitry Andric   // Optimization remarks are selective. They need to check whether the regexp
2320b57cec5SDimitry Andric   // pattern, passed via one of the -pass-remarks* flags, matches the name of
2330b57cec5SDimitry Andric   // the pass that is emitting the diagnostic. If there is no match, ignore the
2340b57cec5SDimitry Andric   // diagnostic and return.
2350b57cec5SDimitry Andric   //
2360b57cec5SDimitry Andric   // Also noisy remarks are only enabled if we have hotness information to sort
2370b57cec5SDimitry Andric   // them.
2380b57cec5SDimitry Andric   if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
2390b57cec5SDimitry Andric     return Remark->isEnabled() &&
2400b57cec5SDimitry Andric            (!Remark->isVerbose() || Remark->getHotness());
2410b57cec5SDimitry Andric 
2420b57cec5SDimitry Andric   return true;
2430b57cec5SDimitry Andric }
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric const char *
2460b57cec5SDimitry Andric LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
2470b57cec5SDimitry Andric   switch (Severity) {
2480b57cec5SDimitry Andric   case DS_Error:
2490b57cec5SDimitry Andric     return "error";
2500b57cec5SDimitry Andric   case DS_Warning:
2510b57cec5SDimitry Andric     return "warning";
2520b57cec5SDimitry Andric   case DS_Remark:
2530b57cec5SDimitry Andric     return "remark";
2540b57cec5SDimitry Andric   case DS_Note:
2550b57cec5SDimitry Andric     return "note";
2560b57cec5SDimitry Andric   }
2570b57cec5SDimitry Andric   llvm_unreachable("Unknown DiagnosticSeverity");
2580b57cec5SDimitry Andric }
2590b57cec5SDimitry Andric 
2600b57cec5SDimitry Andric void LLVMContext::diagnose(const DiagnosticInfo &DI) {
2610b57cec5SDimitry Andric   if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
2625ffd83dbSDimitry Andric     if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer())
2630b57cec5SDimitry Andric       RS->emit(*OptDiagBase);
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric   // If there is a report handler, use it.
266cb14a3feSDimitry Andric   if (pImpl->DiagHandler) {
267cb14a3feSDimitry Andric     if (DI.getSeverity() == DS_Error)
268cb14a3feSDimitry Andric       pImpl->DiagHandler->HasErrors = true;
269cb14a3feSDimitry Andric     if ((!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
2700b57cec5SDimitry Andric         pImpl->DiagHandler->handleDiagnostics(DI))
2710b57cec5SDimitry Andric       return;
272cb14a3feSDimitry Andric   }
2730b57cec5SDimitry Andric 
2740b57cec5SDimitry Andric   if (!isDiagnosticEnabled(DI))
2750b57cec5SDimitry Andric     return;
2760b57cec5SDimitry Andric 
2770b57cec5SDimitry Andric   // Otherwise, print the message with a prefix based on the severity.
2780b57cec5SDimitry Andric   DiagnosticPrinterRawOStream DP(errs());
2790b57cec5SDimitry Andric   errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
2800b57cec5SDimitry Andric   DI.print(DP);
2810b57cec5SDimitry Andric   errs() << "\n";
2820b57cec5SDimitry Andric   if (DI.getSeverity() == DS_Error)
2830b57cec5SDimitry Andric     exit(1);
2840b57cec5SDimitry Andric }
2850b57cec5SDimitry Andric 
286fe6060f1SDimitry Andric void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) {
2870b57cec5SDimitry Andric   diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
2880b57cec5SDimitry Andric }
2890b57cec5SDimitry Andric 
2900b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
2910b57cec5SDimitry Andric // Metadata Kind Uniquing
2920b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric /// Return a unique non-zero ID for the specified metadata kind.
2950b57cec5SDimitry Andric unsigned LLVMContext::getMDKindID(StringRef Name) const {
2960b57cec5SDimitry Andric   // If this is new, assign it its ID.
2970b57cec5SDimitry Andric   return pImpl->CustomMDKindNames.insert(
2980b57cec5SDimitry Andric                                      std::make_pair(
2990b57cec5SDimitry Andric                                          Name, pImpl->CustomMDKindNames.size()))
3000b57cec5SDimitry Andric       .first->second;
3010b57cec5SDimitry Andric }
3020b57cec5SDimitry Andric 
3030b57cec5SDimitry Andric /// getHandlerNames - Populate client-supplied smallvector using custom
3040b57cec5SDimitry Andric /// metadata name and ID.
3050b57cec5SDimitry Andric void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
3060b57cec5SDimitry Andric   Names.resize(pImpl->CustomMDKindNames.size());
3070b57cec5SDimitry Andric   for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
3080b57cec5SDimitry Andric        E = pImpl->CustomMDKindNames.end(); I != E; ++I)
3090b57cec5SDimitry Andric     Names[I->second] = I->first();
3100b57cec5SDimitry Andric }
3110b57cec5SDimitry Andric 
3120b57cec5SDimitry Andric void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
3130b57cec5SDimitry Andric   pImpl->getOperandBundleTags(Tags);
3140b57cec5SDimitry Andric }
3150b57cec5SDimitry Andric 
3165ffd83dbSDimitry Andric StringMapEntry<uint32_t> *
3175ffd83dbSDimitry Andric LLVMContext::getOrInsertBundleTag(StringRef TagName) const {
3185ffd83dbSDimitry Andric   return pImpl->getOrInsertBundleTag(TagName);
3195ffd83dbSDimitry Andric }
3205ffd83dbSDimitry Andric 
3210b57cec5SDimitry Andric uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
3220b57cec5SDimitry Andric   return pImpl->getOperandBundleTagID(Tag);
3230b57cec5SDimitry Andric }
3240b57cec5SDimitry Andric 
3250b57cec5SDimitry Andric SyncScope::ID LLVMContext::getOrInsertSyncScopeID(StringRef SSN) {
3260b57cec5SDimitry Andric   return pImpl->getOrInsertSyncScopeID(SSN);
3270b57cec5SDimitry Andric }
3280b57cec5SDimitry Andric 
3290b57cec5SDimitry Andric void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
3300b57cec5SDimitry Andric   pImpl->getSyncScopeNames(SSNs);
3310b57cec5SDimitry Andric }
3320b57cec5SDimitry Andric 
3330b57cec5SDimitry Andric void LLVMContext::setGC(const Function &Fn, std::string GCName) {
3340b57cec5SDimitry Andric   auto It = pImpl->GCNames.find(&Fn);
3350b57cec5SDimitry Andric 
3360b57cec5SDimitry Andric   if (It == pImpl->GCNames.end()) {
3370b57cec5SDimitry Andric     pImpl->GCNames.insert(std::make_pair(&Fn, std::move(GCName)));
3380b57cec5SDimitry Andric     return;
3390b57cec5SDimitry Andric   }
3400b57cec5SDimitry Andric   It->second = std::move(GCName);
3410b57cec5SDimitry Andric }
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric const std::string &LLVMContext::getGC(const Function &Fn) {
3440b57cec5SDimitry Andric   return pImpl->GCNames[&Fn];
3450b57cec5SDimitry Andric }
3460b57cec5SDimitry Andric 
3470b57cec5SDimitry Andric void LLVMContext::deleteGC(const Function &Fn) {
3480b57cec5SDimitry Andric   pImpl->GCNames.erase(&Fn);
3490b57cec5SDimitry Andric }
3500b57cec5SDimitry Andric 
3510b57cec5SDimitry Andric bool LLVMContext::shouldDiscardValueNames() const {
3520b57cec5SDimitry Andric   return pImpl->DiscardValueNames;
3530b57cec5SDimitry Andric }
3540b57cec5SDimitry Andric 
3550b57cec5SDimitry Andric bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; }
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric void LLVMContext::enableDebugTypeODRUniquing() {
3580b57cec5SDimitry Andric   if (pImpl->DITypeMap)
3590b57cec5SDimitry Andric     return;
3600b57cec5SDimitry Andric 
3610b57cec5SDimitry Andric   pImpl->DITypeMap.emplace();
3620b57cec5SDimitry Andric }
3630b57cec5SDimitry Andric 
3640b57cec5SDimitry Andric void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
3650b57cec5SDimitry Andric 
3660b57cec5SDimitry Andric void LLVMContext::setDiscardValueNames(bool Discard) {
3670b57cec5SDimitry Andric   pImpl->DiscardValueNames = Discard;
3680b57cec5SDimitry Andric }
3690b57cec5SDimitry Andric 
3700b57cec5SDimitry Andric OptPassGate &LLVMContext::getOptPassGate() const {
3710b57cec5SDimitry Andric   return pImpl->getOptPassGate();
3720b57cec5SDimitry Andric }
3730b57cec5SDimitry Andric 
3740b57cec5SDimitry Andric void LLVMContext::setOptPassGate(OptPassGate& OPG) {
3750b57cec5SDimitry Andric   pImpl->setOptPassGate(OPG);
3760b57cec5SDimitry Andric }
3770b57cec5SDimitry Andric 
3780b57cec5SDimitry Andric const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
3790b57cec5SDimitry Andric   return pImpl->DiagHandler.get();
3800b57cec5SDimitry Andric }
3810b57cec5SDimitry Andric 
3820b57cec5SDimitry Andric std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
3830b57cec5SDimitry Andric   return std::move(pImpl->DiagHandler);
3840b57cec5SDimitry Andric }
385fe6060f1SDimitry Andric 
38681ad6265SDimitry Andric void LLVMContext::setOpaquePointers(bool Enable) const {
38706c3fb27SDimitry Andric   assert(Enable && "Cannot disable opaque pointers");
388349cc55cSDimitry Andric }
389349cc55cSDimitry Andric 
390fe6060f1SDimitry Andric bool LLVMContext::supportsTypedPointers() const {
39106c3fb27SDimitry Andric   return false;
392fe6060f1SDimitry Andric }
393*0fca6ea1SDimitry Andric 
394*0fca6ea1SDimitry Andric StringRef LLVMContext::getDefaultTargetCPU() {
395*0fca6ea1SDimitry Andric   return pImpl->DefaultTargetCPU;
396*0fca6ea1SDimitry Andric }
397*0fca6ea1SDimitry Andric 
398*0fca6ea1SDimitry Andric void LLVMContext::setDefaultTargetCPU(StringRef CPU) {
399*0fca6ea1SDimitry Andric   pImpl->DefaultTargetCPU = CPU;
400*0fca6ea1SDimitry Andric }
401*0fca6ea1SDimitry Andric 
402*0fca6ea1SDimitry Andric StringRef LLVMContext::getDefaultTargetFeatures() {
403*0fca6ea1SDimitry Andric   return pImpl->DefaultTargetFeatures;
404*0fca6ea1SDimitry Andric }
405*0fca6ea1SDimitry Andric 
406*0fca6ea1SDimitry Andric void LLVMContext::setDefaultTargetFeatures(StringRef Features) {
407*0fca6ea1SDimitry Andric   pImpl->DefaultTargetFeatures = Features;
408*0fca6ea1SDimitry Andric }
409