LLVM  14.0.0git
HexagonMCELFStreamer.cpp
Go to the documentation of this file.
1 //=== HexagonMCELFStreamer.cpp - Hexagon subclass of MCELFStreamer -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a stub that parses a MCInst bundle and passes the
10 // instructions on to the real streamer.
11 //
12 //===----------------------------------------------------------------------===//
13 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/ELF.h"
19 #include "llvm/MC/MCAsmBackend.h"
20 #include "llvm/MC/MCAssembler.h"
21 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCInst.h"
26 #include "llvm/MC/MCObjectWriter.h"
27 #include "llvm/MC/MCSection.h"
28 #include "llvm/MC/MCSectionELF.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/MC/MCSymbolELF.h"
32 #include "llvm/Support/Casting.h"
36 #include <cassert>
37 #include <cstdint>
38 
39 #define DEBUG_TYPE "hexagonmcelfstreamer"
40 
41 using namespace llvm;
42 
44  ("gpsize", cl::NotHidden,
45  cl::desc("Global Pointer Addressing Size. The default size is 8."),
46  cl::Prefix,
47  cl::init(8));
48 
50  MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
51  std::unique_ptr<MCObjectWriter> OW, std::unique_ptr<MCCodeEmitter> Emitter)
52  : MCELFStreamer(Context, std::move(TAB), std::move(OW), std::move(Emitter)),
53  MCII(createHexagonMCInstrInfo()) {}
54 
56  MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
57  std::unique_ptr<MCObjectWriter> OW, std::unique_ptr<MCCodeEmitter> Emitter,
58  MCAssembler *Assembler)
59  : MCELFStreamer(Context, std::move(TAB), std::move(OW), std::move(Emitter)),
60  MCII(createHexagonMCInstrInfo()) {}
61 
63  const MCSubtargetInfo &STI) {
64  assert(MCB.getOpcode() == Hexagon::BUNDLE);
67 
68  // At this point, MCB is a bundle
69  // Iterate through the bundle and assign addends for the instructions
70  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
71  MCInst *MCI = const_cast<MCInst *>(I.getInst());
72  EmitSymbol(*MCI);
73  }
74 
76 }
77 
79  // Scan for values.
80  for (unsigned i = Inst.getNumOperands(); i--;)
81  if (Inst.getOperand(i).isExpr())
83 }
84 
85 // EmitCommonSymbol and EmitLocalCommonSymbol are extended versions of the
86 // functions found in MCELFStreamer.cpp taking AccessSize as an additional
87 // parameter.
89  uint64_t Size,
90  unsigned ByteAlignment,
91  unsigned AccessSize) {
93  StringRef sbss[4] = {".sbss.1", ".sbss.2", ".sbss.4", ".sbss.8"};
94 
95  auto ELFSymbol = cast<MCSymbolELF>(Symbol);
96  if (!ELFSymbol->isBindingSet()) {
97  ELFSymbol->setBinding(ELF::STB_GLOBAL);
98  ELFSymbol->setExternal(true);
99  }
100 
101  ELFSymbol->setType(ELF::STT_OBJECT);
102 
103  if (ELFSymbol->getBinding() == ELF::STB_LOCAL) {
105  ((AccessSize == 0) || (Size == 0) || (Size > GPSize))
106  ? ".bss"
107  : sbss[(Log2_64(AccessSize))];
112 
113  if (ELFSymbol->isUndefined()) {
115  emitLabel(Symbol);
116  emitZeros(Size);
117  }
118 
119  // Update the maximum alignment of the section if necessary.
120  if (Align(ByteAlignment) > Section.getAlignment())
121  Section.setAlignment(Align(ByteAlignment));
122 
123  SwitchSection(P.first, P.second);
124  } else {
125  if (ELFSymbol->declareCommon(Size, ByteAlignment))
126  report_fatal_error("Symbol: " + Symbol->getName() +
127  " redeclared as different type");
128  if ((AccessSize) && (Size <= GPSize)) {
129  uint64_t SectionIndex =
130  (AccessSize <= GPSize)
131  ? ELF::SHN_HEXAGON_SCOMMON + (Log2_64(AccessSize) + 1)
132  : (unsigned)ELF::SHN_HEXAGON_SCOMMON;
133  ELFSymbol->setIndex(SectionIndex);
134  }
135  }
136 
137  ELFSymbol->setSize(MCConstantExpr::create(Size, getContext()));
138 }
139 
141  uint64_t Size,
142  unsigned ByteAlignment,
143  unsigned AccessSize) {
145  auto ELFSymbol = cast<MCSymbolELF>(Symbol);
146  ELFSymbol->setBinding(ELF::STB_LOCAL);
147  ELFSymbol->setExternal(false);
149 }
150 
151 
152 namespace llvm {
154  std::unique_ptr<MCAsmBackend> MAB,
155  std::unique_ptr<MCObjectWriter> OW,
156  std::unique_ptr<MCCodeEmitter> CE) {
157  return new HexagonMCELFStreamer(Context, std::move(MAB), std::move(OW),
158  std::move(CE));
159  }
160 
161 } // end namespace llvm
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
i
i
Definition: README.txt:29
llvm::MCStreamer::visitUsedExpr
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:1059
MathExtras.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCELFStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: MCELFStreamer.cpp:100
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:463
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::HexagonMCELFStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: HexagonMCELFStreamer.cpp:62
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
MCCodeEmitter.h
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
MCSectionELF.h
ErrorHandling.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
MCAssembler.h
llvm::ELF::STB_GLOBAL
@ STB_GLOBAL
Definition: ELF.h:1139
GPSize
static cl::opt< unsigned > GPSize("gpsize", cl::NotHidden, cl::desc("Global Pointer Addressing Size. The default size is 8."), cl::Prefix, cl::init(8))
llvm::MCStreamer::getCurrentSection
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:369
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
llvm::ELF::SHN_HEXAGON_SCOMMON
@ SHN_HEXAGON_SCOMMON
Definition: ELF.h:630
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
MCObjectStreamer.h
CommandLine.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
HexagonMCShuffler.h
llvm::Log2_64
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:602
llvm::createHexagonELFStreamer
MCStreamer * createHexagonELFStreamer(Triple const &TT, MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > CE)
Definition: HexagonMCELFStreamer.cpp:153
ELF.h
llvm::MCELFStreamer
Definition: MCELFStreamer.h:24
MCAsmBackend.h
HexagonMCInstrInfo.h
llvm::MCAssembler::getContext
MCContext & getContext() const
Definition: MCAssembler.h:292
MCSymbolELF.h
MCContext.h
llvm::MCObjectStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: MCObjectStreamer.cpp:362
llvm::cl::NotHidden
@ NotHidden
Definition: CommandLine.h:142
MCSymbol.h
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
MCInst.h
llvm::HexagonMCInstrInfo::bundleInstructions
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:103
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::HexagonMCInstrInfo::bundleSize
size_t bundleSize(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:116
llvm::MCELFStreamer::emitValueToAlignment
void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition: MCELFStreamer.cpp:364
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::MCAssembler
Definition: MCAssembler.h:60
HexagonMCELFStreamer.h
llvm::createHexagonMCInstrInfo
MCInstrInfo * createHexagonMCInstrInfo()
Definition: HexagonMCTargetDesc.cpp:280
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:985
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1605
MCSection.h
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:112
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:988
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::HexagonMCELFStreamer::HexagonMCELFStreamer
HexagonMCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition: HexagonMCELFStreamer.cpp:49
llvm::HexagonMCELFStreamer
Definition: HexagonMCELFStreamer.h:20
MCObjectWriter.h
std
Definition: BitVector.h:838
llvm::ELF::STT_OBJECT
@ STT_OBJECT
Definition: ELF.h:1151
llvm::SectionName
Definition: DWARFSection.h:21
Casting.h
llvm::MCOperand::getExpr
const MCExpr * getExpr() const
Definition: MCInst.h:114
llvm::MCInst::getOpcode
unsigned getOpcode() const
Definition: MCInst.h:198
llvm::MCOperand::isExpr
bool isExpr() const
Definition: MCInst.h:65
llvm::LCOMM::ByteAlignment
@ ByteAlignment
Definition: MCAsmInfo.h:50
llvm::HexagonMCELFStreamer::EmitSymbol
void EmitSymbol(const MCInst &Inst)
Definition: HexagonMCELFStreamer.cpp:78
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:278
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1138
MCStreamer.h
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
llvm::MCSectionSubPair
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:64
llvm::HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
Definition: HexagonMCELFStreamer.cpp:140
llvm::cl::desc
Definition: CommandLine.h:414
HEXAGON_PACKET_SIZE
#define HEXAGON_PACKET_SIZE
Definition: HexagonMCTargetDesc.h:36
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:917
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1209
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::HexagonMCELFStreamer::HexagonMCEmitCommonSymbol
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
Definition: HexagonMCELFStreamer.cpp:88
llvm::MCStreamer::emitZeros
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:224