LLVM  13.0.0git
VEMCExpr.cpp
Go to the documentation of this file.
1 //===-- VEMCExpr.cpp - VE specific MC expression classes ------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the implementation of the assembly expression modifiers
10 // accepted by the VE architecture (e.g. "%hi", "%lo", ...).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "VEMCExpr.h"
15 #include "llvm/MC/MCAssembler.h"
16 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCSymbolELF.h"
19 #include "llvm/BinaryFormat/ELF.h"
20 
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "vemcexpr"
24 
26  MCContext &Ctx) {
27  return new (Ctx) VEMCExpr(Kind, Expr);
28 }
29 
30 void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
31 
32  bool closeParen = printVariantKind(OS, Kind);
33 
34  const MCExpr *Expr = getSubExpr();
35  Expr->print(OS, MAI);
36 
37  if (closeParen)
38  OS << ')';
39  printVariantKindSuffix(OS, Kind);
40 }
41 
43  switch (Kind) {
44  case VK_VE_None:
45  case VK_VE_REFLONG:
46  return false;
47 
48  case VK_VE_HI32:
49  case VK_VE_LO32:
50  case VK_VE_PC_HI32:
51  case VK_VE_PC_LO32:
52  case VK_VE_GOT_HI32:
53  case VK_VE_GOT_LO32:
54  case VK_VE_GOTOFF_HI32:
55  case VK_VE_GOTOFF_LO32:
56  case VK_VE_PLT_HI32:
57  case VK_VE_PLT_LO32:
58  case VK_VE_TLS_GD_HI32:
59  case VK_VE_TLS_GD_LO32:
60  case VK_VE_TPOFF_HI32:
61  case VK_VE_TPOFF_LO32:
62  // Use suffix for these variant kinds
63  return false;
64  }
65  return true;
66 }
67 
69  switch (Kind) {
70  case VK_VE_None:
71  case VK_VE_REFLONG:
72  break;
73  case VK_VE_HI32:
74  OS << "@hi";
75  break;
76  case VK_VE_LO32:
77  OS << "@lo";
78  break;
79  case VK_VE_PC_HI32:
80  OS << "@pc_hi";
81  break;
82  case VK_VE_PC_LO32:
83  OS << "@pc_lo";
84  break;
85  case VK_VE_GOT_HI32:
86  OS << "@got_hi";
87  break;
88  case VK_VE_GOT_LO32:
89  OS << "@got_lo";
90  break;
91  case VK_VE_GOTOFF_HI32:
92  OS << "@gotoff_hi";
93  break;
94  case VK_VE_GOTOFF_LO32:
95  OS << "@gotoff_lo";
96  break;
97  case VK_VE_PLT_HI32:
98  OS << "@plt_hi";
99  break;
100  case VK_VE_PLT_LO32:
101  OS << "@plt_lo";
102  break;
103  case VK_VE_TLS_GD_HI32:
104  OS << "@tls_gd_hi";
105  break;
106  case VK_VE_TLS_GD_LO32:
107  OS << "@tls_gd_lo";
108  break;
109  case VK_VE_TPOFF_HI32:
110  OS << "@tpoff_hi";
111  break;
112  case VK_VE_TPOFF_LO32:
113  OS << "@tpoff_lo";
114  break;
115  }
116 }
117 
120  .Case("hi", VK_VE_HI32)
121  .Case("lo", VK_VE_LO32)
122  .Case("pc_hi", VK_VE_PC_HI32)
123  .Case("pc_lo", VK_VE_PC_LO32)
124  .Case("got_hi", VK_VE_GOT_HI32)
125  .Case("got_lo", VK_VE_GOT_LO32)
126  .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
127  .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
128  .Case("plt_hi", VK_VE_PLT_HI32)
129  .Case("plt_lo", VK_VE_PLT_LO32)
130  .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
131  .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
132  .Case("tpoff_hi", VK_VE_TPOFF_HI32)
133  .Case("tpoff_lo", VK_VE_TPOFF_LO32)
135 }
136 
138  switch (Kind) {
139  default:
140  llvm_unreachable("Unhandled VEMCExpr::VariantKind");
141  case VK_VE_REFLONG:
142  return VE::fixup_ve_reflong;
143  case VK_VE_HI32:
144  return VE::fixup_ve_hi32;
145  case VK_VE_LO32:
146  return VE::fixup_ve_lo32;
147  case VK_VE_PC_HI32:
148  return VE::fixup_ve_pc_hi32;
149  case VK_VE_PC_LO32:
150  return VE::fixup_ve_pc_lo32;
151  case VK_VE_GOT_HI32:
152  return VE::fixup_ve_got_hi32;
153  case VK_VE_GOT_LO32:
154  return VE::fixup_ve_got_lo32;
155  case VK_VE_GOTOFF_HI32:
157  case VK_VE_GOTOFF_LO32:
159  case VK_VE_PLT_HI32:
160  return VE::fixup_ve_plt_hi32;
161  case VK_VE_PLT_LO32:
162  return VE::fixup_ve_plt_lo32;
163  case VK_VE_TLS_GD_HI32:
165  case VK_VE_TLS_GD_LO32:
167  case VK_VE_TPOFF_HI32:
169  case VK_VE_TPOFF_LO32:
171  }
172 }
173 
175  const MCAsmLayout *Layout,
176  const MCFixup *Fixup) const {
177  return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
178 }
179 
181  switch (Expr->getKind()) {
182  case MCExpr::Target:
183  llvm_unreachable("Can't handle nested target expr!");
184  break;
185 
186  case MCExpr::Constant:
187  break;
188 
189  case MCExpr::Binary: {
190  const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
193  break;
194  }
195 
196  case MCExpr::SymbolRef: {
197  // We're known to be under a TLS fixup, so any symbol should be
198  // modified. There should be only one.
199  const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
200  cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
201  break;
202  }
203 
204  case MCExpr::Unary:
205  fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
206  break;
207  }
208 }
209 
210 void VEMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
211  Streamer.visitUsedExpr(*getSubExpr());
212 }
213 
215  switch (getKind()) {
216  default:
217  return;
218  case VK_VE_TLS_GD_HI32:
219  case VK_VE_TLS_GD_LO32:
220  case VK_VE_TPOFF_HI32:
221  case VK_VE_TPOFF_LO32:
222  break;
223  }
225 }
llvm::VE::fixup_ve_reflong
@ fixup_ve_reflong
fixup_ve_reflong - 32-bit fixup corresponding to foo
Definition: VEFixupKinds.h:18
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm::EngineKind::Kind
Kind
Definition: ExecutionEngine.h:524
llvm::VE::fixup_ve_plt_hi32
@ fixup_ve_plt_hi32
fixup_ve_plt_hi32/lo32
Definition: VEFixupKinds.h:45
llvm::VEMCExpr::getSubExpr
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this expression.
Definition: VEMCExpr.h:65
llvm::MCStreamer::visitUsedExpr
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:1046
llvm::VE::fixup_ve_pc_lo32
@ fixup_ve_pc_lo32
fixup_ve_pc_lo32 - 32-bit fixup corresponding to foo@pc_lo
Definition: VEFixupKinds.h:30
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::VEMCExpr::VK_VE_PLT_HI32
@ VK_VE_PLT_HI32
Definition: VEMCExpr.h:36
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::VEMCExpr::VariantKind
VariantKind
Definition: VEMCExpr.h:25
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::VEMCExpr::VK_VE_REFLONG
@ VK_VE_REFLONG
Definition: VEMCExpr.h:27
llvm::VEMCExpr::VK_VE_None
@ VK_VE_None
Definition: VEMCExpr.h:26
llvm::VE::fixup_ve_pc_hi32
@ fixup_ve_pc_hi32
fixup_ve_pc_hi32 - 32-bit fixup corresponding to foo@pc_hi
Definition: VEFixupKinds.h:27
MCAssembler.h
llvm::VEMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: VEMCExpr.cpp:174
llvm::VE::fixup_ve_tls_gd_lo32
@ fixup_ve_tls_gd_lo32
Definition: VEFixupKinds.h:50
llvm::VEMCExpr::VK_VE_PC_HI32
@ VK_VE_PC_HI32
Definition: VEMCExpr.h:30
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:477
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1095
llvm::VE::Fixups
Fixups
Definition: VEFixupKinds.h:16
llvm::MCExpr::evaluateAsRelocatable
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:762
llvm::VEMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: VEMCExpr.cpp:30
MCObjectStreamer.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::VEMCExpr::VK_VE_GOT_LO32
@ VK_VE_GOT_LO32
Definition: VEMCExpr.h:33
llvm::VEMCExpr::VK_VE_PLT_LO32
@ VK_VE_PLT_LO32
Definition: VEMCExpr.h:37
ELF.h
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
MCSymbolELF.h
MCContext.h
llvm::VEMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: VEMCExpr.cpp:210
llvm::MCBinaryExpr::getRHS
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:627
llvm::VEMCExpr
Definition: VEMCExpr.h:23
llvm::VE::fixup_ve_lo32
@ fixup_ve_lo32
fixup_ve_lo32 - 32-bit fixup corresponding to foo@lo
Definition: VEFixupKinds.h:24
llvm::VEMCExpr::create
static const VEMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: VEMCExpr.cpp:25
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:395
llvm::VEMCExpr::VK_VE_LO32
@ VK_VE_LO32
Definition: VEMCExpr.h:29
llvm::VEMCExpr::getKind
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: VEMCExpr.h:62
llvm::MCExpr::getKind
ExprKind getKind() const
Definition: MCExpr.h:81
llvm::VEMCExpr::VK_VE_TLS_GD_LO32
@ VK_VE_TLS_GD_LO32
Definition: VEMCExpr.h:39
llvm::MCExpr::Binary
@ Binary
Binary expressions.
Definition: MCExpr.h:38
llvm::VEMCExpr::VK_VE_GOT_HI32
@ VK_VE_GOT_HI32
Definition: VEMCExpr.h:32
llvm::VEMCExpr::getFixupKind
VE::Fixups getFixupKind() const
getFixupKind - Get the fixup kind of this expression.
Definition: VEMCExpr.h:68
llvm::VEMCExpr::VK_VE_PC_LO32
@ VK_VE_PC_LO32
Definition: VEMCExpr.h:31
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::VEMCExpr::VK_VE_GOTOFF_LO32
@ VK_VE_GOTOFF_LO32
Definition: VEMCExpr.h:35
llvm::VE::fixup_ve_tls_gd_hi32
@ fixup_ve_tls_gd_hi32
fixups for Thread Local Storage
Definition: VEFixupKinds.h:49
llvm::VEMCExpr::printVariantKindSuffix
static void printVariantKindSuffix(raw_ostream &OS, VariantKind Kind)
Definition: VEMCExpr.cpp:68
llvm::VE::fixup_ve_gotoff_lo32
@ fixup_ve_gotoff_lo32
fixup_ve_gotoff_lo32 - 32-bit fixup corresponding to foo@gotoff_lo
Definition: VEFixupKinds.h:42
llvm::VEMCExpr::VK_VE_TPOFF_HI32
@ VK_VE_TPOFF_HI32
Definition: VEMCExpr.h:40
llvm::VE::fixup_ve_gotoff_hi32
@ fixup_ve_gotoff_hi32
fixup_ve_gotoff_hi32 - 32-bit fixup corresponding to foo@gotoff_hi
Definition: VEFixupKinds.h:39
llvm::VE::fixup_ve_hi32
@ fixup_ve_hi32
fixup_ve_hi32 - 32-bit fixup corresponding to foo@hi
Definition: VEFixupKinds.h:21
llvm::VE::fixup_ve_got_lo32
@ fixup_ve_got_lo32
fixup_ve_got_lo32 - 32-bit fixup corresponding to foo@got_lo
Definition: VEFixupKinds.h:36
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::VE::fixup_ve_got_hi32
@ fixup_ve_got_hi32
fixup_ve_got_hi32 - 32-bit fixup corresponding to foo@got_hi
Definition: VEFixupKinds.h:33
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:212
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:91
VEMCExpr.h
llvm::VE::fixup_ve_tpoff_lo32
@ fixup_ve_tpoff_lo32
Definition: VEFixupKinds.h:52
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::VEMCExpr::VK_VE_TLS_GD_HI32
@ VK_VE_TLS_GD_HI32
Definition: VEMCExpr.h:38
llvm::VEMCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: VEMCExpr.cpp:214
llvm::VEMCExpr::VK_VE_TPOFF_LO32
@ VK_VE_TPOFF_LO32
Definition: VEMCExpr.h:41
llvm::VE::fixup_ve_plt_lo32
@ fixup_ve_plt_lo32
Definition: VEFixupKinds.h:46
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
llvm::MCExpr::SymbolRef
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:40
llvm::MCExpr::Unary
@ Unary
Unary expressions.
Definition: MCExpr.h:41
llvm::MCExpr::Constant
@ Constant
Constant expressions.
Definition: MCExpr.h:39
llvm::VEMCExpr::parseVariantKind
static VariantKind parseVariantKind(StringRef name)
Definition: VEMCExpr.cpp:118
llvm::VEMCExpr::printVariantKind
static bool printVariantKind(raw_ostream &OS, VariantKind Kind)
Definition: VEMCExpr.cpp:42
fixELFSymbolsInTLSFixupsImpl
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
Definition: VEMCExpr.cpp:180
llvm::VE::fixup_ve_tpoff_hi32
@ fixup_ve_tpoff_hi32
Definition: VEFixupKinds.h:51
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::VEMCExpr::VK_VE_HI32
@ VK_VE_HI32
Definition: VEMCExpr.h:28
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:81
llvm::VEMCExpr::VK_VE_GOTOFF_HI32
@ VK_VE_GOTOFF_HI32
Definition: VEMCExpr.h:34
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCBinaryExpr::getLHS
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:624