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_VREG_BIT_SET_H_ 18 #define BERBERIS_BACKEND_X86_64_VREG_BIT_SET_H_ 19 20 #include <cstddef> 21 22 #include "berberis/backend/x86_64/machine_ir.h" 23 #include "berberis/base/arena_vector.h" 24 25 namespace berberis::x86_64 { 26 27 // TODO(b/179708579): Use something with fast bitwise operators like std::bitset, 28 // but with the dynamic size. 29 class VRegBitSet { 30 public: VRegBitSet(size_t size,Arena * arena)31 VRegBitSet(size_t size, Arena* arena) : bit_set_(size, false, arena) {} 32 Set(MachineReg reg)33 void Set(MachineReg reg) { bit_set_[reg.GetVRegIndex()] = true; } Reset(MachineReg reg)34 void Reset(MachineReg reg) { bit_set_[reg.GetVRegIndex()] = false; } Clear()35 void Clear() { bit_set_.clear(); } Size()36 size_t Size() const { return bit_set_.size(); } 37 38 bool operator[](MachineReg reg) const { return bit_set_[reg.GetVRegIndex()]; } 39 40 VRegBitSet& operator|=(const VRegBitSet& other) { 41 CHECK_EQ(this->bit_set_.size(), other.bit_set_.size()); 42 for (size_t i = 0; i < this->bit_set_.size(); i++) { 43 this->bit_set_[i] = this->bit_set_[i] || other.bit_set_[i]; 44 } 45 return *this; 46 } 47 48 bool operator!=(const VRegBitSet& other) const { return this->bit_set_ != other.bit_set_; } 49 50 private: 51 ArenaVector<bool> bit_set_; 52 }; 53 54 } // namespace berberis::x86_64 55 56 #endif // BERBERIS_BACKEND_X86_64_VREG_BIT_SET_H_ 57