30 return BuiltinID == Builtin::BI__builtin_classify_type;
34 bool IsLambdaStaticInvoker =
false;
35 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl);
36 MD && MD->isLambdaStaticInvoker()) {
42 IsLambdaStaticInvoker =
true;
48 assert(MD->isFunctionTemplateSpecialization() &&
49 "A generic lambda's static-invoker function must be a "
50 "template specialization");
54 void *InsertPos =
nullptr;
57 assert(CorrespondingCallOpSpecialization);
58 FuncDecl = cast<CXXMethodDecl>(CorrespondingCallOpSpecialization);
66 llvm::DenseMap<unsigned, Function::ParamDescriptor> ParamDescriptors;
75 ParamTypes.push_back(
PT_Ptr);
83 bool HasThisPointer =
false;
84 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl)) {
85 if (!IsLambdaStaticInvoker) {
86 HasThisPointer = MD->isInstance();
87 if (MD->isImplicitObjectMemberFunction()) {
88 ParamTypes.push_back(
PT_Ptr);
97 llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
100 MD->
getParent()->getCaptureFields(LC, LTC);
102 for (
auto Cap : LC) {
110 Offset, Cap.second->getType()->isReferenceType()};
124 std::optional<PrimType>
T = Ctx.
classify(PD->getType());
127 ParamDescriptors.insert({
ParamOffset, {PT, Desc}});
131 ParamTypes.push_back(PT);
137 bool IsUnevaluatedBuiltin =
false;
143 std::move(ParamDescriptors), std::move(ParamOffsets),
144 HasThisPointer, HasRVO, IsUnevaluatedBuiltin);
151 Func->setDefined(
false);
155 Func->setDefined(
true);
158 bool IsEligibleForCompilation =
false;
159 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl))
160 IsEligibleForCompilation = MD->isLambdaStaticInvoker();
161 if (!IsEligibleForCompilation)
162 IsEligibleForCompilation =
166 if (!IsEligibleForCompilation || !
visitFunc(FuncDecl)) {
167 Func->setIsFullyCompiled(
true);
174 Scopes.emplace_back(std::move(DS));
178 Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
179 std::move(Scopes), FuncDecl->
hasBody());
180 Func->setIsFullyCompiled(
true);
185 NextLocalOffset +=
sizeof(
Block);
186 unsigned Location = NextLocalOffset;
188 return {Location, D};
192 const size_t Target = Code.size();
195 if (
auto It = LabelRelocs.find(
Label);
196 It != LabelRelocs.end()) {
197 for (
unsigned Reloc : It->second) {
198 using namespace llvm::support;
201 void *Location = Code.data() + Reloc -
align(
sizeof(int32_t));
203 const int32_t Offset =
Target -
static_cast<int64_t
>(Reloc);
204 endian::write<int32_t, llvm::endianness::native>(Location, Offset);
206 LabelRelocs.erase(It);
210int32_t ByteCodeEmitter::getOffset(LabelTy
Label) {
212 const int64_t Position =
217 if (
auto It = LabelOffsets.find(
Label);
218 It != LabelOffsets.end())
219 return It->second - Position;
222 LabelRelocs[
Label].push_back(Position);
233 if constexpr (std::is_pointer_v<T>)
234 Size =
sizeof(uint32_t);
238 if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
244 size_t ValPos =
align(Code.size());
246 assert(
aligned(ValPos + Size));
247 Code.resize(ValPos + Size);
249 if constexpr (!std::is_pointer_v<T>) {
250 new (Code.data() + ValPos)
T(Val);
252 uint32_t ID =
P.getOrCreateNativePointer(Val);
253 new (Code.data() + ValPos) uint32_t(ID);
262 size_t Size = Val.bytesToSerialize();
264 if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
270 size_t ValPos =
align(Code.size());
272 assert(
aligned(ValPos + Size));
273 Code.resize(ValPos + Size);
275 Val.serialize(Code.data() + ValPos);
296template <
typename... Tys>
297bool ByteCodeEmitter::emitOp(
Opcode Op,
const Tys &... Args,
const SourceInfo &SI) {
304 SrcMap.emplace_back(Code.size(), SI);
332#include "Opcodes.inc"
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
static bool isUnevaluatedBuiltin(unsigned BuiltinID)
Unevaluated builtins don't get their arguments put on the stack automatically.
static void emit(Program &P, std::vector< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitSerialized(std::vector< std::byte > &Code, const T &Val, bool &Success)
Emits a serializable value.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Target Target
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
capture_const_iterator captures_end() const
capture_const_iterator captures_begin() const
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Represents a member of a struct/union/class.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Represents a function declaration or definition.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Declaration of a template function.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Represents a parameter to a function.
A (possibly-)qualified type.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
bool isPointerType() const
bool isReferenceType() const
A memory block, either on the stack or in the heap.
bool jump(const LabelTy &Label)
void emitLabel(LabelTy Label)
Define a label.
ParamOffset LambdaThisCapture
Offset of the This parameter in a lambda record.
llvm::DenseMap< const ParmVarDecl *, ParamOffset > Params
Parameter indices.
llvm::DenseMap< const ValueDecl *, ParamOffset > LambdaCaptures
Lambda captures.
bool fallthrough(const LabelTy &Label)
Local createLocal(Descriptor *D)
Callback for local registration.
Function * compileFunc(const FunctionDecl *FuncDecl)
Compiles the function into the module.
virtual bool visitFunc(const FunctionDecl *E)=0
Methods implemented by the compiler.
bool jumpTrue(const LabelTy &Label)
Emits jumps.
bool jumpFalse(const LabelTy &Label)
llvm::SmallVector< SmallVector< Local, 8 >, 2 > Descriptors
Local descriptors.
std::optional< PrimType > classify(QualType T) const
Classifies a type.
The program contains and links the bytecode for all functions.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, Descriptor::MetadataSize MDSize=std::nullopt, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
Function * createFunction(const FunctionDecl *Def, Ts &&... Args)
Creates a new function from a code range.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Structure/Class descriptor.
const Field * getField(const FieldDecl *FD) const
Returns a field.
Describes the statement/declaration an opcode was generated from.
constexpr bool aligned(uintptr_t Value)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
PrimType
Enumeration of the primitive types of the VM.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
The JSON file list parser is used to communicate input to InstallAPI.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
const FunctionProtoType * T
@ Success
Template argument deduction was successful.
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Information about a local's storage.