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 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 37 | // Base class for reflecting control-side forEach |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 38 | class RSExportForEach : public RSExportable { |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 39 | public: |
| 40 | |
| 41 | typedef llvm::SmallVectorImpl<const clang::ParmVarDecl*> InVec; |
| 42 | typedef llvm::SmallVectorImpl<const RSExportType*> InTypeVec; |
| 43 | |
| 44 | typedef InVec::const_iterator InIter; |
| 45 | typedef InTypeVec::const_iterator InTypeIter; |
| 46 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 47 | private: |
| 48 | std::string mName; |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 49 | |
| 50 | // For diagnostic purposes, we record the order in which we parse |
Jeff Sharkey | 1ebb342 | 2020-07-31 09:26:44 -0600 | [diff] [blame] | 51 | // foreach kernels. Does not apply to a placeholder root. |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 52 | unsigned mOrdinal; |
| 53 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 54 | RSExportRecordType *mParamPacketType; |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 55 | llvm::SmallVector<const RSExportType*, 16> mInTypes; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 56 | RSExportType *mOutType; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 57 | size_t numParams; |
| 58 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 59 | unsigned int mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 60 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 61 | llvm::SmallVector<const clang::ParmVarDecl*, 16> mIns; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 62 | const clang::ParmVarDecl *mOut; |
| 63 | const clang::ParmVarDecl *mUsrData; |
David Gross | 18c50eb | 2015-01-30 11:39:22 -0800 | [diff] [blame] | 64 | |
| 65 | // Accumulator for metadata bits corresponding to special parameters. |
| 66 | unsigned int mSpecialParameterSignatureMetadata; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 67 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 68 | clang::QualType mResultType; // return type (if present). |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 69 | bool mHasReturnType; // does this kernel have a return type? |
| 70 | bool mIsKernelStyle; // is this a pass-by-value kernel? |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 71 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 72 | bool mDummyRoot; |
| 73 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 74 | // TODO(all): Add support for LOD/face when we have them |
David Gross | 63e6108 | 2017-07-13 14:17:29 -0700 | [diff] [blame] | 75 | RSExportForEach(RSContext *Context, const llvm::StringRef &Name, clang::SourceLocation Loc) |
| 76 | : RSExportable(Context, RSExportable::EX_FOREACH, Loc), |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 77 | mName(Name.data(), Name.size()), mOrdinal(~unsigned(0)), |
| 78 | mParamPacketType(nullptr), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 79 | mOutType(nullptr), numParams(0), mSignatureMetadata(0), |
David Gross | 18c50eb | 2015-01-30 11:39:22 -0800 | [diff] [blame] | 80 | mOut(nullptr), mUsrData(nullptr), mSpecialParameterSignatureMetadata(0), |
Narayan Kamath | 50cab07 | 2014-03-25 15:06:36 +0000 | [diff] [blame] | 81 | mResultType(clang::QualType()), mHasReturnType(false), |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 82 | mIsKernelStyle(false), mDummyRoot(false) { |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 85 | bool validateAndConstructParams(RSContext *Context, |
| 86 | const clang::FunctionDecl *FD); |
| 87 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 88 | bool validateAndConstructOldStyleParams(RSContext *Context, |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 89 | const clang::FunctionDecl *FD); |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 90 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 91 | bool validateAndConstructKernelParams(RSContext *Context, |
| 92 | const clang::FunctionDecl *FD); |
| 93 | |
Jean-Luc Brouillet | 9764eb3 | 2015-08-07 16:43:18 -0700 | [diff] [blame] | 94 | bool processSpecialParameters(RSContext *Context, |
| 95 | const clang::FunctionDecl *FD, |
| 96 | size_t *IndexOfFirstSpecialParameter); |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 97 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 98 | bool setSignatureMetadata(RSContext *Context, |
| 99 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 100 | public: |
| 101 | static RSExportForEach *Create(RSContext *Context, |
| 102 | const clang::FunctionDecl *FD); |
| 103 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 104 | static RSExportForEach *CreateDummyRoot(RSContext *Context); |
| 105 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 106 | inline const std::string &getName() const { |
| 107 | return mName; |
| 108 | } |
| 109 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 110 | inline unsigned getOrdinal() const { |
| 111 | slangAssert(!mDummyRoot); |
| 112 | return mOrdinal; |
| 113 | } |
| 114 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 115 | inline size_t getNumParameters() const { |
| 116 | return numParams; |
| 117 | } |
| 118 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 119 | inline bool hasIns() const { |
| 120 | return (!mIns.empty()); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | inline bool hasOut() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 124 | return (mOut != nullptr); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | inline bool hasUsrData() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 128 | return (mUsrData != nullptr); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 131 | inline bool hasReturn() const { |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 132 | return mHasReturnType; |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 135 | inline const InVec& getIns() const { |
| 136 | return mIns; |
| 137 | } |
| 138 | |
| 139 | inline const InTypeVec& getInTypes() const { |
| 140 | return mInTypes; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | inline const RSExportType *getOutType() const { |
| 144 | return mOutType; |
| 145 | } |
| 146 | |
| 147 | inline const RSExportRecordType *getParamPacketType() const { |
| 148 | return mParamPacketType; |
| 149 | } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 150 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 151 | inline unsigned int getSignatureMetadata() const { |
| 152 | return mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 155 | inline bool isDummyRoot() const { |
| 156 | return mDummyRoot; |
| 157 | } |
| 158 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 159 | // is this a pass-by-value kernel? |
| 160 | inline bool isKernelStyle() const { |
| 161 | return mIsKernelStyle; |
| 162 | } |
| 163 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 164 | typedef RSExportRecordType::const_field_iterator const_param_iterator; |
| 165 | |
| 166 | inline const_param_iterator params_begin() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 167 | slangAssert((mParamPacketType != nullptr) && |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 168 | "Get parameter from export foreach having no parameter!"); |
| 169 | return mParamPacketType->fields_begin(); |
| 170 | } |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 171 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 172 | inline const_param_iterator params_end() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 173 | slangAssert((mParamPacketType != nullptr) && |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 174 | "Get parameter from export foreach having no parameter!"); |
| 175 | return mParamPacketType->fields_end(); |
| 176 | } |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 177 | inline size_t params_count() const { |
| 178 | return (mParamPacketType ? mParamPacketType->fields_size() : 0); |
| 179 | } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 180 | |
Matt Wala | f5b882c | 2015-06-15 17:45:45 -0700 | [diff] [blame] | 181 | static bool isRSForEachFunc(unsigned int targetAPI, |
Stephen Hines | 089cde3 | 2012-12-07 19:19:10 -0800 | [diff] [blame] | 182 | const clang::FunctionDecl *FD); |
Yang Ni | 1946749 | 2015-10-27 15:24:41 -0700 | [diff] [blame] | 183 | |
| 184 | static unsigned getNumInputs(unsigned int targetAPI, |
| 185 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 186 | }; // RSExportForEach |
| 187 | |
| 188 | } // namespace slang |
| 189 | |
| 190 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT |