LLVM  14.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"
17 
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "hexagon-mcexpr"
21 
23  return new (Ctx) HexagonMCExpr(Expr);
24 }
25 
27  MCAsmLayout const *Layout,
28  MCFixup const *Fixup) const {
29  return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
30 }
31 
33  Streamer.visitUsedExpr(*Expr);
34 }
35 
37  return Expr->findAssociatedFragment();
38 }
39 
40 static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
41  switch (Expr->getKind()) {
42  case MCExpr::Target:
43  llvm_unreachable("Cannot handle nested target MCExpr");
44  break;
45  case MCExpr::Constant:
46  break;
47 
48  case MCExpr::Binary: {
49  const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
52  break;
53  }
54  case MCExpr::SymbolRef: {
55  const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
56  switch (symRef.getKind()) {
57  default:
58  return;
66  break;
67  }
68  cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
69  break;
70  }
71  case MCExpr::Unary:
72  fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
73  break;
74  }
75 }
76 
78  auto expr = getExpr();
80 }
81 
82 MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
83 
85  assert((!Val || !MustNotExtend) && "Extension contradiction");
86  MustExtend = Val;
87 }
88 
89 bool HexagonMCExpr::mustExtend() const { return MustExtend; }
91  assert((!Val || !MustExtend) && "Extension contradiction");
92  MustNotExtend = Val;
93 }
94 bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
95 
96 bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
98  S27_2_reloc = Val;
99 }
100 
102  return E->getKind() == MCExpr::Target;
103 }
104 
105 HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
106  : Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
107  SignMismatch(false) {}
108 
109 void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
110  Expr->print(OS, MAI);
111 }
112 
114  SignMismatch = Val;
115 }
116 
118  return SignMismatch;
119 }
llvm::MCSymbolRefExpr::getKind
VariantKind getKind() const
Definition: MCExpr.h:399
llvm::MCStreamer::visitUsedExpr
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:1059
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::HexagonMCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: HexagonMCExpr.cpp:36
llvm::HexagonMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: HexagonMCExpr.cpp:109
llvm::MCSymbolRefExpr::VK_Hexagon_LD_PLT
@ VK_Hexagon_LD_PLT
Definition: MCExpr.h:323
llvm::HexagonMCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: HexagonMCExpr.cpp:77
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
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:322
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1156
llvm::HexagonMCExpr::mustExtend
bool mustExtend() const
Definition: HexagonMCExpr.cpp:89
fixELFSymbolsInTLSFixupsImpl
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
Definition: HexagonMCExpr.cpp:40
llvm::HexagonMCExpr::classof
static bool classof(MCExpr const *E)
Definition: HexagonMCExpr.cpp:101
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:479
llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT
@ VK_Hexagon_GD_GOT
Definition: MCExpr.h:320
llvm::HexagonMCExpr
Definition: HexagonMCExpr.h:15
llvm::HexagonMCExpr::getExpr
const MCExpr * getExpr() const
Definition: HexagonMCExpr.cpp:82
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:745
llvm::HexagonMCExpr::signMismatch
bool signMismatch() const
Definition: HexagonMCExpr.cpp:117
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
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:96
MCContext.h
llvm::HexagonMCExpr::create
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
Definition: HexagonMCExpr.cpp:22
false
Definition: StackSlotColoring.cpp:142
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:53
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:397
llvm::HexagonMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: HexagonMCExpr.cpp:32
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:113
llvm::HexagonMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: HexagonMCExpr.cpp:26
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::HexagonMCExpr::setMustNotExtend
void setMustNotExtend(bool Val=true)
Definition: HexagonMCExpr.cpp:90
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:235
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::HexagonMCExpr::setS27_2_reloc
void setS27_2_reloc(bool Val=true)
Definition: HexagonMCExpr.cpp:97
llvm::HexagonMCExpr::mustNotExtend
bool mustNotExtend() const
Definition: HexagonMCExpr.cpp:94
llvm::MCSymbolRefExpr::VK_TPREL
@ VK_TPREL
Definition: MCExpr.h:355
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT
@ VK_Hexagon_IE_GOT
Definition: MCExpr.h:325
MCValue.h
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
MCStreamer.h
llvm::MCExpr::Constant
@ Constant
Constant expressions.
Definition: MCExpr.h:39
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
raw_ostream.h
llvm::MCSymbolRefExpr::VK_Hexagon_IE
@ VK_Hexagon_IE
Definition: MCExpr.h:324
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:84
llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT
@ VK_Hexagon_LD_GOT
Definition: MCExpr.h:321
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35