[clang] [SYCL] AST support for SYCL kernel entry point functions. (PR #122379)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 18 20:06:25 PST 2025
================
@@ -4678,6 +4678,95 @@ class BlockDecl : public Decl, public DeclContext {
}
};
+/// Represents a partial function definition.
+///
+/// An outlined function declaration contains the parameters and body of
+/// a function independent of other function definition concerns such
+/// as function name, type, and calling convention. Such declarations may
+/// be used to hold a parameterized and transformed sequence of statements
+/// used to generate a target dependent function definition without losing
+/// association with the original statements. See SYCLKernelCallStmt as an
+/// example.
+class OutlinedFunctionDecl final
+ : public Decl,
+ public DeclContext,
+ private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
+protected:
+ size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
+ return NumParams;
+ }
+
+private:
+ /// The number of parameters to the outlined function.
+ unsigned NumParams;
+
+ /// The body of the outlined function.
+ llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
+
+ explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
+
+ ImplicitParamDecl *const *getParams() const {
+ return getTrailingObjects<ImplicitParamDecl *>();
+ }
+
+ ImplicitParamDecl **getParams() {
+ return getTrailingObjects<ImplicitParamDecl *>();
+ }
+
+public:
+ friend class ASTDeclReader;
+ friend class ASTDeclWriter;
+ friend TrailingObjects;
+
+ static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
+ unsigned NumParams);
+ static OutlinedFunctionDecl *
+ CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
+
+ Stmt *getBody() const override;
+ void setBody(Stmt *B);
+
+ bool isNothrow() const;
+ void setNothrow(bool Nothrow = true);
+
+ unsigned getNumParams() const { return NumParams; }
+
+ ImplicitParamDecl *getParam(unsigned i) const {
+ assert(i < NumParams);
+ return getParams()[i];
+ }
+ void setParam(unsigned i, ImplicitParamDecl *P) {
+ assert(i < NumParams);
+ getParams()[i] = P;
+ }
+
+ // ArrayRef interface to parameters.
+ ArrayRef<ImplicitParamDecl *> parameters() const {
+ return {getParams(), getNumParams()};
+ }
+ MutableArrayRef<ImplicitParamDecl *> parameters() {
+ return {getParams(), getNumParams()};
+ }
+
+ using param_iterator = ImplicitParamDecl *const *;
+ using param_range = llvm::iterator_range<param_iterator>;
+
+ /// Retrieve an iterator pointing to the first parameter decl.
+ param_iterator param_begin() const { return getParams(); }
----------------
tahonermann wrote:
This was also copy/paste from `CapturedDecl`. `param_begin()` is the name used for `FunctionDecl`, `BlockDecl`, `CapturedDecl`, and `ObjCMethodDecl`. We don't currently use `parameters_begin()` anywhere. I agree with your naming preferences here, but I think consistency with other related classes is more important. A separate effort to change the existing names would make sense, but would affect downstream forks for little benefit.
I'll make the change to implement these functions in terms of each other.
https://github.com/llvm/llvm-project/pull/122379
More information about the cfe-commits
mailing list