clang 24.0.0git
Compiler.h
Go to the documentation of this file.
1//===--- Compiler.h - Code generator for expressions -----*- C++ -*-===//
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// Defines the constexpr bytecode compiler.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_INTERP_BYTECODEEXPRGEN_H
14#define LLVM_CLANG_AST_INTERP_BYTECODEEXPRGEN_H
15
16#include "ByteCodeEmitter.h"
17#include "DeclOrExpr.h"
18#include "EvalEmitter.h"
19#include "Pointer.h"
20#include "PrimType.h"
21#include "Record.h"
22#include "clang/AST/Decl.h"
23#include "clang/AST/Expr.h"
25
26namespace clang {
27class QualType;
28
29namespace interp {
30
31template <class Emitter> class LocalScope;
32template <class Emitter> class DestructorScope;
33template <class Emitter> class VariableScope;
34template <class Emitter> class DeclScope;
35template <class Emitter> class InitLinkScope;
36template <class Emitter> class InitStackScope;
37template <class Emitter> class OptionScope;
38template <class Emitter> class ArrayIndexScope;
39template <class Emitter> class SourceLocScope;
40template <class Emitter> class LoopScope;
41template <class Emitter> class LabelScope;
42template <class Emitter> class SwitchScope;
43template <class Emitter> class StmtExprScope;
44template <class Emitter> class LocOverrideScope;
45
46template <class Emitter> class Compiler;
47struct InitLink {
48public:
49 enum {
50 K_This = 0,
52 K_Base = 2,
53 K_Temp = 3,
54 K_Decl = 4,
55 K_Elem = 6,
56 K_RVO = 7,
58 K_DIE = 9,
59 };
60
61 static InitLink This() { return InitLink{K_This}; }
62 static InitLink InitList() { return InitLink{K_InitList}; }
63 static InitLink RVO() { return InitLink{K_RVO}; }
64 static InitLink DIE() { return InitLink{K_DIE}; }
65 static InitLink Field(unsigned Offset) {
66 InitLink IL{K_Field};
67 IL.Offset = Offset;
68 return IL;
69 }
70 static InitLink Base(unsigned Offset) {
71 InitLink IL{K_Base};
72 IL.Offset = Offset;
73 return IL;
74 }
75 static InitLink Temp(unsigned Offset) {
76 InitLink IL{K_Temp};
77 IL.Offset = Offset;
78 return IL;
79 }
80 static InitLink Decl(const ValueDecl *D) {
81 InitLink IL{K_Decl};
82 IL.D = D;
83 return IL;
84 }
85 static InitLink Elem(unsigned Index) {
86 InitLink IL{K_Elem};
87 IL.Offset = Index;
88 return IL;
89 }
90
92 template <class Emitter>
93 bool emit(Compiler<Emitter> *Ctx, const Expr *E) const;
94
96 union {
97 unsigned Offset;
98 const ValueDecl *D;
99 };
100};
101
102/// State encapsulating if a the variable creation has been successful,
103/// unsuccessful, or no variable has been created at all.
105 std::optional<bool> S = std::nullopt;
106 VarCreationState() = default;
107 VarCreationState(bool b) : S(b) {}
109
110 operator bool() const { return S && *S; }
111 bool notCreated() const { return !S; }
112};
113
115
116/// Compilation context for expressions.
117template <class Emitter>
118class Compiler final : public ConstStmtVisitor<Compiler<Emitter>, bool>,
119 public Emitter {
120protected:
121 // Aliases for types defined in the emitter.
122 using LabelTy = typename Emitter::LabelTy;
123 using AddrTy = typename Emitter::AddrTy;
125 using CaseMap = llvm::DenseMap<const SwitchCase *, LabelTy>;
126
140
141 /// Current compilation context.
143 /// Program to link to.
145
146public:
147 /// Initializes the compiler and the backend emitter.
148 template <typename... Tys>
149 Compiler(Context &Ctx, Program &P, Tys &&...Args)
150 : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
151
152 // Expressions.
153 bool VisitCastExpr(const CastExpr *E);
155 bool VisitIntegerLiteral(const IntegerLiteral *E);
159 bool VisitParenExpr(const ParenExpr *E);
160 bool VisitBinaryOperator(const BinaryOperator *E);
161 bool VisitLogicalBinOp(const BinaryOperator *E);
163 bool VisitComplexBinOp(const BinaryOperator *E);
164 bool VisitVectorBinOp(const BinaryOperator *E);
168 bool VisitCallExpr(const CallExpr *E);
169 bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID);
173 bool VisitGNUNullExpr(const GNUNullExpr *E);
174 bool VisitCXXThisExpr(const CXXThisExpr *E);
175 bool VisitUnaryOperator(const UnaryOperator *E);
178 bool VisitDeclRefExpr(const DeclRefExpr *E);
182 bool VisitInitListExpr(const InitListExpr *E);
184 bool VisitConstantExpr(const ConstantExpr *E);
186 bool VisitMemberExpr(const MemberExpr *E);
191 bool VisitStringLiteral(const StringLiteral *E);
193 bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E);
203 bool VisitTypeTraitExpr(const TypeTraitExpr *E);
205 bool VisitLambdaExpr(const LambdaExpr *E);
206 bool VisitPredefinedExpr(const PredefinedExpr *E);
207 bool VisitCXXThrowExpr(const CXXThrowExpr *E);
212 bool VisitSourceLocExpr(const SourceLocExpr *E);
213 bool VisitOffsetOfExpr(const OffsetOfExpr *E);
215 bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
217 bool VisitChooseExpr(const ChooseExpr *E);
218 bool VisitEmbedExpr(const EmbedExpr *E);
222 bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
223 bool VisitRequiresExpr(const RequiresExpr *E);
228 bool VisitRecoveryExpr(const RecoveryExpr *E);
229 bool VisitAddrLabelExpr(const AddrLabelExpr *E);
233 bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E);
235 bool VisitStmtExpr(const StmtExpr *E);
236 bool VisitCXXNewExpr(const CXXNewExpr *E);
237 bool VisitCXXDeleteExpr(const CXXDeleteExpr *E);
238 bool VisitBlockExpr(const BlockExpr *E);
239 bool VisitCXXTypeidExpr(const CXXTypeidExpr *E);
243
244 // Statements.
245 bool visitCompoundStmt(const CompoundStmt *S);
246 bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl = false);
247 bool visitReturnStmt(const ReturnStmt *RS);
248 bool visitIfStmt(const IfStmt *IS);
249 bool visitWhileStmt(const WhileStmt *S);
250 bool visitDoStmt(const DoStmt *S);
251 bool visitForStmt(const ForStmt *S);
253 bool visitBreakStmt(const BreakStmt *S);
254 bool visitContinueStmt(const ContinueStmt *S);
255 bool visitSwitchStmt(const SwitchStmt *S);
256 bool visitCaseStmt(const CaseStmt *S);
257 bool visitDefaultStmt(const DefaultStmt *S);
258 bool visitAttributedStmt(const AttributedStmt *S);
259 bool visitCXXTryStmt(const CXXTryStmt *S);
260 bool
262
263 bool registerRedecl(const VarDecl *VD, const APValue &V);
264
265protected:
266 bool visitStmt(const Stmt *S);
267 bool visitExpr(const Expr *E, bool DestroyToplevelScope) override;
268 bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override;
269 bool visitFunc(const FunctionDecl *F) override;
270
271 bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init,
272 bool ConstantContext) override;
273 bool visitDtorCall(const VarDecl *VD, const APValue &Value) override;
274 bool visitWithSubstitutions(const FunctionDecl *Callee,
275 ArrayRef<const Expr *> Args, const Expr *This,
276 const Expr *Condition) override;
277
278protected:
279 /// Emits scope cleanup instructions.
280 bool emitCleanup();
281
282 /// Returns a record type from a record or pointer type.
283 const RecordType *getRecordTy(QualType Ty);
284
285 /// Returns a record from a record or pointer type.
287 Record *getRecord(const RecordDecl *RD);
288
289 /// Returns a function for the given FunctionDecl.
290 /// If the function does not exist yet, it is compiled.
291 const Function *getFunction(const FunctionDecl *FD);
292
293 OptPrimType classify(const Expr *E) const { return Ctx.classify(E); }
294 OptPrimType classify(QualType Ty) const { return Ctx.classify(Ty); }
295 bool canClassify(const Expr *E) const { return Ctx.canClassify(E); }
296 bool canClassify(QualType T) const { return Ctx.canClassify(T); }
297
298 /// Classifies a known primitive type.
300 if (auto T = classify(Ty)) {
301 return *T;
302 }
303 llvm_unreachable("not a primitive type");
304 }
305 /// Classifies a known primitive expression.
306 PrimType classifyPrim(const Expr *E) const {
307 if (auto T = classify(E))
308 return *T;
309 llvm_unreachable("not a primitive type");
310 }
311
312 /// Evaluates an expression and places the result on the stack. If the
313 /// expression is of composite type, a local variable will be created
314 /// and a pointer to said variable will be placed on the stack.
315 bool visit(const Expr *E) override;
316 /// Compiles an initializer. This is like visit() but it will never
317 /// create a variable and instead rely on a variable already having
318 /// been created. visitInitializer() then relies on a pointer to this
319 /// variable being on top of the stack.
320 bool visitInitializer(const Expr *E);
321 /// Similar, but will also pop the pointer.
322 bool visitInitializerPop(const Expr *E);
323 bool visitAsLValue(const Expr *E);
324 /// Evaluates an expression for side effects and discards the result.
325 bool discard(const Expr *E);
326 /// Just pass evaluation on to \p E. This leaves all the parsing flags
327 /// intact.
328 bool delegate(const Expr *E);
329 /// Creates and initializes a variable from the given decl.
331 bool Toplevel = false);
333 /// Visit an APValue.
334 bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info);
335 bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T,
336 bool IsCompleteClass = true);
337 /// Visit the given decl as if we have a reference to it.
338 bool visitDeclRef(const ValueDecl *D, const Expr *E);
339
340 /// Visits an expression and converts it to a boolean.
341 bool visitBool(const Expr *E);
342
343 bool visitInitList(ArrayRef<const Expr *> Inits, const Expr *ArrayFiller,
344 const Expr *E);
345 bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
346 OptPrimType InitT);
347 bool visitCallArgs(ArrayRef<const Expr *> Args, const FunctionDecl *FuncDecl,
348 bool Activate, bool IsOperatorCall);
349
350 /// Creates a local primitive value.
351 unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst,
352 bool IsVolatile = false,
354
355 /// Allocates a space storing a local given its type.
359
360private:
361 friend class VariableScope<Emitter>;
362 friend class LocalScope<Emitter>;
363 friend class DestructorScope<Emitter>;
364 friend class DeclScope<Emitter>;
365 friend class InitLinkScope<Emitter>;
366 friend class InitStackScope<Emitter>;
367 friend class OptionScope<Emitter>;
368 friend class ArrayIndexScope<Emitter>;
369 friend class SourceLocScope<Emitter>;
370 friend struct InitLink;
371 friend class LoopScope<Emitter>;
372 friend class LabelScope<Emitter>;
373 friend class SwitchScope<Emitter>;
374 friend class StmtExprScope<Emitter>;
375 friend class LocOverrideScope<Emitter>;
376
377 /// Emits a zero initializer.
378 bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
379 bool visitZeroRecordInitializer(const Record *R, const Expr *E,
380 bool IsCompleteClass = true);
381 bool visitZeroArrayInitializer(QualType T, const Expr *E);
382 bool visitAssignment(const Expr *LHS, const Expr *RHS, const Expr *E);
383
384 /// Emits an APSInt constant.
385 bool emitConst(const llvm::APSInt &Value, PrimType Ty, SourceInfo Info);
386 bool emitConst(const llvm::APInt &Value, PrimType Ty, SourceInfo Info);
387 bool emitConst(const llvm::APSInt &Value, const Expr *E);
388 bool emitConst(const llvm::APInt &Value, const Expr *E) {
389 return emitConst(Value, classifyPrim(E), E);
390 }
391
392 /// Emits an integer constant.
393 template <typename T> bool emitConst(T Value, PrimType Ty, SourceInfo Info);
394 template <typename T> bool emitConst(T Value, const Expr *E);
395 bool emitBool(bool V, const Expr *E) override {
396 return this->emitConst(V, E);
397 }
398
399 llvm::RoundingMode getRoundingMode(const Expr *E) const {
401
402 if (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic)
403 return llvm::RoundingMode::NearestTiesToEven;
404
405 return FPO.getRoundingMode();
406 }
407
408 uint32_t getFPOptions(const Expr *E) const {
409 return E->getFPFeaturesInEffect(Ctx.getLangOpts()).getAsOpaqueInt();
410 }
411
412 bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
413 bool emitIntegralCast(PrimType FromT, PrimType ToT, QualType ToQT,
414 const Expr *E);
415 PrimType classifyComplexElementType(QualType T) const {
416 assert(T->isAnyComplexType());
417
418 QualType ElemType = T->getAs<ComplexType>()->getElementType();
419
420 return *this->classify(ElemType);
421 }
422
423 PrimType classifyVectorElementType(QualType T) const {
424 assert(T->isVectorType());
425 return *this->classify(T->getAs<VectorType>()->getElementType());
426 }
427
428 PrimType classifyMatrixElementType(QualType T) const {
429 assert(T->isMatrixType());
430 return *this->classify(T->getAs<MatrixType>()->getElementType());
431 }
432
433 bool emitComplexReal(const Expr *SubExpr);
434 bool emitComplexBoolCast(const Expr *E);
435 bool emitComplexComparison(const Expr *LHS, const Expr *RHS,
436 const BinaryOperator *E);
437 bool emitRecordDestructionPop(const Record *R, SourceInfo Loc);
438 bool emitDestructionPop(const Descriptor *Desc, SourceInfo Loc);
439 bool emitDummyPtr(DeclOrExpr D, const Expr *E, bool CU = false);
440 bool emitFloat(const APFloat &F, SourceInfo Info);
441 unsigned collectBaseOffset(const QualType BaseType,
442 const QualType DerivedType);
443 bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
444 bool emitBuiltinBitCast(const CastExpr *E);
445
446 bool emitHLSLAggregateSplat(PrimType SrcT, unsigned SrcOffset,
447 QualType DestType, const Expr *E);
448 bool emitVectorConversion(const Expr *Src, const Expr *E);
449
450 /// A scalar element extracted during HLSL aggregate flattening.
451 struct HLSLFlatElement {
452 unsigned LocalOffset;
453 PrimType Type;
454 };
455 unsigned countHLSLFlatElements(QualType Ty);
456 bool emitHLSLFlattenAggregate(QualType SrcType, unsigned SrcPtrOffset,
457 SmallVectorImpl<HLSLFlatElement> &Elements,
458 unsigned MaxElements, const Expr *E);
459 bool emitHLSLConstructAggregate(QualType DestType,
460 ArrayRef<HLSLFlatElement> Elements,
461 unsigned &ElemIdx, const Expr *E);
462 bool emitHLSLConstructAggregate(QualType DestType,
463 ArrayRef<HLSLFlatElement> Elements,
464 const Expr *E) {
465 unsigned ElemIdx = 0;
466 return emitHLSLConstructAggregate(DestType, Elements, ElemIdx, E);
467 }
468
469 bool compileConstructor(const CXXConstructorDecl *Ctor);
470 bool compileDestructor(const CXXDestructorDecl *Dtor);
471 bool compileUnionAssignmentOperator(const CXXMethodDecl *MD);
472
473 bool checkLiteralType(const Expr *E);
474 bool maybeEmitDeferredVarInit(const VarDecl *VD);
475
476 bool refersToUnion(const Expr *E);
477
478protected:
479 /// Variable to storage mapping.
480 llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;
481
482 /// OpaqueValueExpr to location mapping.
483 llvm::DenseMap<const OpaqueValueExpr *, unsigned> OpaqueExprs;
484
485 /// Current scope.
487
488 /// Current argument index. Needed to emit ArrayInitIndexExpr.
489 std::optional<uint64_t> ArrayIndex;
490
491 /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
492 const Expr *SourceLocDefaultExpr = nullptr;
493
494 /// Flag indicating if return value is to be discarded.
495 bool DiscardResult = false;
496
497 bool SwitchInStmtExpr = false;
498 bool InStmtExpr = false;
499 bool ToLValue = false;
500
502
503 /// Flag inidicating if we're initializing an already created
504 /// variable. This is set in visitInitializer().
505 bool Initializing = false;
506 const VarDecl *InitializingDecl = nullptr;
507
509 bool InitStackActive = false;
510
511 /// Type of the expression returned by the function.
513
514 /// Switch case mapping.
516 /// Stack of label information for loops and switch statements.
518
520};
521
522extern template class Compiler<ByteCodeEmitter>;
523extern template class Compiler<EvalEmitter>;
524
525} // namespace interp
526} // namespace clang
527
528#endif
#define V(N, I)
llvm::MachO::Record Record
Definition MachO.h:31
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:123
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4397
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4594
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6071
Represents a loop initializing the elements of an array.
Definition Expr.h:6018
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2765
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3010
Represents an attribute applied to a statement.
Definition Stmt.h:2215
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4082
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6722
BreakStmt - This represents a break.
Definition Stmt.h:3147
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5529
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:485
Represents the code generated for an expanded expansion statement.
Definition StmtCXX.h:1028
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:136
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4362
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:772
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5194
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:530
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:290
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2200
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:804
Represents the this expression in C++.
Definition ExprCXX.h:1158
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:70
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:852
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1072
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2987
CaseStmt - Represent a case statement.
Definition Stmt.h:1932
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3720
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4892
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4344
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3649
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
Represents the specialization of a concept - evaluates to a prvalue of type bool.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1102
ContinueStmt - This represents a continue.
Definition Stmt.h:3131
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4763
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1290
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1643
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2844
Represents a reference to emded data.
Definition Expr.h:5179
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3714
This represents one expression.
Definition Expr.h:113
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition Expr.cpp:4025
An expression trait intrinsic.
Definition ExprCXX.h:3083
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6660
RoundingMode getRoundingMode() const
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2900
Represents a function declaration or definition.
Definition Decl.h:2059
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4967
Represents a C11 generic selection.
Definition Expr.h:6232
IfStmt - This represents an if/then/else.
Definition Stmt.h:2271
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1751
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6107
Describes an C or C++ initializer list.
Definition Expr.h:5352
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1972
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4973
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3408
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:219
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:118
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:158
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:341
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:440
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:83
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2571
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1198
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2226
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2049
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6854
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4460
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7553
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3172
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4687
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4494
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5070
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4639
Stmt - This represents one statement.
Definition Stmt.h:85
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4717
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2521
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2900
bool isAnyComplexType() const
Definition TypeBase.h:8800
bool isMatrixType() const
Definition TypeBase.h:8828
bool isVectorType() const
Definition TypeBase.h:8804
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9264
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2669
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
Represents a variable declaration or definition.
Definition Decl.h:933
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2709
A memory block, either on the stack or in the heap.
Definition InterpBlock.h:43
Compilation context for expressions.
Definition Compiler.h:119
llvm::SmallVector< InitLink > InitStack
Definition Compiler.h:508
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
bool VisitCXXDeleteExpr(const CXXDeleteExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool visitContinueStmt(const ContinueStmt *S)
bool VisitCharacterLiteral(const CharacterLiteral *E)
PrimType classifyPrim(const Expr *E) const
Classifies a known primitive expression.
Definition Compiler.h:306
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init, OptPrimType InitT)
Pointer to the array(not the element!) must be on the stack when calling this.
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool visitInitializerPop(const Expr *E)
Similar, but will also pop the pointer.
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
Definition Compiler.h:299
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
Definition Compiler.h:483
bool VisitBinaryOperator(const BinaryOperator *E)
bool visitCXXExpansionStmtInstantiation(const CXXExpansionStmtInstantiation *S)
template for (auto x : {1, 2}) {}
bool visitAttributedStmt(const AttributedStmt *S)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
bool VisitCallExpr(const CallExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
Definition Compiler.h:489
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitAPValueInitializer(const APValue &Val, SourceInfo Info, QualType T, bool IsCompleteClass=true)
const Function * getFunction(const FunctionDecl *FD)
Returns a function for the given FunctionDecl.
bool VisitFixedPointBinOp(const BinaryOperator *E)
bool VisitCastExpr(const CastExpr *E)
Definition Compiler.cpp:453
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
bool VisitFixedPointUnaryOperator(const UnaryOperator *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
llvm::DenseMap< const SwitchCase *, LabelTy > CaseMap
Definition Compiler.h:125
bool VisitBlockExpr(const BlockExpr *E)
friend struct InitLink
Definition Compiler.h:370
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitCompoundStmt(const CompoundStmt *S)
Context & Ctx
Current compilation context.
Definition Compiler.h:142
const VarDecl * InitializingDecl
Definition Compiler.h:506
bool visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
bool visitBreakStmt(const BreakStmt *S)
bool visitExpr(const Expr *E, bool DestroyToplevelScope) override
bool visitForStmt(const ForStmt *S)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool visitAPValue(const APValue &Val, PrimType ValType, SourceInfo Info)
Visit an APValue.
bool VisitStmtExpr(const StmtExpr *E)
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
const FunctionDecl * CompilingFunction
Definition Compiler.h:519
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
VarCreationState visitVarDecl(const VarDecl *VD, const Expr *Init, bool Toplevel=false)
Creates and initializes a variable from the given decl.
VariableScope< Emitter > * VarScope
Current scope.
Definition Compiler.h:486
bool visitDeclAndReturn(const VarDecl *VD, const Expr *Init, bool ConstantContext) override
Toplevel visitDeclAndReturn().
bool VisitCXXNewExpr(const CXXNewExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool visit(const Expr *E) override
Evaluates an expression and places the result on the stack.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool visitLValueExpr(const Expr *E, bool DestroyToplevelScope) override
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
CaseMap CaseLabels
Switch case mapping.
Definition Compiler.h:515
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitSourceLocExpr(const SourceLocExpr *E)
Compiler(Context &Ctx, Program &P, Tys &&...Args)
Initializes the compiler and the backend emitter.
Definition Compiler.h:149
bool visitDeclStmt(const DeclStmt *DS, bool EvaluateConditionDecl=false)
bool registerRedecl(const VarDecl *VD, const APValue &V)
bool emitCleanup()
Emits scope cleanup instructions.
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E)
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool visitDtorCall(const VarDecl *VD, const APValue &Value) override
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
Definition Compiler.h:492
bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E)
UnsignedOrNone OptLabelTy
Definition Compiler.h:124
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool visitCallArgs(ArrayRef< const Expr * > Args, const FunctionDecl *FuncDecl, bool Activate, bool IsOperatorCall)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
bool visitDefaultStmt(const DefaultStmt *S)
bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E)
bool visitWithSubstitutions(const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition) override
Evaluate the Condition as if it was in the body of Callee.
typename Emitter::LabelTy LabelTy
Definition Compiler.h:122
VarCreationState visitDecl(const VarDecl *VD)
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E)
bool visitStmt(const Stmt *S)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitVectorUnaryOperator(const UnaryOperator *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitRecoveryExpr(const RecoveryExpr *E)
bool VisitRequiresExpr(const RequiresExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
Definition Compiler.h:505
bool visitReturnStmt(const ReturnStmt *RS)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool visitFunc(const FunctionDecl *F) override
bool visitCXXForRangeStmt(const CXXForRangeStmt *S)
bool visitCaseStmt(const CaseStmt *S)
bool VisitComplexBinOp(const BinaryOperator *E)
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
Definition Compiler.h:480
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E)
UnsignedOrNone allocateTemporary(const Expr *E)
bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
typename Emitter::AddrTy AddrTy
Definition Compiler.h:123
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
OptPrimType classify(QualType Ty) const
Definition Compiler.h:294
OptPrimType ReturnType
Type of the expression returned by the function.
Definition Compiler.h:512
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
OptPrimType classify(const Expr *E) const
Definition Compiler.h:293
llvm::SmallVector< LabelInfo > LabelInfoStack
Stack of label information for loops and switch statements.
Definition Compiler.h:517
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool visitDoStmt(const DoStmt *S)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitInitListExpr(const InitListExpr *E)
bool VisitVectorBinOp(const BinaryOperator *E)
bool VisitStringLiteral(const StringLiteral *E)
bool VisitParenExpr(const ParenExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E)
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool DiscardResult
Flag indicating if return value is to be discarded.
Definition Compiler.h:495
bool VisitEmbedExpr(const EmbedExpr *E)
UnsignedOrNone allocateLocal(DeclOrExpr Decl, QualType Ty=QualType(), ScopeKind=ScopeKind::Block)
Allocates a space storing a local given its type.
bool VisitConvertVectorExpr(const ConvertVectorExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool visitSwitchStmt(const SwitchStmt *S)
bool canClassify(QualType T) const
Definition Compiler.h:296
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool visitAsLValue(const Expr *E)
unsigned allocateLocalPrimitive(DeclOrExpr Decl, PrimType Ty, bool IsConst, bool IsVolatile=false, ScopeKind SC=ScopeKind::Block)
Creates a local primitive value.
bool visitWhileStmt(const WhileStmt *S)
bool visitIfStmt(const IfStmt *IS)
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
bool canClassify(const Expr *E) const
Definition Compiler.h:295
bool VisitFloatingLiteral(const FloatingLiteral *E)
Program & P
Program to link to.
Definition Compiler.h:144
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VisitGNUNullExpr(const GNUNullExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
bool visitCXXTryStmt(const CXXTryStmt *S)
Holds all information required to evaluate constexpr code in a module.
Definition Context.h:48
const LangOptions & getLangOpts() const
Returns the language options.
Definition Context.cpp:479
Scope used to handle temporaries in toplevel variable declarations.
Definition Compiler.cpp:291
Bytecode function.
Definition Function.h:98
When generating code for e.g.
Definition Compiler.cpp:428
Generic scope for local variables.
Definition Compiler.cpp:113
Sets the context for break/continue statements.
Definition Compiler.cpp:367
Scope used to handle initialization methods.
Definition Compiler.cpp:311
The program contains and links the bytecode for all functions.
Definition Program.h:37
Structure/Class descriptor.
Definition Record.h:27
Describes the statement/declaration an opcode was generated from.
Definition Source.h:77
Scope chain managing the variable lifetimes.
Definition Compiler.cpp:55
bool Call(InterpState &S, CodePtr OpPC, const Function *Func, uint32_t VarArgSize)
Definition Interp.cpp:2127
bool This(InterpState &S, CodePtr OpPC)
Definition Interp.h:3228
llvm::APFloat APFloat
Definition Floating.h:27
PrimType
Enumeration of the primitive types of the VM.
Definition PrimType.h:34
static bool Activate(InterpState &S)
Definition Interp.h:2308
bool Init(InterpState &S, CodePtr OpPC)
Definition Interp.h:2425
Top level wrappers for InstallAPI frontend operations.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
const VariableScope< Emitter > * BreakOrContinueScope
Definition Compiler.h:129
LabelInfo(const Stmt *Name, OptLabelTy BreakLabel, OptLabelTy ContinueLabel, OptLabelTy DefaultLabel, const VariableScope< Emitter > *BreakOrContinueScope)
Definition Compiler.h:133
State encapsulating if a the variable creation has been successful, unsuccessful, or no variable has ...
Definition Compiler.h:104
static VarCreationState NotCreated()
Definition Compiler.h:108
std::optional< bool > S
Definition Compiler.h:105