Path: blob/main/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYTargetStreamer.h
35294 views
//===-- CSKYTargetStreamer.h - CSKY Target Streamer ----------*- C++ -*----===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H9#define LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H1011#include "MCTargetDesc/CSKYMCExpr.h"12#include "llvm/MC/ConstantPools.h"13#include "llvm/MC/MCStreamer.h"1415namespace llvm {1617class CSKYConstantPool {18using EntryVecTy = SmallVector<ConstantPoolEntry, 4>;19EntryVecTy Entries;20std::map<int64_t, const MCSymbolRefExpr *> CachedEntries;2122MCSection *CurrentSection = nullptr;2324public:25// Initialize a new empty constant pool26CSKYConstantPool() = default;2728// Add a new entry to the constant pool in the next slot.29// \param Value is the new entry to put in the constant pool.30// \param Size is the size in bytes of the entry31//32// \returns a MCExpr that references the newly inserted value33const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Value,34unsigned Size, SMLoc Loc, const MCExpr *AdjustExpr);3536void emitAll(MCStreamer &Streamer);3738// Return true if the constant pool is empty39bool empty();4041void clearCache();42};4344class CSKYTargetStreamer : public MCTargetStreamer {45public:46typedef struct {47const MCSymbol *sym;48CSKYMCExpr::VariantKind kind;49} SymbolIndex;5051protected:52std::unique_ptr<CSKYConstantPool> ConstantPool;5354DenseMap<SymbolIndex, const MCExpr *> ConstantMap;5556unsigned ConstantCounter = 0;5758public:59CSKYTargetStreamer(MCStreamer &S);6061virtual void emitTextAttribute(unsigned Attribute, StringRef String);62virtual void emitAttribute(unsigned Attribute, unsigned Value);63virtual void finishAttributeSection();6465virtual void emitTargetAttributes(const MCSubtargetInfo &STI);66/// Add a new entry to the constant pool for the current section and return an67/// MCExpr that can be used to refer to the constant pool location.68const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc,69const MCExpr *AdjustExpr = nullptr);7071void emitCurrentConstantPool();7273void finish() override;74};7576template <> struct DenseMapInfo<CSKYTargetStreamer::SymbolIndex> {77static inline CSKYTargetStreamer::SymbolIndex getEmptyKey() {78return {nullptr, CSKYMCExpr::VK_CSKY_Invalid};79}80static inline CSKYTargetStreamer::SymbolIndex getTombstoneKey() {81return {nullptr, CSKYMCExpr::VK_CSKY_Invalid};82}83static unsigned getHashValue(const CSKYTargetStreamer::SymbolIndex &V) {84return hash_combine(DenseMapInfo<const MCSymbol *>::getHashValue(V.sym),85DenseMapInfo<int>::getHashValue(V.kind));86}87static bool isEqual(const CSKYTargetStreamer::SymbolIndex &A,88const CSKYTargetStreamer::SymbolIndex &B) {89return A.sym == B.sym && A.kind == B.kind;90}91};9293class formatted_raw_ostream;9495class CSKYTargetAsmStreamer : public CSKYTargetStreamer {96formatted_raw_ostream &OS;9798void emitAttribute(unsigned Attribute, unsigned Value) override;99void emitTextAttribute(unsigned Attribute, StringRef String) override;100void finishAttributeSection() override;101102public:103CSKYTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)104: CSKYTargetStreamer(S), OS(OS) {}105};106107} // namespace llvm108109#endif // LLVM_LIB_TARGET_CSKY_CSKYTARGETSTREAMER_H110111112