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 | |
15 | #include "source/opt/freeze_spec_constant_value_pass.h" |
16 | #include "source/opt/ir_context.h" |
17 | |
18 | namespace spvtools { |
19 | namespace opt { |
20 | |
21 | Pass::Status FreezeSpecConstantValuePass::Process() { |
22 | bool modified = false; |
23 | auto ctx = context(); |
24 | ctx->module()->ForEachInst([&modified, ctx](Instruction* inst) { |
25 | switch (inst->opcode()) { |
26 | case SpvOp::SpvOpSpecConstant: |
27 | inst->SetOpcode(SpvOp::SpvOpConstant); |
28 | modified = true; |
29 | break; |
30 | case SpvOp::SpvOpSpecConstantTrue: |
31 | inst->SetOpcode(SpvOp::SpvOpConstantTrue); |
32 | modified = true; |
33 | break; |
34 | case SpvOp::SpvOpSpecConstantFalse: |
35 | inst->SetOpcode(SpvOp::SpvOpConstantFalse); |
36 | modified = true; |
37 | break; |
38 | case SpvOp::SpvOpDecorate: |
39 | if (inst->GetSingleWordInOperand(1) == |
40 | SpvDecoration::SpvDecorationSpecId) { |
41 | ctx->KillInst(inst); |
42 | modified = true; |
43 | } |
44 | break; |
45 | default: |
46 | break; |
47 | } |
48 | }); |
49 | return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange; |
50 | } |
51 | |
52 | } // namespace opt |
53 | } // namespace spvtools |
54 |