Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 2 | * Copyright 2011-2012, The Android Open Source Project |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 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_SLANG_RS_EXPORT_FOREACH_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ |
| 19 | |
| 20 | #include "llvm/ADT/StringRef.h" |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
| 23 | |
| 24 | #include "clang/AST/Decl.h" |
| 25 | |
| 26 | #include "slang_assert.h" |
| 27 | #include "slang_rs_context.h" |
| 28 | #include "slang_rs_exportable.h" |
| 29 | #include "slang_rs_export_type.h" |
| 30 | |
| 31 | namespace clang { |
| 32 | class FunctionDecl; |
| 33 | } // namespace clang |
| 34 | |
| 35 | namespace slang { |
| 36 | |
| 37 | // Base class for reflecting control-side forEach (currently for root() |
| 38 | // functions that fit appropriate criteria) |
| 39 | class RSExportForEach : public RSExportable { |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 40 | public: |
| 41 | |
| 42 | typedef llvm::SmallVectorImpl<const clang::ParmVarDecl*> InVec; |
| 43 | typedef llvm::SmallVectorImpl<const RSExportType*> InTypeVec; |
| 44 | |
| 45 | typedef InVec::const_iterator InIter; |
| 46 | typedef InTypeVec::const_iterator InTypeIter; |
| 47 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 48 | private: |
| 49 | std::string mName; |
| 50 | RSExportRecordType *mParamPacketType; |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 51 | llvm::SmallVector<const RSExportType*, 16> mInTypes; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 52 | RSExportType *mOutType; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 53 | size_t numParams; |
| 54 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 55 | unsigned int mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 56 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 57 | llvm::SmallVector<const clang::ParmVarDecl*, 16> mIns; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 58 | const clang::ParmVarDecl *mOut; |
| 59 | const clang::ParmVarDecl *mUsrData; |
| 60 | const clang::ParmVarDecl *mX; |
| 61 | const clang::ParmVarDecl *mY; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 62 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 63 | clang::QualType mResultType; // return type (if present). |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 64 | bool mHasReturnType; // does this kernel have a return type? |
| 65 | bool mIsKernelStyle; // is this a pass-by-value kernel? |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 66 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 67 | bool mDummyRoot; |
| 68 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 69 | // TODO(all): Add support for LOD/face when we have them |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 70 | RSExportForEach(RSContext *Context, const llvm::StringRef &Name) |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 71 | : RSExportable(Context, RSExportable::EX_FOREACH), |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 72 | mName(Name.data(), Name.size()), mParamPacketType(NULL), |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 73 | mOutType(NULL), numParams(0), mSignatureMetadata(0), |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 74 | mOut(NULL), mUsrData(NULL), mX(NULL), mY(NULL), |
Narayan Kamath | 50cab07 | 2014-03-25 15:06:36 +0000 | [diff] [blame] | 75 | mResultType(clang::QualType()), mHasReturnType(false), |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 76 | mIsKernelStyle(false), mDummyRoot(false) { |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 79 | bool validateAndConstructParams(RSContext *Context, |
| 80 | const clang::FunctionDecl *FD); |
| 81 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 82 | bool validateAndConstructOldStyleParams(RSContext *Context, |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 83 | const clang::FunctionDecl *FD); |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 84 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 85 | bool validateAndConstructKernelParams(RSContext *Context, |
| 86 | const clang::FunctionDecl *FD); |
| 87 | |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 88 | bool validateIterationParameters(RSContext *Context, |
| 89 | const clang::FunctionDecl *FD, |
| 90 | size_t *IndexOfFirstIterator); |
| 91 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 92 | bool setSignatureMetadata(RSContext *Context, |
| 93 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 94 | public: |
| 95 | static RSExportForEach *Create(RSContext *Context, |
| 96 | const clang::FunctionDecl *FD); |
| 97 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 98 | static RSExportForEach *CreateDummyRoot(RSContext *Context); |
| 99 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 100 | inline const std::string &getName() const { |
| 101 | return mName; |
| 102 | } |
| 103 | |
| 104 | inline size_t getNumParameters() const { |
| 105 | return numParams; |
| 106 | } |
| 107 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 108 | inline bool hasIns() const { |
| 109 | return (!mIns.empty()); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | inline bool hasOut() const { |
| 113 | return (mOut != NULL); |
| 114 | } |
| 115 | |
| 116 | inline bool hasUsrData() const { |
| 117 | return (mUsrData != NULL); |
| 118 | } |
| 119 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 120 | inline bool hasReturn() const { |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 121 | return mHasReturnType; |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 124 | inline const InVec& getIns() const { |
| 125 | return mIns; |
| 126 | } |
| 127 | |
| 128 | inline const InTypeVec& getInTypes() const { |
| 129 | return mInTypes; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | inline const RSExportType *getOutType() const { |
| 133 | return mOutType; |
| 134 | } |
| 135 | |
| 136 | inline const RSExportRecordType *getParamPacketType() const { |
| 137 | return mParamPacketType; |
| 138 | } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 139 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 140 | inline unsigned int getSignatureMetadata() const { |
| 141 | return mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 144 | inline bool isDummyRoot() const { |
| 145 | return mDummyRoot; |
| 146 | } |
| 147 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 148 | typedef RSExportRecordType::const_field_iterator const_param_iterator; |
| 149 | |
| 150 | inline const_param_iterator params_begin() const { |
| 151 | slangAssert((mParamPacketType != NULL) && |
| 152 | "Get parameter from export foreach having no parameter!"); |
| 153 | return mParamPacketType->fields_begin(); |
| 154 | } |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 155 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 156 | inline const_param_iterator params_end() const { |
| 157 | slangAssert((mParamPacketType != NULL) && |
| 158 | "Get parameter from export foreach having no parameter!"); |
| 159 | return mParamPacketType->fields_end(); |
| 160 | } |
| 161 | |
| 162 | inline static bool isInitRSFunc(const clang::FunctionDecl *FD) { |
| 163 | if (!FD) { |
| 164 | return false; |
| 165 | } |
| 166 | const llvm::StringRef Name = FD->getName(); |
| 167 | static llvm::StringRef FuncInit("init"); |
| 168 | return Name.equals(FuncInit); |
| 169 | } |
| 170 | |
| 171 | inline static bool isRootRSFunc(const clang::FunctionDecl *FD) { |
| 172 | if (!FD) { |
| 173 | return false; |
| 174 | } |
| 175 | const llvm::StringRef Name = FD->getName(); |
| 176 | static llvm::StringRef FuncRoot("root"); |
| 177 | return Name.equals(FuncRoot); |
| 178 | } |
| 179 | |
Stephen Hines | 688e64b | 2011-08-23 16:01:25 -0700 | [diff] [blame] | 180 | inline static bool isDtorRSFunc(const clang::FunctionDecl *FD) { |
| 181 | if (!FD) { |
| 182 | return false; |
| 183 | } |
| 184 | const llvm::StringRef Name = FD->getName(); |
| 185 | static llvm::StringRef FuncDtor(".rs.dtor"); |
| 186 | return Name.equals(FuncDtor); |
| 187 | } |
| 188 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 189 | static bool isGraphicsRootRSFunc(unsigned int targetAPI, |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 190 | const clang::FunctionDecl *FD); |
| 191 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 192 | static bool isRSForEachFunc(unsigned int targetAPI, slang::RSContext *Context, |
Stephen Hines | 089cde3 | 2012-12-07 19:19:10 -0800 | [diff] [blame] | 193 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 194 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 195 | inline static bool isSpecialRSFunc(unsigned int targetAPI, |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 196 | const clang::FunctionDecl *FD) { |
| 197 | return isGraphicsRootRSFunc(targetAPI, FD) || isInitRSFunc(FD) || |
| 198 | isDtorRSFunc(FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 201 | static bool validateSpecialFuncDecl(unsigned int targetAPI, |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 202 | slang::RSContext *Context, |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 203 | const clang::FunctionDecl *FD); |
| 204 | }; // RSExportForEach |
| 205 | |
| 206 | } // namespace slang |
| 207 | |
| 208 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT |