blob: c786cfb63f4a8cb1e6900e211cfea20db7a36d98 [file] [log] [blame]
Andrea Di Biagiod1569292018-03-26 12:04:53 +00001//===--------------------- 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 Davis0e8402e2018-07-14 23:52:50 +000011/// 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 Davisdea343d2018-06-25 16:53:00 +000014/// the pipeline.
Andrea Di Biagiod1569292018-03-26 12:04:53 +000015///
16//===----------------------------------------------------------------------===//
17
18#include "InstructionTables.h"
19
20namespace mca {
21
22using namespace llvm;
23
Matt Davis4bcf3692018-08-13 18:11:48 +000024Stage::Status InstructionTables::execute(InstRef &IR) {
Andrea Di Biagiod1569292018-03-26 12:04:53 +000025 ArrayRef<uint64_t> Masks = IB.getProcResourceMasks();
Matt Davis0e8402e2018-07-14 23:52:50 +000026 const InstrDesc &Desc = IR.getInstruction()->getDesc();
27 UsedResources.clear();
Andrea Di Biagiod1569292018-03-26 12:04:53 +000028
Matt Davis0e8402e2018-07-14 23:52:50 +000029 // 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 Biagiod1569292018-03-26 12:04:53 +000045 }
Matt Davis0e8402e2018-07-14 23:52:50 +000046 continue;
Andrea Di Biagiod1569292018-03-26 12:04:53 +000047 }
48
Matt Davis0e8402e2018-07-14 23:52:50 +000049 // 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 Biagiod1569292018-03-26 12:04:53 +000062 }
Andrea Di Biagiod1569292018-03-26 12:04:53 +000063
Matt Davis0e8402e2018-07-14 23:52:50 +000064 // Send a fake instruction issued event to all the views.
65 HWInstructionIssuedEvent Event(IR, UsedResources);
66 notifyEvent<HWInstructionIssuedEvent>(Event);
Matt Davis4bcf3692018-08-13 18:11:48 +000067 return Stage::Continue;
Andrea Di Biagio5ffd2c32018-03-26 14:25:52 +000068}
69
Andrea Di Biagiod1569292018-03-26 12:04:53 +000070} // namespace mca