// Copyright (c) 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef SOURCE_OPT_CODE_SINK_H_ #define SOURCE_OPT_CODE_SINK_H_ #include <unordered_map> #include "source/opt/ir_context.h" #include "source/opt/module.h" #include "source/opt/pass.h" namespace spvtools { namespace opt { // This pass does code sinking for OpAccessChain and OpLoad on variables in // uniform storage or in read only memory. Code sinking is a transformation // where an instruction is moved into a more deeply nested construct. // // The goal is to move these instructions as close as possible to their uses // without having to execute them more often or to replicate the instruction. // Moving the instruction in this way can lead to shorter live ranges, which can // lead to less register pressure. It can also cause instructions to be // executed less often because they could be moved into one path of a selection // construct. // // This optimization can cause register pressure to rise if the operands of the // instructions go dead after the instructions being moved. That is why we only // move certain OpLoad and OpAccessChain instructions. They generally have // constants, loop induction variables, and global pointers as operands. The // operands are live for a longer time in most cases. class CodeSinkingPass : public Pass { … }; } // namespace opt } // namespace spvtools #endif // SOURCE_OPT_CODE_SINK_H_