chromium/v8/src/compiler/backend/instruction.h

// Copyright 2014 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_BACKEND_INSTRUCTION_H_
#define V8_COMPILER_BACKEND_INSTRUCTION_H_

#include <iosfwd>
#include <map>
#include <optional>

#include "src/base/compiler-specific.h"
#include "src/base/numbers/double.h"
#include "src/codegen/external-reference.h"
#include "src/codegen/register.h"
#include "src/codegen/source-position.h"
#include "src/common/globals.h"
#include "src/compiler/backend/instruction-codes.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/feedback-source.h"
#include "src/compiler/frame.h"
#include "src/compiler/opcodes.h"
#include "src/zone/zone-allocator.h"

namespace v8 {
namespace internal {

class RegisterConfiguration;

namespace compiler {

class Schedule;
class SourcePositionTable;

namespace turboshaft {
class Graph;
}

#if defined(V8_CC_MSVC) && defined(V8_TARGET_ARCH_IA32)
// MSVC on x86 has issues with ALIGNAS(8) on InstructionOperand, but does
// align the object to 8 bytes anyway (covered by a static assert below).
// See crbug.com/v8/10796
#define INSTRUCTION_OPERAND_ALIGN
#else
#define INSTRUCTION_OPERAND_ALIGN
#endif

class V8_EXPORT_PRIVATE INSTRUCTION_OPERAND_ALIGN InstructionOperand {}};

InstructionOperandVector;

std::ostream& operator<<(std::ostream&, const InstructionOperand&);

#define INSTRUCTION_OPERAND_CASTS

class UnallocatedOperand final : public InstructionOperand {};

class ConstantOperand : public InstructionOperand {};

class ImmediateOperand : public InstructionOperand {};

class PendingOperand : public InstructionOperand {};

class LocationOperand : public InstructionOperand {};

class AllocatedOperand : public LocationOperand {};

#undef INSTRUCTION_OPERAND_CASTS

bool InstructionOperand::IsAnyLocationOperand() const {}

bool InstructionOperand::IsLocationOperand() const {}

bool InstructionOperand::IsFPLocationOperand() const {}

bool InstructionOperand::IsAnyRegister() const {}

bool InstructionOperand::IsRegister() const {}

bool InstructionOperand::IsFPRegister() const {}

bool InstructionOperand::IsFloatRegister() const {}

bool InstructionOperand::IsDoubleRegister() const {}

bool InstructionOperand::IsSimd128Register() const {}

bool InstructionOperand::IsSimd256Register() const {}

bool InstructionOperand::IsAnyStackSlot() const {}

bool InstructionOperand::IsStackSlot() const {}

bool InstructionOperand::IsFPStackSlot() const {}

bool InstructionOperand::IsFloatStackSlot() const {}

bool InstructionOperand::IsDoubleStackSlot() const {}

bool InstructionOperand::IsSimd128StackSlot() const {}

bool InstructionOperand::IsSimd256StackSlot() const {}

uint64_t InstructionOperand::GetCanonicalizedValue() const {}

// Required for maps that don't care about machine type.
struct CompareOperandModuloType {};

class V8_EXPORT_PRIVATE MoveOperands final
    : public NON_EXPORTED_BASE(ZoneObject) {};

V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, const MoveOperands&);

class V8_EXPORT_PRIVATE ParallelMove final
    : public NON_EXPORTED_BASE(ZoneVector<MoveOperands*>),
      public NON_EXPORTED_BASE(ZoneObject) {};

std::ostream& operator<<(std::ostream&, const ParallelMove&);

// TODOC(dmercadier): what is a ReferenceMap exactly, what does it contain,
// when is it created, and what is it used for?
class ReferenceMap final : public ZoneObject {};

std::ostream& operator<<(std::ostream&, const ReferenceMap&);

class InstructionBlock;

class V8_EXPORT_PRIVATE Instruction final {};

std::ostream& operator<<(std::ostream&, const Instruction&);

class RpoNumber final {};

V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, const RpoNumber&);

class V8_EXPORT_PRIVATE Constant final {};

std::ostream& operator<<(std::ostream&, const Constant&);

// Forward declarations.
class FrameStateDescriptor;

enum class StateValueKind : uint8_t {};

std::ostream& operator<<(std::ostream& os, StateValueKind kind);

class StateValueDescriptor {};

class StateValueList {};

class FrameStateDescriptor : public ZoneObject {};

#if V8_ENABLE_WEBASSEMBLY
class JSToWasmFrameStateDescriptor : public FrameStateDescriptor {};
#endif  // V8_ENABLE_WEBASSEMBLY

// A deoptimization entry is a pair of the reason why we deoptimize and the
// frame state descriptor that we have to go back to.
class DeoptimizationEntry final {};

DeoptimizationVector;

class V8_EXPORT_PRIVATE PhiInstruction final
    : public NON_EXPORTED_BASE(ZoneObject) {};

// Analogue of BasicBlock for Instructions instead of Nodes.
class V8_EXPORT_PRIVATE InstructionBlock final
    : public NON_EXPORTED_BASE(ZoneObject) {};

class InstructionSequence;

struct PrintableInstructionBlock {};

std::ostream& operator<<(std::ostream&, const PrintableInstructionBlock&);

using ConstantMap = ZoneUnorderedMap</* virtual register */ int, Constant>;
Instructions;
ReferenceMaps;
InstructionBlocks;

// Represents architecture-specific generated code before, during, and after
// register allocation.
class V8_EXPORT_PRIVATE InstructionSequence final
    : public NON_EXPORTED_BASE(ZoneObject) {};

V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&,
                                           const InstructionSequence&);
#undef INSTRUCTION_OPERAND_ALIGN

// Constants for accessing ConditionalCompare data, shared between isel and
// codegen.
constexpr size_t kNumCcmpOperands =;
constexpr size_t kCcmpOffsetOfOpcode =;
constexpr size_t kCcmpOffsetOfLhs =;
constexpr size_t kCcmpOffsetOfRhs =;
constexpr size_t kCcmpOffsetOfDefaultFlags =;
constexpr size_t kCcmpOffsetOfCompareCondition =;
constexpr size_t kConditionalSetEndOffsetOfNumCcmps =;
constexpr size_t kConditionalSetEndOffsetOfCondition =;
constexpr size_t kBranchEndOffsetOfFalseBlock =;
constexpr size_t kBranchEndOffsetOfTrueBlock =;
constexpr size_t kConditionalBranchEndOffsetOfNumCcmps =;
constexpr size_t kConditionalBranchEndOffsetOfCondition =;

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_BACKEND_INSTRUCTION_H_