blob: a8e1b70d123d7710e0f2878b9a049df707429e1a [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
17#include <llvm/Support/CommandLine.h>
18
19namespace {
David Neto862b7d82018-06-14 18:48:37 -040020
David Netoc5fb5242018-07-30 13:28:31 -040021// Should the compiler try to use direct resource accesses within helper
David Neto862b7d82018-06-14 18:48:37 -040022// functions instead of passing pointers via function arguments?
David Netoc5fb5242018-07-30 13:28:31 -040023llvm::cl::opt<bool> no_direct_resource_access(
24 "no-dra", llvm::cl::init(false),
David Neto862b7d82018-06-14 18:48:37 -040025 llvm::cl::desc(
David Netoc5fb5242018-07-30 13:28:31 -040026 "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 Neto862b7d82018-06-14 18:48:37 -040030
Alan Bakerfc6888e2018-08-20 20:54:33 -040031llvm::cl::opt<bool> no_share_module_scope_variables(
32 "no-smsv", llvm::cl::init(false),
33 llvm::cl::desc("No Share Module Scope Variables: Avoid de-duplicating "
34 "module scope variables."));
35
David Neto482550a2018-03-24 05:21:07 -070036// By default, reuse the same descriptor set number for all arguments.
37// To turn that off, use -distinct-kernel-descriptor-sets
38llvm::cl::opt<bool> distinct_kernel_descriptor_sets(
39 "distinct-kernel-descriptor-sets", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040040 llvm::cl::desc("Each kernel uses its own descriptor set for its arguments. "
41 "Turns off direct-resource-access optimizations."));
David Neto482550a2018-03-24 05:21:07 -070042
43// TODO(dneto): As per Neil Henning suggestion, might not need this if
44// you can trace the pointer back far enough to see that it's 32-bit
45// aligned. However, even in the vstore_half case, you'll probably get
46// better performance if you can rely on SPV_KHR_16bit_storage since in
47// the alternate case you're using a (relaxed) atomic, and therefore
48// have to write through to the cache.
49llvm::cl::opt<bool> f16bit_storage(
50 "f16bit_storage", llvm::cl::init(false),
51 llvm::cl::desc("Assume the target supports SPV_KHR_16bit_storage"));
52
David Netob6e2e062018-04-25 10:32:06 -040053llvm::cl::opt<bool> hack_initializers(
54 "hack-initializers", llvm::cl::init(false),
55 llvm::cl::desc(
56 "At the start of each kernel, explicitly write the initializer "
57 "value for a compiler-generated variable containing the workgroup "
58 "size. Required by some drivers to make the get_global_size builtin "
59 "function work when used with non-constant dimension index."));
60
David Neto862b7d82018-06-14 18:48:37 -040061llvm::cl::opt<bool> hack_dis(
62 "hack-dis", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040063 llvm::cl::desc("Force use of a distinct image or sampler variable for each "
64 "image or sampler kernel argument. This prevents sharing "
65 "of resource variables."));
David Neto862b7d82018-06-14 18:48:37 -040066
David Neto482550a2018-03-24 05:21:07 -070067llvm::cl::opt<bool> hack_inserts(
68 "hack-inserts", llvm::cl::init(false),
69 llvm::cl::desc(
70 "Avoid all single-index OpCompositInsert instructions "
71 "into struct types by using complete composite construction and "
72 "extractions"));
73
David Neto3a0df832018-08-03 14:35:42 -040074llvm::cl::opt<bool> hack_signed_compare_fixup(
75 "hack-scf", llvm::cl::init(false),
76 llvm::cl::desc("Rewrite signed integer comparisons to use other kinds of "
77 "instructions"));
78
David Neto482550a2018-03-24 05:21:07 -070079// Some drivers don't like to see constant composite values constructed
80// from scalar Undef values. Replace numeric scalar and vector Undef with
81// corresponding OpConstantNull. We need to keep Undef for image values,
82// for example. In the LLVM domain, image values are passed as pointer to
83// struct.
84// See https://github.com/google/clspv/issues/95
85llvm::cl::opt<bool> hack_undef(
86 "hack-undef", llvm::cl::init(false),
87 llvm::cl::desc("Use OpConstantNull instead of OpUndef for floating point, "
88 "integer, or vectors of them"));
89
90llvm::cl::opt<bool>
91 pod_ubo("pod-ubo", llvm::cl::init(false),
92 llvm::cl::desc("POD kernel arguments are in uniform buffers"));
93
David Neto85082642018-03-24 06:55:20 -070094llvm::cl::opt<bool> module_constants_in_storage_buffer(
95 "module-constants-in-storage-buffer", llvm::cl::init(false),
96 llvm::cl::desc(
97 "Module-scope __constants are collected into a single storage buffer. "
98 "The binding and initialization data are reported in the descriptor "
99 "map."));
100
David Neto482550a2018-03-24 05:21:07 -0700101llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false),
102 llvm::cl::desc("Show SPIR-V IDs for functions"));
103
104} // namespace
105
106namespace clspv {
107namespace Option {
108
David Netoc5fb5242018-07-30 13:28:31 -0400109bool DirectResourceAccess() {
110 return !(no_direct_resource_access || distinct_kernel_descriptor_sets);
111}
Alan Bakerfc6888e2018-08-20 20:54:33 -0400112bool ShareModuleScopeVariables() { return !no_share_module_scope_variables; }
David Neto482550a2018-03-24 05:21:07 -0700113bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; }
114bool F16BitStorage() { return f16bit_storage; }
David Neto862b7d82018-06-14 18:48:37 -0400115bool HackDistinctImageSampler() { return hack_dis; }
David Netob6e2e062018-04-25 10:32:06 -0400116bool HackInitializers() { return hack_initializers; }
David Neto482550a2018-03-24 05:21:07 -0700117bool HackInserts() { return hack_inserts; }
David Neto3a0df832018-08-03 14:35:42 -0400118bool HackSignedCompareFixup() { return hack_signed_compare_fixup; }
David Neto482550a2018-03-24 05:21:07 -0700119bool HackUndef() { return hack_undef; }
Alan Bakerfc6888e2018-08-20 20:54:33 -0400120bool ModuleConstantsInStorageBuffer() {
121 return module_constants_in_storage_buffer;
122}
David Neto482550a2018-03-24 05:21:07 -0700123bool PodArgsInUniformBuffer() { return pod_ubo; }
124bool ShowIDs() { return show_ids; }
125
126} // namespace Option
127} // namespace clspv