LLVM  8.0.1
HexagonMCExpr.cpp
Go to the documentation of this file.
1 //===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes
2 //----------===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include "HexagonMCExpr.h"
12 #include "llvm/BinaryFormat/ELF.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCStreamer.h"
15 #include "llvm/MC/MCSymbolELF.h"
16 #include "llvm/MC/MCValue.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 }
void setMustExtend(bool Val=true)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
VariantKind getKind() const
Definition: MCExpr.h:338
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:564
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
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:29
MCFragment * findAssociatedFragment() const override
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
static bool classof(MCExpr const *E)
Context object for machine code objects.
Definition: MCContext.h:63
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:647
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:567
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Unary expressions.
Definition: MCExpr.h:42
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:56
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCExpr const * getExpr() const
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
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:417
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:336
ExprKind getKind() const
Definition: MCExpr.h:73
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:867
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:930
void visitUsedExpr(MCStreamer &Streamer) const override
bool mustExtend() const
References to labels and assigned expressions.
Definition: MCExpr.h:41
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Constant expressions.
Definition: MCExpr.h:40
Binary expressions.
Definition: MCExpr.h:39
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Target specific expression.
Definition: MCExpr.h:43