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