]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/include/llvm/MC/MachineLocation.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / include / llvm / MC / MachineLocation.h
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 // 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   /// Create a direct register location.
41   explicit MachineLocation(unsigned R)
42     : IsRegister(true), Register(R), Offset(0) {}
43   /// Create a register-indirect location with an offset.
44   MachineLocation(unsigned R, int O)
45     : IsRegister(false), Register(R), Offset(O) {}
46
47   bool operator==(const MachineLocation &Other) const {
48       return IsRegister == Other.IsRegister && Register == Other.Register &&
49         Offset == Other.Offset;
50   }
51
52   // Accessors
53   bool isIndirect()      const { return !IsRegister; }
54   bool isReg()           const { return IsRegister; }
55   unsigned getReg()      const { return Register; }
56   int getOffset()        const { return Offset; }
57   void setIsRegister(bool Is)  { IsRegister = Is; }
58   void setRegister(unsigned R) { Register = R; }
59   void setOffset(int O)        { Offset = O; }
60   /// Make this location a direct register location.
61   void set(unsigned R) {
62     IsRegister = true;
63     Register = R;
64     Offset = 0;
65   }
66   /// Make this location a register-indirect+offset location.
67   void set(unsigned R, int O) {
68     IsRegister = false;
69     Register = R;
70     Offset = O;
71   }
72
73 #ifndef NDEBUG
74   void dump();
75 #endif
76 };
77
78 /// MachineMove - This class represents the save or restore of a callee saved
79 /// register that exception or debug info needs to know about.
80 class MachineMove {
81 private:
82   /// Label - Symbol for post-instruction address when result of move takes
83   /// effect.
84   MCSymbol *Label;
85
86   // Move to & from location.
87   MachineLocation Destination, Source;
88 public:
89   MachineMove() : Label(0) {}
90
91   MachineMove(MCSymbol *label, const MachineLocation &D,
92               const MachineLocation &S)
93   : Label(label), Destination(D), Source(S) {}
94
95   // Accessors
96   MCSymbol *getLabel()                    const { return Label; }
97   const MachineLocation &getDestination() const { return Destination; }
98   const MachineLocation &getSource()      const { return Source; }
99 };
100
101 } // End llvm namespace
102
103 #endif