1*98e5ede6SSebastian Neubauer //===- MIRYamlMapping.cpp - Describe mapping between MIR and YAML ---------===// 2*98e5ede6SSebastian Neubauer // 3*98e5ede6SSebastian Neubauer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*98e5ede6SSebastian Neubauer // See https://llvm.org/LICENSE.txt for license information. 5*98e5ede6SSebastian Neubauer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*98e5ede6SSebastian Neubauer // 7*98e5ede6SSebastian Neubauer //===----------------------------------------------------------------------===// 8*98e5ede6SSebastian Neubauer // 9*98e5ede6SSebastian Neubauer // This file implements the mapping between various MIR data structures and 10*98e5ede6SSebastian Neubauer // their corresponding YAML representation. 11*98e5ede6SSebastian Neubauer // 12*98e5ede6SSebastian Neubauer //===----------------------------------------------------------------------===// 13*98e5ede6SSebastian Neubauer 14*98e5ede6SSebastian Neubauer #include "llvm/CodeGen/MIRYamlMapping.h" 15*98e5ede6SSebastian Neubauer #include "llvm/CodeGen/MachineFrameInfo.h" 16*98e5ede6SSebastian Neubauer #include "llvm/Support/Error.h" 17*98e5ede6SSebastian Neubauer #include "llvm/Support/FormatVariadic.h" 18*98e5ede6SSebastian Neubauer 19*98e5ede6SSebastian Neubauer using namespace llvm; 20*98e5ede6SSebastian Neubauer using namespace llvm::yaml; 21*98e5ede6SSebastian Neubauer FrameIndex(int FI,const llvm::MachineFrameInfo & MFI)22*98e5ede6SSebastian NeubauerFrameIndex::FrameIndex(int FI, const llvm::MachineFrameInfo &MFI) { 23*98e5ede6SSebastian Neubauer IsFixed = MFI.isFixedObjectIndex(FI); 24*98e5ede6SSebastian Neubauer if (IsFixed) 25*98e5ede6SSebastian Neubauer FI -= MFI.getObjectIndexBegin(); 26*98e5ede6SSebastian Neubauer this->FI = FI; 27*98e5ede6SSebastian Neubauer } 28*98e5ede6SSebastian Neubauer 29*98e5ede6SSebastian Neubauer // Returns the value and if the frame index is fixed or not. getFI(const llvm::MachineFrameInfo & MFI) const30*98e5ede6SSebastian NeubauerExpected<int> FrameIndex::getFI(const llvm::MachineFrameInfo &MFI) const { 31*98e5ede6SSebastian Neubauer int FI = this->FI; 32*98e5ede6SSebastian Neubauer if (IsFixed) { 33*98e5ede6SSebastian Neubauer if (unsigned(FI) >= MFI.getNumFixedObjects()) 34*98e5ede6SSebastian Neubauer return make_error<StringError>( 35*98e5ede6SSebastian Neubauer formatv("invalid fixed frame index {0}", FI).str(), 36*98e5ede6SSebastian Neubauer inconvertibleErrorCode()); 37*98e5ede6SSebastian Neubauer FI += MFI.getObjectIndexBegin(); 38*98e5ede6SSebastian Neubauer } 39*98e5ede6SSebastian Neubauer if (unsigned(FI + MFI.getNumFixedObjects()) >= MFI.getNumObjects()) 40*98e5ede6SSebastian Neubauer return make_error<StringError>(formatv("invalid frame index {0}", FI).str(), 41*98e5ede6SSebastian Neubauer inconvertibleErrorCode()); 42*98e5ede6SSebastian Neubauer return FI; 43*98e5ede6SSebastian Neubauer } 44