1 //===--------------------- Support.cpp --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file implements a few helper functions used by various pipeline
14 //===----------------------------------------------------------------------===//
17 #include "llvm/MC/MCSchedule.h"
23 void computeProcResourceMasks(const MCSchedModel &SM,
24 SmallVectorImpl<uint64_t> &Masks) {
25 unsigned ProcResourceID = 0;
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)
34 Masks[I] = 1ULL << ProcResourceID;
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)
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;
52 double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth,
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;
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];
68 const MCProcResourceDesc &MCDesc = *SM.getProcResource(I);
69 double Throughput = static_cast<double>(ResourceCycles) / MCDesc.NumUnits;
70 Max = std::max(Max, Throughput);
73 // The block reciprocal throughput is computed as the MAX of:
74 // - (NumMicroOps / DispatchWidth)
75 // - (NumUnits / ResourceCycles) for every consumed processor resource.