• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
BytecodeLiveness(int register_count,Zone * zone)11 BytecodeLiveness::BytecodeLiveness(int register_count, Zone* zone)
12     : in(zone->New<BytecodeLivenessState>(register_count, zone)),
13       out(zone->New<BytecodeLivenessState>(register_count, zone)) {}
14 
BytecodeLivenessMap(int bytecode_size,Zone * zone)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 
OffsetHash(int offset)20 uint32_t OffsetHash(int offset) { return offset; }
21 
InitializeLiveness(int offset,int register_count,Zone * zone)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       ->value;
29 }
30 
GetLiveness(int offset)31 BytecodeLiveness& BytecodeLivenessMap::GetLiveness(int offset) {
32   return liveness_map_.Lookup(offset, OffsetHash(offset))->value;
33 }
34 
GetLiveness(int offset) const35 const BytecodeLiveness& BytecodeLivenessMap::GetLiveness(int offset) const {
36   return liveness_map_.Lookup(offset, OffsetHash(offset))->value;
37 }
38 
39 }  // namespace compiler
40 }  // namespace internal
41 }  // namespace v8
42