chromium/v8/src/compiler/turboshaft/types.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_TYPES_H_
#define V8_COMPILER_TURBOSHAFT_TYPES_H_

#include <cmath>
#include <limits>
#include <optional>

#include "src/base/container-utils.h"
#include "src/base/export-template.h"
#include "src/base/logging.h"
#include "src/base/small-vector.h"
#include "src/common/globals.h"
#include "src/compiler/turboshaft/fast-hash.h"
#include "src/numbers/conversions.h"
#include "src/objects/turboshaft-types.h"
#include "src/utils/ostreams.h"
#include "src/zone/zone-containers.h"

#ifdef DEBUG
#define TURBOSHAFT_TRACE_TYPING(...)

#define TURBOSHAFT_TRACE_TYPING_WITH_COLOR(colorcode, str, ...)
#define TURBOSHAFT_TRACE_TYPING_OK(str, ...)
#define TURBOSHAFT_TRACE_TYPING_FAIL(str, ...)
#else
#define TURBOSHAFT_TRACE_TYPING
#define TURBOSHAFT_TRACE_TYPING_WITH_COLOR
#define TURBOSHAFT_TRACE_TYPING_OK
#define TURBOSHAFT_TRACE_TYPING_FAIL
#endif  // DEBUG

namespace v8::internal {
class Factory;
}

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

namespace detail {

template <typename T>
inline bool is_unique_and_sorted(const T& container) {}

template <typename T>
inline bool is_minus_zero(T value) {}

template <typename T>
inline bool is_float_special_value(T value) {}

template <size_t Bits>
struct TypeForBits;
template <>
struct TypeForBits<32> {};
template <>
struct TypeForBits<64> {};

// gcc versions < 9 may produce the following compilation error:
// > '<anonymous>' is used uninitialized in this function
// if Payload_Empty is initialized without any data, link to a relevant bug:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465
// A workaround is to add a dummy value which is zero initialized by default.
// More information as well as a sample reproducible code can be found at the
// comment section of this CL crrev.com/c/4057111
// TODO(nicohartmann@): Remove dummy once all platforms are using gcc >= 9.
struct Payload_Empty {};

template <typename T>
struct Payload_Range {};

template <typename T>
struct Payload_InlineSet {};

template <typename T>
struct Payload_OutlineSet {};

}  // namespace detail

template <typename T>
std::enable_if_t<std::is_floating_point<T>::value, T> next_smaller(T v) {}

template <typename T>
std::enable_if_t<std::is_floating_point<T>::value, T> next_larger(T v) {}

template <typename T>
std::enable_if_t<std::is_integral<T>::value, T> next_smaller(T v) {}

template <typename T>
std::enable_if_t<std::is_integral<T>::value, T> next_larger(T v) {}

uint_type;
float_type;
nan_v = detail::TypeForBits<Bits>::nan;

template <size_t Bits>
class WordType;
template <size_t Bits>
class FloatType;
class TupleType;

Word32Type;
Word64Type;
Float32Type;
Float64Type;

class V8_EXPORT_PRIVATE Type {};
static_assert;

template <size_t Bits>
class WordType : public Type {};

extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) WordType<32>;
extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) WordType<64>;

template <size_t Bits>
class FloatType : public Type {};

extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FloatType<32>;
extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FloatType<64>;

class TupleType : public Type {};

const Word32Type& Type::AsWord32() const {}

const Word64Type& Type::AsWord64() const {}

const Float32Type& Type::AsFloat32() const {}

const Float64Type& Type::AsFloat64() const {}

const TupleType& Type::AsTuple() const {}

inline std::ostream& operator<<(std::ostream& stream, Type::Kind kind) {}

inline std::ostream& operator<<(std::ostream& stream, const Type& type) {}

inline bool operator==(const Type& lhs, const Type& rhs) {}

inline bool operator!=(const Type& lhs, const Type& rhs) {}

template <>
struct fast_hash<Type> {};

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

#endif  // V8_COMPILER_TURBOSHAFT_TYPES_H_