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