1 //===--------------------- Support.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 a few helper functions used by various pipeline
12 /// components.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #include "Support.h"
17 #include "llvm/MC/MCSchedule.h"
18
19 namespace mca {
20
21 using namespace llvm;
22
computeProcResourceMasks(const MCSchedModel & SM,SmallVectorImpl<uint64_t> & Masks)23 void computeProcResourceMasks(const MCSchedModel &SM,
24 SmallVectorImpl<uint64_t> &Masks) {
25 unsigned ProcResourceID = 0;
26
27 // Create a unique bitmask for every processor resource unit.
28 // Skip resource at index 0, since it always references 'InvalidUnit'.
29 Masks.resize(SM.getNumProcResourceKinds());
30 for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {
31 const MCProcResourceDesc &Desc = *SM.getProcResource(I);
32 if (Desc.SubUnitsIdxBegin)
33 continue;
34 Masks[I] = 1ULL << ProcResourceID;
35 ProcResourceID++;
36 }
37
38 // Create a unique bitmask for every processor resource group.
39 for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {
40 const MCProcResourceDesc &Desc = *SM.getProcResource(I);
41 if (!Desc.SubUnitsIdxBegin)
42 continue;
43 Masks[I] = 1ULL << ProcResourceID;
44 for (unsigned U = 0; U < Desc.NumUnits; ++U) {
45 uint64_t OtherMask = Masks[Desc.SubUnitsIdxBegin[U]];
46 Masks[I] |= OtherMask;
47 }
48 ProcResourceID++;
49 }
50 }
51
computeBlockRThroughput(const MCSchedModel & SM,unsigned DispatchWidth,unsigned NumMicroOps,ArrayRef<unsigned> ProcResourceUsage)52 double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth,
53 unsigned NumMicroOps,
54 ArrayRef<unsigned> ProcResourceUsage) {
55 // The block throughput is bounded from above by the hardware dispatch
56 // throughput. That is because the DispatchWidth is an upper bound on the
57 // number of opcodes that can be part of a single dispatch group.
58 double Max = static_cast<double>(NumMicroOps) / DispatchWidth;
59
60 // The block throughput is also limited by the amount of hardware parallelism.
61 // The number of available resource units affects the resource pressure
62 // distribution, as well as how many blocks can be executed every cycle.
63 for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
64 unsigned ResourceCycles = ProcResourceUsage[I];
65 if (!ResourceCycles)
66 continue;
67
68 const MCProcResourceDesc &MCDesc = *SM.getProcResource(I);
69 double Throughput = static_cast<double>(ResourceCycles) / MCDesc.NumUnits;
70 Max = std::max(Max, Throughput);
71 }
72
73 // The block reciprocal throughput is computed as the MAX of:
74 // - (NumMicroOps / DispatchWidth)
75 // - (NumUnits / ResourceCycles) for every consumed processor resource.
76 return Max;
77 }
78
79 } // namespace mca
80