blob: 902377daab06673e77a5801b01e6af4a0f886535 [file] [log] [blame]
David Neto482550a2018-03-24 05:21:07 -07001// 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 Neto118188e2018-08-24 11:27:54 -040017#include "llvm/Support/CommandLine.h"
David Neto482550a2018-03-24 05:21:07 -070018
19namespace {
David Neto862b7d82018-06-14 18:48:37 -040020
Alan Bakeraf289ab2018-08-29 11:26:44 -040021llvm::cl::opt<bool>
22 inline_entry_points("inline-entry-points", llvm::cl::init(false),
23 llvm::cl::desc("Exhaustively inline entry points."));
24
Alan Baker0dd3fd22018-08-24 11:03:12 -040025llvm::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 Netoc5fb5242018-07-30 13:28:31 -040029// Should the compiler try to use direct resource accesses within helper
David Neto862b7d82018-06-14 18:48:37 -040030// functions instead of passing pointers via function arguments?
David Netoc5fb5242018-07-30 13:28:31 -040031llvm::cl::opt<bool> no_direct_resource_access(
32 "no-dra", llvm::cl::init(false),
David Neto862b7d82018-06-14 18:48:37 -040033 llvm::cl::desc(
David Netoc5fb5242018-07-30 13:28:31 -040034 "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 Neto862b7d82018-06-14 18:48:37 -040038
Alan Bakerfc6888e2018-08-20 20:54:33 -040039llvm::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 Neto482550a2018-03-24 05:21:07 -070044// By default, reuse the same descriptor set number for all arguments.
45// To turn that off, use -distinct-kernel-descriptor-sets
46llvm::cl::opt<bool> distinct_kernel_descriptor_sets(
47 "distinct-kernel-descriptor-sets", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040048 llvm::cl::desc("Each kernel uses its own descriptor set for its arguments. "
49 "Turns off direct-resource-access optimizations."));
David Neto482550a2018-03-24 05:21:07 -070050
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.
57llvm::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 Netob6e2e062018-04-25 10:32:06 -040061llvm::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 Neto862b7d82018-06-14 18:48:37 -040069llvm::cl::opt<bool> hack_dis(
70 "hack-dis", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040071 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 Neto862b7d82018-06-14 18:48:37 -040074
David Neto482550a2018-03-24 05:21:07 -070075llvm::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 Neto3a0df832018-08-03 14:35:42 -040082llvm::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 Neto482550a2018-03-24 05:21:07 -070087// 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
93llvm::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 Baker33376ea2018-08-30 12:02:31 -040098llvm::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
David Neto482550a2018-03-24 05:21:07 -0700103llvm::cl::opt<bool>
104 pod_ubo("pod-ubo", llvm::cl::init(false),
105 llvm::cl::desc("POD kernel arguments are in uniform buffers"));
106
David Neto85082642018-03-24 06:55:20 -0700107llvm::cl::opt<bool> module_constants_in_storage_buffer(
108 "module-constants-in-storage-buffer", llvm::cl::init(false),
109 llvm::cl::desc(
110 "Module-scope __constants are collected into a single storage buffer. "
111 "The binding and initialization data are reported in the descriptor "
112 "map."));
113
David Neto482550a2018-03-24 05:21:07 -0700114llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false),
115 llvm::cl::desc("Show SPIR-V IDs for functions"));
116
Alan Bakerfcda9482018-10-02 17:09:59 -0400117llvm::cl::opt<bool> constant_args_in_uniform_buffer(
118 "constant-args-ubo", llvm::cl::init(false),
119 llvm::cl::desc("Put pointer-to-constant kernel args in UBOs."));
120
David Neto482550a2018-03-24 05:21:07 -0700121} // namespace
122
123namespace clspv {
124namespace Option {
125
Alan Bakeraf289ab2018-08-29 11:26:44 -0400126bool InlineEntryPoints() { return inline_entry_points; }
Alan Baker0dd3fd22018-08-24 11:03:12 -0400127bool InlineSingleCallSite() { return !no_inline_single_call_site; }
David Netoc5fb5242018-07-30 13:28:31 -0400128bool DirectResourceAccess() {
129 return !(no_direct_resource_access || distinct_kernel_descriptor_sets);
130}
Alan Bakerfc6888e2018-08-20 20:54:33 -0400131bool ShareModuleScopeVariables() { return !no_share_module_scope_variables; }
David Neto482550a2018-03-24 05:21:07 -0700132bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; }
133bool F16BitStorage() { return f16bit_storage; }
David Neto862b7d82018-06-14 18:48:37 -0400134bool HackDistinctImageSampler() { return hack_dis; }
David Netob6e2e062018-04-25 10:32:06 -0400135bool HackInitializers() { return hack_initializers; }
David Neto482550a2018-03-24 05:21:07 -0700136bool HackInserts() { return hack_inserts; }
David Neto3a0df832018-08-03 14:35:42 -0400137bool HackSignedCompareFixup() { return hack_signed_compare_fixup; }
David Neto482550a2018-03-24 05:21:07 -0700138bool HackUndef() { return hack_undef; }
Alan Baker33376ea2018-08-30 12:02:31 -0400139bool HackPhis() { return hack_phis; }
Alan Bakerfc6888e2018-08-20 20:54:33 -0400140bool ModuleConstantsInStorageBuffer() {
141 return module_constants_in_storage_buffer;
142}
David Neto482550a2018-03-24 05:21:07 -0700143bool PodArgsInUniformBuffer() { return pod_ubo; }
144bool ShowIDs() { return show_ids; }
Alan Bakerfcda9482018-10-02 17:09:59 -0400145bool ConstantArgsInUniformBuffer() {
146 return constant_args_in_uniform_buffer;
147}
David Neto482550a2018-03-24 05:21:07 -0700148
149} // namespace Option
150} // namespace clspv