// Copyright (c) 2017 Google Inc. // // 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. // This file implements conditional constant propagation as described in // // Constant propagation with conditional branches, // Wegman and Zadeck, ACM TOPLAS 13(2):181-210. #include "source/opt/ccp_pass.h" #include <algorithm> #include <limits> #include "source/opt/fold.h" #include "source/opt/function.h" #include "source/opt/propagator.h" namespace spvtools { namespace opt { namespace { // This SSA id is never defined nor referenced in the IR. It is a special ID // which represents varying values. When an ID is found to have a varying // value, its entry in the |values_| table maps to kVaryingSSAId. constexpr uint32_t kVaryingSSAId = …; } // namespace bool CCPPass::IsVaryingValue(uint32_t id) const { … } SSAPropagator::PropStatus CCPPass::MarkInstructionVarying(Instruction* instr) { … } SSAPropagator::PropStatus CCPPass::VisitPhi(Instruction* phi) { … } uint32_t CCPPass::ComputeLatticeMeet(Instruction* instr, uint32_t val2) { … } SSAPropagator::PropStatus CCPPass::VisitAssignment(Instruction* instr) { … } SSAPropagator::PropStatus CCPPass::VisitBranch(Instruction* instr, BasicBlock** dest_bb) const { … } SSAPropagator::PropStatus CCPPass::VisitInstruction(Instruction* instr, BasicBlock** dest_bb) { … } bool CCPPass::ReplaceValues() { … } bool CCPPass::PropagateConstants(Function* fp) { … } void CCPPass::Initialize() { … } Pass::Status CCPPass::Process() { … } } // namespace opt } // namespace spvtools