blob: 42f476d9741137789c6185c51300fdd360b9e3c9 [file] [log] [blame]
Yang Nifb40ee22015-10-13 20:34:06 +00001/*
2 * Copyright 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H
18#define _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H
19
20#include "clang/AST/StmtVisitor.h"
21
22namespace clang {
23 class ASTContext;
24 class CallExpr;
25 class Expr;
26 class FunctionDecl;
27}
28
29namespace slang {
30
31class RSContext;
32
33class RSForEachLowering : public clang::StmtVisitor<RSForEachLowering> {
34 public:
Chih-Hung Hsiehe2ead842016-08-12 15:57:25 -070035 explicit RSForEachLowering(RSContext* ctxt);
Yang Nifb40ee22015-10-13 20:34:06 +000036
Yang Niedfcc692016-02-25 15:14:37 -080037 // Given a FunctionDecl FD and the target API level, either translates all
38 // rsForEach() and rsForEachWithOptions() calls inside FD into calls to the
39 // low-level rsForEachInternal() API, if FD is not a kernel function itself;
40 // or, in the case where FD is a kernel function, reports a compiler error on
41 // any calls to either kernel launching API function.
42 void handleForEachCalls(clang::FunctionDecl* FD, unsigned int targetAPI);
43
Yang Nifb40ee22015-10-13 20:34:06 +000044 void VisitCallExpr(clang::CallExpr *CE);
45 void VisitStmt(clang::Stmt *S);
46
47 private:
48 RSContext* mCtxt;
49 clang::ASTContext& mASTCtxt;
Yang Niedfcc692016-02-25 15:14:37 -080050 // A flag, if true, indicating that the visitor is walking inside a kernel
51 // function, in which case any call to rsForEach() or rsForEachWithOptions()
52 // is a compiler error.
53 bool mInsideKernel;
Yang Nifb40ee22015-10-13 20:34:06 +000054
55 const clang::FunctionDecl* matchFunctionDesignator(clang::Expr* expr);
Yang Ni19467492015-10-27 15:24:41 -070056 const clang::FunctionDecl* matchKernelLaunchCall(clang::CallExpr* CE,
57 int* slot,
58 bool* hasOptions);
Yang Nifb40ee22015-10-13 20:34:06 +000059 clang::FunctionDecl* CreateForEachInternalFunctionDecl();
60 clang::Expr* CreateCalleeExprForInternalForEach();
61}; // RSForEachLowering
62
63} // namespace slang
64
65#endif // _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H