-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode][NFC] Add a FunctionKind enum #125391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesSome function types are special to us, so add an enum and determinte the function kind once when creating the function, instead of looking at the Decl every time we need the information. Full diff: https://github.com/llvm/llvm-project/pull/125391.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 19e2416c4c9422..5bd1b73133d654 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -135,11 +135,9 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
// Create a handle over the emitted code.
Function *Func = P.getFunction(FuncDecl);
if (!Func) {
- unsigned BuiltinID = FuncDecl->getBuiltinID();
- Func =
- P.createFunction(FuncDecl, ParamOffset, std::move(ParamTypes),
- std::move(ParamDescriptors), std::move(ParamOffsets),
- HasThisPointer, HasRVO, BuiltinID);
+ Func = P.createFunction(FuncDecl, ParamOffset, std::move(ParamTypes),
+ std::move(ParamDescriptors),
+ std::move(ParamOffsets), HasThisPointer, HasRVO);
}
assert(Func);
@@ -212,8 +210,7 @@ Function *ByteCodeEmitter::compileObjCBlock(const BlockExpr *BE) {
Function *Func =
P.createFunction(BE, ParamOffset, std::move(ParamTypes),
std::move(ParamDescriptors), std::move(ParamOffsets),
- /*HasThisPointer=*/false, /*HasRVO=*/false,
- /*IsUnevaluatedBuiltin=*/false);
+ /*HasThisPointer=*/false, /*HasRVO=*/false);
assert(Func);
Func->setDefined(true);
diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp
index 896a4fb3f9469a..5207894c266ac8 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -19,12 +19,24 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
llvm::SmallVectorImpl<PrimType> &&ParamTypes,
llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
llvm::SmallVectorImpl<unsigned> &&ParamOffsets,
- bool HasThisPointer, bool HasRVO, unsigned BuiltinID)
- : P(P), Source(Source), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)),
- Params(std::move(Params)), ParamOffsets(std::move(ParamOffsets)),
- HasThisPointer(HasThisPointer), HasRVO(HasRVO), BuiltinID(BuiltinID) {
- if (const auto *F = Source.dyn_cast<const FunctionDecl *>())
+ bool HasThisPointer, bool HasRVO)
+ : P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize),
+ ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
+ ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
+ HasRVO(HasRVO) {
+ if (const auto *F = Source.dyn_cast<const FunctionDecl *>()) {
Variadic = F->isVariadic();
+ BuiltinID = F->getBuiltinID();
+ if (isa<CXXConstructorDecl>(F))
+ Kind = FunctionKind::Ctor;
+ else if (isa<CXXDestructorDecl>(F))
+ Kind = FunctionKind::Dtor;
+ else if (const auto *MD = dyn_cast<CXXMethodDecl>(F);
+ MD && MD->isLambdaStaticInvoker())
+ Kind = FunctionKind::LambdaStaticInvoker;
+ else if (clang::isLambdaCallOperator(F))
+ Kind = FunctionKind::LambdaCallOperator;
+ }
}
Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h
index 409a80f59f1e94..696185d4a71225 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -80,6 +80,13 @@ using FunctionDeclTy =
///
class Function final {
public:
+ enum class FunctionKind {
+ Normal,
+ Ctor,
+ Dtor,
+ LambdaStaticInvoker,
+ LambdaCallOperator,
+ };
using ParamDescriptor = std::pair<PrimType, Descriptor *>;
/// Returns the size of the function's local stack.
@@ -144,40 +151,28 @@ class Function final {
bool isVirtual() const;
/// Checks if the function is a constructor.
- bool isConstructor() const {
- return isa_and_nonnull<CXXConstructorDecl>(
- dyn_cast<const FunctionDecl *>(Source));
- }
+ bool isConstructor() const { return Kind == FunctionKind::Ctor; }
/// Checks if the function is a destructor.
- bool isDestructor() const {
- return isa_and_nonnull<CXXDestructorDecl>(
- dyn_cast<const FunctionDecl *>(Source));
- }
-
- /// Returns the parent record decl, if any.
- const CXXRecordDecl *getParentDecl() const {
- if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
- dyn_cast<const FunctionDecl *>(Source)))
- return MD->getParent();
- return nullptr;
- }
+ bool isDestructor() const { return Kind == FunctionKind::Dtor; }
/// Returns whether this function is a lambda static invoker,
/// which we generate custom byte code for.
bool isLambdaStaticInvoker() const {
- if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
- dyn_cast<const FunctionDecl *>(Source)))
- return MD->isLambdaStaticInvoker();
- return false;
+ return Kind == FunctionKind::LambdaStaticInvoker;
}
/// Returns whether this function is the call operator
/// of a lambda record decl.
bool isLambdaCallOperator() const {
+ return Kind == FunctionKind::LambdaCallOperator;
+ }
+
+ /// Returns the parent record decl, if any.
+ const CXXRecordDecl *getParentDecl() const {
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
dyn_cast<const FunctionDecl *>(Source)))
- return clang::isLambdaCallOperator(MD);
- return false;
+ return MD->getParent();
+ return nullptr;
}
/// Checks if the function is fully done compiling.
@@ -232,7 +227,7 @@ class Function final {
llvm::SmallVectorImpl<PrimType> &&ParamTypes,
llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
llvm::SmallVectorImpl<unsigned> &&ParamOffsets, bool HasThisPointer,
- bool HasRVO, unsigned BuiltinID);
+ bool HasRVO);
/// Sets the code of a function.
void setCode(unsigned NewFrameSize, std::vector<std::byte> &&NewCode,
@@ -255,6 +250,8 @@ class Function final {
/// Program reference.
Program &P;
+ /// Function Kind.
+ FunctionKind Kind;
/// Declaration this function was compiled from.
FunctionDeclTy Source;
/// Local area size: storage + metadata.
|
d0925d2
to
5fea55e
Compare
Some function types are special to us, so add an enum and determinte the function kind once when creating the function, instead of looking at the Decl every time we need the information.
5fea55e
to
df8e464
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some function types are special to us, so add an enum and determinte the function kind once when creating the function, instead of looking at the Decl every time we need the information.