David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 1 | // Copyright 2017 The Clspv Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
David Neto | 4feb7a4 | 2017-10-06 17:29:42 -0400 | [diff] [blame] | 15 | #ifndef CLSPV_LIB_ARGKIND_H_ |
| 16 | #define CLSPV_LIB_ARGKIND_H_ |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 17 | |
Diego Novillo | a4c44fa | 2019-04-11 10:56:15 -0400 | [diff] [blame^] | 18 | #include "llvm/ADT/DenseMap.h" |
David Neto | c6f3ab2 | 2018-04-06 18:02:31 -0400 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" |
| 20 | #include "llvm/IR/Module.h" |
| 21 | #include "llvm/IR/Type.h" |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 22 | |
alan-baker | f5e5f69 | 2018-11-27 08:33:24 -0500 | [diff] [blame] | 23 | #include "clspv/ArgKind.h" |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 24 | |
alan-baker | f5e5f69 | 2018-11-27 08:33:24 -0500 | [diff] [blame] | 25 | namespace clspv { |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 26 | |
| 27 | // Maps an LLVM type for a kernel argument to an argument kind. |
| 28 | ArgKind GetArgKindForType(llvm::Type *type); |
| 29 | |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 30 | // Maps an LLVM type for a kernel argument to an argument |
David Neto | 4feb7a4 | 2017-10-06 17:29:42 -0400 | [diff] [blame] | 31 | // kind suitable for a descriptor map. The result is one of: |
Alan Baker | fcda948 | 2018-10-02 17:09:59 -0400 | [diff] [blame] | 32 | // buffer - storage buffer |
| 33 | // buffer_ubo - uniform buffer |
| 34 | // local - array in Workgroup storage, number of elements given by |
| 35 | // a specialization constant |
| 36 | // pod - plain-old-data |
| 37 | // ro_image - read-only image |
| 38 | // wo_image - write-only image |
| 39 | // sampler - sampler |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 40 | inline const char *GetArgKindNameForType(llvm::Type *type) { |
| 41 | return GetArgKindName(GetArgKindForType(type)); |
| 42 | } |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 43 | |
David Neto | c6f3ab2 | 2018-04-06 18:02:31 -0400 | [diff] [blame] | 44 | // Returns true if the given type is a pointer-to-local type. |
Diego Novillo | a4c44fa | 2019-04-11 10:56:15 -0400 | [diff] [blame^] | 45 | bool IsLocalPtr(llvm::Type *type); |
David Neto | c6f3ab2 | 2018-04-06 18:02:31 -0400 | [diff] [blame] | 46 | |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 47 | // Returns true if the given type is a sampler type. If it is, then the |
| 48 | // struct type is sent back through the ptr argument. |
| 49 | bool IsSamplerType(llvm::Type *type, llvm::Type **struct_type_ptr = nullptr); |
| 50 | |
| 51 | // Returns true if the given type is a image type. If it is, then the |
| 52 | // struct type is sent back through the ptr argument. |
| 53 | bool IsImageType(llvm::Type *type, llvm::Type **struct_type_ptr = nullptr); |
| 54 | |
Diego Novillo | a4c44fa | 2019-04-11 10:56:15 -0400 | [diff] [blame^] | 55 | using ArgIdMapType = llvm::DenseMap<const llvm::Argument *, int>; |
David Neto | c6f3ab2 | 2018-04-06 18:02:31 -0400 | [diff] [blame] | 56 | |
| 57 | // Returns a mapping from pointer-to-local Argument to a specialization constant |
| 58 | // ID for that argument's array size. The lowest value allocated is 3. |
| 59 | // |
| 60 | // The mapping is as follows: |
| 61 | // - The first index used is 3. |
| 62 | // - There are no gaps in the list of used indices. |
| 63 | // - Arguments from earlier kernel bodies have lower indices than arguments from |
| 64 | // later kernel bodies. |
| 65 | // - Lower-numbered arguments have lower indices than higher-numbered arguments |
| 66 | // in the same function. |
| 67 | // Note that this mapping is stable as long as the order of kernel bodies is |
| 68 | // retained, and the number and order of pointer-to-local arguments is retained. |
| 69 | ArgIdMapType AllocateArgSpecIds(llvm::Module &M); |
| 70 | |
David Neto | 48f56a4 | 2017-10-06 16:44:25 -0400 | [diff] [blame] | 71 | } // namespace clspv |
| 72 | |
| 73 | #endif |