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