Home | History | Annotate | Download | only in opt
      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 "function.h"
     16 
     17 namespace spvtools {
     18 namespace ir {
     19 
     20 void Function::ForEachInst(const std::function<void(Instruction*)>& f,
     21                            bool run_on_debug_line_insts) {
     22   if (def_inst_) def_inst_->ForEachInst(f, run_on_debug_line_insts);
     23   for (auto& param : params_) param->ForEachInst(f, run_on_debug_line_insts);
     24   for (auto& bb : blocks_) bb->ForEachInst(f, run_on_debug_line_insts);
     25   if (end_inst_) end_inst_->ForEachInst(f, run_on_debug_line_insts);
     26 }
     27 
     28 void Function::ForEachInst(const std::function<void(const Instruction*)>& f,
     29                            bool run_on_debug_line_insts) const {
     30   if (def_inst_)
     31     static_cast<const Instruction*>(def_inst_.get())
     32         ->ForEachInst(f, run_on_debug_line_insts);
     33 
     34   for (const auto& param : params_)
     35     static_cast<const Instruction*>(param.get())
     36         ->ForEachInst(f, run_on_debug_line_insts);
     37 
     38   for (const auto& bb : blocks_)
     39     static_cast<const BasicBlock*>(bb.get())
     40         ->ForEachInst(f, run_on_debug_line_insts);
     41 
     42   if (end_inst_)
     43     static_cast<const Instruction*>(end_inst_.get())
     44         ->ForEachInst(f, run_on_debug_line_insts);
     45 }
     46 
     47 void Function::ForEachParam(const std::function<void(const Instruction*)>& f,
     48                             bool run_on_debug_line_insts) const {
     49   for (const auto& param : params_)
     50     static_cast<const Instruction*>(param.get())
     51         ->ForEachInst(f, run_on_debug_line_insts);
     52 }
     53 
     54 }  // namespace ir
     55 }  // namespace spvtools
     56