LLVM  15.0.0git
CSKYTargetStreamer.cpp
Go to the documentation of this file.
1 //===-- CSKYTargetStreamer.h - CSKY Target Streamer ----------*- C++ -*----===//
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 #include "CSKYTargetStreamer.h"
10 #include "CSKYSubtarget.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSectionELF.h"
16 
17 using namespace llvm;
18 
19 //
20 // ConstantPool implementation
21 //
22 // Emit the contents of the constant pool using the provided streamer.
24  if (Entries.empty())
25  return;
26 
27  if (CurrentSection != nullptr)
28  Streamer.switchSection(CurrentSection);
29 
31  for (const ConstantPoolEntry &Entry : Entries) {
32  Streamer.emitCodeAlignment(
33  Entry.Size,
34  Streamer.getContext().getSubtargetInfo()); // align naturally
35  Streamer.emitLabel(Entry.Label);
36  Streamer.emitValue(Entry.Value, Entry.Size, Entry.Loc);
37  }
39  Entries.clear();
40 }
41 
43  const MCExpr *Value, unsigned Size,
44  SMLoc Loc, const MCExpr *AdjustExpr) {
45  if (CurrentSection == nullptr)
46  CurrentSection = Streamer.getCurrentSectionOnly();
47 
48  auto &Context = Streamer.getContext();
49 
50  const MCConstantExpr *C = dyn_cast<MCConstantExpr>(Value);
51 
52  // Check if there is existing entry for the same constant. If so, reuse it.
53  auto Itr = C ? CachedEntries.find(C->getValue()) : CachedEntries.end();
54  if (Itr != CachedEntries.end())
55  return Itr->second;
56 
57  MCSymbol *CPEntryLabel = Context.createTempSymbol();
58  const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context);
59 
60  if (AdjustExpr) {
61  const CSKYMCExpr *CSKYExpr = cast<CSKYMCExpr>(Value);
62 
63  Value = MCBinaryExpr::createSub(AdjustExpr, SymRef, Context);
65  Value = CSKYMCExpr::create(Value, CSKYExpr->getKind(), Context);
66  }
67 
68  Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
69 
70  if (C)
71  CachedEntries[C->getValue()] = SymRef;
72  return SymRef;
73 }
74 
75 bool CSKYConstantPool::empty() { return Entries.empty(); }
76 
78  CurrentSection = nullptr;
79  CachedEntries.clear();
80 }
81 
84 
85 const MCExpr *
87  const MCExpr *AdjustExpr) {
88  auto ELFRefKind = CSKYMCExpr::VK_CSKY_Invalid;
90 
91  const MCExpr *OrigExpr = Expr;
92 
93  if (const CSKYMCExpr *CE = dyn_cast<CSKYMCExpr>(Expr)) {
94  Expr = CE->getSubExpr();
95  ELFRefKind = CE->getKind();
96  }
97 
98  if (const MCSymbolRefExpr *SymExpr = dyn_cast<MCSymbolRefExpr>(Expr)) {
99  const MCSymbol *Sym = &SymExpr->getSymbol();
100 
101  SymbolIndex Index = {Sym, ELFRefKind};
102 
103  if (ConstantMap.find(Index) == ConstantMap.end()) {
104  ConstantMap[Index] =
105  ConstantPool->addEntry(getStreamer(), OrigExpr, 4, Loc, AdjustExpr);
106  }
107  return ConstantMap[Index];
108  }
109 
110  return ConstantPool->addEntry(getStreamer(), Expr, 4, Loc, AdjustExpr);
111 }
112 
114  ConstantPool->emitAll(Streamer);
116 }
117 
118 // finish() - write out any non-empty assembler constant pools.
120  if (ConstantCounter != 0) {
121  ConstantPool->emitAll(Streamer);
122  }
123 
125 }
126 
128 
131  StringRef String) {}
133 
134 void CSKYTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
135  OS << "\t.csky_attribute\t" << Attribute << ", " << Twine(Value) << "\n";
136 }
137 
138 void CSKYTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
139  StringRef String) {
140  OS << "\t.csky_attribute\t" << Attribute << ", \"" << String << "\"\n";
141 }
142 
143 void CSKYTargetAsmStreamer::finishAttributeSection() {}
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
llvm::MCTargetStreamer::getStreamer
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
llvm::MCStreamer::emitDataRegion
virtual void emitDataRegion(MCDataRegionType Kind)
Note in the output the specified region Kind.
Definition: MCStreamer.h:499
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::CSKYTargetStreamer::CSKYTargetStreamer
CSKYTargetStreamer(MCStreamer &S)
Definition: CSKYTargetStreamer.cpp:82
llvm::ConstantPoolEntry
Definition: ConstantPools.h:31
llvm::Attribute
Definition: Attributes.h:65
llvm::CSKYMCExpr::VK_CSKY_Invalid
@ VK_CSKY_Invalid
Definition: CSKYMCExpr.h:36
MCSectionELF.h
llvm::CSKYTargetStreamer::emitCurrentConstantPool
void emitCurrentConstantPool()
Definition: CSKYTargetStreamer.cpp:113
llvm::ConstantPool
Definition: ConstantPools.h:43
llvm::MCStreamer::emitValue
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:178
llvm::CSKYTargetStreamer::finish
void finish() override
Definition: CSKYTargetStreamer.cpp:119
llvm::CSKYMCExpr::create
static const CSKYMCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
Definition: CSKYMCExpr.cpp:22
llvm::CSKYConstantPool::emitAll
void emitAll(MCStreamer &Streamer)
Definition: CSKYTargetStreamer.cpp:23
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
FormattedStream.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::MCDR_DataRegion
@ MCDR_DataRegion
.data_region
Definition: MCDirectives.h:60
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
CSKYSubtarget.h
llvm::CSKYConstantPool::addEntry
const MCExpr * addEntry(MCStreamer &Streamer, const MCExpr *Value, unsigned Size, SMLoc Loc, const MCExpr *AdjustExpr)
Definition: CSKYTargetStreamer.cpp:42
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
MCContext.h
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:423
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:1225
llvm::CSKYMCExpr::getKind
VariantKind getKind() const
Definition: CSKYMCExpr.h:51
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::CSKYConstantPool
Definition: CSKYTargetStreamer.h:18
CSKYTargetStreamer.h
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:389
llvm::CSKYTargetStreamer::SymbolIndex
Definition: CSKYTargetStreamer.h:47
llvm::MCContext::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCContext.h:452
llvm::MCConstantExpr
Definition: MCExpr.h:144
Index
uint32_t Index
Definition: ELFObjHandler.cpp:82
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:95
llvm::CSKYTargetStreamer::emitTextAttribute
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
Definition: CSKYTargetStreamer.cpp:130
llvm::CSKYConstantPool::clearCache
void clearCache()
Definition: CSKYTargetStreamer.cpp:77
llvm::CSKYMCExpr
Definition: CSKYMCExpr.h:17
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:610
llvm::CSKYMCExpr::getSubExpr
const MCExpr * getSubExpr() const
Definition: CSKYMCExpr.h:54
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
TargetSubtargetInfo.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::CSKYTargetStreamer::addConstantPoolEntry
const MCExpr * addConstantPoolEntry(const MCExpr *, SMLoc Loc, const MCExpr *AdjustExpr=nullptr)
Add a new entry to the constant pool for the current section and return an MCExpr that can be used to...
Definition: CSKYTargetStreamer.cpp:86
MachineFrameInfo.h
llvm::CSKYTargetStreamer::emitAttribute
virtual void emitAttribute(unsigned Attribute, unsigned Value)
Definition: CSKYTargetStreamer.cpp:129
llvm::ConstantPool::addEntry
const MCExpr * addEntry(const MCExpr *Value, MCContext &Context, unsigned Size, SMLoc Loc)
Definition: ConstantPools.cpp:39
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
llvm::CSKYTargetStreamer::ConstantMap
DenseMap< SymbolIndex, const MCExpr * > ConstantMap
Definition: CSKYTargetStreamer.h:55
llvm::ConstantPool::clearCache
void clearCache()
Definition: ConstantPools.cpp:71
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:293
llvm::CSKYTargetStreamer::finishAttributeSection
virtual void finishAttributeSection()
Definition: CSKYTargetStreamer.cpp:132
llvm::MCStreamer::emitCodeAlignment
virtual void emitCodeAlignment(unsigned ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:1215
llvm::CSKYConstantPool::empty
bool empty()
Definition: CSKYTargetStreamer.cpp:75
llvm::pdb::String
@ String
Definition: PDBTypes.h:408
llvm::CSKYTargetStreamer::ConstantCounter
unsigned ConstantCounter
Definition: CSKYTargetStreamer.h:57
llvm::MCDR_DataRegionEnd
@ MCDR_DataRegionEnd
.end_data_region
Definition: MCDirectives.h:64
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::CSKYTargetStreamer::emitTargetAttributes
virtual void emitTargetAttributes(const MCSubtargetInfo &STI)
Definition: CSKYTargetStreamer.cpp:127