LLVM 19.0.0git
HexagonMCExpr.cpp
Go to the documentation of this file.
1//===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes
2//----------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#include "HexagonMCExpr.h"
12#include "llvm/MC/MCContext.h"
13#include "llvm/MC/MCStreamer.h"
14#include "llvm/MC/MCSymbolELF.h"
15#include "llvm/MC/MCValue.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "hexagon-mcexpr"
22
24 return new (Ctx) HexagonMCExpr(Expr);
25}
26
28 MCAsmLayout const *Layout,
29 MCFixup const *Fixup) const {
30 return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
31}
32
34 Streamer.visitUsedExpr(*Expr);
35}
36
38 return Expr->findAssociatedFragment();
39}
40
41static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
42 switch (Expr->getKind()) {
43 case MCExpr::Target:
44 llvm_unreachable("Cannot handle nested target MCExpr");
45 break;
47 break;
48
49 case MCExpr::Binary: {
50 const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
53 break;
54 }
55 case MCExpr::SymbolRef: {
56 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
57 switch (symRef.getKind()) {
58 default:
59 return;
67 break;
68 }
69 cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
70 break;
71 }
72 case MCExpr::Unary:
73 fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
74 break;
75 }
76}
77
79 auto expr = getExpr();
81}
82
83MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
84
86 assert((!Val || !MustNotExtend) && "Extension contradiction");
87 MustExtend = Val;
88}
89
90bool HexagonMCExpr::mustExtend() const { return MustExtend; }
92 assert((!Val || !MustExtend) && "Extension contradiction");
93 MustNotExtend = Val;
94}
95bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
96
97bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
99 S27_2_reloc = Val;
100}
101
102HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
103 : Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
104 SignMismatch(false) {}
105
107 Expr->print(OS, MAI);
108}
109
111 SignMismatch = Val;
112}
113
115 return SignMismatch;
116}
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
void setMustNotExtend(bool Val=true)
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
bool mustNotExtend() const
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
bool signMismatch() const
bool mustExtend() const
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
bool s27_2_reloc() const
void setMustExtend(bool Val=true)
MCFragment * findAssociatedFragment() const override
MCExpr const * getExpr() const
void setS27_2_reloc(bool Val=true)
void setSignMismatch(bool Val=true)
void visitUsedExpr(MCStreamer &Streamer) const override
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
Binary assembler expressions.
Definition: MCExpr.h:490
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:637
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:640
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
@ Unary
Unary expressions.
Definition: MCExpr.h:41
@ Constant
Constant expressions.
Definition: MCExpr.h:39
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:40
@ Target
Target specific expression.
Definition: MCExpr.h:42
@ Binary
Binary expressions.
Definition: MCExpr.h:38
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:810
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:1058
ExprKind getKind() const
Definition: MCExpr.h:81
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:212
void visitUsedExpr(const MCExpr &Expr)
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
const MCSymbol & getSymbol() const
Definition: MCExpr.h:408
VariantKind getKind() const
Definition: MCExpr.h:410
This represents an "assembler immediate".
Definition: MCValue.h:36
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:1326
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18