LLVM  15.0.0git
CSKYTargetStreamer.h
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 #ifndef LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H
10 #define LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H
11 
13 #include "llvm/MC/ConstantPools.h"
14 #include "llvm/MC/MCStreamer.h"
15 
16 namespace llvm {
17 
20  EntryVecTy Entries;
21  std::map<int64_t, const MCSymbolRefExpr *> CachedEntries;
22 
23  MCSection *CurrentSection = nullptr;
24 
25 public:
26  // Initialize a new empty constant pool
27  CSKYConstantPool() = default;
28 
29  // Add a new entry to the constant pool in the next slot.
30  // \param Value is the new entry to put in the constant pool.
31  // \param Size is the size in bytes of the entry
32  //
33  // \returns a MCExpr that references the newly inserted value
34  const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Value,
35  unsigned Size, SMLoc Loc, const MCExpr *AdjustExpr);
36 
37  void emitAll(MCStreamer &Streamer);
38 
39  // Return true if the constant pool is empty
40  bool empty();
41 
42  void clearCache();
43 };
44 
46 public:
47  typedef struct {
48  const MCSymbol *sym;
50  } SymbolIndex;
51 
52 protected:
53  std::unique_ptr<CSKYConstantPool> ConstantPool;
54 
56 
57  unsigned ConstantCounter = 0;
58 
59 public:
61 
62  virtual void emitTextAttribute(unsigned Attribute, StringRef String);
63  virtual void emitAttribute(unsigned Attribute, unsigned Value);
64  virtual void finishAttributeSection();
65 
66  virtual void emitTargetAttributes(const MCSubtargetInfo &STI);
67  /// Add a new entry to the constant pool for the current section and return an
68  /// MCExpr that can be used to refer to the constant pool location.
69  const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc,
70  const MCExpr *AdjustExpr = nullptr);
71 
73 
74  void finish() override;
75 };
76 
77 template <> struct DenseMapInfo<CSKYTargetStreamer::SymbolIndex> {
79  return {nullptr, CSKYMCExpr::VK_CSKY_Invalid};
80  }
82  return {nullptr, CSKYMCExpr::VK_CSKY_Invalid};
83  }
84  static unsigned getHashValue(const CSKYTargetStreamer::SymbolIndex &V) {
87  }
90  return A.sym == B.sym && A.kind == B.kind;
91  }
92 };
93 
94 class formatted_raw_ostream;
95 
98 
99  void emitAttribute(unsigned Attribute, unsigned Value) override;
100  void emitTextAttribute(unsigned Attribute, StringRef String) override;
101  void finishAttributeSection() override;
102 
103 public:
105  : CSKYTargetStreamer(S), OS(OS) {}
106 };
107 
108 } // namespace llvm
109 
110 #endif // LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H
llvm::DenseMapInfo< CSKYTargetStreamer::SymbolIndex >::getTombstoneKey
static CSKYTargetStreamer::SymbolIndex getTombstoneKey()
Definition: CSKYTargetStreamer.h:81
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::Attribute
Definition: Attributes.h:65
llvm::CSKYMCExpr::VK_CSKY_Invalid
@ VK_CSKY_Invalid
Definition: CSKYMCExpr.h:36
llvm::CSKYTargetAsmStreamer::CSKYTargetAsmStreamer
CSKYTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
Definition: CSKYTargetStreamer.h:104
llvm::SmallVector< ConstantPoolEntry, 4 >
llvm::CSKYTargetStreamer::emitCurrentConstantPool
void emitCurrentConstantPool()
Definition: CSKYTargetStreamer.cpp:113
llvm::DenseMapInfo< CSKYTargetStreamer::SymbolIndex >::getHashValue
static unsigned getHashValue(const CSKYTargetStreamer::SymbolIndex &V)
Definition: CSKYTargetStreamer.h:84
llvm::CSKYTargetStreamer::finish
void finish() override
Definition: CSKYTargetStreamer.cpp:119
llvm::CSKYConstantPool::emitAll
void emitAll(MCStreamer &Streamer)
Definition: CSKYTargetStreamer.cpp:23
llvm::CSKYConstantPool::CSKYConstantPool
CSKYConstantPool()=default
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::CSKYConstantPool::addEntry
const MCExpr * addEntry(MCStreamer &Streamer, const MCExpr *Value, unsigned Size, SMLoc Loc, const MCExpr *AdjustExpr)
Definition: CSKYTargetStreamer.cpp:42
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::CSKYConstantPool
Definition: CSKYTargetStreamer.h:18
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
llvm::CSKYTargetStreamer
Definition: CSKYTargetStreamer.h:45
llvm::CSKYTargetStreamer::SymbolIndex
Definition: CSKYTargetStreamer.h:47
ConstantPools.h
llvm::CSKYTargetStreamer::emitTextAttribute
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
Definition: CSKYTargetStreamer.cpp:130
llvm::DenseMap
Definition: DenseMap.h:716
llvm::CSKYConstantPool::clearCache
void clearCache()
Definition: CSKYTargetStreamer.cpp:77
llvm::CSKYMCExpr::VariantKind
VariantKind
Definition: CSKYMCExpr.h:19
llvm::formatted_raw_ostream
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Definition: FormattedStream.h:30
llvm::CSKYTargetAsmStreamer
Definition: CSKYTargetStreamer.h:96
llvm::CSKYTargetStreamer::SymbolIndex::kind
CSKYMCExpr::VariantKind kind
Definition: CSKYTargetStreamer.h:49
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
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::CSKYTargetStreamer::ConstantPool
std::unique_ptr< CSKYConstantPool > ConstantPool
Definition: CSKYTargetStreamer.h:53
llvm::DenseMapInfo< CSKYTargetStreamer::SymbolIndex >::isEqual
static bool isEqual(const CSKYTargetStreamer::SymbolIndex &A, const CSKYTargetStreamer::SymbolIndex &B)
Definition: CSKYTargetStreamer.h:88
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
llvm::CSKYTargetStreamer::emitAttribute
virtual void emitAttribute(unsigned Attribute, unsigned Value)
Definition: CSKYTargetStreamer.cpp:129
CSKYMCExpr.h
llvm::CSKYTargetStreamer::ConstantMap
DenseMap< SymbolIndex, const MCExpr * > ConstantMap
Definition: CSKYTargetStreamer.h:55
llvm::CSKYTargetStreamer::finishAttributeSection
virtual void finishAttributeSection()
Definition: CSKYTargetStreamer.cpp:132
llvm::CSKYTargetStreamer::SymbolIndex::sym
const MCSymbol * sym
Definition: CSKYTargetStreamer.h:48
llvm::hash_combine
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:605
llvm::CSKYConstantPool::empty
bool empty()
Definition: CSKYTargetStreamer.cpp:75
MCStreamer.h
llvm::CSKYTargetStreamer::ConstantCounter
unsigned ConstantCounter
Definition: CSKYTargetStreamer.h:57
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::DenseMapInfo< CSKYTargetStreamer::SymbolIndex >::getEmptyKey
static CSKYTargetStreamer::SymbolIndex getEmptyKey()
Definition: CSKYTargetStreamer.h:78
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