Home | History | Annotate | Download | only in MC
      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 // using an offset of zero.
     13 //
     14 // The MachineMove class is used to represent abstract move operations in the
     15 // prolog/epilog of a compiled function.  A collection of these objects can be
     16 // used by a debug consumer to track the location of values when unwinding stack
     17 // frames.
     18 //===----------------------------------------------------------------------===//
     19 
     20 
     21 #ifndef LLVM_MC_MACHINELOCATION_H
     22 #define LLVM_MC_MACHINELOCATION_H
     23 
     24 namespace llvm {
     25   class MCSymbol;
     26 
     27 class MachineLocation {
     28 private:
     29   bool IsRegister;                      // True if location is a register.
     30   unsigned Register;                    // gcc/gdb register number.
     31   int Offset;                           // Displacement if not register.
     32 public:
     33   enum {
     34     // The target register number for an abstract frame pointer. The value is
     35     // an arbitrary value that doesn't collide with any real target register.
     36     VirtualFP = ~0U
     37   };
     38   MachineLocation()
     39     : IsRegister(false), Register(0), Offset(0) {}
     40   explicit MachineLocation(unsigned R)
     41     : IsRegister(true), Register(R), Offset(0) {}
     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   bool isReg()           const { return IsRegister; }
     52   unsigned getReg()      const { return Register; }
     53   int getOffset()        const { return Offset; }
     54   void setIsRegister(bool Is)  { IsRegister = Is; }
     55   void setRegister(unsigned R) { Register = R; }
     56   void setOffset(int O)        { Offset = O; }
     57   void set(unsigned R) {
     58     IsRegister = true;
     59     Register = R;
     60     Offset = 0;
     61   }
     62   void set(unsigned R, int O) {
     63     IsRegister = false;
     64     Register = R;
     65     Offset = O;
     66   }
     67 
     68 #ifndef NDEBUG
     69   void dump();
     70 #endif
     71 };
     72 
     73 /// MachineMove - This class represents the save or restore of a callee saved
     74 /// register that exception or debug info needs to know about.
     75 class MachineMove {
     76 private:
     77   /// Label - Symbol for post-instruction address when result of move takes
     78   /// effect.
     79   MCSymbol *Label;
     80 
     81   // Move to & from location.
     82   MachineLocation Destination, Source;
     83 public:
     84   MachineMove() : Label(0) {}
     85 
     86   MachineMove(MCSymbol *label, const MachineLocation &D,
     87               const MachineLocation &S)
     88   : Label(label), Destination(D), Source(S) {}
     89 
     90   // Accessors
     91   MCSymbol *getLabel()                    const { return Label; }
     92   const MachineLocation &getDestination() const { return Destination; }
     93   const MachineLocation &getSource()      const { return Source; }
     94 };
     95 
     96 } // End llvm namespace
     97 
     98 #endif
     99