blob: 8f6b8a91f38f499c3c913665d2bfee44c4840020 [file] [log] [blame]
Andrea Di Biagio35622482018-03-22 10:19:20 +00001//===--------------------- Support.cpp --------------------------*- C++ -*-===//
Andrea Di Biagio4704f032018-03-20 12:25:54 +00002//
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 Davisdea343d2018-06-25 16:53:00 +000011/// This file implements a few helper functions used by various pipeline
Andrea Di Biagio4704f032018-03-20 12:25:54 +000012/// components.
13///
14//===----------------------------------------------------------------------===//
15
16#include "Support.h"
17#include "llvm/MC/MCSchedule.h"
18
19namespace mca {
20
21using namespace llvm;
22
23void 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}
Andrea Di Biagiobdc67062018-06-01 14:35:21 +000051
52double 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
Andrea Di Biagio4704f032018-03-20 12:25:54 +000079} // namespace mca