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 15 #ifndef LLVM_MC_MACHINELOCATION_H 16 #define LLVM_MC_MACHINELOCATION_H 17 18 #include <cstdint> 19 20 namespace llvm { 21 22 class MachineLocation { 23 private: 24 bool IsRegister = false; // True if location is a register. 25 unsigned Register = 0; // gcc/gdb register number. 26 int Offset = 0; // Displacement if not register. 27 28 public: 29 enum : uint32_t { 30 // The target register number for an abstract frame pointer. The value is 31 // an arbitrary value that doesn't collide with any real target register. 32 VirtualFP = ~0U 33 }; 34 35 MachineLocation() = default; 36 /// Create a direct register location. 37 explicit MachineLocation(unsigned R) : IsRegister(true), Register(R) {} 38 /// Create a register-indirect location with an offset. 39 MachineLocation(unsigned R, int O) : Register(R), Offset(O) {} 40 41 bool operator==(const MachineLocation &Other) const { 42 return IsRegister == Other.IsRegister && Register == Other.Register && 43 Offset == Other.Offset; 44 } 45 46 // Accessors. 47 /// \return true iff this is a register-indirect location. 48 bool isIndirect() const { return !IsRegister; } 49 bool isReg() const { return IsRegister; } 50 unsigned getReg() const { return Register; } 51 int getOffset() const { return Offset; } 52 void setIsRegister(bool Is) { IsRegister = Is; } 53 void setRegister(unsigned R) { Register = R; } 54 void setOffset(int O) { Offset = O; } 55 56 /// Make this location a direct register location. 57 void set(unsigned R) { 58 IsRegister = true; 59 Register = R; 60 Offset = 0; 61 } 62 63 /// Make this location a register-indirect+offset location. 64 void set(unsigned R, int O) { 65 IsRegister = false; 66 Register = R; 67 Offset = O; 68 } 69 }; 70 71 inline bool operator!=(const MachineLocation &LHS, const MachineLocation &RHS) { 72 return !(LHS == RHS); 73 } 74 75 } // end namespace llvm 76 77 #endif // LLVM_MC_MACHINELOCATION_H 78