|
|
|||
File indexing completed on 2026-05-10 08:44:16
0001 //===---------------- IncrementalSourceMgr.h --------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// \file 0009 /// This file contains IncrementalSourceMgr, an implementation of SourceMgr 0010 /// that allows users to add new instructions incrementally / dynamically. 0011 /// 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_MCA_INCREMENTALSOURCEMGR_H 0015 #define LLVM_MCA_INCREMENTALSOURCEMGR_H 0016 0017 #include "llvm/MCA/SourceMgr.h" 0018 #include <deque> 0019 0020 namespace llvm { 0021 namespace mca { 0022 0023 /// An implementation of \a SourceMgr that allows users to add new instructions 0024 /// incrementally / dynamically. 0025 /// Note that this SourceMgr takes ownership of all \a mca::Instruction. 0026 class IncrementalSourceMgr : public SourceMgr { 0027 /// Owner of all mca::Instruction instances. Note that we use std::deque here 0028 /// to have a better throughput, in comparison to std::vector or 0029 /// llvm::SmallVector, as they usually pay a higher re-allocation cost when 0030 /// there is a large number of instructions. 0031 std::deque<UniqueInst> InstStorage; 0032 0033 /// Instructions that are ready to be used. Each of them is a pointer of an 0034 /// \a UniqueInst inside InstStorage. 0035 std::deque<Instruction *> Staging; 0036 0037 /// Current instruction index. 0038 unsigned TotalCounter = 0U; 0039 0040 /// End-of-stream flag. 0041 bool EOS = false; 0042 0043 /// Called when an instruction is no longer needed. 0044 using InstFreedCallback = std::function<void(Instruction *)>; 0045 InstFreedCallback InstFreedCB; 0046 0047 public: 0048 IncrementalSourceMgr() = default; 0049 0050 void clear(); 0051 0052 /// Set a callback that is invoked when a mca::Instruction is 0053 /// no longer needed. This is usually used for recycling the 0054 /// instruction. 0055 void setOnInstFreedCallback(InstFreedCallback CB) { InstFreedCB = CB; } 0056 0057 ArrayRef<UniqueInst> getInstructions() const override { 0058 llvm_unreachable("Not applicable"); 0059 } 0060 0061 bool hasNext() const override { return !Staging.empty(); } 0062 bool isEnd() const override { return EOS; } 0063 0064 SourceRef peekNext() const override { 0065 assert(hasNext()); 0066 return SourceRef(TotalCounter, *Staging.front()); 0067 } 0068 0069 /// Add a new instruction. 0070 void addInst(UniqueInst &&Inst) { 0071 InstStorage.emplace_back(std::move(Inst)); 0072 Staging.push_back(InstStorage.back().get()); 0073 } 0074 0075 /// Add a recycled instruction. 0076 void addRecycledInst(Instruction *Inst) { Staging.push_back(Inst); } 0077 0078 void updateNext() override; 0079 0080 /// Mark the end of instruction stream. 0081 void endOfStream() { EOS = true; } 0082 0083 #ifndef NDEBUG 0084 /// Print statistic about instruction recycling stats. 0085 void printStatistic(raw_ostream &OS); 0086 #endif 0087 }; 0088 0089 } // end namespace mca 0090 } // end namespace llvm 0091 0092 #endif // LLVM_MCA_INCREMENTALSOURCEMGR_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|