Index: head/contrib/llvm/include/llvm/MC/ConstantPools.h =================================================================== --- head/contrib/llvm/include/llvm/MC/ConstantPools.h (revision 318654) +++ head/contrib/llvm/include/llvm/MC/ConstantPools.h (revision 318655) @@ -1,95 +1,98 @@ //===- ConstantPool.h - Keep track of assembler-generated ------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file declares the ConstantPool and AssemblerConstantPools classes. // //===----------------------------------------------------------------------===// #ifndef LLVM_MC_CONSTANTPOOLS_H #define LLVM_MC_CONSTANTPOOLS_H #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/SMLoc.h" namespace llvm { class MCContext; class MCExpr; class MCSection; class MCStreamer; class MCSymbol; class MCSymbolRefExpr; struct ConstantPoolEntry { ConstantPoolEntry(MCSymbol *L, const MCExpr *Val, unsigned Sz, SMLoc Loc_) : Label(L), Value(Val), Size(Sz), Loc(Loc_) {} MCSymbol *Label; const MCExpr *Value; unsigned Size; SMLoc Loc; }; // A class to keep track of assembler-generated constant pools that are use to // implement the ldr-pseudo. class ConstantPool { typedef SmallVector EntryVecTy; EntryVecTy Entries; DenseMap CachedEntries; public: // Initialize a new empty constant pool ConstantPool() {} // Add a new entry to the constant pool in the next slot. // \param Value is the new entry to put in the constant pool. // \param Size is the size in bytes of the entry // // \returns a MCExpr that references the newly inserted value const MCExpr *addEntry(const MCExpr *Value, MCContext &Context, unsigned Size, SMLoc Loc); // Emit the contents of the constant pool using the provided streamer. void emitEntries(MCStreamer &Streamer); // Return true if the constant pool is empty bool empty(); + + void clearCache(); }; class AssemblerConstantPools { // Map type used to keep track of per-Section constant pools used by the // ldr-pseudo opcode. The map associates a section to its constant pool. The // constant pool is a vector of (label, value) pairs. When the ldr // pseudo is parsed we insert a new (label, value) pair into the constant pool // for the current section and add MCSymbolRefExpr to the new label as // an opcode to the ldr. After we have parsed all the user input we // output the (label, value) pairs in each constant pool at the end of the // section. // // We use the MapVector for the map type to ensure stable iteration of // the sections at the end of the parse. We need to iterate over the // sections in a stable order to ensure that we have print the // constant pools in a deterministic order when printing an assembly // file. typedef MapVector ConstantPoolMapTy; ConstantPoolMapTy ConstantPools; public: void emitAll(MCStreamer &Streamer); void emitForCurrentSection(MCStreamer &Streamer); + void clearCacheForCurrentSection(MCStreamer &Streamer); const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr, unsigned Size, SMLoc Loc); private: ConstantPool *getConstantPool(MCSection *Section); ConstantPool &getOrCreateConstantPool(MCSection *Section); }; } // end namespace llvm #endif Index: head/contrib/llvm/lib/MC/ConstantPools.cpp =================================================================== --- head/contrib/llvm/lib/MC/ConstantPools.cpp (revision 318654) +++ head/contrib/llvm/lib/MC/ConstantPools.cpp (revision 318655) @@ -1,104 +1,115 @@ //===- ConstantPools.cpp - ConstantPool class --*- C++ -*---------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements the ConstantPool and AssemblerConstantPools classes. // //===----------------------------------------------------------------------===// #include "llvm/ADT/MapVector.h" #include "llvm/MC/ConstantPools.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCStreamer.h" using namespace llvm; // // ConstantPool implementation // // Emit the contents of the constant pool using the provided streamer. void ConstantPool::emitEntries(MCStreamer &Streamer) { if (Entries.empty()) return; Streamer.EmitDataRegion(MCDR_DataRegion); for (const ConstantPoolEntry &Entry : Entries) { Streamer.EmitCodeAlignment(Entry.Size); // align naturally Streamer.EmitLabel(Entry.Label); Streamer.EmitValue(Entry.Value, Entry.Size, Entry.Loc); } Streamer.EmitDataRegion(MCDR_DataRegionEnd); Entries.clear(); } const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context, unsigned Size, SMLoc Loc) { const MCConstantExpr *C = dyn_cast(Value); // Check if there is existing entry for the same constant. If so, reuse it. auto Itr = C ? CachedEntries.find(C->getValue()) : CachedEntries.end(); if (Itr != CachedEntries.end()) return Itr->second; MCSymbol *CPEntryLabel = Context.createTempSymbol(); Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc)); const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context); if (C) CachedEntries[C->getValue()] = SymRef; return SymRef; } bool ConstantPool::empty() { return Entries.empty(); } +void ConstantPool::clearCache() { + CachedEntries.clear(); +} + // // AssemblerConstantPools implementation // ConstantPool *AssemblerConstantPools::getConstantPool(MCSection *Section) { ConstantPoolMapTy::iterator CP = ConstantPools.find(Section); if (CP == ConstantPools.end()) return nullptr; return &CP->second; } ConstantPool & AssemblerConstantPools::getOrCreateConstantPool(MCSection *Section) { return ConstantPools[Section]; } static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP) { if (!CP.empty()) { Streamer.SwitchSection(Section); CP.emitEntries(Streamer); } } void AssemblerConstantPools::emitAll(MCStreamer &Streamer) { // Dump contents of assembler constant pools. for (auto &CPI : ConstantPools) { MCSection *Section = CPI.first; ConstantPool &CP = CPI.second; emitConstantPool(Streamer, Section, CP); } } void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) { MCSection *Section = Streamer.getCurrentSectionOnly(); if (ConstantPool *CP = getConstantPool(Section)) { emitConstantPool(Streamer, Section, *CP); + } +} + +void AssemblerConstantPools::clearCacheForCurrentSection(MCStreamer &Streamer) { + MCSection *Section = Streamer.getCurrentSectionOnly(); + if (ConstantPool *CP = getConstantPool(Section)) { + CP->clearCache(); } } const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer, const MCExpr *Expr, unsigned Size, SMLoc Loc) { MCSection *Section = Streamer.getCurrentSectionOnly(); return getOrCreateConstantPool(Section).addEntry(Expr, Streamer.getContext(), Size, Loc); } Index: head/contrib/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp =================================================================== --- head/contrib/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp (revision 318654) +++ head/contrib/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp (revision 318655) @@ -1,77 +1,78 @@ //===- ARMTargetStreamer.cpp - ARMTargetStreamer class --*- C++ -*---------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements the ARMTargetStreamer class. // //===----------------------------------------------------------------------===// #include "llvm/ADT/MapVector.h" #include "llvm/MC/ConstantPools.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCStreamer.h" using namespace llvm; // // ARMTargetStreamer Implemenation // ARMTargetStreamer::ARMTargetStreamer(MCStreamer &S) : MCTargetStreamer(S), ConstantPools(new AssemblerConstantPools()) {} ARMTargetStreamer::~ARMTargetStreamer() {} // The constant pool handling is shared by all ARMTargetStreamer // implementations. const MCExpr *ARMTargetStreamer::addConstantPoolEntry(const MCExpr *Expr, SMLoc Loc) { return ConstantPools->addEntry(Streamer, Expr, 4, Loc); } void ARMTargetStreamer::emitCurrentConstantPool() { ConstantPools->emitForCurrentSection(Streamer); + ConstantPools->clearCacheForCurrentSection(Streamer); } // finish() - write out any non-empty assembler constant pools. void ARMTargetStreamer::finish() { ConstantPools->emitAll(Streamer); } // reset() - Reset any state void ARMTargetStreamer::reset() {} // The remaining callbacks should be handled separately by each // streamer. void ARMTargetStreamer::emitFnStart() {} void ARMTargetStreamer::emitFnEnd() {} void ARMTargetStreamer::emitCantUnwind() {} void ARMTargetStreamer::emitPersonality(const MCSymbol *Personality) {} void ARMTargetStreamer::emitPersonalityIndex(unsigned Index) {} void ARMTargetStreamer::emitHandlerData() {} void ARMTargetStreamer::emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset) {} void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {} void ARMTargetStreamer::emitPad(int64_t Offset) {} void ARMTargetStreamer::emitRegSave(const SmallVectorImpl &RegList, bool isVector) {} void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset, const SmallVectorImpl &Opcodes) { } void ARMTargetStreamer::switchVendor(StringRef Vendor) {} void ARMTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {} void ARMTargetStreamer::emitTextAttribute(unsigned Attribute, StringRef String) {} void ARMTargetStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) {} void ARMTargetStreamer::emitArch(unsigned Arch) {} void ARMTargetStreamer::emitArchExtension(unsigned ArchExt) {} void ARMTargetStreamer::emitObjectArch(unsigned Arch) {} void ARMTargetStreamer::emitFPU(unsigned FPU) {} void ARMTargetStreamer::finishAttributeSection() {} void ARMTargetStreamer::emitInst(uint32_t Inst, char Suffix) {} void ARMTargetStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) {} void ARMTargetStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {}