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 | |
Diego Novillo | a4c44fa | 2019-04-11 10:56:15 -0400 | [diff] [blame] | 17 | #include "llvm/PassRegistry.h" |
David Neto | 118188e | 2018-08-24 11:27:54 -0400 | [diff] [blame] | 18 | #include "llvm/Support/CommandLine.h" |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 19 | |
Diego Novillo | a4c44fa | 2019-04-11 10:56:15 -0400 | [diff] [blame] | 20 | #include "Passes.h" |
| 21 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 22 | namespace { |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 23 | |
Alan Baker | af289ab | 2018-08-29 11:26:44 -0400 | [diff] [blame] | 24 | llvm::cl::opt<bool> |
| 25 | inline_entry_points("inline-entry-points", llvm::cl::init(false), |
| 26 | llvm::cl::desc("Exhaustively inline entry points.")); |
| 27 | |
Alan Baker | 0dd3fd2 | 2018-08-24 11:03:12 -0400 | [diff] [blame] | 28 | llvm::cl::opt<bool> no_inline_single_call_site( |
| 29 | "no-inline-single", llvm::cl::init(false), |
| 30 | llvm::cl::desc("Disable inlining functions with single call sites.")); |
| 31 | |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 32 | // Should the compiler try to use direct resource accesses within helper |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 33 | // functions instead of passing pointers via function arguments? |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 34 | llvm::cl::opt<bool> no_direct_resource_access( |
| 35 | "no-dra", llvm::cl::init(false), |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 36 | llvm::cl::desc( |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 37 | "No Direct Resource Access: Avoid rewriting helper functions " |
| 38 | "to access resources directly instead of by pointers " |
| 39 | "in function arguments. Affects kernel arguments of type " |
| 40 | "pointer-to-global, pointer-to-constant, image, and sampler.")); |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 41 | |
Alan Baker | fc6888e | 2018-08-20 20:54:33 -0400 | [diff] [blame] | 42 | llvm::cl::opt<bool> no_share_module_scope_variables( |
| 43 | "no-smsv", llvm::cl::init(false), |
| 44 | llvm::cl::desc("No Share Module Scope Variables: Avoid de-duplicating " |
| 45 | "module scope variables.")); |
| 46 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 47 | // By default, reuse the same descriptor set number for all arguments. |
| 48 | // To turn that off, use -distinct-kernel-descriptor-sets |
| 49 | llvm::cl::opt<bool> distinct_kernel_descriptor_sets( |
| 50 | "distinct-kernel-descriptor-sets", llvm::cl::init(false), |
Alan Baker | fc6888e | 2018-08-20 20:54:33 -0400 | [diff] [blame] | 51 | llvm::cl::desc("Each kernel uses its own descriptor set for its arguments. " |
| 52 | "Turns off direct-resource-access optimizations.")); |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 53 | |
| 54 | // TODO(dneto): As per Neil Henning suggestion, might not need this if |
| 55 | // you can trace the pointer back far enough to see that it's 32-bit |
| 56 | // aligned. However, even in the vstore_half case, you'll probably get |
| 57 | // better performance if you can rely on SPV_KHR_16bit_storage since in |
| 58 | // the alternate case you're using a (relaxed) atomic, and therefore |
| 59 | // have to write through to the cache. |
| 60 | llvm::cl::opt<bool> f16bit_storage( |
| 61 | "f16bit_storage", llvm::cl::init(false), |
| 62 | llvm::cl::desc("Assume the target supports SPV_KHR_16bit_storage")); |
| 63 | |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 64 | llvm::cl::opt<bool> hack_initializers( |
| 65 | "hack-initializers", llvm::cl::init(false), |
| 66 | llvm::cl::desc( |
| 67 | "At the start of each kernel, explicitly write the initializer " |
| 68 | "value for a compiler-generated variable containing the workgroup " |
| 69 | "size. Required by some drivers to make the get_global_size builtin " |
| 70 | "function work when used with non-constant dimension index.")); |
| 71 | |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 72 | llvm::cl::opt<bool> hack_dis( |
| 73 | "hack-dis", llvm::cl::init(false), |
Alan Baker | fc6888e | 2018-08-20 20:54:33 -0400 | [diff] [blame] | 74 | llvm::cl::desc("Force use of a distinct image or sampler variable for each " |
| 75 | "image or sampler kernel argument. This prevents sharing " |
| 76 | "of resource variables.")); |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 77 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 78 | llvm::cl::opt<bool> hack_inserts( |
| 79 | "hack-inserts", llvm::cl::init(false), |
| 80 | llvm::cl::desc( |
| 81 | "Avoid all single-index OpCompositInsert instructions " |
| 82 | "into struct types by using complete composite construction and " |
| 83 | "extractions")); |
| 84 | |
David Neto | 3a0df83 | 2018-08-03 14:35:42 -0400 | [diff] [blame] | 85 | llvm::cl::opt<bool> hack_signed_compare_fixup( |
| 86 | "hack-scf", llvm::cl::init(false), |
| 87 | llvm::cl::desc("Rewrite signed integer comparisons to use other kinds of " |
| 88 | "instructions")); |
| 89 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 90 | // Some drivers don't like to see constant composite values constructed |
| 91 | // from scalar Undef values. Replace numeric scalar and vector Undef with |
| 92 | // corresponding OpConstantNull. We need to keep Undef for image values, |
| 93 | // for example. In the LLVM domain, image values are passed as pointer to |
| 94 | // struct. |
| 95 | // See https://github.com/google/clspv/issues/95 |
| 96 | llvm::cl::opt<bool> hack_undef( |
| 97 | "hack-undef", llvm::cl::init(false), |
| 98 | llvm::cl::desc("Use OpConstantNull instead of OpUndef for floating point, " |
| 99 | "integer, or vectors of them")); |
| 100 | |
Alan Baker | 33376ea | 2018-08-30 12:02:31 -0400 | [diff] [blame] | 101 | llvm::cl::opt<bool> hack_phis( |
| 102 | "hack-phis", llvm::cl::init(false), |
| 103 | llvm::cl::desc( |
| 104 | "Scalarize phi instructions of struct type before code generation")); |
| 105 | |
alan-baker | 3fa76d9 | 2018-11-12 14:54:40 -0500 | [diff] [blame] | 106 | llvm::cl::opt<bool> hack_block_order( |
| 107 | "hack-block-order", llvm::cl::init(false), |
| 108 | llvm::cl::desc("Order basic blocks using structured order")); |
| 109 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 110 | llvm::cl::opt<bool> |
| 111 | pod_ubo("pod-ubo", llvm::cl::init(false), |
| 112 | llvm::cl::desc("POD kernel arguments are in uniform buffers")); |
| 113 | |
David Neto | 8508264 | 2018-03-24 06:55:20 -0700 | [diff] [blame] | 114 | llvm::cl::opt<bool> module_constants_in_storage_buffer( |
| 115 | "module-constants-in-storage-buffer", llvm::cl::init(false), |
| 116 | llvm::cl::desc( |
| 117 | "Module-scope __constants are collected into a single storage buffer. " |
| 118 | "The binding and initialization data are reported in the descriptor " |
| 119 | "map.")); |
| 120 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 121 | llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false), |
| 122 | llvm::cl::desc("Show SPIR-V IDs for functions")); |
| 123 | |
Alan Baker | fcda948 | 2018-10-02 17:09:59 -0400 | [diff] [blame] | 124 | llvm::cl::opt<bool> constant_args_in_uniform_buffer( |
| 125 | "constant-args-ubo", llvm::cl::init(false), |
| 126 | llvm::cl::desc("Put pointer-to-constant kernel args in UBOs.")); |
| 127 | |
alan-baker | 3d9e201 | 2019-01-11 14:55:30 -0500 | [diff] [blame] | 128 | // Default to 64kB. |
| 129 | llvm::cl::opt<int> maximum_ubo_size( |
| 130 | "max-ubo-size", llvm::cl::init(64 << 10), |
| 131 | llvm::cl::desc("Specify the maximum UBO array size in bytes.")); |
| 132 | |
| 133 | llvm::cl::opt<bool> relaxed_ubo_layout( |
| 134 | "relaxed-ubo-layout", |
| 135 | llvm::cl::desc("Allow UBO layouts, that do not satisfy the restriction " |
| 136 | "that ArrayStride is a multiple of array alignment. This " |
| 137 | "does not generate valid SPIR-V for the Vulkan environment; " |
| 138 | "however, some drivers may accept it.")); |
| 139 | |
alan-baker | a3e0238 | 2019-02-15 08:27:27 -0500 | [diff] [blame] | 140 | llvm::cl::opt<bool> std430_ubo_layout( |
alan-baker | 4217b32 | 2019-03-06 08:56:12 -0500 | [diff] [blame] | 141 | "std430-ubo-layout", llvm::cl::init(false), |
alan-baker | a3e0238 | 2019-02-15 08:27:27 -0500 | [diff] [blame] | 142 | llvm::cl::desc("Allow UBO layouts that conform to std430 (SSBO) layout " |
| 143 | "requirements. This does not generate valid SPIR-V for the " |
| 144 | "Vulkan environment; however, some drivers may accept it.")); |
| 145 | |
alan-baker | 4217b32 | 2019-03-06 08:56:12 -0500 | [diff] [blame] | 146 | llvm::cl::opt<bool> keep_unused_arguments( |
| 147 | "keep-unused-arguments", llvm::cl::init(false), |
| 148 | llvm::cl::desc("Do not remove unused non-kernel function arguments.")); |
| 149 | |
alan-baker | ace4e59 | 2019-04-09 08:43:22 -0400 | [diff] [blame] | 150 | llvm::cl::opt<bool> int8_support("int8", llvm::cl::init(true), |
alan-baker | b39c826 | 2019-03-08 14:03:37 -0500 | [diff] [blame] | 151 | llvm::cl::desc("Allow 8-bit integers")); |
| 152 | |
Kévin Petit | 0fc8804 | 2019-04-09 23:25:02 +0100 | [diff] [blame] | 153 | static llvm::cl::opt<bool> |
| 154 | cplusplus("c++", llvm::cl::init(false), |
Diego Novillo | 3cc8d7a | 2019-04-10 13:30:34 -0400 | [diff] [blame] | 155 | llvm::cl::desc("Enable experimental C++ support")); |
Kévin Petit | a624c0c | 2019-05-07 20:27:43 +0800 | [diff] [blame^] | 156 | |
| 157 | static llvm::cl::opt<bool> images("images", llvm::cl::init(true), |
| 158 | llvm::cl::desc("Enable support for images")); |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 159 | } // namespace |
| 160 | |
| 161 | namespace clspv { |
| 162 | namespace Option { |
| 163 | |
Alan Baker | af289ab | 2018-08-29 11:26:44 -0400 | [diff] [blame] | 164 | bool InlineEntryPoints() { return inline_entry_points; } |
Alan Baker | 0dd3fd2 | 2018-08-24 11:03:12 -0400 | [diff] [blame] | 165 | bool InlineSingleCallSite() { return !no_inline_single_call_site; } |
David Neto | c5fb524 | 2018-07-30 13:28:31 -0400 | [diff] [blame] | 166 | bool DirectResourceAccess() { |
| 167 | return !(no_direct_resource_access || distinct_kernel_descriptor_sets); |
| 168 | } |
Alan Baker | fc6888e | 2018-08-20 20:54:33 -0400 | [diff] [blame] | 169 | bool ShareModuleScopeVariables() { return !no_share_module_scope_variables; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 170 | bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; } |
| 171 | bool F16BitStorage() { return f16bit_storage; } |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame] | 172 | bool HackDistinctImageSampler() { return hack_dis; } |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 173 | bool HackInitializers() { return hack_initializers; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 174 | bool HackInserts() { return hack_inserts; } |
David Neto | 3a0df83 | 2018-08-03 14:35:42 -0400 | [diff] [blame] | 175 | bool HackSignedCompareFixup() { return hack_signed_compare_fixup; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 176 | bool HackUndef() { return hack_undef; } |
Alan Baker | 33376ea | 2018-08-30 12:02:31 -0400 | [diff] [blame] | 177 | bool HackPhis() { return hack_phis; } |
alan-baker | 3fa76d9 | 2018-11-12 14:54:40 -0500 | [diff] [blame] | 178 | bool HackBlockOrder() { return hack_block_order; } |
Alan Baker | fc6888e | 2018-08-20 20:54:33 -0400 | [diff] [blame] | 179 | bool ModuleConstantsInStorageBuffer() { |
| 180 | return module_constants_in_storage_buffer; |
| 181 | } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 182 | bool PodArgsInUniformBuffer() { return pod_ubo; } |
| 183 | bool ShowIDs() { return show_ids; } |
alan-baker | 3fa76d9 | 2018-11-12 14:54:40 -0500 | [diff] [blame] | 184 | bool ConstantArgsInUniformBuffer() { return constant_args_in_uniform_buffer; } |
alan-baker | 3d9e201 | 2019-01-11 14:55:30 -0500 | [diff] [blame] | 185 | uint64_t MaxUniformBufferSize() { return maximum_ubo_size; } |
| 186 | bool RelaxedUniformBufferLayout() { return relaxed_ubo_layout; } |
alan-baker | a3e0238 | 2019-02-15 08:27:27 -0500 | [diff] [blame] | 187 | bool Std430UniformBufferLayout() { return std430_ubo_layout; } |
alan-baker | 4217b32 | 2019-03-06 08:56:12 -0500 | [diff] [blame] | 188 | bool KeepUnusedArguments() { return keep_unused_arguments; } |
alan-baker | b39c826 | 2019-03-08 14:03:37 -0500 | [diff] [blame] | 189 | bool Int8Support() { return int8_support; } |
Kévin Petit | 0fc8804 | 2019-04-09 23:25:02 +0100 | [diff] [blame] | 190 | bool CPlusPlus() { return cplusplus; } |
Kévin Petit | a624c0c | 2019-05-07 20:27:43 +0800 | [diff] [blame^] | 191 | bool ImageSupport() { return images; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 192 | |
| 193 | } // namespace Option |
| 194 | } // namespace clspv |