LLVM  16.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"
11 #include "llvm/BinaryFormat/ELF.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"
16 #include "llvm/Support/Casting.h"
18 
19 using 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 
41 static 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;
46  case MCExpr::Constant:
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 
83 MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
84 
86  assert((!Val || !MustNotExtend) && "Extension contradiction");
87  MustExtend = Val;
88 }
89 
90 bool HexagonMCExpr::mustExtend() const { return MustExtend; }
92  assert((!Val || !MustExtend) && "Extension contradiction");
93  MustNotExtend = Val;
94 }
95 bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
96 
97 bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
99  S27_2_reloc = Val;
100 }
101 
103  return E->getKind() == MCExpr::Target;
104 }
105 
106 HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
107  : Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
108  SignMismatch(false) {}
109 
110 void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
111  Expr->print(OS, MAI);
112 }
113 
115  SignMismatch = Val;
116 }
117 
119  return SignMismatch;
120 }
llvm::MCSymbolRefExpr::getKind
VariantKind getKind() const
Definition: MCExpr.h:401
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1231
llvm::MCStreamer::visitUsedExpr
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:1070
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::HexagonMCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: HexagonMCExpr.cpp:37
llvm::HexagonMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: HexagonMCExpr.cpp:110
llvm::MCSymbolRefExpr::VK_Hexagon_LD_PLT
@ VK_Hexagon_LD_PLT
Definition: MCExpr.h:324
llvm::HexagonMCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: HexagonMCExpr.cpp:78
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
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::MCSymbolRefExpr::VK_Hexagon_GD_PLT
@ VK_Hexagon_GD_PLT
Definition: MCExpr.h:323
llvm::HexagonMCExpr::mustExtend
bool mustExtend() const
Definition: HexagonMCExpr.cpp:90
fixELFSymbolsInTLSFixupsImpl
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
Definition: HexagonMCExpr.cpp:41
llvm::HexagonMCExpr::classof
static bool classof(MCExpr const *E)
Definition: HexagonMCExpr.cpp:102
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:481
llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT
@ VK_Hexagon_GD_GOT
Definition: MCExpr.h:321
llvm::HexagonMCExpr
Definition: HexagonMCExpr.h:15
llvm::HexagonMCExpr::getExpr
const MCExpr * getExpr() const
Definition: HexagonMCExpr.cpp:83
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:749
llvm::HexagonMCExpr::signMismatch
bool signMismatch() const
Definition: HexagonMCExpr.cpp:118
llvm::MCFragment
Definition: MCFragment.h:30
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
ELF.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
MCSymbolELF.h
llvm::HexagonMCExpr::s27_2_reloc
bool s27_2_reloc() const
Definition: HexagonMCExpr.cpp:97
MCContext.h
llvm::HexagonMCExpr::create
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
Definition: HexagonMCExpr.cpp:23
false
Definition: StackSlotColoring.cpp:141
HexagonMCExpr.h
be
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can be
Definition: README.txt:14
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:399
llvm::HexagonMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: HexagonMCExpr.cpp:33
llvm::MCExpr::getKind
ExprKind getKind() const
Definition: MCExpr.h:81
llvm::MCExpr::Binary
@ Binary
Binary expressions.
Definition: MCExpr.h:38
llvm::HexagonMCExpr::setSignMismatch
void setSignMismatch(bool Val=true)
Definition: HexagonMCExpr.cpp:114
llvm::HexagonMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: HexagonMCExpr.cpp:27
llvm::MCAssembler
Definition: MCAssembler.h:73
llvm::HexagonMCExpr::setMustNotExtend
void setMustNotExtend(bool Val=true)
Definition: HexagonMCExpr.cpp:91
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:215
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::HexagonMCExpr::setS27_2_reloc
void setS27_2_reloc(bool Val=true)
Definition: HexagonMCExpr.cpp:98
llvm::HexagonMCExpr::mustNotExtend
bool mustNotExtend() const
Definition: HexagonMCExpr.cpp:95
llvm::MCSymbolRefExpr::VK_TPREL
@ VK_TPREL
Definition: MCExpr.h:357
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
Casting.h
llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT
@ VK_Hexagon_IE_GOT
Definition: MCExpr.h:326
MCValue.h
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
llvm::MCExpr::SymbolRef
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:40
llvm::MCExpr::Unary
@ Unary
Unary expressions.
Definition: MCExpr.h:41
MCStreamer.h
llvm::MCExpr::Constant
@ Constant
Constant expressions.
Definition: MCExpr.h:39
llvm::MCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:987
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
raw_ostream.h
llvm::MCSymbolRefExpr::VK_Hexagon_IE
@ VK_Hexagon_IE
Definition: MCExpr.h:325
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::HexagonMCExpr::setMustExtend
void setMustExtend(bool Val=true)
Definition: HexagonMCExpr.cpp:85
llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT
@ VK_Hexagon_LD_GOT
Definition: MCExpr.h:322
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35