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