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; |
David Gross | 18c50eb | 2015-01-30 11:39:22 -0800 | [diff] [blame] | 60 | |
| 61 | // Accumulator for metadata bits corresponding to special parameters. |
| 62 | unsigned int mSpecialParameterSignatureMetadata; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 63 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 64 | clang::QualType mResultType; // return type (if present). |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 65 | bool mHasReturnType; // does this kernel have a return type? |
| 66 | bool mIsKernelStyle; // is this a pass-by-value kernel? |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 67 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 68 | bool mDummyRoot; |
| 69 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 70 | // TODO(all): Add support for LOD/face when we have them |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 71 | RSExportForEach(RSContext *Context, const llvm::StringRef &Name) |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 72 | : RSExportable(Context, RSExportable::EX_FOREACH), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 73 | mName(Name.data(), Name.size()), mParamPacketType(nullptr), |
| 74 | mOutType(nullptr), numParams(0), mSignatureMetadata(0), |
David Gross | 18c50eb | 2015-01-30 11:39:22 -0800 | [diff] [blame] | 75 | mOut(nullptr), mUsrData(nullptr), mSpecialParameterSignatureMetadata(0), |
Narayan Kamath | 50cab07 | 2014-03-25 15:06:36 +0000 | [diff] [blame] | 76 | mResultType(clang::QualType()), mHasReturnType(false), |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 77 | mIsKernelStyle(false), mDummyRoot(false) { |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 80 | bool validateAndConstructParams(RSContext *Context, |
| 81 | const clang::FunctionDecl *FD); |
| 82 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 83 | bool validateAndConstructOldStyleParams(RSContext *Context, |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 84 | const clang::FunctionDecl *FD); |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 85 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 86 | bool validateAndConstructKernelParams(RSContext *Context, |
| 87 | const clang::FunctionDecl *FD); |
| 88 | |
Jean-Luc Brouillet | 9764eb3 | 2015-08-07 16:43:18 -0700 | [diff] [blame] | 89 | bool processSpecialParameters(RSContext *Context, |
| 90 | const clang::FunctionDecl *FD, |
| 91 | size_t *IndexOfFirstSpecialParameter); |
Jean-Luc Brouillet | 42f81b2 | 2014-01-16 21:50:52 -0800 | [diff] [blame] | 92 | |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 93 | bool setSignatureMetadata(RSContext *Context, |
| 94 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 95 | public: |
| 96 | static RSExportForEach *Create(RSContext *Context, |
| 97 | const clang::FunctionDecl *FD); |
| 98 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 99 | static RSExportForEach *CreateDummyRoot(RSContext *Context); |
| 100 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 101 | inline const std::string &getName() const { |
| 102 | return mName; |
| 103 | } |
| 104 | |
| 105 | inline size_t getNumParameters() const { |
| 106 | return numParams; |
| 107 | } |
| 108 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 109 | inline bool hasIns() const { |
| 110 | return (!mIns.empty()); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | inline bool hasOut() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 114 | return (mOut != nullptr); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | inline bool hasUsrData() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 118 | return (mUsrData != nullptr); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 121 | inline bool hasReturn() const { |
Jean-Luc Brouillet | 0f2a239 | 2014-01-14 11:40:57 -0800 | [diff] [blame] | 122 | return mHasReturnType; |
Stephen Hines | 9ca96e7 | 2012-09-13 16:57:06 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 125 | inline const InVec& getIns() const { |
| 126 | return mIns; |
| 127 | } |
| 128 | |
| 129 | inline const InTypeVec& getInTypes() const { |
| 130 | return mInTypes; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | inline const RSExportType *getOutType() const { |
| 134 | return mOutType; |
| 135 | } |
| 136 | |
| 137 | inline const RSExportRecordType *getParamPacketType() const { |
| 138 | return mParamPacketType; |
| 139 | } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 140 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 141 | inline unsigned int getSignatureMetadata() const { |
| 142 | return mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 145 | inline bool isDummyRoot() const { |
| 146 | return mDummyRoot; |
| 147 | } |
| 148 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 149 | typedef RSExportRecordType::const_field_iterator const_param_iterator; |
| 150 | |
| 151 | inline const_param_iterator params_begin() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 152 | slangAssert((mParamPacketType != nullptr) && |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 153 | "Get parameter from export foreach having no parameter!"); |
| 154 | return mParamPacketType->fields_begin(); |
| 155 | } |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 156 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 157 | inline const_param_iterator params_end() const { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 158 | slangAssert((mParamPacketType != nullptr) && |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 159 | "Get parameter from export foreach having no parameter!"); |
| 160 | return mParamPacketType->fields_end(); |
| 161 | } |
| 162 | |
Matt Wala | f5b882c | 2015-06-15 17:45:45 -0700 | [diff] [blame] | 163 | static bool isRSForEachFunc(unsigned int targetAPI, |
Stephen Hines | 089cde3 | 2012-12-07 19:19:10 -0800 | [diff] [blame] | 164 | const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 165 | }; // RSExportForEach |
| 166 | |
| 167 | } // namespace slang |
| 168 | |
| 169 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT |