1*b847692eSMin-Yih Hsu //===-------------------- IncrementalSourceMgr.cpp ------------------------===// 2*b847692eSMin-Yih Hsu // 3*b847692eSMin-Yih Hsu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*b847692eSMin-Yih Hsu // See https://llvm.org/LICENSE.txt for license information. 5*b847692eSMin-Yih Hsu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*b847692eSMin-Yih Hsu // 7*b847692eSMin-Yih Hsu //===----------------------------------------------------------------------===// 8*b847692eSMin-Yih Hsu /// 9*b847692eSMin-Yih Hsu /// \file 10*b847692eSMin-Yih Hsu /// This file defines some implementations for IncrementalSourceMgr. 11*b847692eSMin-Yih Hsu /// 12*b847692eSMin-Yih Hsu //===----------------------------------------------------------------------===// 13*b847692eSMin-Yih Hsu 14*b847692eSMin-Yih Hsu #include "llvm/MCA/IncrementalSourceMgr.h" 15*b847692eSMin-Yih Hsu #ifndef NDEBUG 16*b847692eSMin-Yih Hsu #include "llvm/Support/Format.h" 17*b847692eSMin-Yih Hsu #endif 18*b847692eSMin-Yih Hsu 19*b847692eSMin-Yih Hsu using namespace llvm; 20*b847692eSMin-Yih Hsu using namespace llvm::mca; 21*b847692eSMin-Yih Hsu clear()22*b847692eSMin-Yih Hsuvoid IncrementalSourceMgr::clear() { 23*b847692eSMin-Yih Hsu Staging.clear(); 24*b847692eSMin-Yih Hsu InstStorage.clear(); 25*b847692eSMin-Yih Hsu TotalCounter = 0U; 26*b847692eSMin-Yih Hsu EOS = false; 27*b847692eSMin-Yih Hsu } 28*b847692eSMin-Yih Hsu updateNext()29*b847692eSMin-Yih Hsuvoid IncrementalSourceMgr::updateNext() { 30*b847692eSMin-Yih Hsu ++TotalCounter; 31*b847692eSMin-Yih Hsu Instruction *I = Staging.front(); 32*b847692eSMin-Yih Hsu Staging.pop_front(); 33*b847692eSMin-Yih Hsu I->reset(); 34*b847692eSMin-Yih Hsu 35*b847692eSMin-Yih Hsu if (InstFreedCB) 36*b847692eSMin-Yih Hsu InstFreedCB(I); 37*b847692eSMin-Yih Hsu } 38*b847692eSMin-Yih Hsu 39*b847692eSMin-Yih Hsu #ifndef NDEBUG printStatistic(raw_ostream & OS)40*b847692eSMin-Yih Hsuvoid IncrementalSourceMgr::printStatistic(raw_ostream &OS) { 41*b847692eSMin-Yih Hsu unsigned MaxInstStorageSize = InstStorage.size(); 42*b847692eSMin-Yih Hsu if (MaxInstStorageSize <= TotalCounter) { 43*b847692eSMin-Yih Hsu auto Ratio = double(MaxInstStorageSize) / double(TotalCounter); 44*b847692eSMin-Yih Hsu OS << "Cache ratio = " << MaxInstStorageSize << " / " << TotalCounter 45*b847692eSMin-Yih Hsu << llvm::format(" (%.2f%%)", (1.0 - Ratio) * 100.0) << "\n"; 46*b847692eSMin-Yih Hsu } else { 47*b847692eSMin-Yih Hsu OS << "Error: Number of created instructions " 48*b847692eSMin-Yih Hsu << "are larger than the number of issued instructions\n"; 49*b847692eSMin-Yih Hsu } 50*b847692eSMin-Yih Hsu } 51*b847692eSMin-Yih Hsu #endif 52