33
33
34
34
namespace spvtools {
35
35
36
+ std::vector<std::string> GetVectorOfStrings (const char ** strings,
37
+ const size_t string_count) {
38
+ std::vector<std::string> result;
39
+ for (uint32_t i = 0 ; i < string_count; i++) {
40
+ result.emplace_back (strings[i]);
41
+ }
42
+ return result;
43
+ }
44
+
36
45
struct Optimizer ::PassToken::Impl {
37
46
Impl (std::unique_ptr<opt::Pass> p) : pass(std::move(p)) {}
38
47
@@ -256,8 +265,13 @@ Optimizer& Optimizer::RegisterSizePasses(bool preserve_interface) {
256
265
Optimizer& Optimizer::RegisterSizePasses () { return RegisterSizePasses (false ); }
257
266
258
267
bool Optimizer::RegisterPassesFromFlags (const std::vector<std::string>& flags) {
268
+ return RegisterPassesFromFlags (flags, false );
269
+ }
270
+
271
+ bool Optimizer::RegisterPassesFromFlags (const std::vector<std::string>& flags,
272
+ bool preserve_interface) {
259
273
for (const auto & flag : flags) {
260
- if (!RegisterPassFromFlag (flag)) {
274
+ if (!RegisterPassFromFlag (flag, preserve_interface )) {
261
275
return false ;
262
276
}
263
277
}
@@ -281,6 +295,11 @@ bool Optimizer::FlagHasValidForm(const std::string& flag) const {
281
295
}
282
296
283
297
bool Optimizer::RegisterPassFromFlag (const std::string& flag) {
298
+ return RegisterPassFromFlag (flag, false );
299
+ }
300
+
301
+ bool Optimizer::RegisterPassFromFlag (const std::string& flag,
302
+ bool preserve_interface) {
284
303
if (!FlagHasValidForm (flag)) {
285
304
return false ;
286
305
}
@@ -342,7 +361,7 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag) {
342
361
} else if (pass_name == " descriptor-scalar-replacement" ) {
343
362
RegisterPass (CreateDescriptorScalarReplacementPass ());
344
363
} else if (pass_name == " eliminate-dead-code-aggressive" ) {
345
- RegisterPass (CreateAggressiveDCEPass ());
364
+ RegisterPass (CreateAggressiveDCEPass (preserve_interface ));
346
365
} else if (pass_name == " eliminate-insert-extract" ) {
347
366
RegisterPass (CreateInsertExtractElimPass ());
348
367
} else if (pass_name == " eliminate-local-single-block" ) {
@@ -513,11 +532,11 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag) {
513
532
} else if (pass_name == " fix-storage-class" ) {
514
533
RegisterPass (CreateFixStorageClassPass ());
515
534
} else if (pass_name == " O" ) {
516
- RegisterPerformancePasses ();
535
+ RegisterPerformancePasses (preserve_interface );
517
536
} else if (pass_name == " Os" ) {
518
- RegisterSizePasses ();
537
+ RegisterSizePasses (preserve_interface );
519
538
} else if (pass_name == " legalize-hlsl" ) {
520
- RegisterLegalizationPasses ();
539
+ RegisterLegalizationPasses (preserve_interface );
521
540
} else if (pass_name == " remove-unused-interface-variables" ) {
522
541
RegisterPass (CreateRemoveUnusedInterfaceVariablesPass ());
523
542
} else if (pass_name == " graphics-robust-access" ) {
@@ -1170,13 +1189,19 @@ SPIRV_TOOLS_EXPORT bool spvOptimizerRegisterPassFromFlag(
1170
1189
1171
1190
SPIRV_TOOLS_EXPORT bool spvOptimizerRegisterPassesFromFlags (
1172
1191
spv_optimizer_t * optimizer, const char ** flags, const size_t flag_count) {
1173
- std::vector<std::string> opt_flags;
1174
- for (uint32_t i = 0 ; i < flag_count; i++) {
1175
- opt_flags.emplace_back (flags[i]);
1176
- }
1192
+ std::vector<std::string> opt_flags =
1193
+ spvtools::GetVectorOfStrings (flags, flag_count);
1194
+ return reinterpret_cast <spvtools::Optimizer*>(optimizer)
1195
+ ->RegisterPassesFromFlags (opt_flags, false );
1196
+ }
1177
1197
1178
- return reinterpret_cast <spvtools::Optimizer*>(optimizer)->
1179
- RegisterPassesFromFlags (opt_flags);
1198
+ SPIRV_TOOLS_EXPORT bool
1199
+ spvOptimizerRegisterPassesFromFlagsWhilePreservingTheInterface (
1200
+ spv_optimizer_t * optimizer, const char ** flags, const size_t flag_count) {
1201
+ std::vector<std::string> opt_flags =
1202
+ spvtools::GetVectorOfStrings (flags, flag_count);
1203
+ return reinterpret_cast <spvtools::Optimizer*>(optimizer)
1204
+ ->RegisterPassesFromFlags (opt_flags, true );
1180
1205
}
1181
1206
1182
1207
SPIRV_TOOLS_EXPORT
0 commit comments