MachineLocation.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/MC/MachineLocation.h --------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. // The MachineLocation class is used to represent a simple location in a machine
  14. // frame. Locations will be one of two forms; a register or an address formed
  15. // from a base address plus an offset. Register indirection can be specified by
  16. // explicitly passing an offset to the constructor.
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_MC_MACHINELOCATION_H
  19. #define LLVM_MC_MACHINELOCATION_H
  20. #include <cstdint>
  21. #include <cassert>
  22. namespace llvm {
  23. class MachineLocation {
  24. private:
  25. bool IsRegister = false; ///< True if location is a register.
  26. unsigned Register = 0; ///< gcc/gdb register number.
  27. public:
  28. enum : uint32_t {
  29. // The target register number for an abstract frame pointer. The value is
  30. // an arbitrary value that doesn't collide with any real target register.
  31. VirtualFP = ~0U
  32. };
  33. MachineLocation() = default;
  34. /// Create a direct register location.
  35. explicit MachineLocation(unsigned R, bool Indirect = false)
  36. : IsRegister(!Indirect), Register(R) {}
  37. bool operator==(const MachineLocation &Other) const {
  38. return IsRegister == Other.IsRegister && Register == Other.Register;
  39. }
  40. // Accessors.
  41. /// \return true iff this is a register-indirect location.
  42. bool isIndirect() const { return !IsRegister; }
  43. bool isReg() const { return IsRegister; }
  44. unsigned getReg() const { return Register; }
  45. void setIsRegister(bool Is) { IsRegister = Is; }
  46. void setRegister(unsigned R) { Register = R; }
  47. };
  48. inline bool operator!=(const MachineLocation &LHS, const MachineLocation &RHS) {
  49. return !(LHS == RHS);
  50. }
  51. } // end namespace llvm
  52. #endif // LLVM_MC_MACHINELOCATION_H
  53. #ifdef __GNUC__
  54. #pragma GCC diagnostic pop
  55. #endif