[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / CodeGen / MIRYamlMapping.cpp
blobb1a538cad8a0d7d8b39a8a9981a2fe166782d724
1 //===- MIRYamlMapping.cpp - Describe mapping between MIR and YAML ---------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the mapping between various MIR data structures and
10 // their corresponding YAML representation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MIRYamlMapping.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/FormatVariadic.h"
19 using namespace llvm;
20 using namespace llvm::yaml;
22 FrameIndex::FrameIndex(int FI, const llvm::MachineFrameInfo &MFI) {
23 IsFixed = MFI.isFixedObjectIndex(FI);
24 if (IsFixed)
25 FI -= MFI.getObjectIndexBegin();
26 this->FI = FI;
29 // Returns the value and if the frame index is fixed or not.
30 Expected<int> FrameIndex::getFI(const llvm::MachineFrameInfo &MFI) const {
31 int FI = this->FI;
32 if (IsFixed) {
33 if (unsigned(FI) >= MFI.getNumFixedObjects())
34 return make_error<StringError>(
35 formatv("invalid fixed frame index {0}", FI).str(),
36 inconvertibleErrorCode());
37 FI += MFI.getObjectIndexBegin();
39 if (unsigned(FI + MFI.getNumFixedObjects()) >= MFI.getNumObjects())
40 return make_error<StringError>(formatv("invalid frame index {0}", FI).str(),
41 inconvertibleErrorCode());
42 return FI;