• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Process()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 spv::Op::OpSpecConstant:
27         inst->SetOpcode(spv::Op::OpConstant);
28         modified = true;
29         break;
30       case spv::Op::OpSpecConstantTrue:
31         inst->SetOpcode(spv::Op::OpConstantTrue);
32         modified = true;
33         break;
34       case spv::Op::OpSpecConstantFalse:
35         inst->SetOpcode(spv::Op::OpConstantFalse);
36         modified = true;
37         break;
38       case spv::Op::OpDecorate:
39         if (spv::Decoration(inst->GetSingleWordInOperand(1)) ==
40             spv::Decoration::SpecId) {
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