LLVM  9.0.0svn
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 }
void setMustExtend(bool Val=true)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
VariantKind getKind() const
Definition: MCExpr.h:337
bool s27_2_reloc() const
void setMustNotExtend(bool Val=true)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:563
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:73
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
MCFragment * findAssociatedFragment() const override
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:165
static bool classof(MCExpr const *E)
Context object for machine code objects.
Definition: MCContext.h:62
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:641
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:566
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Unary expressions.
Definition: MCExpr.h:41
void setS27_2_reloc(bool Val=true)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
Streaming machine code generation interface.
Definition: MCStreamer.h:188
MCExpr const * getExpr() const
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void setSignMismatch(bool Val=true)
Binary assembler expressions.
Definition: MCExpr.h:416
bool mustNotExtend() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool signMismatch() const
const MCSymbol & getSymbol() const
Definition: MCExpr.h:335
ExprKind getKind() const
Definition: MCExpr.h:72
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:861
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:929
void visitUsedExpr(MCStreamer &Streamer) const override
bool mustExtend() const
References to labels and assigned expressions.
Definition: MCExpr.h:40
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Constant expressions.
Definition: MCExpr.h:39
Binary expressions.
Definition: MCExpr.h:38
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Target specific expression.
Definition: MCExpr.h:42