llvm/llvm/include/llvm/CodeGen/MIRYamlMapping.h

//===- MIRYamlMapping.h - Describe mapping between MIR and YAML--*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the mapping between various MIR data structures and
// their corresponding YAML representation.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_MIRYAMLMAPPING_H
#define LLVM_CODEGEN_MIRYAMLMAPPING_H

#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

namespace llvm {
namespace yaml {

/// A wrapper around std::string which contains a source range that's being
/// set during parsing.
struct StringValue {};

template <> struct ScalarTraits<StringValue> {};

struct FlowStringValue : StringValue {};

template <> struct ScalarTraits<FlowStringValue> {};

struct BlockStringValue {};

template <> struct BlockScalarTraits<BlockStringValue> {};

/// A wrapper around unsigned which contains a source range that's being set
/// during parsing.
struct UnsignedValue {};

template <> struct ScalarTraits<UnsignedValue> {};

template <> struct ScalarEnumerationTraits<MachineJumpTableInfo::JTEntryKind> {};

template <> struct ScalarTraits<MaybeAlign> {};

template <> struct ScalarTraits<Align> {};

} // end namespace yaml
} // end namespace llvm

LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue)
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::FlowStringValue)
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::UnsignedValue)

namespace llvm {
namespace yaml {

struct VirtualRegisterDefinition {};

template <> struct MappingTraits<VirtualRegisterDefinition> {};

struct MachineFunctionLiveIn {};

template <> struct MappingTraits<MachineFunctionLiveIn> {};

/// Serializable representation of stack object from the MachineFrameInfo class.
///
/// The flags 'isImmutable' and 'isAliased' aren't serialized, as they are
/// determined by the object's type and frame information flags.
/// Dead stack objects aren't serialized.
///
/// The 'isPreallocated' flag is determined by the local offset.
struct MachineStackObject {};

template <> struct ScalarEnumerationTraits<MachineStackObject::ObjectType> {};

template <> struct MappingTraits<MachineStackObject> {};

/// Serializable representation of the MCRegister variant of
/// MachineFunction::VariableDbgInfo.
struct EntryValueObject {};

template <> struct MappingTraits<EntryValueObject> {};

/// Serializable representation of the fixed stack object from the
/// MachineFrameInfo class.
struct FixedMachineStackObject {};

template <>
struct ScalarEnumerationTraits<FixedMachineStackObject::ObjectType> {};

template <>
struct ScalarEnumerationTraits<TargetStackID::Value> {};

template <> struct MappingTraits<FixedMachineStackObject> {};

/// A serializaable representation of a reference to a stack object or fixed
/// stack object.
struct FrameIndex {};

template <> struct ScalarTraits<FrameIndex> {};

/// Serializable representation of CallSiteInfo.
struct CallSiteInfo {};

template <> struct MappingTraits<CallSiteInfo::ArgRegPair> {};
}
}

LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo::ArgRegPair)

namespace llvm {
namespace yaml {

template <> struct MappingTraits<CallSiteInfo> {};

/// Serializable representation of debug value substitutions.
struct DebugValueSubstitution {};

template <> struct MappingTraits<DebugValueSubstitution> {};
} // namespace yaml
} // namespace llvm

LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::DebugValueSubstitution)

namespace llvm {
namespace yaml {
struct MachineConstantPoolValue {};

template <> struct MappingTraits<MachineConstantPoolValue> {};

struct MachineJumpTable {};

template <> struct MappingTraits<MachineJumpTable::Entry> {};

} // end namespace yaml
} // end namespace llvm

LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineFunctionLiveIn)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::VirtualRegisterDefinition)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineStackObject)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::EntryValueObject)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::FixedMachineStackObject)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineConstantPoolValue)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)

namespace llvm {
namespace yaml {

template <> struct MappingTraits<MachineJumpTable> {};

/// Serializable representation of MachineFrameInfo.
///
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
/// 'RealignOption' as they are determined by the target and LLVM function
/// attributes.
/// It also doesn't serialize attributes like 'NumFixedObject' and
/// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
struct MachineFrameInfo {};

template <> struct MappingTraits<MachineFrameInfo> {};

/// Targets should override this in a way that mirrors the implementation of
/// llvm::MachineFunctionInfo.
struct MachineFunctionInfo {};

template <> struct MappingTraits<std::unique_ptr<MachineFunctionInfo>> {};

struct MachineFunction {};

template <> struct MappingTraits<MachineFunction> {};

} // end namespace yaml
} // end namespace llvm

#endif // LLVM_CODEGEN_MIRYAMLMAPPING_H