blob: 1f6ac10be2a3142e6832067f44cd7432252b3805 [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
Alan Baker0dd3fd22018-08-24 11:03:12 -040021llvm::cl::opt<bool> no_inline_single_call_site(
22 "no-inline-single", llvm::cl::init(false),
23 llvm::cl::desc("Disable inlining functions with single call sites."));
24
David Netoc5fb5242018-07-30 13:28:31 -040025// Should the compiler try to use direct resource accesses within helper
David Neto862b7d82018-06-14 18:48:37 -040026// functions instead of passing pointers via function arguments?
David Netoc5fb5242018-07-30 13:28:31 -040027llvm::cl::opt<bool> no_direct_resource_access(
28 "no-dra", llvm::cl::init(false),
David Neto862b7d82018-06-14 18:48:37 -040029 llvm::cl::desc(
David Netoc5fb5242018-07-30 13:28:31 -040030 "No Direct Resource Access: Avoid rewriting helper functions "
31 "to access resources directly instead of by pointers "
32 "in function arguments. Affects kernel arguments of type "
33 "pointer-to-global, pointer-to-constant, image, and sampler."));
David Neto862b7d82018-06-14 18:48:37 -040034
Alan Bakerfc6888e2018-08-20 20:54:33 -040035llvm::cl::opt<bool> no_share_module_scope_variables(
36 "no-smsv", llvm::cl::init(false),
37 llvm::cl::desc("No Share Module Scope Variables: Avoid de-duplicating "
38 "module scope variables."));
39
David Neto482550a2018-03-24 05:21:07 -070040// By default, reuse the same descriptor set number for all arguments.
41// To turn that off, use -distinct-kernel-descriptor-sets
42llvm::cl::opt<bool> distinct_kernel_descriptor_sets(
43 "distinct-kernel-descriptor-sets", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040044 llvm::cl::desc("Each kernel uses its own descriptor set for its arguments. "
45 "Turns off direct-resource-access optimizations."));
David Neto482550a2018-03-24 05:21:07 -070046
47// TODO(dneto): As per Neil Henning suggestion, might not need this if
48// you can trace the pointer back far enough to see that it's 32-bit
49// aligned. However, even in the vstore_half case, you'll probably get
50// better performance if you can rely on SPV_KHR_16bit_storage since in
51// the alternate case you're using a (relaxed) atomic, and therefore
52// have to write through to the cache.
53llvm::cl::opt<bool> f16bit_storage(
54 "f16bit_storage", llvm::cl::init(false),
55 llvm::cl::desc("Assume the target supports SPV_KHR_16bit_storage"));
56
David Netob6e2e062018-04-25 10:32:06 -040057llvm::cl::opt<bool> hack_initializers(
58 "hack-initializers", llvm::cl::init(false),
59 llvm::cl::desc(
60 "At the start of each kernel, explicitly write the initializer "
61 "value for a compiler-generated variable containing the workgroup "
62 "size. Required by some drivers to make the get_global_size builtin "
63 "function work when used with non-constant dimension index."));
64
David Neto862b7d82018-06-14 18:48:37 -040065llvm::cl::opt<bool> hack_dis(
66 "hack-dis", llvm::cl::init(false),
Alan Bakerfc6888e2018-08-20 20:54:33 -040067 llvm::cl::desc("Force use of a distinct image or sampler variable for each "
68 "image or sampler kernel argument. This prevents sharing "
69 "of resource variables."));
David Neto862b7d82018-06-14 18:48:37 -040070
David Neto482550a2018-03-24 05:21:07 -070071llvm::cl::opt<bool> hack_inserts(
72 "hack-inserts", llvm::cl::init(false),
73 llvm::cl::desc(
74 "Avoid all single-index OpCompositInsert instructions "
75 "into struct types by using complete composite construction and "
76 "extractions"));
77
David Neto3a0df832018-08-03 14:35:42 -040078llvm::cl::opt<bool> hack_signed_compare_fixup(
79 "hack-scf", llvm::cl::init(false),
80 llvm::cl::desc("Rewrite signed integer comparisons to use other kinds of "
81 "instructions"));
82
David Neto482550a2018-03-24 05:21:07 -070083// Some drivers don't like to see constant composite values constructed
84// from scalar Undef values. Replace numeric scalar and vector Undef with
85// corresponding OpConstantNull. We need to keep Undef for image values,
86// for example. In the LLVM domain, image values are passed as pointer to
87// struct.
88// See https://github.com/google/clspv/issues/95
89llvm::cl::opt<bool> hack_undef(
90 "hack-undef", llvm::cl::init(false),
91 llvm::cl::desc("Use OpConstantNull instead of OpUndef for floating point, "
92 "integer, or vectors of them"));
93
94llvm::cl::opt<bool>
95 pod_ubo("pod-ubo", llvm::cl::init(false),
96 llvm::cl::desc("POD kernel arguments are in uniform buffers"));
97
David Neto85082642018-03-24 06:55:20 -070098llvm::cl::opt<bool> module_constants_in_storage_buffer(
99 "module-constants-in-storage-buffer", llvm::cl::init(false),
100 llvm::cl::desc(
101 "Module-scope __constants are collected into a single storage buffer. "
102 "The binding and initialization data are reported in the descriptor "
103 "map."));
104
David Neto482550a2018-03-24 05:21:07 -0700105llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false),
106 llvm::cl::desc("Show SPIR-V IDs for functions"));
107
108} // namespace
109
110namespace clspv {
111namespace Option {
112
Alan Baker0dd3fd22018-08-24 11:03:12 -0400113bool InlineSingleCallSite() { return !no_inline_single_call_site; }
David Netoc5fb5242018-07-30 13:28:31 -0400114bool DirectResourceAccess() {
115 return !(no_direct_resource_access || distinct_kernel_descriptor_sets);
116}
Alan Bakerfc6888e2018-08-20 20:54:33 -0400117bool ShareModuleScopeVariables() { return !no_share_module_scope_variables; }
David Neto482550a2018-03-24 05:21:07 -0700118bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; }
119bool F16BitStorage() { return f16bit_storage; }
David Neto862b7d82018-06-14 18:48:37 -0400120bool HackDistinctImageSampler() { return hack_dis; }
David Netob6e2e062018-04-25 10:32:06 -0400121bool HackInitializers() { return hack_initializers; }
David Neto482550a2018-03-24 05:21:07 -0700122bool HackInserts() { return hack_inserts; }
David Neto3a0df832018-08-03 14:35:42 -0400123bool HackSignedCompareFixup() { return hack_signed_compare_fixup; }
David Neto482550a2018-03-24 05:21:07 -0700124bool HackUndef() { return hack_undef; }
Alan Bakerfc6888e2018-08-20 20:54:33 -0400125bool ModuleConstantsInStorageBuffer() {
126 return module_constants_in_storage_buffer;
127}
David Neto482550a2018-03-24 05:21:07 -0700128bool PodArgsInUniformBuffer() { return pod_ubo; }
129bool ShowIDs() { return show_ids; }
130
131} // namespace Option
132} // namespace clspv