chromium/v8/src/compiler/turboshaft/sidetable.h

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_TURBOSHAFT_SIDETABLE_H_
#define V8_COMPILER_TURBOSHAFT_SIDETABLE_H_

#include <algorithm>
#include <iterator>
#include <limits>
#include <memory>
#include <type_traits>

#include "src/base/iterator.h"
#include "src/base/small-vector.h"
#include "src/base/vector.h"
#include "src/compiler/turboshaft/operations.h"
#include "src/zone/zone-containers.h"

namespace v8::internal::compiler::turboshaft {

#ifdef DEBUG
V8_EXPORT_PRIVATE bool OpIndexBelongsToTableGraph(const Graph* graph,
                                                  OpIndex index);
#endif

namespace detail {

// This sidetable is a conceptually infinite mapping from Turboshaft operation
// indices to values. It grows automatically and default-initializes the table
// when accessed out-of-bounds.
template <class T, class Key>
class GrowingSidetable {};

// A fixed-size sidetable mapping from `Key` to `T`.
// Elements are default-initialized.
template <class T, class Key>
class FixedSidetable {};

}  // namespace detail

template <typename T>
class GrowingBlockSidetable : public detail::GrowingSidetable<T, BlockIndex> {};

template <typename T>
class FixedBlockSidetable : public detail::FixedSidetable<T, BlockIndex> {};

template <class T>
class GrowingOpIndexSidetable : public detail::GrowingSidetable<T, OpIndex> {};

template <class T>
class FixedOpIndexSidetable : public detail::FixedSidetable<T, OpIndex> {};

}  // namespace v8::internal::compiler::turboshaft

#endif  // V8_COMPILER_TURBOSHAFT_SIDETABLE_H_