LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MipsBaseInfo.h
Go to the documentation of this file.
1 //===-- MipsBaseInfo.h - Top level definitions for MIPS MC ------*- 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 small standalone helper functions and enum definitions for
11 // the Mips target useful for the compiler back-end and the MC libraries.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef MIPSBASEINFO_H
15 #define MIPSBASEINFO_H
16 
17 #include "MipsFixupKinds.h"
18 #include "MipsMCTargetDesc.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/Support/DataTypes.h"
22 
23 namespace llvm {
24 
25 /// MipsII - This namespace holds all of the target specific flags that
26 /// instruction info tracks.
27 ///
28 namespace MipsII {
29  /// Target Operand Flag enum.
30  enum TOF {
31  //===------------------------------------------------------------------===//
32  // Mips Specific MachineOperand flags.
33 
35 
36  /// MO_GOT16 - Represents the offset into the global offset table at which
37  /// the address the relocation entry symbol resides during execution.
40 
41  /// MO_GOT_CALL - Represents the offset into the global offset table at
42  /// which the address of a call site relocation entry symbol resides
43  /// during execution. This is different from the above since this flag
44  /// can only be present in call instructions.
46 
47  /// MO_GPREL - Represents the offset from the current gp value to be used
48  /// for the relocatable object file being produced.
50 
51  /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
52  /// address.
55 
56  /// MO_TLSGD - Represents the offset into the global offset table at which
57  // the module ID and TSL block offset reside during execution (General
58  // Dynamic TLS).
60 
61  /// MO_TLSLDM - Represents the offset into the global offset table at which
62  // the module ID and TSL block offset reside during execution (Local
63  // Dynamic TLS).
67 
68  /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial
69  // Exec TLS).
71 
72  /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from
73  // the thread pointer (Local Exec TLS).
76 
77  // N32/64 Flags.
83 
84  /// MO_HIGHER/HIGHEST - Represents the highest or higher half word of a
85  /// 64-bit symbol address.
88 
89  /// MO_GOT_HI16/LO16, MO_CALL_HI16/LO16 - Relocations used for large GOTs.
94  };
95 
96  enum {
97  //===------------------------------------------------------------------===//
98  // Instruction encodings. These are the standard/most common forms for
99  // Mips instructions.
100  //
101 
102  // Pseudo - This represents an instruction that is a pseudo instruction
103  // or one that has not been implemented yet. It is illegal to code generate
104  // it, but tolerated for intermediate implementation stages.
105  Pseudo = 0,
106 
107  /// FrmR - This form is for instructions of the format R.
108  FrmR = 1,
109  /// FrmI - This form is for instructions of the format I.
110  FrmI = 2,
111  /// FrmJ - This form is for instructions of the format J.
112  FrmJ = 3,
113  /// FrmFR - This form is for instructions of the format FR.
114  FrmFR = 4,
115  /// FrmFI - This form is for instructions of the format FI.
116  FrmFI = 5,
117  /// FrmOther - This form is for instructions that have no specific format.
118  FrmOther = 6,
119 
120  FormMask = 15
121  };
122 }
123 
124 inline static std::pair<const MCSymbolRefExpr*, int64_t>
126  MCFixupKind FixupKind = Fixup.getKind();
127 
128  if ((FixupKind < FirstTargetFixupKind) ||
129  (FixupKind >= MCFixupKind(Mips::LastTargetFixupKind)))
130  return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
131 
132  const MCExpr *Expr = Fixup.getValue();
133  MCExpr::ExprKind Kind = Expr->getKind();
134 
135  if (Kind == MCExpr::Binary) {
136  const MCBinaryExpr *BE = static_cast<const MCBinaryExpr*>(Expr);
137  const MCExpr *LHS = BE->getLHS();
138  const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
139 
140  if ((LHS->getKind() != MCExpr::SymbolRef) || !CE)
141  return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
142 
143  return std::make_pair(cast<MCSymbolRefExpr>(LHS), CE->getValue());
144  }
145 
146  if (Kind != MCExpr::SymbolRef)
147  return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
148 
149  return std::make_pair(cast<MCSymbolRefExpr>(Expr), 0);
150 }
151 }
152 
153 #endif
FrmOther - This form is for instructions that have no specific format.
Definition: MipsBaseInfo.h:118
FrmFR - This form is for instructions of the format FR.
Definition: MipsBaseInfo.h:114
MO_TLSLDM - Represents the offset into the global offset table at which.
Definition: MipsBaseInfo.h:64
MO_GOT_HI16/LO16, MO_CALL_HI16/LO16 - Relocations used for large GOTs.
Definition: MipsBaseInfo.h:90
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
MO_TLSGD - Represents the offset into the global offset table at which.
Definition: MipsBaseInfo.h:59
FrmFI - This form is for instructions of the format FI.
Definition: MipsBaseInfo.h:116
ExprKind getKind() const
Definition: MCExpr.h:61
FrmJ - This form is for instructions of the format J.
Definition: MipsBaseInfo.h:112
FrmR - This form is for instructions of the format R.
Definition: MipsBaseInfo.h:108
const MCExpr * getLHS() const
getLHS - Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:477
const MCExpr * getValue() const
Definition: MCFixup.h:93
int64_t getValue() const
Definition: MCExpr.h:126
MCFixupKind
MCFixupKind - Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:22
MCFixupKind getKind() const
Definition: MCFixup.h:88
MCBinaryExpr - Binary assembler expressions.
Definition: MCExpr.h:356
MO_GOTTPREL - Represents the offset from the thread pointer (Initial.
Definition: MipsBaseInfo.h:70
static std::pair< const MCSymbolRefExpr *, int64_t > MipsGetSymAndOffset(const MCFixup &Fixup)
Definition: MipsBaseInfo.h:125
MO_TPREL_HI/LO - Represents the hi and low part of the offset from.
Definition: MipsBaseInfo.h:74
const MCExpr * getRHS() const
getRHS - Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:480
FrmI - This form is for instructions of the format I.
Definition: MipsBaseInfo.h:110
References to labels and assigned expressions.
Definition: MCExpr.h:36
TOF
Target Operand Flag enum.
Definition: MipsBaseInfo.h:30
Binary expressions.
Definition: MCExpr.h:34