slang_rs_export_foreach.h revision 42f81b2b44205f421c6bd4727ce8c25b0effcb55
1/* 2 * Copyright 2011-2012, 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_SLANG_RS_EXPORT_FOREACH_H_ // NOLINT 18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ 19 20#include "llvm/ADT/StringRef.h" 21#include "llvm/Support/raw_ostream.h" 22 23#include "clang/AST/Decl.h" 24 25#include "slang_assert.h" 26#include "slang_rs_context.h" 27#include "slang_rs_exportable.h" 28#include "slang_rs_export_type.h" 29 30namespace clang { 31 class FunctionDecl; 32} // namespace clang 33 34namespace slang { 35 36// Base class for reflecting control-side forEach (currently for root() 37// functions that fit appropriate criteria) 38class RSExportForEach : public RSExportable { 39 private: 40 std::string mName; 41 RSExportRecordType *mParamPacketType; 42 RSExportType *mInType; 43 RSExportType *mOutType; 44 size_t numParams; 45 46 unsigned int mSignatureMetadata; 47 48 const clang::ParmVarDecl *mIn; 49 const clang::ParmVarDecl *mOut; 50 const clang::ParmVarDecl *mUsrData; 51 const clang::ParmVarDecl *mX; 52 const clang::ParmVarDecl *mY; 53 const clang::ParmVarDecl *mZ; 54 const clang::ParmVarDecl *mAr; 55 56 clang::QualType mResultType; // return type (if present). 57 bool mHasReturnType; // does this kernel have a return type? 58 bool mIsKernelStyle; // is this a pass-by-value kernel? 59 60 bool mDummyRoot; 61 62 // TODO(all): Add support for LOD/face when we have them 63 RSExportForEach(RSContext *Context, const llvm::StringRef &Name) 64 : RSExportable(Context, RSExportable::EX_FOREACH), 65 mName(Name.data(), Name.size()), mParamPacketType(NULL), mInType(NULL), 66 mOutType(NULL), numParams(0), mSignatureMetadata(0), 67 mIn(NULL), mOut(NULL), mUsrData(NULL), mX(NULL), mY(NULL), mZ(NULL), 68 mAr(NULL), mResultType(clang::QualType()), mHasReturnType(false), 69 mIsKernelStyle(false), mDummyRoot(false) { 70 return; 71 } 72 73 bool validateAndConstructParams(RSContext *Context, 74 const clang::FunctionDecl *FD); 75 76 bool validateAndConstructOldStyleParams(RSContext *Context, 77 const clang::FunctionDecl *FD); 78 79 bool validateAndConstructKernelParams(RSContext *Context, 80 const clang::FunctionDecl *FD); 81 82 bool validateIterationParameters(RSContext *Context, 83 const clang::FunctionDecl *FD, 84 size_t *IndexOfFirstIterator); 85 86 bool setSignatureMetadata(RSContext *Context, 87 const clang::FunctionDecl *FD); 88 public: 89 static RSExportForEach *Create(RSContext *Context, 90 const clang::FunctionDecl *FD); 91 92 static RSExportForEach *CreateDummyRoot(RSContext *Context); 93 94 inline const std::string &getName() const { 95 return mName; 96 } 97 98 inline size_t getNumParameters() const { 99 return numParams; 100 } 101 102 inline bool hasIn() const { 103 return (mIn != NULL); 104 } 105 106 inline bool hasOut() const { 107 return (mOut != NULL); 108 } 109 110 inline bool hasUsrData() const { 111 return (mUsrData != NULL); 112 } 113 114 inline bool hasReturn() const { 115 return mHasReturnType; 116 } 117 118 inline const RSExportType *getInType() const { 119 return mInType; 120 } 121 122 inline const RSExportType *getOutType() const { 123 return mOutType; 124 } 125 126 inline const RSExportRecordType *getParamPacketType() const { 127 return mParamPacketType; 128 } 129 130 inline unsigned int getSignatureMetadata() const { 131 return mSignatureMetadata; 132 } 133 134 inline bool isDummyRoot() const { 135 return mDummyRoot; 136 } 137 138 typedef RSExportRecordType::const_field_iterator const_param_iterator; 139 140 inline const_param_iterator params_begin() const { 141 slangAssert((mParamPacketType != NULL) && 142 "Get parameter from export foreach having no parameter!"); 143 return mParamPacketType->fields_begin(); 144 } 145 146 inline const_param_iterator params_end() const { 147 slangAssert((mParamPacketType != NULL) && 148 "Get parameter from export foreach having no parameter!"); 149 return mParamPacketType->fields_end(); 150 } 151 152 inline static bool isInitRSFunc(const clang::FunctionDecl *FD) { 153 if (!FD) { 154 return false; 155 } 156 const llvm::StringRef Name = FD->getName(); 157 static llvm::StringRef FuncInit("init"); 158 return Name.equals(FuncInit); 159 } 160 161 inline static bool isRootRSFunc(const clang::FunctionDecl *FD) { 162 if (!FD) { 163 return false; 164 } 165 const llvm::StringRef Name = FD->getName(); 166 static llvm::StringRef FuncRoot("root"); 167 return Name.equals(FuncRoot); 168 } 169 170 inline static bool isDtorRSFunc(const clang::FunctionDecl *FD) { 171 if (!FD) { 172 return false; 173 } 174 const llvm::StringRef Name = FD->getName(); 175 static llvm::StringRef FuncDtor(".rs.dtor"); 176 return Name.equals(FuncDtor); 177 } 178 179 static bool isGraphicsRootRSFunc(int targetAPI, 180 const clang::FunctionDecl *FD); 181 182 static bool isRSForEachFunc(int targetAPI, slang::RSContext *Context, 183 const clang::FunctionDecl *FD); 184 185 inline static bool isSpecialRSFunc(int targetAPI, 186 const clang::FunctionDecl *FD) { 187 return isGraphicsRootRSFunc(targetAPI, FD) || isInitRSFunc(FD) || 188 isDtorRSFunc(FD); 189 } 190 191 static bool validateSpecialFuncDecl(int targetAPI, 192 slang::RSContext *Context, 193 const clang::FunctionDecl *FD); 194}; // RSExportForEach 195 196} // namespace slang 197 198#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT 199