LLVM API Documentation

MachineLocation.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MachineLocation.h -------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 // The MachineLocation class is used to represent a simple location in a machine
00010 // frame.  Locations will be one of two forms; a register or an address formed
00011 // from a base address plus an offset.  Register indirection can be specified by
00012 // explicitly passing an offset to the constructor.
00013 //===----------------------------------------------------------------------===//
00014 
00015 
00016 #ifndef LLVM_MC_MACHINELOCATION_H
00017 #define LLVM_MC_MACHINELOCATION_H
00018 
00019 #include "llvm/Support/Compiler.h"
00020 #include "llvm/Support/DataTypes.h"
00021 
00022 namespace llvm {
00023   class MCSymbol;
00024 
00025 class MachineLocation {
00026 private:
00027   bool IsRegister;                      // True if location is a register.
00028   unsigned Register;                    // gcc/gdb register number.
00029   int Offset;                           // Displacement if not register.
00030 public:
00031   enum : uint32_t {
00032     // The target register number for an abstract frame pointer. The value is
00033     // an arbitrary value that doesn't collide with any real target register.
00034     VirtualFP = ~0U
00035   };
00036   MachineLocation()
00037     : IsRegister(false), Register(0), Offset(0) {}
00038   /// Create a direct register location.
00039   explicit MachineLocation(unsigned R)
00040     : IsRegister(true), Register(R), Offset(0) {}
00041   /// Create a register-indirect location with an offset.
00042   MachineLocation(unsigned R, int O)
00043     : IsRegister(false), Register(R), Offset(O) {}
00044 
00045   bool operator==(const MachineLocation &Other) const {
00046       return IsRegister == Other.IsRegister && Register == Other.Register &&
00047         Offset == Other.Offset;
00048   }
00049 
00050   // Accessors.
00051   /// \return true iff this is a register-indirect location.
00052   bool isIndirect()      const { return !IsRegister; }
00053   bool isReg()           const { return IsRegister; }
00054   unsigned getReg()      const { return Register; }
00055   int getOffset()        const { return Offset; }
00056   void setIsRegister(bool Is)  { IsRegister = Is; }
00057   void setRegister(unsigned R) { Register = R; }
00058   void setOffset(int O)        { Offset = O; }
00059   /// Make this location a direct register location.
00060   void set(unsigned R) {
00061     IsRegister = true;
00062     Register = R;
00063     Offset = 0;
00064   }
00065   /// Make this location a register-indirect+offset location.
00066   void set(unsigned R, int O) {
00067     IsRegister = false;
00068     Register = R;
00069     Offset = O;
00070   }
00071 
00072 #ifndef NDEBUG
00073   void dump();
00074 #endif
00075 };
00076 
00077 inline bool operator!=(const MachineLocation &LHS, const MachineLocation &RHS) {
00078   return !(LHS == RHS);
00079 }
00080 
00081 } // End llvm namespace
00082 
00083 #endif