[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
//===--- Function.h - Bytecode function for the VM --------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Defines the Function class which holds all bytecode function-specific data.
|
|
|
|
//
|
|
|
|
// The scope class which describes local variables is also defined here.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_H
|
|
|
|
#define LLVM_CLANG_AST_INTERP_FUNCTION_H
|
|
|
|
|
2023-10-12 07:09:12 +02:00
|
|
|
#include "Descriptor.h"
|
2024-02-25 14:03:47 +01:00
|
|
|
#include "Source.h"
|
2023-05-08 15:36:56 +02:00
|
|
|
#include "clang/AST/ASTLambda.h"
|
2024-02-25 14:03:47 +01:00
|
|
|
#include "clang/AST/Attr.h"
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
#include "clang/AST/Decl.h"
|
2024-08-20 06:08:53 +02:00
|
|
|
#include "llvm/ADT/PointerUnion.h"
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace interp {
|
|
|
|
class Program;
|
|
|
|
class ByteCodeEmitter;
|
2023-10-12 07:09:12 +02:00
|
|
|
class Pointer;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
enum PrimType : uint32_t;
|
|
|
|
|
|
|
|
/// Describes a scope block.
|
|
|
|
///
|
|
|
|
/// The block gathers all the descriptors of the locals defined in this block.
|
2022-09-17 15:14:32 +02:00
|
|
|
class Scope final {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
public:
|
|
|
|
/// Information about a local's storage.
|
|
|
|
struct Local {
|
|
|
|
/// Offset of the local in frame.
|
|
|
|
unsigned Offset;
|
|
|
|
/// Descriptor of the local.
|
|
|
|
Descriptor *Desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
using LocalVectorTy = llvm::SmallVector<Local, 8>;
|
|
|
|
|
|
|
|
Scope(LocalVectorTy &&Descriptors) : Descriptors(std::move(Descriptors)) {}
|
|
|
|
|
2022-09-23 15:15:09 +02:00
|
|
|
llvm::iterator_range<LocalVectorTy::const_iterator> locals() const {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
return llvm::make_range(Descriptors.begin(), Descriptors.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Object descriptors in this block.
|
|
|
|
LocalVectorTy Descriptors;
|
|
|
|
};
|
|
|
|
|
2024-08-20 06:08:53 +02:00
|
|
|
using FunctionDeclTy =
|
|
|
|
llvm::PointerUnion<const FunctionDecl *, const BlockExpr *>;
|
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Bytecode function.
|
|
|
|
///
|
|
|
|
/// Contains links to the bytecode of the function, as well as metadata
|
|
|
|
/// describing all arguments and stack-local variables.
|
2022-09-18 20:40:27 +02:00
|
|
|
///
|
|
|
|
/// # Calling Convention
|
|
|
|
///
|
|
|
|
/// When calling a function, all argument values must be on the stack.
|
|
|
|
///
|
|
|
|
/// If the function has a This pointer (i.e. hasThisPointer() returns true,
|
|
|
|
/// the argument values need to be preceeded by a Pointer for the This object.
|
|
|
|
///
|
|
|
|
/// If the function uses Return Value Optimization, the arguments (and
|
2023-05-08 15:36:56 +02:00
|
|
|
/// potentially the This pointer) need to be preceeded by a Pointer pointing
|
2022-09-18 20:40:27 +02:00
|
|
|
/// to the location to construct the returned value.
|
|
|
|
///
|
|
|
|
/// After the function has been called, it will remove all arguments,
|
|
|
|
/// including RVO and This pointer, from the stack.
|
|
|
|
///
|
2022-09-17 15:14:32 +02:00
|
|
|
class Function final {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
public:
|
|
|
|
using ParamDescriptor = std::pair<PrimType, Descriptor *>;
|
|
|
|
|
|
|
|
/// Returns the size of the function's local stack.
|
|
|
|
unsigned getFrameSize() const { return FrameSize; }
|
2022-08-19 13:45:11 +02:00
|
|
|
/// Returns the size of the argument stack.
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
unsigned getArgSize() const { return ArgSize; }
|
|
|
|
|
|
|
|
/// Returns a pointer to the start of the code.
|
2022-08-05 13:57:39 +02:00
|
|
|
CodePtr getCodeBegin() const { return Code.data(); }
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Returns a pointer to the end of the code.
|
2022-08-05 13:57:39 +02:00
|
|
|
CodePtr getCodeEnd() const { return Code.data() + Code.size(); }
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Returns the original FunctionDecl.
|
2024-08-20 06:08:53 +02:00
|
|
|
const FunctionDecl *getDecl() const {
|
|
|
|
return Source.dyn_cast<const FunctionDecl *>();
|
|
|
|
}
|
|
|
|
const BlockExpr *getExpr() const {
|
|
|
|
return Source.dyn_cast<const BlockExpr *>();
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2022-08-05 13:57:39 +02:00
|
|
|
/// Returns the name of the function decl this code
|
|
|
|
/// was generated for.
|
2023-02-16 08:22:26 +01:00
|
|
|
const std::string getName() const {
|
2024-08-20 06:08:53 +02:00
|
|
|
if (!Source)
|
2023-02-16 08:22:26 +01:00
|
|
|
return "<<expr>>";
|
|
|
|
|
2024-08-20 06:08:53 +02:00
|
|
|
return Source.get<const FunctionDecl *>()->getQualifiedNameAsString();
|
2023-02-16 08:22:26 +01:00
|
|
|
}
|
2022-08-05 13:57:39 +02:00
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Returns a parameter descriptor.
|
|
|
|
ParamDescriptor getParamDescriptor(unsigned Offset) const;
|
|
|
|
|
|
|
|
/// Checks if the first argument is a RVO pointer.
|
2022-09-18 20:40:27 +02:00
|
|
|
bool hasRVO() const { return HasRVO; }
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2024-02-25 14:03:47 +01:00
|
|
|
bool hasNonNullAttr() const { return getDecl()->hasAttr<NonNullAttr>(); }
|
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Range over the scope blocks.
|
2022-09-23 15:15:09 +02:00
|
|
|
llvm::iterator_range<llvm::SmallVector<Scope, 2>::const_iterator>
|
|
|
|
scopes() const {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
return llvm::make_range(Scopes.begin(), Scopes.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Range over argument types.
|
2022-09-23 15:15:09 +02:00
|
|
|
using arg_reverse_iterator =
|
|
|
|
SmallVectorImpl<PrimType>::const_reverse_iterator;
|
|
|
|
llvm::iterator_range<arg_reverse_iterator> args_reverse() const {
|
2022-10-15 21:54:13 -07:00
|
|
|
return llvm::reverse(ParamTypes);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a specific scope.
|
|
|
|
Scope &getScope(unsigned Idx) { return Scopes[Idx]; }
|
2022-09-23 15:15:09 +02:00
|
|
|
const Scope &getScope(unsigned Idx) const { return Scopes[Idx]; }
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Returns the source information at a given PC.
|
|
|
|
SourceInfo getSource(CodePtr PC) const;
|
|
|
|
|
|
|
|
/// Checks if the function is valid to call in constexpr.
|
2023-05-08 15:36:56 +02:00
|
|
|
bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); }
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Checks if the function is virtual.
|
|
|
|
bool isVirtual() const;
|
|
|
|
|
|
|
|
/// Checks if the function is a constructor.
|
2024-08-20 06:08:53 +02:00
|
|
|
bool isConstructor() const {
|
|
|
|
return isa_and_nonnull<CXXConstructorDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>());
|
|
|
|
}
|
2022-10-26 11:20:13 +02:00
|
|
|
/// Checks if the function is a destructor.
|
2024-08-20 06:08:53 +02:00
|
|
|
bool isDestructor() const {
|
|
|
|
return isa_and_nonnull<CXXDestructorDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>());
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2023-01-26 16:25:52 +01:00
|
|
|
/// Returns the parent record decl, if any.
|
|
|
|
const CXXRecordDecl *getParentDecl() const {
|
2024-08-20 06:08:53 +02:00
|
|
|
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>()))
|
2023-01-26 16:25:52 +01:00
|
|
|
return MD->getParent();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-08 15:36:56 +02:00
|
|
|
/// Returns whether this function is a lambda static invoker,
|
|
|
|
/// which we generate custom byte code for.
|
|
|
|
bool isLambdaStaticInvoker() const {
|
2024-08-20 06:08:53 +02:00
|
|
|
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>()))
|
2023-05-08 15:36:56 +02:00
|
|
|
return MD->isLambdaStaticInvoker();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this function is the call operator
|
|
|
|
/// of a lambda record decl.
|
|
|
|
bool isLambdaCallOperator() const {
|
2024-08-20 06:08:53 +02:00
|
|
|
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>()))
|
2023-05-08 15:36:56 +02:00
|
|
|
return clang::isLambdaCallOperator(MD);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:20:24 +02:00
|
|
|
/// Checks if the function is fully done compiling.
|
|
|
|
bool isFullyCompiled() const { return IsFullyCompiled; }
|
|
|
|
|
2022-09-18 20:40:27 +02:00
|
|
|
bool hasThisPointer() const { return HasThisPointer; }
|
|
|
|
|
2023-07-15 15:11:27 +02:00
|
|
|
/// Checks if the function already has a body attached.
|
2022-10-28 10:31:47 +02:00
|
|
|
bool hasBody() const { return HasBody; }
|
|
|
|
|
2023-09-25 17:28:44 +02:00
|
|
|
/// Checks if the function is defined.
|
|
|
|
bool isDefined() const { return Defined; }
|
|
|
|
|
2023-10-24 12:33:29 +02:00
|
|
|
bool isVariadic() const { return Variadic; }
|
|
|
|
|
2024-08-31 01:50:59 +02:00
|
|
|
unsigned getBuiltinID() const { return BuiltinID; }
|
2022-11-05 13:08:40 +01:00
|
|
|
|
2024-08-31 01:50:59 +02:00
|
|
|
bool isBuiltin() const { return getBuiltinID() != 0; }
|
2023-07-28 21:01:05 +02:00
|
|
|
|
2024-08-31 01:50:59 +02:00
|
|
|
bool isUnevaluatedBuiltin() const;
|
2023-11-17 16:13:23 +01:00
|
|
|
|
2022-09-18 20:40:27 +02:00
|
|
|
unsigned getNumParams() const { return ParamTypes.size(); }
|
|
|
|
|
2024-02-14 15:29:47 +01:00
|
|
|
/// Returns the number of parameter this function takes when it's called,
|
|
|
|
/// i.e excluding the instance pointer and the RVO pointer.
|
|
|
|
unsigned getNumWrittenParams() const {
|
2024-02-15 09:43:13 +00:00
|
|
|
assert(getNumParams() >= (unsigned)(hasThisPointer() + hasRVO()));
|
2024-02-14 15:29:47 +01:00
|
|
|
return getNumParams() - hasThisPointer() - hasRVO();
|
|
|
|
}
|
|
|
|
unsigned getWrittenArgSize() const {
|
|
|
|
return ArgSize - (align(primSize(PT_Ptr)) * (hasThisPointer() + hasRVO()));
|
|
|
|
}
|
|
|
|
|
2024-06-15 07:34:47 +02:00
|
|
|
bool isThisPointerExplicit() const {
|
2024-08-20 06:08:53 +02:00
|
|
|
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
|
|
|
|
Source.dyn_cast<const FunctionDecl *>()))
|
2024-06-15 07:34:47 +02:00
|
|
|
return MD->isExplicitObjectMemberFunction();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-04 07:29:57 +02:00
|
|
|
unsigned getParamOffset(unsigned ParamIndex) const {
|
|
|
|
return ParamOffsets[ParamIndex];
|
|
|
|
}
|
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
private:
|
|
|
|
/// Construct a function representing an actual function.
|
2024-08-20 06:08:53 +02:00
|
|
|
Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
|
2023-05-04 07:29:57 +02:00
|
|
|
llvm::SmallVectorImpl<PrimType> &&ParamTypes,
|
2022-09-18 20:40:27 +02:00
|
|
|
llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
|
2023-05-04 07:29:57 +02:00
|
|
|
llvm::SmallVectorImpl<unsigned> &&ParamOffsets, bool HasThisPointer,
|
2024-08-31 01:50:59 +02:00
|
|
|
bool HasRVO, unsigned BuiltinID);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Sets the code of a function.
|
2023-07-12 09:48:24 +02:00
|
|
|
void setCode(unsigned NewFrameSize, std::vector<std::byte> &&NewCode,
|
2023-01-12 12:25:10 +01:00
|
|
|
SourceMap &&NewSrcMap, llvm::SmallVector<Scope, 2> &&NewScopes,
|
|
|
|
bool NewHasBody) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
FrameSize = NewFrameSize;
|
|
|
|
Code = std::move(NewCode);
|
|
|
|
SrcMap = std::move(NewSrcMap);
|
|
|
|
Scopes = std::move(NewScopes);
|
|
|
|
IsValid = true;
|
2023-01-12 12:25:10 +01:00
|
|
|
HasBody = NewHasBody;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 10:20:24 +02:00
|
|
|
void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }
|
2023-09-25 17:28:44 +02:00
|
|
|
void setDefined(bool D) { Defined = D; }
|
2022-08-29 10:20:24 +02:00
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
private:
|
|
|
|
friend class Program;
|
|
|
|
friend class ByteCodeEmitter;
|
|
|
|
|
|
|
|
/// Program reference.
|
|
|
|
Program &P;
|
|
|
|
/// Declaration this function was compiled from.
|
2024-08-20 06:08:53 +02:00
|
|
|
FunctionDeclTy Source;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Local area size: storage + metadata.
|
2022-10-05 06:11:57 +02:00
|
|
|
unsigned FrameSize = 0;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Size of the argument stack.
|
|
|
|
unsigned ArgSize;
|
|
|
|
/// Program code.
|
2023-07-12 09:48:24 +02:00
|
|
|
std::vector<std::byte> Code;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Opcode-to-expression mapping.
|
|
|
|
SourceMap SrcMap;
|
|
|
|
/// List of block descriptors.
|
|
|
|
llvm::SmallVector<Scope, 2> Scopes;
|
|
|
|
/// List of argument types.
|
|
|
|
llvm::SmallVector<PrimType, 8> ParamTypes;
|
|
|
|
/// Map from byte offset to parameter descriptor.
|
|
|
|
llvm::DenseMap<unsigned, ParamDescriptor> Params;
|
2023-05-04 07:29:57 +02:00
|
|
|
/// List of parameter offsets.
|
|
|
|
llvm::SmallVector<unsigned, 8> ParamOffsets;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
/// Flag to indicate if the function is valid.
|
|
|
|
bool IsValid = false;
|
2022-08-29 10:20:24 +02:00
|
|
|
/// Flag to indicate if the function is done being
|
|
|
|
/// compiled to bytecode.
|
|
|
|
bool IsFullyCompiled = false;
|
2022-09-18 20:40:27 +02:00
|
|
|
/// Flag indicating if this function takes the this pointer
|
|
|
|
/// as the first implicit argument
|
|
|
|
bool HasThisPointer = false;
|
|
|
|
/// Whether this function has Return Value Optimization, i.e.
|
|
|
|
/// the return value is constructed in the caller's stack frame.
|
|
|
|
/// This is done for functions that return non-primive values.
|
|
|
|
bool HasRVO = false;
|
2022-10-28 10:31:47 +02:00
|
|
|
/// If we've already compiled the function's body.
|
|
|
|
bool HasBody = false;
|
2023-09-25 17:28:44 +02:00
|
|
|
bool Defined = false;
|
2023-10-24 12:33:29 +02:00
|
|
|
bool Variadic = false;
|
2024-08-31 01:50:59 +02:00
|
|
|
unsigned BuiltinID = 0;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Dumps the disassembled bytecode to \c llvm::errs().
|
|
|
|
void dump() const;
|
|
|
|
void dump(llvm::raw_ostream &OS) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace interp
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|