1//===- LLVMContextImpl.cpp - Implement LLVMContextImpl --------------------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file implements the opaque LLVMContextImpl.
11//===----------------------------------------------------------------------===//
45 // Check that any variable location records that fell off the end of a block
46 // when it's terminator was removed were eventually replaced. This assertion
47 // firing indicates that DbgVariableRecords went missing during the lifetime
48 // of the LLVMContext.
52 // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
53 // will call LLVMContextImpl::removeModule, thus invalidating iterators into
54 // the container. Avoid iterators during this operation:
59 // Check for metadata references from leaked Values.
65 // Drop references for MDNodes. Do this before Values get deleted to avoid
66 // unnecessary RAUW when nodes are still unresolved.
68 I->dropAllReferences();
69#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
70 for (auto *I : CLASS##s) \
71 I->dropAllReferences();
72#include "llvm/IR/Metadata.def"
74 // Also drop references that come from the Value bridges.
76 Pair.second->dropUsers();
78 Pair.second->dropUse();
79 // Do not untrack ValueAsMetadata references for DIArgLists, as they have
80 // already been more efficiently untracked above.
82 AL->dropAllReferences(
/* Untrack */ false);
89 I->deleteAsSubclass();
92 ConstantRangeListAttribute->~ConstantRangeListAttributeImpl();
93#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
94 for (CLASS * I : CLASS##s) \
96#include "llvm/IR/Metadata.def"
98 // Free the constants.
100 I->dropAllReferences();
102 I->dropAllReferences();
104 I->dropAllReferences();
106 I->dropAllReferences();
126 // Destroy attribute node lists.
133 // Destroy MetadataAsValues.
144 // Destroy ValuesAsMetadata.
151/// Make MDOperand transparent for hashing.
153/// This overload of an implementation detail of the hashing library makes
154/// MDOperand hash to the same value as a \a Metadata pointer.
156/// Note that overloading \a hash_value() as follows:
159/// size_t hash_value(const MDOperand &X) { return hash_value(X.get()); }
162/// does not cause MDOperand to be transparent. In particular, a bare pointer
163/// doesn't get hashed before it's combined, whereas \a MDOperand would.
166}
// end namespace llvm
175 "Expected hash of MDOperand to equal hash of Metadata*");
193 Tags[
T.second] =
T.first();
203 auto NewSSID =
SSC.size();
204 assert(NewSSID < std::numeric_limits<SyncScope::ID>::max() &&
205 "Hit the maximum number of synchronization scopes allowed!");
206 return SSC.insert(std::make_pair(SSN,
SyncScope::ID(NewSSID))).first->second;
212 for (
const auto &
SSE :
SSC)
213 SSNs[
SSE.second] =
SSE.first();
216std::optional<StringRef>
218 for (
const auto &
SSE :
SSC) {
219 if (
SSE.second != Id)
226/// Gets the OptPassGate for this LLVMContextImpl, which defaults to the
227/// singleton OptBisect if not explicitly set.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMapEntry class - it is intended to be a low dependency implementation det...
This file defines various helper methods and classes used by LLVMContextImpl for creating and managin...
Module.h This file contains the declarations for the Module class.
This defines the Use class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
const Type::TypeID FloatTyID
const Type::TypeID DoubleTyID
This file declares the interface for bisecting optimizations.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
DenseMap< Metadata *, MetadataAsValue * > MetadataAsValues
DenseMap< APFloat, std::unique_ptr< ConstantFP > > FPConstants
SmallPtrSet< Module *, 4 > OwnedModules
OwnedModules - The set of modules instantiated in this context, and which will be automatically delet...
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
DenseMap< APInt, std::unique_ptr< ConstantInt > > IntConstants
std::vector< MDNode * > DistinctMDNodes
SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
void setOptPassGate(OptPassGate &)
Set the object which can disable optional passes and individual optimizations at compile time.
VectorConstantsTy VectorConstants
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
OptPassGate & getOptPassGate() const
Access the object which can disable optional passes and individual optimizations at compile time.
DenseMap< const Value *, MDAttachments > ValueMetadata
Collection of metadata used in this context.
StringMapEntry< uint32_t > * getOrInsertBundleTag(StringRef Tag)
std::unique_ptr< DiagnosticHandler > DiagHandler
StringMap< uint32_t > BundleTagCache
A set of interned tags for operand bundles.
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
StructConstantsTy StructConstants
void getOperandBundleTags(SmallVectorImpl< StringRef > &Tags) const
FoldingSet< AttributeSetNode > AttrsSetNodes
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
uint32_t getOperandBundleTagID(StringRef Tag) const
StringMap< SyncScope::ID > SSC
A set of interned synchronization scopes.
DenseMap< std::pair< ElementCount, APInt >, std::unique_ptr< ConstantInt > > IntSplatConstants
std::vector< ConstantRangeListAttributeImpl * > ConstantRangeListAttributes
DenseSet< DIArgList *, DIArgListInfo > DIArgLists
std::optional< StringRef > getSyncScopeName(SyncScope::ID Id) const
getSyncScopeName - Returns the name of a SyncScope::ID registered with LLVMContext,...
ArrayConstantsTy ArrayConstants
DenseMap< Value *, ValueAsMetadata * > ValuesAsMetadata
ConstantUniqueMap< InlineAsm > InlineAsms
LLVMContextImpl(LLVMContext &C)
SmallDenseMap< BasicBlock *, DbgMarker * > TrailingDbgRecords
Mapping of blocks to collections of "trailing" DbgVariableRecords.
DenseMap< std::pair< ElementCount, APFloat >, std::unique_ptr< ConstantFP > > FPSplatConstants
This is an important class for using LLVM in a threaded context.
static unsigned calculateHash(MDNode *N, unsigned Offset=0)
Tracking metadata reference owned by Metadata.
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
static const Metadata * get_hashable_data(const MDOperand &X)
Make MDOperand transparent for hashing.
LLVM_ABI OptPassGate & getGlobalPassGate()
Singleton instance of the OptPassGate class, so multiple pass managers don't need to coordinate their...
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Implement std::hash so that hash_code can be used in STL containers.
This is the base class for diagnostic handling in LLVM.