• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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
14 /// the pipeline.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #include "InstructionTables.h"
19 
20 namespace mca {
21 
22 using namespace llvm;
23 
execute(InstRef & IR)24 bool InstructionTables::execute(InstRef &IR) {
25   ArrayRef<uint64_t> Masks = IB.getProcResourceMasks();
26   const InstrDesc &Desc = IR.getInstruction()->getDesc();
27   UsedResources.clear();
28 
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));
45       }
46       continue;
47     }
48 
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     }
62   }
63 
64   // Send a fake instruction issued event to all the views.
65   HWInstructionIssuedEvent Event(IR, UsedResources);
66   notifyEvent<HWInstructionIssuedEvent>(Event);
67   return true;
68 }
69 
70 } // namespace mca
71