35 if (
Func->isLambdaCallOperator()) {
38 const Record *R = P.getOrCreateRecord(ParentDecl);
40 llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
48 Offset, Cap.second->getType()->isReferenceType()};
59 unsigned ParamIndex = 0;
60 unsigned Drop =
Func->hasRVO() +
61 (
Func->hasThisPointer() && !
Func->isThisPointerExplicit());
63 for (
const auto &ParamDesc : llvm::drop_begin(
Func->ParamDescriptors, Drop)) {
68 {PD, {ParamDesc.Offset, Ctx.canClassify(PD->
getType())}});
72 Func->setDefined(
true);
75 bool IsEligibleForCompilation =
Func->isLambdaStaticInvoker() ||
77 FuncDecl->
hasAttr<MSConstexprAttr>();
80 if (!IsEligibleForCompilation || !
visitFunc(FuncDecl)) {
81 Func->setIsFullyCompiled(
true);
88 Scopes.emplace_back(std::move(DS));
92 Func->setCode(FuncDecl, NextLocalOffset, std::move(Code), std::move(SrcMap),
93 std::move(Scopes), FuncDecl->
hasBody(), IsValid);
94 Func->setIsFullyCompiled(
true);
98 NextLocalOffset +=
sizeof(
Block);
99 unsigned Location = NextLocalOffset;
101 return {Location, D};
105 const size_t Target = Code.size();
106 LabelOffsets.insert({Label,
Target});
108 if (
auto It = LabelRelocs.find(Label); It != LabelRelocs.end()) {
109 for (
unsigned Reloc : It->second) {
110 using namespace llvm::support;
113 void *Location = Code.data() + Reloc -
align(
sizeof(int32_t));
115 const int32_t Offset =
Target -
static_cast<int64_t
>(Reloc);
116 endian::write<int32_t, llvm::endianness::native>(Location, Offset);
118 LabelRelocs.erase(It);
122int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
124 const int64_t Position =
129 if (
auto It = LabelOffsets.find(Label); It != LabelOffsets.end())
130 return It->second - Position;
133 LabelRelocs[Label].push_back(Position);
142 size_t ValPos = Code.size();
145 if constexpr (std::is_pointer_v<T>)
146 Size =
align(
sizeof(uint32_t));
150 if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
157 assert(
aligned(ValPos + Size));
158 Code.resize_for_overwrite(ValPos + Size);
160 if constexpr (!std::is_pointer_v<T>) {
161 new (Code.data() + ValPos)
T(Val);
164 new (Code.data() + ValPos) uint32_t(ID);
173 size_t ValPos = Code.size();
174 size_t Size =
align(Val.bytesToSerialize());
176 if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
183 assert(
aligned(ValPos + Size));
184 Code.resize_for_overwrite(ValPos + Size);
186 Val.serialize(Code.data() + ValPos);
213template <
typename... Tys>
223 SrcMap.emplace_back(Code.size(), SI);
230 return emitJt(getOffset(Label),
SourceInfo{});
234 return emitJf(getOffset(Label),
SourceInfo{});
238 return emitJmp(getOffset(Label),
SourceInfo{});
249 if (!this->emitBCP(getOffset(EndLabel),
T, E))
251 if (!this->
visit(Arg))
261#include "Opcodes.inc"
This file provides some common utility functions for processing Lambda related AST Constructs.
static void emitSerialized(llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Emits a serializable value.
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Represents a C++ struct/union/class.
void getCaptureFields(llvm::DenseMap< const ValueDecl *, FieldDecl * > &Captures, FieldDecl *&ThisCapture) const
For a closure type, retrieve the mapping from captured variables and this to the non-static data memb...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
bool isInvalidDecl() const
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
param_iterator param_begin()
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.
Represents a parameter to a function.
A (possibly-)qualified type.
bool isPointerOrReferenceType() 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 speculate(const CallExpr *E, const LabelTy &EndLabel)
Speculative execution.
void compileFunc(const FunctionDecl *FuncDecl, Function *Func=nullptr)
Compiles the function into the module.
bool fallthrough(const LabelTy &Label)
Local createLocal(Descriptor *D)
Callback for local registration.
virtual bool visitFunc(const FunctionDecl *E)=0
Methods implemented by the compiler.
bool jumpTrue(const LabelTy &Label)
Emits jumps.
std::optional< SourceInfo > LocOverride
bool jumpFalse(const LabelTy &Label)
virtual bool visit(const Expr *E)=0
llvm::SmallVector< SmallVector< Local, 8 >, 2 > Descriptors
Local descriptors.
Wrapper around fixed point types.
If a Floating is constructed from Memory, it DOES NOT OWN THAT MEMORY.
If an IntegralAP is constructed from Memory, it DOES NOT OWN THAT MEMORY.
The program contains and links the bytecode for all functions.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
Structure/Class descriptor.
const Field * getField(unsigned I) const
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Success
Annotation was successful.
const FunctionProtoType * T
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Information about a local's storage.