LLVM 20.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"
16#include "llvm/MC/MCAssembler.h"
17#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCSymbolELF.h"
20#include "llvm/MC/MCValue.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "vemcexpr"
26
28 MCContext &Ctx) {
29 return new (Ctx) VEMCExpr(Kind, Expr);
30}
31
32void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
33
34 bool closeParen = printVariantKind(OS, Kind);
35
36 const MCExpr *Expr = getSubExpr();
37 Expr->print(OS, MAI);
38
39 if (closeParen)
40 OS << ')';
42}
43
45 switch (Kind) {
46 case VK_VE_None:
47 case VK_VE_REFLONG:
48 return false;
49
50 case VK_VE_HI32:
51 case VK_VE_LO32:
52 case VK_VE_PC_HI32:
53 case VK_VE_PC_LO32:
54 case VK_VE_GOT_HI32:
55 case VK_VE_GOT_LO32:
58 case VK_VE_PLT_HI32:
59 case VK_VE_PLT_LO32:
64 // Use suffix for these variant kinds
65 return false;
66 }
67 return true;
68}
69
71 switch (Kind) {
72 case VK_VE_None:
73 case VK_VE_REFLONG:
74 break;
75 case VK_VE_HI32:
76 OS << "@hi";
77 break;
78 case VK_VE_LO32:
79 OS << "@lo";
80 break;
81 case VK_VE_PC_HI32:
82 OS << "@pc_hi";
83 break;
84 case VK_VE_PC_LO32:
85 OS << "@pc_lo";
86 break;
87 case VK_VE_GOT_HI32:
88 OS << "@got_hi";
89 break;
90 case VK_VE_GOT_LO32:
91 OS << "@got_lo";
92 break;
94 OS << "@gotoff_hi";
95 break;
97 OS << "@gotoff_lo";
98 break;
99 case VK_VE_PLT_HI32:
100 OS << "@plt_hi";
101 break;
102 case VK_VE_PLT_LO32:
103 OS << "@plt_lo";
104 break;
106 OS << "@tls_gd_hi";
107 break;
109 OS << "@tls_gd_lo";
110 break;
111 case VK_VE_TPOFF_HI32:
112 OS << "@tpoff_hi";
113 break;
114 case VK_VE_TPOFF_LO32:
115 OS << "@tpoff_lo";
116 break;
117 }
118}
119
122 .Case("hi", VK_VE_HI32)
123 .Case("lo", VK_VE_LO32)
124 .Case("pc_hi", VK_VE_PC_HI32)
125 .Case("pc_lo", VK_VE_PC_LO32)
126 .Case("got_hi", VK_VE_GOT_HI32)
127 .Case("got_lo", VK_VE_GOT_LO32)
128 .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
129 .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
130 .Case("plt_hi", VK_VE_PLT_HI32)
131 .Case("plt_lo", VK_VE_PLT_LO32)
132 .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
133 .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
134 .Case("tpoff_hi", VK_VE_TPOFF_HI32)
135 .Case("tpoff_lo", VK_VE_TPOFF_LO32)
137}
138
140 switch (Kind) {
141 default:
142 llvm_unreachable("Unhandled VEMCExpr::VariantKind");
143 case VK_VE_REFLONG:
145 case VK_VE_HI32:
146 return VE::fixup_ve_hi32;
147 case VK_VE_LO32:
148 return VE::fixup_ve_lo32;
149 case VK_VE_PC_HI32:
151 case VK_VE_PC_LO32:
153 case VK_VE_GOT_HI32:
155 case VK_VE_GOT_LO32:
161 case VK_VE_PLT_HI32:
163 case VK_VE_PLT_LO32:
169 case VK_VE_TPOFF_HI32:
171 case VK_VE_TPOFF_LO32:
173 }
174}
175
177 const MCFixup *Fixup) const {
178 if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
179 return false;
180
181 Res =
182 MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
183
184 return true;
185}
186
187static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
188 switch (Expr->getKind()) {
189 case MCExpr::Target:
190 llvm_unreachable("Can't handle nested target expr!");
191 break;
192
193 case MCExpr::Constant:
194 break;
195
196 case MCExpr::Binary: {
197 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
200 break;
201 }
202
203 case MCExpr::SymbolRef: {
204 // We're known to be under a TLS fixup, so any symbol should be
205 // modified. There should be only one.
206 const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
207 cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
208 break;
209 }
210
211 case MCExpr::Unary:
212 fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
213 break;
214 }
215}
216
217void VEMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
218 Streamer.visitUsedExpr(*getSubExpr());
219}
220
222 switch (getKind()) {
223 default:
224 return;
227 case VK_VE_TPOFF_HI32:
228 case VK_VE_TPOFF_LO32:
229 break;
230 }
232}
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
PowerPC TLS Dynamic Call Fixup
static const char * name
Definition: SMEABIPass.cpp:50
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Binary assembler expressions.
Definition: MCExpr.h:488
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:635
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:638
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
@ Unary
Unary expressions.
Definition: MCExpr.h:40
@ Constant
Constant expressions.
Definition: MCExpr.h:38
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:39
@ Target
Target specific expression.
Definition: MCExpr.h:41
@ Binary
Binary expressions.
Definition: MCExpr.h:37
bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:788
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:40
ExprKind getKind() const
Definition: MCExpr.h:78
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
Streaming machine code generation interface.
Definition: MCStreamer.h:213
void visitUsedExpr(const MCExpr &Expr)
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:188
const MCSymbol & getSymbol() const
Definition: MCExpr.h:406
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:59
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
static VariantKind parseVariantKind(StringRef name)
Definition: VEMCExpr.cpp:120
static void printVariantKindSuffix(raw_ostream &OS, VariantKind Kind)
Definition: VEMCExpr.cpp:70
static const VEMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: VEMCExpr.cpp:27
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override
Definition: VEMCExpr.cpp:176
VE::Fixups getFixupKind() const
getFixupKind - Get the fixup kind of this expression.
Definition: VEMCExpr.h:68
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: VEMCExpr.cpp:217
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: VEMCExpr.h:62
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this expression.
Definition: VEMCExpr.h:65
static bool printVariantKind(raw_ostream &OS, VariantKind Kind)
Definition: VEMCExpr.cpp:44
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: VEMCExpr.cpp:221
@ VK_VE_TLS_GD_HI32
Definition: VEMCExpr.h:38
@ VK_VE_TPOFF_HI32
Definition: VEMCExpr.h:40
@ VK_VE_TPOFF_LO32
Definition: VEMCExpr.h:41
@ VK_VE_TLS_GD_LO32
Definition: VEMCExpr.h:39
@ VK_VE_GOTOFF_HI32
Definition: VEMCExpr.h:34
@ VK_VE_GOTOFF_LO32
Definition: VEMCExpr.h:35
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: VEMCExpr.cpp:32
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ STT_TLS
Definition: ELF.h:1357
@ fixup_ve_tpoff_hi32
Definition: VEFixupKinds.h:54
@ fixup_ve_plt_lo32
Definition: VEFixupKinds.h:49
@ fixup_ve_got_hi32
fixup_ve_got_hi32 - 32-bit fixup corresponding to foo@got_hi
Definition: VEFixupKinds.h:36
@ fixup_ve_gotoff_hi32
fixup_ve_gotoff_hi32 - 32-bit fixup corresponding to foo@gotoff_hi
Definition: VEFixupKinds.h:42
@ fixup_ve_got_lo32
fixup_ve_got_lo32 - 32-bit fixup corresponding to foo@got_lo
Definition: VEFixupKinds.h:39
@ fixup_ve_pc_hi32
fixup_ve_pc_hi32 - 32-bit fixup corresponding to foo@pc_hi
Definition: VEFixupKinds.h:30
@ fixup_ve_lo32
fixup_ve_lo32 - 32-bit fixup corresponding to foo@lo
Definition: VEFixupKinds.h:27
@ fixup_ve_gotoff_lo32
fixup_ve_gotoff_lo32 - 32-bit fixup corresponding to foo@gotoff_lo
Definition: VEFixupKinds.h:45
@ fixup_ve_hi32
fixup_ve_hi32 - 32-bit fixup corresponding to foo@hi
Definition: VEFixupKinds.h:24
@ fixup_ve_pc_lo32
fixup_ve_pc_lo32 - 32-bit fixup corresponding to foo@pc_lo
Definition: VEFixupKinds.h:33
@ fixup_ve_tpoff_lo32
Definition: VEFixupKinds.h:55
@ fixup_ve_plt_hi32
fixup_ve_plt_hi32/lo32
Definition: VEFixupKinds.h:48
@ fixup_ve_reflong
fixup_ve_reflong - 32-bit fixup corresponding to foo
Definition: VEFixupKinds.h:18
@ fixup_ve_tls_gd_lo32
Definition: VEFixupKinds.h:53
@ fixup_ve_tls_gd_hi32
fixups for Thread Local Storage
Definition: VEFixupKinds.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18