simplify some code.
[oota-llvm.git] / include / llvm / CodeGen / MachineLocation.h
1 //===-- llvm/CodeGen/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_CODEGEN_MACHINELOCATION_H
22 #define LLVM_CODEGEN_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 greater than TargetRegisterInfo::FirstVirtualRegister.
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   // Accessors
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   void set(unsigned R) {
53     IsRegister = true;
54     Register = R;
55     Offset = 0;
56   }
57   void set(unsigned R, int O) {
58     IsRegister = false;
59     Register = R;
60     Offset = O;
61   }
62
63 #ifndef NDEBUG
64   void dump();
65 #endif
66 };
67
68 /// MachineMove - This class represents the save or restore of a callee saved
69 /// register that exception or debug info needs to know about.
70 class MachineMove {
71 private:
72   /// Label - Symbol for post-instruction address when result of move takes
73   /// effect.
74   MCSymbol *Label;
75   
76   // Move to & from location.
77   MachineLocation Destination, Source;
78 public:
79   MachineMove() : Label(0) {}
80
81   MachineMove(MCSymbol *label, const MachineLocation &D,
82               const MachineLocation &S)
83   : Label(label), Destination(D), Source(S) {}
84   
85   // Accessors
86   MCSymbol *getLabel()                    const { return Label; }
87   const MachineLocation &getDestination() const { return Destination; }
88   const MachineLocation &getSource()      const { return Source; }
89 };
90
91 } // End llvm namespace
92
93 #endif