[LPM] Group the addPreserved template with the non-template variants,
[oota-llvm.git] / include / llvm / MC / MCValue.h
1 //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- 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 //
10 // This file contains the declaration of the MCValue class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCVALUE_H
15 #define LLVM_MC_MCVALUE_H
16
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <cassert>
21
22 namespace llvm {
23 class MCAsmInfo;
24 class raw_ostream;
25
26 /// \brief This represents an "assembler immediate".
27 ///
28 ///  In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
29 ///  imm64)".  Not all targets supports relocations of this general form, but we
30 ///  need to represent this anyway.
31 ///
32 /// In general both SymbolA and SymbolB will also have a modifier
33 /// analogous to the top-level Kind. Current targets are not expected
34 /// to make use of both though. The choice comes down to whether
35 /// relocation modifiers apply to the closest symbol or the whole
36 /// expression.
37 ///
38 /// In the general form, SymbolB can only be defined if SymbolA is, and both
39 /// must be in the same (non-external) section. The latter constraint is not
40 /// enforced, since a symbol's section may not be known at construction.
41 ///
42 /// Note that this class must remain a simple POD value class, because we need
43 /// it to live in unions etc.
44 class MCValue {
45   const MCSymbolRefExpr *SymA, *SymB;
46   int64_t Cst;
47   uint32_t RefKind;
48 public:
49
50   int64_t getConstant() const { return Cst; }
51   const MCSymbolRefExpr *getSymA() const { return SymA; }
52   const MCSymbolRefExpr *getSymB() const { return SymB; }
53   uint32_t getRefKind() const { return RefKind; }
54
55   /// \brief Is this an absolute (as opposed to relocatable) value.
56   bool isAbsolute() const { return !SymA && !SymB; }
57
58   /// \brief Print the value to the stream \p OS.
59   void print(raw_ostream &OS) const;
60
61   /// \brief Print the value to stderr.
62   void dump() const;
63
64   MCSymbolRefExpr::VariantKind getAccessVariant() const;
65
66   static MCValue get(const MCSymbolRefExpr *SymA,
67                      const MCSymbolRefExpr *SymB = nullptr,
68                      int64_t Val = 0, uint32_t RefKind = 0) {
69     MCValue R;
70     assert((!SymB || SymA) && "Invalid relocatable MCValue!");
71     R.Cst = Val;
72     R.SymA = SymA;
73     R.SymB = SymB;
74     R.RefKind = RefKind;
75     return R;
76   }
77
78   static MCValue get(int64_t Val) {
79     MCValue R;
80     R.Cst = Val;
81     R.SymA = nullptr;
82     R.SymB = nullptr;
83     R.RefKind = 0;
84     return R;
85   }
86
87 };
88
89 } // end namespace llvm
90
91 #endif