MIRYamlMapping.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MIRYamlMapping.h"
  14. #include "llvm/CodeGen/MachineFrameInfo.h"
  15. #include "llvm/Support/Error.h"
  16. #include "llvm/Support/FormatVariadic.h"
  17. using namespace llvm;
  18. using namespace llvm::yaml;
  19. FrameIndex::FrameIndex(int FI, const llvm::MachineFrameInfo &MFI) {
  20. IsFixed = MFI.isFixedObjectIndex(FI);
  21. if (IsFixed)
  22. FI -= MFI.getObjectIndexBegin();
  23. this->FI = FI;
  24. }
  25. // Returns the value and if the frame index is fixed or not.
  26. Expected<int> FrameIndex::getFI(const llvm::MachineFrameInfo &MFI) const {
  27. int FI = this->FI;
  28. if (IsFixed) {
  29. if (unsigned(FI) >= MFI.getNumFixedObjects())
  30. return make_error<StringError>(
  31. formatv("invalid fixed frame index {0}", FI).str(),
  32. inconvertibleErrorCode());
  33. FI += MFI.getObjectIndexBegin();
  34. }
  35. if (unsigned(FI + MFI.getNumFixedObjects()) >= MFI.getNumObjects())
  36. return make_error<StringError>(formatv("invalid frame index {0}", FI).str(),
  37. inconvertibleErrorCode());
  38. return FI;
  39. }