David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 1 | // Copyright 2018 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 | |
| 15 | // This translation unit defines all Clspv command line option variables. |
| 16 | |
| 17 | #include <llvm/Support/CommandLine.h> |
| 18 | |
| 19 | namespace { |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 20 | |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 21 | // Should the compiler try to use direct resource accesses within helper |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 22 | // functions instead of passing pointers via function arguments? |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 23 | llvm::cl::opt<bool> no_direct_resource_access( |
| 24 | "no-dra", llvm::cl::init(false), |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 25 | llvm::cl::desc( |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 26 | "No Direct Resource Access: Avoid rewriting helper functions " |
| 27 | "to access resources directly instead of by pointers " |
| 28 | "in function arguments. Affects kernel arguments of type " |
| 29 | "pointer-to-global, pointer-to-constant, image, and sampler.")); |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 30 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 31 | // By default, reuse the same descriptor set number for all arguments. |
| 32 | // To turn that off, use -distinct-kernel-descriptor-sets |
| 33 | llvm::cl::opt<bool> distinct_kernel_descriptor_sets( |
| 34 | "distinct-kernel-descriptor-sets", llvm::cl::init(false), |
| 35 | llvm::cl::desc( |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 36 | "Each kernel uses its own descriptor set for its arguments. " |
| 37 | "Turns off direct-resource-access optimizations.")); |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 38 | |
| 39 | // TODO(dneto): As per Neil Henning suggestion, might not need this if |
| 40 | // you can trace the pointer back far enough to see that it's 32-bit |
| 41 | // aligned. However, even in the vstore_half case, you'll probably get |
| 42 | // better performance if you can rely on SPV_KHR_16bit_storage since in |
| 43 | // the alternate case you're using a (relaxed) atomic, and therefore |
| 44 | // have to write through to the cache. |
| 45 | llvm::cl::opt<bool> f16bit_storage( |
| 46 | "f16bit_storage", llvm::cl::init(false), |
| 47 | llvm::cl::desc("Assume the target supports SPV_KHR_16bit_storage")); |
| 48 | |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 49 | llvm::cl::opt<bool> hack_initializers( |
| 50 | "hack-initializers", llvm::cl::init(false), |
| 51 | llvm::cl::desc( |
| 52 | "At the start of each kernel, explicitly write the initializer " |
| 53 | "value for a compiler-generated variable containing the workgroup " |
| 54 | "size. Required by some drivers to make the get_global_size builtin " |
| 55 | "function work when used with non-constant dimension index.")); |
| 56 | |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 57 | llvm::cl::opt<bool> hack_dis( |
| 58 | "hack-dis", llvm::cl::init(false), |
| 59 | llvm::cl::desc( |
| 60 | "Force use of a distinct image or sampler variable for each " |
| 61 | "image or sampler kernel argument. This prevents sharing " |
| 62 | "of resource variables.")); |
| 63 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 64 | llvm::cl::opt<bool> hack_inserts( |
| 65 | "hack-inserts", llvm::cl::init(false), |
| 66 | llvm::cl::desc( |
| 67 | "Avoid all single-index OpCompositInsert instructions " |
| 68 | "into struct types by using complete composite construction and " |
| 69 | "extractions")); |
| 70 | |
David Neto | 3a0df83 | 2018-08-03 14:35:42 -0400 | [diff] [blame^] | 71 | llvm::cl::opt<bool> hack_signed_compare_fixup( |
| 72 | "hack-scf", llvm::cl::init(false), |
| 73 | llvm::cl::desc("Rewrite signed integer comparisons to use other kinds of " |
| 74 | "instructions")); |
| 75 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 76 | // Some drivers don't like to see constant composite values constructed |
| 77 | // from scalar Undef values. Replace numeric scalar and vector Undef with |
| 78 | // corresponding OpConstantNull. We need to keep Undef for image values, |
| 79 | // for example. In the LLVM domain, image values are passed as pointer to |
| 80 | // struct. |
| 81 | // See https://github.com/google/clspv/issues/95 |
| 82 | llvm::cl::opt<bool> hack_undef( |
| 83 | "hack-undef", llvm::cl::init(false), |
| 84 | llvm::cl::desc("Use OpConstantNull instead of OpUndef for floating point, " |
| 85 | "integer, or vectors of them")); |
| 86 | |
| 87 | llvm::cl::opt<bool> |
| 88 | pod_ubo("pod-ubo", llvm::cl::init(false), |
| 89 | llvm::cl::desc("POD kernel arguments are in uniform buffers")); |
| 90 | |
David Neto | 8508264 | 2018-03-24 06:55:20 -0700 | [diff] [blame] | 91 | llvm::cl::opt<bool> module_constants_in_storage_buffer( |
| 92 | "module-constants-in-storage-buffer", llvm::cl::init(false), |
| 93 | llvm::cl::desc( |
| 94 | "Module-scope __constants are collected into a single storage buffer. " |
| 95 | "The binding and initialization data are reported in the descriptor " |
| 96 | "map.")); |
| 97 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 98 | llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false), |
| 99 | llvm::cl::desc("Show SPIR-V IDs for functions")); |
| 100 | |
| 101 | } // namespace |
| 102 | |
| 103 | namespace clspv { |
| 104 | namespace Option { |
| 105 | |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 106 | bool DirectResourceAccess() { |
| 107 | return !(no_direct_resource_access || distinct_kernel_descriptor_sets); |
| 108 | } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 109 | bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; } |
| 110 | bool F16BitStorage() { return f16bit_storage; } |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 111 | bool HackDistinctImageSampler() { return hack_dis; } |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 112 | bool HackInitializers() { return hack_initializers; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 113 | bool HackInserts() { return hack_inserts; } |
David Neto | 3a0df83 | 2018-08-03 14:35:42 -0400 | [diff] [blame^] | 114 | bool HackSignedCompareFixup() { return hack_signed_compare_fixup; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 115 | bool HackUndef() { return hack_undef; } |
David Neto | 8508264 | 2018-03-24 06:55:20 -0700 | [diff] [blame] | 116 | bool ModuleConstantsInStorageBuffer() { return module_constants_in_storage_buffer; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 117 | bool PodArgsInUniformBuffer() { return pod_ubo; } |
| 118 | bool ShowIDs() { return show_ids; } |
| 119 | |
| 120 | } // namespace Option |
| 121 | } // namespace clspv |