MachineLocation.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //===-- llvm/MC/MachineLocation.h -------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // The MachineLocation class is used to represent a simple location in a machine
  10. // frame. Locations will be one of two forms; a register or an address formed
  11. // from a base address plus an offset. Register indirection can be specified by
  12. // explicitly passing an offset to the constructor.
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_MC_MACHINELOCATION_H
  15. #define LLVM_MC_MACHINELOCATION_H
  16. #include "llvm/Support/Compiler.h"
  17. #include "llvm/Support/DataTypes.h"
  18. namespace llvm {
  19. class MCSymbol;
  20. class MachineLocation {
  21. private:
  22. bool IsRegister; // True if location is a register.
  23. unsigned Register; // gcc/gdb register number.
  24. int Offset; // Displacement if not register.
  25. public:
  26. enum : uint32_t {
  27. // The target register number for an abstract frame pointer. The value is
  28. // an arbitrary value that doesn't collide with any real target register.
  29. VirtualFP = ~0U
  30. };
  31. MachineLocation()
  32. : IsRegister(false), Register(0), Offset(0) {}
  33. /// Create a direct register location.
  34. explicit MachineLocation(unsigned R)
  35. : IsRegister(true), Register(R), Offset(0) {}
  36. /// Create a register-indirect location with an offset.
  37. MachineLocation(unsigned R, int O)
  38. : IsRegister(false), Register(R), Offset(O) {}
  39. bool operator==(const MachineLocation &Other) const {
  40. return IsRegister == Other.IsRegister && Register == Other.Register &&
  41. Offset == Other.Offset;
  42. }
  43. // Accessors.
  44. /// \return true iff this is a register-indirect location.
  45. bool isIndirect() const { return !IsRegister; }
  46. bool isReg() const { return IsRegister; }
  47. unsigned getReg() const { return Register; }
  48. int getOffset() const { return Offset; }
  49. void setIsRegister(bool Is) { IsRegister = Is; }
  50. void setRegister(unsigned R) { Register = R; }
  51. void setOffset(int O) { Offset = O; }
  52. /// Make this location a direct register location.
  53. void set(unsigned R) {
  54. IsRegister = true;
  55. Register = R;
  56. Offset = 0;
  57. }
  58. /// Make this location a register-indirect+offset location.
  59. void set(unsigned R, int O) {
  60. IsRegister = false;
  61. Register = R;
  62. Offset = O;
  63. }
  64. #ifndef NDEBUG
  65. void dump();
  66. #endif
  67. };
  68. inline bool operator!=(const MachineLocation &LHS, const MachineLocation &RHS) {
  69. return !(LHS == RHS);
  70. }
  71. } // End llvm namespace
  72. #endif