LLVM 24.0.0git
FunctionLocalMetadata.cpp
Go to the documentation of this file.
1//===- FunctionLocalMetadata.cpp - Function-Local Metadata Info -----------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains definitions for the function-local metadata types and the
10// MDFunctionLocalContext class which stores them.
11//
12//===----------------------------------------------------------------------===//
13
16
17using namespace llvm;
18
21 MDFunctionLocalContext *NewMD =
22 new (0u, Distinct) MDFunctionLocalContext(Context, Distinct, NonDebug);
24 return NewMD;
25}
26
29 // Scopes should have no duplicate entries, just append.
30 for (auto Scope : getScopes())
31 Nodes.push_back(Scope.get());
32 // InlineeContexts may be repeated, so use a set to avoid duplicate entries.
34 for (auto InlinedCall : getInlinedCalls())
35 if (SeenInlineeContexts.insert(InlinedCall.InlineeContext).second)
36 Nodes.push_back(InlinedCall.InlineeContext);
37}
38
40 const DISubprogram *SP)
41 : FLContext(FLContext) {
42 assert(!FLContext->isNonDebug() &&
43 "Trying to build debug info in a NonDebug FLContext?");
44 assert(SP && "FLMDBuilder requires a valid DISubprogram");
45 assert(
46 (FLContext->getScopes().empty() || FLContext->getScope(0).Scope == SP) &&
47 "FLContext already contains non-matching subprogram?");
48 /// If there are no existing FLMD entries, create the required DISubprogram
49 /// scope and then insert some commonly-required srclocs.
50 if (FLContext->getScopes().empty()) {
51 assert(FLContext->getSrcLocs().empty() &&
52 FLContext->getInlinedCalls().empty() &&
53 "FLContext contains SrcLocs or InlinedCalls without Scopes?");
54 getScope(SP);
55 getSrcLoc(0, 0, 0);
56 getSrcLoc(SP->getLine(), 0, 0);
57 getSrcLoc(SP->getScopeLine(), 0, 0);
58 return;
59 }
60 /// Otherwise, load all existing FLMD entries into the builder map.
61 for (auto [Idx, SrcLoc] : enumerate(FLContext->getSrcLocs()))
62 SrcLocMap.insert({SrcLoc, Idx});
63 for (auto [Idx, Scope] : enumerate(FLContext->getScopes()))
64 ScopeMap.insert({Scope, Idx});
65}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Subprogram description. Uses SubclassData1.
FLIndex< FLSrcLoc > getSrcLoc(uint32_t Line, uint16_t Column, FLIndex< FLScope > ScopeIdx)
FLIndex< FLScope > getScope(const DILocalScope *Scope)
LLVM_ABI FLMDBuilder(MDFunctionLocalContext *FLContext, const DISubprogram *SP)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Storage class for function-local metadata objects.
ArrayRef< FLInlinedCall > getInlinedCalls() const
LLVM_ABI void getUsedMDNodes(SmallVectorImpl< const MDNode * > &Nodes) const
ArrayRef< FLScope > getScopes() const
static LLVM_ABI MDFunctionLocalContext * getDistinct(LLVMContext &Context, bool NonDebug=false)
LLVM_ABI void storeDistinctInContext()
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2575