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 | /// |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 11 | /// This file implements the method InstructionTables::execute(). |
| 12 | /// Method execute() prints a theoretical resource pressure distribution based |
| 13 | /// on the information available in the scheduling model, and without running |
Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 14 | /// the pipeline. |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #include "InstructionTables.h" |
| 19 | |
| 20 | namespace mca { |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 24 | Stage::Status InstructionTables::execute(InstRef &IR) { |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 25 | ArrayRef<uint64_t> Masks = IB.getProcResourceMasks(); |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 26 | const InstrDesc &Desc = IR.getInstruction()->getDesc(); |
| 27 | UsedResources.clear(); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 28 | |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 29 | // Identify the resources consumed by this instruction. |
| 30 | for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) { |
| 31 | // Skip zero-cycle resources (i.e., unused resources). |
| 32 | if (!Resource.second.size()) |
| 33 | continue; |
| 34 | double Cycles = static_cast<double>(Resource.second.size()); |
| 35 | unsigned Index = std::distance( |
| 36 | Masks.begin(), std::find(Masks.begin(), Masks.end(), Resource.first)); |
| 37 | const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index); |
| 38 | unsigned NumUnits = ProcResource.NumUnits; |
| 39 | if (!ProcResource.SubUnitsIdxBegin) { |
| 40 | // The number of cycles consumed by each unit. |
| 41 | Cycles /= NumUnits; |
| 42 | for (unsigned I = 0, E = NumUnits; I < E; ++I) { |
| 43 | ResourceRef ResourceUnit = std::make_pair(Index, 1U << I); |
| 44 | UsedResources.emplace_back(std::make_pair(ResourceUnit, Cycles)); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 45 | } |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 46 | continue; |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 49 | // This is a group. Obtain the set of resources contained in this |
| 50 | // group. Some of these resources may implement multiple units. |
| 51 | // Uniformly distribute Cycles across all of the units. |
| 52 | for (unsigned I1 = 0; I1 < NumUnits; ++I1) { |
| 53 | unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1]; |
| 54 | const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx); |
| 55 | // Compute the number of cycles consumed by each resource unit. |
| 56 | double RUCycles = Cycles / (NumUnits * SubUnit.NumUnits); |
| 57 | for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) { |
| 58 | ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2); |
| 59 | UsedResources.emplace_back(std::make_pair(ResourceUnit, RUCycles)); |
| 60 | } |
| 61 | } |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 62 | } |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 63 | |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 64 | // Send a fake instruction issued event to all the views. |
| 65 | HWInstructionIssuedEvent Event(IR, UsedResources); |
| 66 | notifyEvent<HWInstructionIssuedEvent>(Event); |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 67 | return Stage::Continue; |
Andrea Di Biagio | 5ffd2c3 | 2018-03-26 14:25:52 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 70 | } // namespace mca |