Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 1 | //===--------------------- InstructionTables.cpp ----------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
| 11 | /// This file implements method InstructionTables::run(). |
| 12 | /// Method run() prints a theoretical resource pressure distribution based on |
| 13 | /// the information available in the scheduling model, and without running |
| 14 | /// the backend pipeline. |
| 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #include "InstructionTables.h" |
| 19 | |
| 20 | namespace mca { |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | using ResourceRef = std::pair<uint64_t, uint64_t>; |
| 25 | |
| 26 | void InstructionTables::run() { |
| 27 | ArrayRef<uint64_t> Masks = IB.getProcResourceMasks(); |
| 28 | SmallVector<std::pair<ResourceRef, double>, 4> UsedResources; |
| 29 | |
| 30 | // Create an instruction descriptor for every instruction in the sequence. |
| 31 | while (S.hasNext()) { |
| 32 | UsedResources.clear(); |
Matt Davis | 21a8d32 | 2018-05-07 18:29:15 +0000 | [diff] [blame] | 33 | SourceRef SR = S.peekNext(); |
| 34 | std::unique_ptr<Instruction> Inst = IB.createInstruction(*SR.second); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 35 | const InstrDesc &Desc = Inst->getDesc(); |
| 36 | // Now identify the resources consumed by this instruction. |
| 37 | for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) { |
| 38 | // Skip zero-cycle resources (i.e. unused resources). |
| 39 | if (!Resource.second.size()) |
| 40 | continue; |
| 41 | double Cycles = static_cast<double>(Resource.second.size()); |
| 42 | unsigned Index = |
| 43 | std::distance(Masks.begin(), std::find(Masks.begin(), Masks.end(), |
| 44 | Resource.first)); |
| 45 | const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index); |
| 46 | unsigned NumUnits = ProcResource.NumUnits; |
| 47 | if (!ProcResource.SubUnitsIdxBegin) { |
| 48 | // The number of cycles consumed by each unit. |
| 49 | Cycles /= NumUnits; |
| 50 | for (unsigned I = 0, E = NumUnits; I < E; ++I) { |
| 51 | ResourceRef ResourceUnit = std::make_pair(Index, 1U << I); |
| 52 | UsedResources.emplace_back(std::make_pair(ResourceUnit, Cycles)); |
| 53 | } |
| 54 | continue; |
| 55 | } |
| 56 | |
| 57 | // This is a group. Obtain the set of resources contained in this |
| 58 | // group. Some of these resources may implement multiple units. |
| 59 | // Uniformly distribute Cycles across all of the units. |
| 60 | for (unsigned I1 = 0; I1 < NumUnits; ++I1) { |
| 61 | unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1]; |
| 62 | const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx); |
| 63 | // Compute the number of cycles consumed by each resource unit. |
| 64 | double RUCycles = Cycles / (NumUnits * SubUnit.NumUnits); |
| 65 | for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) { |
| 66 | ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2); |
| 67 | UsedResources.emplace_back(std::make_pair(ResourceUnit, RUCycles)); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
Andrea Di Biagio | 5ffd2c3 | 2018-03-26 14:25:52 +0000 | [diff] [blame] | 72 | // Now send a fake instruction issued event to all the views. |
Matt Davis | 21a8d32 | 2018-05-07 18:29:15 +0000 | [diff] [blame] | 73 | InstRef IR(SR.first, Inst.get()); |
| 74 | HWInstructionIssuedEvent Event(IR, UsedResources); |
Andrea Di Biagio | 5ffd2c3 | 2018-03-26 14:25:52 +0000 | [diff] [blame] | 75 | for (std::unique_ptr<View> &Listener : Views) |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 76 | Listener->onInstructionEvent(Event); |
| 77 | S.updateNext(); |
| 78 | } |
| 79 | } |
| 80 | |
Andrea Di Biagio | 5ffd2c3 | 2018-03-26 14:25:52 +0000 | [diff] [blame] | 81 | void InstructionTables::printReport(llvm::raw_ostream &OS) const { |
| 82 | for (const std::unique_ptr<View> &V : Views) |
| 83 | V->printView(OS); |
| 84 | } |
| 85 | |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 86 | } // namespace mca |