1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef BERBERIS_BACKEND_X86_64_CONTEXT_LIVENESS_ANALYZER_H_ 18 #define BERBERIS_BACKEND_X86_64_CONTEXT_LIVENESS_ANALYZER_H_ 19 20 #include <bitset> 21 #include <cstdint> 22 23 #include "berberis/backend/x86_64/machine_ir.h" 24 #include "berberis/base/arena_vector.h" 25 26 namespace berberis::x86_64 { 27 28 class ContextLivenessAnalyzer { 29 public: ContextLivenessAnalyzer(const MachineIR * ir)30 explicit ContextLivenessAnalyzer(const MachineIR* ir) 31 : machine_ir_(ir), context_live_in_(ir->NumBasicBlocks(), ContextLiveness(), ir->arena()) {} 32 33 void Init(); 34 bool IsLiveIn(const MachineBasicBlock* bb, uint32_t offset) const; 35 36 private: 37 using ContextLiveness = std::bitset<sizeof(CPUState)>; 38 39 bool VisitBasicBlock(const MachineBasicBlock* bb); 40 41 const MachineIR* machine_ir_; 42 ArenaVector<ContextLiveness> context_live_in_; 43 }; 44 45 } // namespace berberis::x86_64 46 47 #endif // BERBERIS_BACKEND_X86_64_CONTEXT_LIVENESS_ANALYZER_H_ 48