Home | History | Annotate | Download | only in compiler
      1 // Copyright 2016 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "src/compiler/bytecode-liveness-map.h"
      6 
      7 namespace v8 {
      8 namespace internal {
      9 namespace compiler {
     10 
     11 BytecodeLiveness::BytecodeLiveness(int register_count, Zone* zone)
     12     : in(new (zone) BytecodeLivenessState(register_count, zone)),
     13       out(new (zone) BytecodeLivenessState(register_count, zone)) {}
     14 
     15 BytecodeLivenessMap::BytecodeLivenessMap(int bytecode_size, Zone* zone)
     16     : liveness_map_(base::bits::RoundUpToPowerOfTwo32(bytecode_size / 4 + 1),
     17                     base::KeyEqualityMatcher<int>(),
     18                     ZoneAllocationPolicy(zone)) {}
     19 
     20 uint32_t OffsetHash(int offset) { return offset; }
     21 
     22 BytecodeLiveness& BytecodeLivenessMap::InitializeLiveness(int offset,
     23                                                           int register_count,
     24                                                           Zone* zone) {
     25   return liveness_map_
     26       .LookupOrInsert(offset, OffsetHash(offset),
     27                       [&]() { return BytecodeLiveness(register_count, zone); },
     28                       ZoneAllocationPolicy(zone))
     29       ->value;
     30 }
     31 
     32 BytecodeLiveness& BytecodeLivenessMap::GetLiveness(int offset) {
     33   return liveness_map_.Lookup(offset, OffsetHash(offset))->value;
     34 }
     35 
     36 const BytecodeLiveness& BytecodeLivenessMap::GetLiveness(int offset) const {
     37   return liveness_map_.Lookup(offset, OffsetHash(offset))->value;
     38 }
     39 
     40 }  // namespace compiler
     41 }  // namespace internal
     42 }  // namespace v8
     43