blob: 5fb153f5f1556ba8e76abd4c552b7eed6fb63f52 [file] [log] [blame]
alan-bakerfec0a472018-11-08 18:09:40 -05001// 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#include "clang/Basic/TargetInfo.h"
16#include "clang/CodeGen/CodeGenAction.h"
17#include "clang/Frontend/CompilerInstance.h"
18#include "clang/Frontend/FrontendPluginRegistry.h"
19#include "clang/Frontend/TextDiagnosticPrinter.h"
20#include "clang/Lex/PreprocessorOptions.h"
21#include "llvm/IR/LLVMContext.h"
22#include "llvm/IR/LegacyPassManager.h"
23#include "llvm/IR/Module.h"
24#include "llvm/IR/Verifier.h"
25#include "llvm/LinkAllPasses.h"
alan-bakerf5e5f692018-11-27 08:33:24 -050026#include "llvm/Support/Allocator.h"
alan-bakerfec0a472018-11-08 18:09:40 -050027#include "llvm/Support/CommandLine.h"
alan-bakerf5e5f692018-11-27 08:33:24 -050028#include "llvm/Support/ErrorOr.h"
alan-bakerfec0a472018-11-08 18:09:40 -050029#include "llvm/Support/MathExtras.h"
alan-bakerf5e5f692018-11-27 08:33:24 -050030#include "llvm/Support/StringSaver.h"
Diego Novillo89500852019-04-15 08:45:10 -040031#include "llvm/Support/ToolOutputFile.h"
alan-bakerfec0a472018-11-08 18:09:40 -050032#include "llvm/Support/raw_ostream.h"
33#include "llvm/Transforms/IPO/PassManagerBuilder.h"
34
Kévin Petit38c52482019-05-07 20:28:00 +080035#include "clspv/AddressSpace.h"
alan-bakerf5e5f692018-11-27 08:33:24 -050036#include "clspv/DescriptorMap.h"
alan-bakerfec0a472018-11-08 18:09:40 -050037#include "clspv/Option.h"
38#include "clspv/Passes.h"
39#include "clspv/opencl_builtins_header.h"
40
41#include "FrontendPlugin.h"
Diego Novilloa4c44fa2019-04-11 10:56:15 -040042#include "Passes.h"
alan-bakerfec0a472018-11-08 18:09:40 -050043
alan-bakerf5e5f692018-11-27 08:33:24 -050044#include <cassert>
alan-bakerfec0a472018-11-08 18:09:40 -050045#include <numeric>
alan-bakerf5e5f692018-11-27 08:33:24 -050046#include <sstream>
Diego Novillo3cc8d7a2019-04-10 13:30:34 -040047#include <string>
alan-bakerfec0a472018-11-08 18:09:40 -050048
49using namespace clang;
50
51namespace {
52// This registration must be located in the same file as the execution of the
53// action.
54static FrontendPluginRegistry::Add<clspv::ExtraValidationASTAction>
55 X("extra-validation",
56 "Perform extra validation on OpenCL C when targeting Vulkan");
57
58static llvm::cl::opt<bool> cl_single_precision_constants(
59 "cl-single-precision-constant", llvm::cl::init(false),
60 llvm::cl::desc("Treat double precision floating-point constant as single "
61 "precision constant."));
62
63static llvm::cl::opt<bool> cl_denorms_are_zero(
64 "cl-denorms-are-zero", llvm::cl::init(false),
65 llvm::cl::desc("If specified, denormalized floating point numbers may be "
66 "flushed to zero."));
67
68static llvm::cl::opt<bool> cl_fp32_correctly_rounded_divide_sqrt(
69 "cl-fp32-correctly-rounded-divide-sqrt", llvm::cl::init(false),
70 llvm::cl::desc("Single precision floating-point divide (x/y and 1/x) and "
71 "sqrt used are correctly rounded."));
72
73static llvm::cl::opt<bool>
74 cl_opt_disable("cl-opt-disable", llvm::cl::init(false),
75 llvm::cl::desc("This option disables all optimizations. The "
76 "default is optimizations are enabled."));
77
78static llvm::cl::opt<bool> cl_mad_enable(
79 "cl-mad-enable", llvm::cl::init(false),
80 llvm::cl::desc("Allow a * b + c to be replaced by a mad. The mad computes "
81 "a * b + c with reduced accuracy."));
82
83static llvm::cl::opt<bool> cl_no_signed_zeros(
84 "cl-no-signed-zeros", llvm::cl::init(false),
85 llvm::cl::desc("Allow optimizations for floating-point arithmetic that "
86 "ignore the signedness of zero."));
87
88static llvm::cl::opt<bool> cl_unsafe_math_optimizations(
89 "cl-unsafe-math-optimizations", llvm::cl::init(false),
90 llvm::cl::desc("Allow optimizations for floating-point arithmetic that (a) "
91 "assume that arguments and results are valid, (b) may "
92 "violate IEEE 754 standard and (c) may violate the OpenCL "
93 "numerical compliance requirements. This option includes "
94 "the -cl-no-signed-zeros and -cl-mad-enable options."));
95
96static llvm::cl::opt<bool> cl_finite_math_only(
97 "cl-finite-math-only", llvm::cl::init(false),
98 llvm::cl::desc("Allow optimizations for floating-point arithmetic that "
99 "assume that arguments and results are not NaNs or INFs."));
100
101static llvm::cl::opt<bool> cl_fast_relaxed_math(
102 "cl-fast-relaxed-math", llvm::cl::init(false),
103 llvm::cl::desc("This option causes the preprocessor macro "
104 "__FAST_RELAXED_MATH__ to be defined. Sets the optimization "
105 "options -cl-finite-math-only and "
106 "-cl-unsafe-math-optimizations."));
107
108static llvm::cl::list<std::string>
109 Includes(llvm::cl::Prefix, "I",
110 llvm::cl::desc("Add a directory to the list of directories "
111 "to be searched for header files."),
112 llvm::cl::ZeroOrMore, llvm::cl::value_desc("include path"));
113
114static llvm::cl::list<std::string>
115 Defines(llvm::cl::Prefix, "D",
116 llvm::cl::desc("Define a #define directive."), llvm::cl::ZeroOrMore,
117 llvm::cl::value_desc("define"));
118
119static llvm::cl::opt<std::string>
120 InputFilename(llvm::cl::Positional, llvm::cl::desc("<input .cl file>"),
121 llvm::cl::init("-"));
122
123static llvm::cl::opt<std::string>
124 OutputFilename("o", llvm::cl::desc("Override output filename"),
125 llvm::cl::value_desc("filename"));
126
127static llvm::cl::opt<std::string>
128 DescriptorMapFilename("descriptormap",
129 llvm::cl::desc("Output file for descriptor map"),
130 llvm::cl::value_desc("filename"));
131
132static llvm::cl::opt<char>
133 OptimizationLevel(llvm::cl::Prefix, "O", llvm::cl::init('2'),
134 llvm::cl::desc("Optimization level to use"),
135 llvm::cl::value_desc("level"));
136
alan-bakerfec0a472018-11-08 18:09:40 -0500137static llvm::cl::opt<std::string> OutputFormat(
138 "mfmt", llvm::cl::init(""),
139 llvm::cl::desc(
140 "Specify special output format. 'c' is as a C initializer list"),
141 llvm::cl::value_desc("format"));
142
143static llvm::cl::opt<std::string>
144 SamplerMap("samplermap", llvm::cl::desc("Literal sampler map"),
145 llvm::cl::value_desc("filename"));
146
147static llvm::cl::opt<bool> cluster_non_pointer_kernel_args(
148 "cluster-pod-kernel-args", llvm::cl::init(false),
149 llvm::cl::desc("Collect plain-old-data kernel arguments into a struct in "
150 "a single storage buffer, using a binding number after "
151 "other arguments. Use this to reduce storage buffer "
152 "descriptors."));
153
154static llvm::cl::opt<bool> verify("verify", llvm::cl::init(false),
155 llvm::cl::desc("Verify diagnostic outputs"));
156
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100157static llvm::cl::opt<bool>
158 IgnoreWarnings("w", llvm::cl::init(false),
159 llvm::cl::desc("Disable all warnings"));
160
161static llvm::cl::opt<bool>
162 WarningsAsErrors("Werror", llvm::cl::init(false),
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400163 llvm::cl::desc("Turn warnings into errors"));
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100164
Diego Novillo89500852019-04-15 08:45:10 -0400165static llvm::cl::opt<std::string> IROutputFile(
166 "emit-ir",
167 llvm::cl::desc(
168 "Emit LLVM IR to the given file after parsing and stop compilation."),
169 llvm::cl::value_desc("filename"));
170
alan-bakerfec0a472018-11-08 18:09:40 -0500171// Populates |SamplerMapEntries| with data from the input sampler map. Returns 0
172// if successful.
alan-bakerf5e5f692018-11-27 08:33:24 -0500173int ParseSamplerMap(const std::string &sampler_map,
174 llvm::SmallVectorImpl<std::pair<unsigned, std::string>>
175 *SamplerMapEntries) {
176 std::unique_ptr<llvm::MemoryBuffer> samplerMapBuffer(nullptr);
177 if (!sampler_map.empty()) {
178 // Parse the sampler map from the provided string.
179 samplerMapBuffer = llvm::MemoryBuffer::getMemBuffer(sampler_map);
180
181 if (!SamplerMap.empty()) {
182 llvm::outs() << "Warning: -samplermap is ignored when the sampler map is "
183 "provided through a string.\n";
184 }
185 } else if (!SamplerMap.empty()) {
186 // Parse the sampler map from the option provided file.
alan-bakerfec0a472018-11-08 18:09:40 -0500187 auto errorOrSamplerMapFile =
188 llvm::MemoryBuffer::getFile(SamplerMap.getValue());
189
190 // If there was an error in getting the sampler map file.
191 if (!errorOrSamplerMapFile) {
192 llvm::errs() << "Error: " << errorOrSamplerMapFile.getError().message()
193 << " '" << SamplerMap.getValue() << "'\n";
194 return -1;
195 }
196
alan-bakerf5e5f692018-11-27 08:33:24 -0500197 samplerMapBuffer = std::move(errorOrSamplerMapFile.get());
alan-bakerfec0a472018-11-08 18:09:40 -0500198 if (0 == samplerMapBuffer->getBufferSize()) {
199 llvm::errs() << "Error: Sampler map was an empty file!\n";
200 return -1;
201 }
alan-bakerf5e5f692018-11-27 08:33:24 -0500202 }
alan-bakerfec0a472018-11-08 18:09:40 -0500203
alan-bakerf5e5f692018-11-27 08:33:24 -0500204 // No sampler map to parse.
205 if (!samplerMapBuffer || 0 == samplerMapBuffer->getBufferSize())
206 return 0;
alan-bakerfec0a472018-11-08 18:09:40 -0500207
alan-bakerf5e5f692018-11-27 08:33:24 -0500208 llvm::SmallVector<llvm::StringRef, 3> samplerStrings;
alan-bakerfec0a472018-11-08 18:09:40 -0500209
alan-bakerf5e5f692018-11-27 08:33:24 -0500210 // We need to keep track of the beginning of the current entry.
211 const char *b = samplerMapBuffer->getBufferStart();
212 for (const char *i = b, *e = samplerMapBuffer->getBufferEnd();; i++) {
213 // If we have a separator between declarations.
214 if ((*i == '|') || (*i == ',') || (i == e)) {
215 if (i == b) {
216 llvm::errs() << "Error: Sampler map contained an empty entry!\n";
217 return -1;
alan-bakerfec0a472018-11-08 18:09:40 -0500218 }
219
alan-bakerf5e5f692018-11-27 08:33:24 -0500220 samplerStrings.push_back(llvm::StringRef(b, i - b).trim());
alan-bakerfec0a472018-11-08 18:09:40 -0500221
alan-bakerf5e5f692018-11-27 08:33:24 -0500222 // And set b the next character after i.
223 b = i + 1;
224 }
alan-bakerfec0a472018-11-08 18:09:40 -0500225
alan-bakerf5e5f692018-11-27 08:33:24 -0500226 // If we have a separator between declarations within a single sampler.
227 if ((*i == ',') || (i == e)) {
228 enum NormalizedCoords {
229 CLK_NORMALIZED_COORDS_FALSE = 0x00,
230 CLK_NORMALIZED_COORDS_TRUE = 0x01,
231 CLK_NORMALIZED_COORDS_NOT_SET
232 } NormalizedCoord = CLK_NORMALIZED_COORDS_NOT_SET;
alan-bakerfec0a472018-11-08 18:09:40 -0500233
alan-bakerf5e5f692018-11-27 08:33:24 -0500234 enum AddressingModes {
235 CLK_ADDRESS_NONE = 0x00,
236 CLK_ADDRESS_CLAMP_TO_EDGE = 0x02,
237 CLK_ADDRESS_CLAMP = 0x04,
238 CLK_ADDRESS_MIRRORED_REPEAT = 0x08,
239 CLK_ADDRESS_REPEAT = 0x06,
240 CLK_ADDRESS_NOT_SET
241 } AddressingMode = CLK_ADDRESS_NOT_SET;
242
243 enum FilterModes {
244 CLK_FILTER_NEAREST = 0x10,
245 CLK_FILTER_LINEAR = 0x20,
246 CLK_FILTER_NOT_SET
247 } FilterMode = CLK_FILTER_NOT_SET;
248
249 for (auto str : samplerStrings) {
250 if ("CLK_NORMALIZED_COORDS_FALSE" == str) {
251 if (CLK_NORMALIZED_COORDS_NOT_SET != NormalizedCoord) {
252 llvm::errs() << "Error: Sampler map normalized coordinates was "
253 "previously set!\n";
alan-bakerfec0a472018-11-08 18:09:40 -0500254 return -1;
255 }
alan-bakerf5e5f692018-11-27 08:33:24 -0500256 NormalizedCoord = CLK_NORMALIZED_COORDS_FALSE;
257 } else if ("CLK_NORMALIZED_COORDS_TRUE" == str) {
258 if (CLK_NORMALIZED_COORDS_NOT_SET != NormalizedCoord) {
259 llvm::errs() << "Error: Sampler map normalized coordinates was "
260 "previously set!\n";
261 return -1;
262 }
263 NormalizedCoord = CLK_NORMALIZED_COORDS_TRUE;
264 } else if ("CLK_ADDRESS_NONE" == str) {
265 if (CLK_ADDRESS_NOT_SET != AddressingMode) {
266 llvm::errs()
267 << "Error: Sampler map addressing mode was previously set!\n";
268 return -1;
269 }
270 AddressingMode = CLK_ADDRESS_NONE;
271 } else if ("CLK_ADDRESS_CLAMP_TO_EDGE" == str) {
272 if (CLK_ADDRESS_NOT_SET != AddressingMode) {
273 llvm::errs()
274 << "Error: Sampler map addressing mode was previously set!\n";
275 return -1;
276 }
277 AddressingMode = CLK_ADDRESS_CLAMP_TO_EDGE;
278 } else if ("CLK_ADDRESS_CLAMP" == str) {
279 if (CLK_ADDRESS_NOT_SET != AddressingMode) {
280 llvm::errs()
281 << "Error: Sampler map addressing mode was previously set!\n";
282 return -1;
283 }
284 AddressingMode = CLK_ADDRESS_CLAMP;
285 } else if ("CLK_ADDRESS_MIRRORED_REPEAT" == str) {
286 if (CLK_ADDRESS_NOT_SET != AddressingMode) {
287 llvm::errs()
288 << "Error: Sampler map addressing mode was previously set!\n";
289 return -1;
290 }
291 AddressingMode = CLK_ADDRESS_MIRRORED_REPEAT;
292 } else if ("CLK_ADDRESS_REPEAT" == str) {
293 if (CLK_ADDRESS_NOT_SET != AddressingMode) {
294 llvm::errs()
295 << "Error: Sampler map addressing mode was previously set!\n";
296 return -1;
297 }
298 AddressingMode = CLK_ADDRESS_REPEAT;
299 } else if ("CLK_FILTER_NEAREST" == str) {
300 if (CLK_FILTER_NOT_SET != FilterMode) {
301 llvm::errs()
302 << "Error: Sampler map filtering mode was previously set!\n";
303 return -1;
304 }
305 FilterMode = CLK_FILTER_NEAREST;
306 } else if ("CLK_FILTER_LINEAR" == str) {
307 if (CLK_FILTER_NOT_SET != FilterMode) {
308 llvm::errs()
309 << "Error: Sampler map filtering mode was previously set!\n";
310 return -1;
311 }
312 FilterMode = CLK_FILTER_LINEAR;
313 } else {
314 llvm::errs() << "Error: Unknown sampler string '" << str
315 << "' found!\n";
alan-bakerfec0a472018-11-08 18:09:40 -0500316 return -1;
317 }
alan-bakerfec0a472018-11-08 18:09:40 -0500318 }
319
alan-bakerf5e5f692018-11-27 08:33:24 -0500320 if (CLK_NORMALIZED_COORDS_NOT_SET == NormalizedCoord) {
321 llvm::errs() << "Error: Sampler map entry did not contain normalized "
322 "coordinates entry!\n";
323 return -1;
alan-bakerfec0a472018-11-08 18:09:40 -0500324 }
alan-bakerf5e5f692018-11-27 08:33:24 -0500325
326 if (CLK_ADDRESS_NOT_SET == AddressingMode) {
327 llvm::errs() << "Error: Sampler map entry did not contain addressing "
328 "mode entry!\n";
329 return -1;
330 }
331
332 if (CLK_FILTER_NOT_SET == FilterMode) {
333 llvm::errs()
334 << "Error: Sampler map entry did not contain filer mode entry!\n";
335 return -1;
336 }
337
338 // Generate an equivalent expression in string form. Sort the
339 // strings to get a canonical ordering.
340 std::sort(samplerStrings.begin(), samplerStrings.end(),
341 std::less<StringRef>());
342 const auto samplerExpr = std::accumulate(
343 samplerStrings.begin(), samplerStrings.end(), std::string(),
344 [](std::string left, std::string right) {
345 return left + std::string(left.empty() ? "" : "|") + right;
346 });
347
348 // SamplerMapEntries->push_back(std::make_pair(
349 // NormalizedCoord | AddressingMode | FilterMode, samplerExpr));
350 SamplerMapEntries->emplace_back(
351 NormalizedCoord | AddressingMode | FilterMode, samplerExpr);
352
353 // And reset the sampler strings for the next sampler in the map.
354 samplerStrings.clear();
355 }
356
357 // And lastly, if we are at the end of the file
358 if (i == e) {
359 break;
alan-bakerfec0a472018-11-08 18:09:40 -0500360 }
361 }
362
363 return 0;
364}
365
366// Sets |instance|'s options for compiling. Returns 0 if successful.
367int SetCompilerInstanceOptions(CompilerInstance &instance,
368 const llvm::StringRef &overiddenInputFilename,
369 const clang::FrontendInputFile &kernelFile,
alan-bakerf5e5f692018-11-27 08:33:24 -0500370 const std::string &program,
alan-bakerfec0a472018-11-08 18:09:40 -0500371 llvm::raw_string_ostream *diagnosticsStream) {
alan-bakerf5e5f692018-11-27 08:33:24 -0500372 std::unique_ptr<llvm::MemoryBuffer> memory_buffer(nullptr);
373 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> errorOrInputFile(nullptr);
374 if (program.empty()) {
375 auto errorOrInputFile =
376 llvm::MemoryBuffer::getFileOrSTDIN(InputFilename.getValue());
alan-bakerfec0a472018-11-08 18:09:40 -0500377
alan-bakerf5e5f692018-11-27 08:33:24 -0500378 // If there was an error in getting the input file.
379 if (!errorOrInputFile) {
380 llvm::errs() << "Error: " << errorOrInputFile.getError().message() << " '"
381 << InputFilename.getValue() << "'\n";
382 return -1;
383 }
384 memory_buffer.reset(errorOrInputFile.get().release());
385 } else {
386 memory_buffer = llvm::MemoryBuffer::getMemBuffer(program.c_str(),
387 overiddenInputFilename);
alan-bakerfec0a472018-11-08 18:09:40 -0500388 }
alan-bakerf5e5f692018-11-27 08:33:24 -0500389
alan-bakerfec0a472018-11-08 18:09:40 -0500390 if (verify) {
391 instance.getDiagnosticOpts().VerifyDiagnostics = true;
alan-bakerbccf62c2019-03-29 10:32:41 -0400392 instance.getDiagnosticOpts().VerifyPrefixes.push_back("expected");
alan-bakerfec0a472018-11-08 18:09:40 -0500393 }
394
Kévin Petit0fc88042019-04-09 23:25:02 +0100395 clang::LangStandard::Kind standard;
396 if (clspv::Option::CPlusPlus()) {
397 standard = clang::LangStandard::lang_openclcpp;
398 } else {
399 standard = clang::LangStandard::lang_opencl12;
400 }
alan-bakerfec0a472018-11-08 18:09:40 -0500401
402 // We are targeting OpenCL 1.2 only
403 instance.getLangOpts().OpenCLVersion = 120;
404
405 instance.getLangOpts().C99 = true;
406 instance.getLangOpts().RTTI = false;
407 instance.getLangOpts().RTTIData = false;
408 instance.getLangOpts().MathErrno = false;
409 instance.getLangOpts().Optimize = false;
410 instance.getLangOpts().NoBuiltin = true;
411 instance.getLangOpts().ModulesSearchAll = false;
412 instance.getLangOpts().SinglePrecisionConstants = true;
413 instance.getCodeGenOpts().StackRealignment = true;
414 instance.getCodeGenOpts().SimplifyLibCalls = false;
415 instance.getCodeGenOpts().EmitOpenCLArgMetadata = false;
416 instance.getCodeGenOpts().DisableO0ImplyOptNone = true;
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100417 instance.getDiagnosticOpts().IgnoreWarnings = IgnoreWarnings;
alan-bakerfec0a472018-11-08 18:09:40 -0500418
419 instance.getLangOpts().SinglePrecisionConstants =
420 cl_single_precision_constants;
421 // cl_denorms_are_zero ignored for now!
422 // cl_fp32_correctly_rounded_divide_sqrt ignored for now!
423 instance.getCodeGenOpts().LessPreciseFPMAD =
424 cl_mad_enable || cl_unsafe_math_optimizations;
425 // cl_no_signed_zeros ignored for now!
426 instance.getCodeGenOpts().UnsafeFPMath =
427 cl_unsafe_math_optimizations || cl_fast_relaxed_math;
428 instance.getLangOpts().FiniteMathOnly =
429 cl_finite_math_only || cl_fast_relaxed_math;
430 instance.getLangOpts().FastRelaxedMath = cl_fast_relaxed_math;
431
432 // Preprocessor options
Kévin Petita624c0c2019-05-07 20:27:43 +0800433 if (!clspv::Option::ImageSupport()) {
434 instance.getPreprocessorOpts().addMacroUndef("__IMAGE_SUPPORT__");
435 }
alan-bakerfec0a472018-11-08 18:09:40 -0500436 if (cl_fast_relaxed_math) {
437 instance.getPreprocessorOpts().addMacroDef("__FAST_RELAXED_MATH__");
438 }
439
440 for (auto define : Defines) {
441 instance.getPreprocessorOpts().addMacroDef(define);
442 }
443
444 // Header search options
445 for (auto include : Includes) {
446 instance.getHeaderSearchOpts().AddPath(include, clang::frontend::After,
447 false, false);
448 }
449
450 // We always compile on opt 0 so we preserve as much debug information about
451 // the source as possible. We'll run optimization later, once we've had a
452 // chance to view the unoptimal code first
453 instance.getCodeGenOpts().OptimizationLevel = 0;
454
455// Debug information is disabled temporarily to call instruction.
456#if 0
457 instance.getCodeGenOpts().setDebugInfo(clang::codegenoptions::FullDebugInfo);
458#endif
459
460 // We use the 32-bit pointer-width SPIR triple
461 llvm::Triple triple("spir-unknown-unknown");
462
463 instance.getInvocation().setLangDefaults(
464 instance.getLangOpts(), clang::InputKind::OpenCL, triple,
465 instance.getPreprocessorOpts(), standard);
466
467 // Override the C99 inline semantics to accommodate for more OpenCL C
468 // programs in the wild.
469 instance.getLangOpts().GNUInline = true;
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100470
471 // Set up diagnostics
alan-bakerfec0a472018-11-08 18:09:40 -0500472 instance.createDiagnostics(
473 new clang::TextDiagnosticPrinter(*diagnosticsStream,
474 &instance.getDiagnosticOpts()),
475 true);
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100476 instance.getDiagnostics().setWarningsAsErrors(WarningsAsErrors);
477 instance.getDiagnostics().setEnableAllWarnings(true);
alan-bakerfec0a472018-11-08 18:09:40 -0500478
479 instance.getTargetOpts().Triple = triple.str();
480
481 instance.getCodeGenOpts().MainFileName = overiddenInputFilename;
482 instance.getCodeGenOpts().PreserveVec3Type = true;
483 // Disable generation of lifetime intrinsic.
484 instance.getCodeGenOpts().DisableLifetimeMarkers = true;
485 instance.getFrontendOpts().Inputs.push_back(kernelFile);
alan-bakerf5e5f692018-11-27 08:33:24 -0500486 // instance.getPreprocessorOpts().addRemappedFile(
487 // overiddenInputFilename, errorOrInputFile.get().release());
488 instance.getPreprocessorOpts().addRemappedFile(overiddenInputFilename,
489 memory_buffer.release());
alan-bakerfec0a472018-11-08 18:09:40 -0500490
491 struct OpenCLBuiltinMemoryBuffer final : public llvm::MemoryBuffer {
492 OpenCLBuiltinMemoryBuffer(const void *data, uint64_t data_length) {
493 const char *dataCasted = reinterpret_cast<const char *>(data);
494 init(dataCasted, dataCasted + data_length, true);
495 }
496
497 virtual llvm::MemoryBuffer::BufferKind getBufferKind() const override {
498 return llvm::MemoryBuffer::MemoryBuffer_Malloc;
499 }
500
501 virtual ~OpenCLBuiltinMemoryBuffer() override {}
502 };
503
504 std::unique_ptr<llvm::MemoryBuffer> openCLBuiltinMemoryBuffer(
505 new OpenCLBuiltinMemoryBuffer(opencl_builtins_header_data,
506 opencl_builtins_header_size - 1));
507
508 instance.getPreprocessorOpts().Includes.push_back("openclc.h");
509
510 // Add the VULKAN macro.
511 instance.getPreprocessorOpts().addMacroDef("VULKAN=100");
512
513 // Add the __OPENCL_VERSION__ macro.
514 instance.getPreprocessorOpts().addMacroDef("__OPENCL_VERSION__=120");
515
516 instance.setTarget(clang::TargetInfo::CreateTargetInfo(
517 instance.getDiagnostics(),
518 std::make_shared<clang::TargetOptions>(instance.getTargetOpts())));
519
520 instance.createFileManager();
521 instance.createSourceManager(instance.getFileManager());
522
523#ifdef _MSC_VER
524 std::string includePrefix("include\\");
525#else
526 std::string includePrefix("include/");
527#endif
528
529 auto entry = instance.getFileManager().getVirtualFile(
530 includePrefix + "openclc.h", openCLBuiltinMemoryBuffer->getBufferSize(),
531 0);
532
533 instance.getSourceManager().overrideFileContents(
534 entry, std::move(openCLBuiltinMemoryBuffer));
535
536 return 0;
537}
538
alan-bakerf5e5f692018-11-27 08:33:24 -0500539// Populates |pm| with necessary passes to optimize and legalize the IR.
540int PopulatePassManager(
541 llvm::legacy::PassManager *pm, llvm::raw_svector_ostream *binaryStream,
542 std::vector<clspv::version0::DescriptorMapEntry> *descriptor_map_entries,
543 llvm::SmallVectorImpl<std::pair<unsigned, std::string>>
544 *SamplerMapEntries) {
alan-bakerfec0a472018-11-08 18:09:40 -0500545 llvm::PassManagerBuilder pmBuilder;
546
547 switch (OptimizationLevel) {
548 case '0':
alan-bakerf5e5f692018-11-27 08:33:24 -0500549 case '1':
550 case '2':
551 case '3':
552 case 's':
553 case 'z':
554 break;
555 default:
556 llvm::errs() << "Unknown optimization level -O" << OptimizationLevel
557 << " specified!\n";
558 return -1;
559 }
560
561 switch (OptimizationLevel) {
562 case '0':
alan-bakerfec0a472018-11-08 18:09:40 -0500563 pmBuilder.OptLevel = 0;
564 break;
565 case '1':
566 pmBuilder.OptLevel = 1;
567 break;
568 case '2':
569 pmBuilder.OptLevel = 2;
570 break;
571 case '3':
572 pmBuilder.OptLevel = 3;
573 break;
574 case 's':
575 pmBuilder.SizeLevel = 1;
576 break;
577 case 'z':
578 pmBuilder.SizeLevel = 2;
579 break;
580 default:
581 break;
582 }
583
584 pm->add(clspv::createZeroInitializeAllocasPass());
585 pm->add(clspv::createDefineOpenCLWorkItemBuiltinsPass());
586
587 if (0 < pmBuilder.OptLevel) {
588 pm->add(clspv::createOpenCLInlinerPass());
589 }
590
591 pm->add(clspv::createUndoByvalPass());
592 pm->add(clspv::createUndoSRetPass());
593 if (cluster_non_pointer_kernel_args) {
594 pm->add(clspv::createClusterPodKernelArgumentsPass());
595 }
596 pm->add(clspv::createReplaceOpenCLBuiltinPass());
597
598 // We need to run mem2reg and inst combine early because our
599 // createInlineFuncWithPointerBitCastArgPass pass cannot handle the pattern
600 // %1 = alloca i32 1
601 // store <something> %1
602 // %2 = bitcast float* %1
603 // %3 = load float %2
604 pm->add(llvm::createPromoteMemoryToRegisterPass());
605
606 // Hide loads from __constant address space away from instcombine.
607 // This prevents us from generating select between pointers-to-__constant.
608 // See https://github.com/google/clspv/issues/71
609 pm->add(clspv::createHideConstantLoadsPass());
610
611 pm->add(llvm::createInstructionCombiningPass());
612
613 if (clspv::Option::InlineEntryPoints()) {
614 pm->add(clspv::createInlineEntryPointsPass());
615 } else {
616 pm->add(clspv::createInlineFuncWithPointerBitCastArgPass());
617 pm->add(clspv::createInlineFuncWithPointerToFunctionArgPass());
618 pm->add(clspv::createInlineFuncWithSingleCallSitePass());
619 }
620
Kévin Petit0fc88042019-04-09 23:25:02 +0100621 if (clspv::Option::CPlusPlus()) {
622 pm->add(clspv::createDemangleKernelNamesPass());
Kévin Petit38c52482019-05-07 20:28:00 +0800623 pm->add(llvm::createInferAddressSpacesPass(clspv::AddressSpace::Generic));
Kévin Petit0fc88042019-04-09 23:25:02 +0100624 }
625
alan-bakerfec0a472018-11-08 18:09:40 -0500626 if (0 == pmBuilder.OptLevel) {
627 // Mem2Reg pass should be run early because O0 level optimization leaves
628 // redundant alloca, load and store instructions from function arguments.
629 // clspv needs to remove them ahead of transformation.
630 pm->add(llvm::createPromoteMemoryToRegisterPass());
631
632 // SROA pass is run because it will fold structs/unions that are problematic
633 // on Vulkan SPIR-V away.
634 pm->add(llvm::createSROAPass());
635
636 // InstructionCombining pass folds bitcast and gep instructions which are
637 // not supported by Vulkan SPIR-V.
638 pm->add(llvm::createInstructionCombiningPass());
639 }
640
641 // Now we add any of the LLVM optimizations we wanted
642 pmBuilder.populateModulePassManager(*pm);
643
644 // Unhide loads from __constant address space. Undoes the action of
645 // HideConstantLoadsPass.
646 pm->add(clspv::createUnhideConstantLoadsPass());
647
648 pm->add(clspv::createFunctionInternalizerPass());
649 pm->add(clspv::createReplaceLLVMIntrinsicsPass());
650 pm->add(clspv::createUndoBoolPass());
651 pm->add(clspv::createUndoTruncatedSwitchConditionPass());
652 pm->add(llvm::createStructurizeCFGPass(false));
alan-baker3fa76d92018-11-12 14:54:40 -0500653 // Must be run after structurize cfg.
alan-bakerfec0a472018-11-08 18:09:40 -0500654 pm->add(clspv::createReorderBasicBlocksPass());
655 pm->add(clspv::createUndoGetElementPtrConstantExprPass());
656 pm->add(clspv::createSplatArgPass());
657 pm->add(clspv::createSimplifyPointerBitcastPass());
658 pm->add(clspv::createReplacePointerBitcastPass());
659
660 pm->add(clspv::createUndoTranslateSamplerFoldPass());
661
662 if (clspv::Option::ModuleConstantsInStorageBuffer()) {
663 pm->add(clspv::createClusterModuleScopeConstantVars());
664 }
665
666 pm->add(clspv::createShareModuleScopeVariablesPass());
alan-bakere9308012019-03-15 10:25:13 -0400667 // This should be run after LLVM and OpenCL intrinsics are replaced.
alan-bakerfec0a472018-11-08 18:09:40 -0500668 pm->add(clspv::createAllocateDescriptorsPass(*SamplerMapEntries));
669 pm->add(llvm::createVerifierPass());
670 pm->add(clspv::createDirectResourceAccessPass());
671 // Replacing pointer bitcasts can leave some trivial GEPs
672 // that are easy to remove. Also replace GEPs of GEPS
673 // left by replacing indirect buffer accesses.
674 pm->add(clspv::createSimplifyPointerBitcastPass());
alan-baker4217b322019-03-06 08:56:12 -0500675 // Run after DRA to clean up parameters and help reduce the need for variable
676 // pointers.
677 pm->add(clspv::createRemoveUnusedArgumentsPass());
alan-bakerfec0a472018-11-08 18:09:40 -0500678
679 pm->add(clspv::createSplatSelectConditionPass());
680 pm->add(clspv::createSignedCompareFixupPass());
681 // This pass generates insertions that need to be rewritten.
682 pm->add(clspv::createScalarizePass());
683 pm->add(clspv::createRewriteInsertsPass());
alan-bakera71f1932019-04-11 11:04:34 -0400684 // UBO Transformations
685 if (clspv::Option::ConstantArgsInUniformBuffer() &&
686 !clspv::Option::InlineEntryPoints()) {
687 // MultiVersionUBOFunctionsPass will examine non-kernel functions with UBO
688 // arguments and either multi-version them as necessary or inline them if
689 // multi-versioning cannot be accomplished.
690 pm->add(clspv::createMultiVersionUBOFunctionsPass());
691 // Cleanup passes.
692 // Specialization can blindly generate GEP chains that are easily cleaned up
693 // by SimplifyPointerBitcastPass.
694 pm->add(clspv::createSimplifyPointerBitcastPass());
695 // RemoveUnusedArgumentsPass removes the actual UBO arguments that were
696 // problematic to begin with now that they have no uses.
697 pm->add(clspv::createRemoveUnusedArgumentsPass());
698 // DCE cleans up callers of the specialized functions.
699 pm->add(llvm::createDeadCodeEliminationPass());
700 }
alan-bakerfec0a472018-11-08 18:09:40 -0500701 // This pass mucks with types to point where you shouldn't rely on DataLayout
702 // anymore so leave this right before SPIR-V generation.
703 pm->add(clspv::createUBOTypeTransformPass());
704 pm->add(clspv::createSPIRVProducerPass(
alan-bakerf5e5f692018-11-27 08:33:24 -0500705 *binaryStream, descriptor_map_entries, *SamplerMapEntries,
Kévin Petite4786902019-04-02 21:51:47 +0100706 false /* Output assembly */, OutputFormat == "c"));
alan-bakerf5e5f692018-11-27 08:33:24 -0500707
708 return 0;
alan-bakerfec0a472018-11-08 18:09:40 -0500709}
alan-bakerfec0a472018-11-08 18:09:40 -0500710
Kévin Petitd5db2d22019-04-04 13:55:14 +0100711int ParseOptions(const int argc, const char *const argv[]) {
alan-bakerfec0a472018-11-08 18:09:40 -0500712 // We need to change how one of the called passes works by spoofing
713 // ParseCommandLineOptions with the specific option.
714 const int llvmArgc = 2;
715 const char *llvmArgv[llvmArgc] = {
alan-bakerf5e5f692018-11-27 08:33:24 -0500716 argv[0],
717 "-simplifycfg-sink-common=false",
alan-bakerfec0a472018-11-08 18:09:40 -0500718 };
719
Kévin Petitd5db2d22019-04-04 13:55:14 +0100720 llvm::cl::ResetAllOptionOccurrences();
alan-bakerfec0a472018-11-08 18:09:40 -0500721 llvm::cl::ParseCommandLineOptions(llvmArgc, llvmArgv);
alan-bakerfec0a472018-11-08 18:09:40 -0500722 llvm::cl::ParseCommandLineOptions(argc, argv);
723
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400724 if (clspv::Option::CPlusPlus() && !clspv::Option::InlineEntryPoints()) {
Kévin Petit0fc88042019-04-09 23:25:02 +0100725 llvm::errs() << "cannot use -c++ without -inline-entry-points\n";
726 return -1;
727 }
728
Kévin Petitd5db2d22019-04-04 13:55:14 +0100729 return 0;
730}
Diego Novillo89500852019-04-15 08:45:10 -0400731
732int GenerateIRFile(llvm::legacy::PassManager *pm, llvm::Module &module,
733 std::string output) {
734 std::error_code ec;
735 std::unique_ptr<llvm::ToolOutputFile> out(
736 new llvm::ToolOutputFile(output, ec, llvm::sys::fs::F_None));
737 if (ec) {
738 llvm::errs() << output << ": " << ec.message() << '\n';
739 return -1;
740 }
741 pm->add(llvm::createPrintModulePass(out->os(), "", false));
742 pm->run(module);
743 out->keep();
744 return 0;
745}
746
Kévin Petitd5db2d22019-04-04 13:55:14 +0100747} // namespace
748
749namespace clspv {
750int Compile(const int argc, const char *const argv[]) {
751
752 if (auto error = ParseOptions(argc, argv))
753 return error;
754
alan-bakerfec0a472018-11-08 18:09:40 -0500755 llvm::SmallVector<std::pair<unsigned, std::string>, 8> SamplerMapEntries;
alan-bakerf5e5f692018-11-27 08:33:24 -0500756 if (auto error = ParseSamplerMap("", &SamplerMapEntries))
alan-bakerfec0a472018-11-08 18:09:40 -0500757 return error;
758
759 // if no output file was provided, use a default
760 llvm::StringRef overiddenInputFilename = InputFilename.getValue();
761
762 // If we are reading our input file from stdin.
763 if ("-" == InputFilename) {
764 // We need to overwrite the file name we use.
765 overiddenInputFilename = "stdin.cl";
766 }
767
768 clang::CompilerInstance instance;
769 clang::FrontendInputFile kernelFile(overiddenInputFilename,
770 clang::InputKind::OpenCL);
771 std::string log;
772 llvm::raw_string_ostream diagnosticsStream(log);
alan-bakerf5e5f692018-11-27 08:33:24 -0500773 if (auto error = SetCompilerInstanceOptions(
774 instance, overiddenInputFilename, kernelFile, "", &diagnosticsStream))
alan-bakerfec0a472018-11-08 18:09:40 -0500775 return error;
776
777 // Parse.
778 llvm::LLVMContext context;
779 clang::EmitLLVMOnlyAction action(&context);
780
781 // Prepare the action for processing kernelFile
782 const bool success = action.BeginSourceFile(instance, kernelFile);
783 if (!success) {
784 return -1;
785 }
786
787 action.Execute();
788 action.EndSourceFile();
789
790 clang::DiagnosticConsumer *const consumer =
791 instance.getDiagnostics().getClient();
792 consumer->finish();
793
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100794 auto num_warnings = consumer->getNumWarnings();
alan-bakerfec0a472018-11-08 18:09:40 -0500795 auto num_errors = consumer->getNumErrors();
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100796 if ((num_errors > 0) || (num_warnings > 0)) {
797 llvm::errs() << log;
798 }
alan-bakerfec0a472018-11-08 18:09:40 -0500799 if (num_errors > 0) {
alan-bakerfec0a472018-11-08 18:09:40 -0500800 return -1;
801 }
802
Kévin Petit6b07cbe2019-04-02 21:52:16 +0100803 // Don't run the passes or produce any output in verify mode.
804 // Clang doesn't always produce a valid module.
805 if (verify) {
806 return 0;
807 }
808
alan-bakerfec0a472018-11-08 18:09:40 -0500809 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
810 llvm::initializeCore(Registry);
811 llvm::initializeScalarOpts(Registry);
812
813 std::unique_ptr<llvm::Module> module(action.takeModule());
814
815 // Optimize.
816 // Create a memory buffer for temporarily writing the result.
817 SmallVector<char, 10000> binary;
818 llvm::raw_svector_ostream binaryStream(binary);
819 std::string descriptor_map;
alan-bakerfec0a472018-11-08 18:09:40 -0500820 llvm::legacy::PassManager pm;
alan-bakerf5e5f692018-11-27 08:33:24 -0500821 std::vector<version0::DescriptorMapEntry> descriptor_map_entries;
Diego Novillo89500852019-04-15 08:45:10 -0400822
823 // If --emit-ir was requested, emit the initial LLVM IR and stop compilation.
824 if (!IROutputFile.empty()) {
825 return GenerateIRFile(&pm, *module, IROutputFile);
826 }
827
828 // Otherwise, populate the pass manager and run the regular passes.
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400829 if (auto error = PopulatePassManager(
830 &pm, &binaryStream, &descriptor_map_entries, &SamplerMapEntries))
alan-bakerf5e5f692018-11-27 08:33:24 -0500831 return error;
alan-bakerfec0a472018-11-08 18:09:40 -0500832 pm.run(*module);
833
834 // Write outputs
835
836 // Write the descriptor map, if requested.
837 std::error_code error;
838 if (!DescriptorMapFilename.empty()) {
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400839 llvm::raw_fd_ostream descriptor_map_out_fd(
840 DescriptorMapFilename, error, llvm::sys::fs::CD_CreateAlways,
841 llvm::sys::fs::FA_Write, llvm::sys::fs::F_Text);
alan-bakerfec0a472018-11-08 18:09:40 -0500842 if (error) {
843 llvm::errs() << "Unable to open descriptor map file '"
844 << DescriptorMapFilename << "': " << error.message() << '\n';
845 return -1;
846 }
alan-bakerf5e5f692018-11-27 08:33:24 -0500847 std::string descriptor_map_string;
848 std::ostringstream str(descriptor_map_string);
849 for (const auto &entry : descriptor_map_entries) {
850 str << entry << "\n";
851 }
852 descriptor_map_out_fd << str.str();
alan-bakerfec0a472018-11-08 18:09:40 -0500853 descriptor_map_out_fd.close();
854 }
855
856 // Write the resulting binary.
857 // Wait until now to try writing the file so that we only write it on
858 // successful compilation.
859 if (OutputFilename.empty()) {
Kévin Petite4786902019-04-02 21:51:47 +0100860 if (OutputFormat == "c") {
alan-bakerfec0a472018-11-08 18:09:40 -0500861 OutputFilename = "a.spvinc";
862 } else {
863 OutputFilename = "a.spv";
864 }
865 }
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400866 llvm::raw_fd_ostream outStream(OutputFilename, error,
867 llvm::sys::fs::FA_Write);
alan-bakerfec0a472018-11-08 18:09:40 -0500868
869 if (error) {
870 llvm::errs() << "Unable to open output file '" << OutputFilename
871 << "': " << error.message() << '\n';
872 return -1;
873 }
874 outStream << binaryStream.str();
875
876 return 0;
877}
alan-bakerf5e5f692018-11-27 08:33:24 -0500878
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400879int CompileFromSourceString(
880 const std::string &program, const std::string &sampler_map,
881 const std::string &options, std::vector<uint32_t> *output_binary,
882 std::vector<clspv::version0::DescriptorMapEntry> *descriptor_map_entries) {
alan-bakerf5e5f692018-11-27 08:33:24 -0500883
884 llvm::SmallVector<const char *, 20> argv;
885 llvm::BumpPtrAllocator A;
886 llvm::StringSaver Saver(A);
887 argv.push_back(Saver.save("clspv").data());
888 llvm::cl::TokenizeGNUCommandLine(options, Saver, argv);
889 int argc = static_cast<int>(argv.size());
Kévin Petitd5db2d22019-04-04 13:55:14 +0100890
891 if (auto error = ParseOptions(argc, &argv[0]))
892 return error;
alan-bakerf5e5f692018-11-27 08:33:24 -0500893
894 llvm::SmallVector<std::pair<unsigned, std::string>, 8> SamplerMapEntries;
895 if (auto error = ParseSamplerMap(sampler_map, &SamplerMapEntries))
896 return error;
897
898 InputFilename = "source.cl";
899 llvm::StringRef overiddenInputFilename = InputFilename.getValue();
900
901 clang::CompilerInstance instance;
902 clang::FrontendInputFile kernelFile(overiddenInputFilename,
903 clang::InputKind::OpenCL);
904 std::string log;
905 llvm::raw_string_ostream diagnosticsStream(log);
906 if (auto error =
907 SetCompilerInstanceOptions(instance, overiddenInputFilename,
908 kernelFile, program, &diagnosticsStream))
909 return error;
910
911 // Parse.
912 llvm::LLVMContext context;
913 clang::EmitLLVMOnlyAction action(&context);
914
915 // Prepare the action for processing kernelFile
916 const bool success = action.BeginSourceFile(instance, kernelFile);
917 if (!success) {
918 return -1;
919 }
920
921 action.Execute();
922 action.EndSourceFile();
923
924 clang::DiagnosticConsumer *const consumer =
925 instance.getDiagnostics().getClient();
926 consumer->finish();
927
928 auto num_errors = consumer->getNumErrors();
929 if (num_errors > 0) {
930 llvm::errs() << log << "\n";
931 return -1;
932 }
933
alan-bakerf5e5f692018-11-27 08:33:24 -0500934 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
935 llvm::initializeCore(Registry);
936 llvm::initializeScalarOpts(Registry);
937
938 std::unique_ptr<llvm::Module> module(action.takeModule());
939
940 // Optimize.
941 // Create a memory buffer for temporarily writing the result.
942 SmallVector<char, 10000> binary;
943 llvm::raw_svector_ostream binaryStream(binary);
944 std::string descriptor_map;
945 llvm::legacy::PassManager pm;
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400946 if (auto error = PopulatePassManager(
947 &pm, &binaryStream, descriptor_map_entries, &SamplerMapEntries))
alan-bakerf5e5f692018-11-27 08:33:24 -0500948 return error;
949 pm.run(*module);
950
951 // Write outputs
952
953 // Write the descriptor map. This is required.
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400954 assert(descriptor_map_entries &&
955 "Valid descriptor map container is required.");
alan-bakerf5e5f692018-11-27 08:33:24 -0500956 if (!DescriptorMapFilename.empty()) {
Diego Novillo3cc8d7a2019-04-10 13:30:34 -0400957 llvm::errs() << "Warning: -descriptormap is ignored descriptor map "
958 "container is provided.\n";
alan-bakerf5e5f692018-11-27 08:33:24 -0500959 }
960
961 // Write the resulting binary.
962 // Wait until now to try writing the file so that we only write it on
963 // successful compilation.
964 assert(output_binary && "Valid binary container is required.");
965 if (!OutputFilename.empty()) {
966 llvm::outs()
967 << "Warning: -o is ignored when binary container is provided.\n";
968 }
969 output_binary->resize(binary.size() / 4);
970 memcpy(output_binary->data(), binary.data(), binary.size());
971
972 return 0;
973}
alan-bakerfec0a472018-11-08 18:09:40 -0500974} // namespace clspv