freeze_spec_constant_value_pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2016 Google Inc.
  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. #include "source/opt/freeze_spec_constant_value_pass.h"
  15. #include "source/opt/ir_context.h"
  16. namespace spvtools {
  17. namespace opt {
  18. Pass::Status FreezeSpecConstantValuePass::Process() {
  19. bool modified = false;
  20. auto ctx = context();
  21. ctx->module()->ForEachInst([&modified, ctx](Instruction* inst) {
  22. switch (inst->opcode()) {
  23. case spv::Op::OpSpecConstant:
  24. inst->SetOpcode(spv::Op::OpConstant);
  25. modified = true;
  26. break;
  27. case spv::Op::OpSpecConstantTrue:
  28. inst->SetOpcode(spv::Op::OpConstantTrue);
  29. modified = true;
  30. break;
  31. case spv::Op::OpSpecConstantFalse:
  32. inst->SetOpcode(spv::Op::OpConstantFalse);
  33. modified = true;
  34. break;
  35. case spv::Op::OpDecorate:
  36. if (spv::Decoration(inst->GetSingleWordInOperand(1)) ==
  37. spv::Decoration::SpecId) {
  38. ctx->KillInst(inst);
  39. modified = true;
  40. }
  41. break;
  42. default:
  43. break;
  44. }
  45. });
  46. return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
  47. }
  48. } // namespace opt
  49. } // namespace spvtools