From 2008c7c8fdc27ca1ac25cf9758abea066047e67d Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Mon, 4 Jun 2018 12:23:07 +0000 Subject: [llvm-mca] Track cycles contributed by resources that are in a 'Super' relationship. This is required if we want to correctly match the behavior of method SubtargetEmitter::ExpandProcResource() in Tablegen. When computing the set of "consumed" processor resources and resource cycles, the logic in ExpandProcResource() doesn't update the number of resource cycles contributed by a "Super" resource to a group. We need to take this into account when a model declares a processor resource which is part of a 'processor resource group', and it is also used as the "Super" of other resources. llvm-svn: 333892 --- llvm/tools/llvm-mca/InstrBuilder.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'llvm/tools/llvm-mca') diff --git a/llvm/tools/llvm-mca/InstrBuilder.cpp b/llvm/tools/llvm-mca/InstrBuilder.cpp index bca3e4bc0d7..a745e1a6150 100644 --- a/llvm/tools/llvm-mca/InstrBuilder.cpp +++ b/llvm/tools/llvm-mca/InstrBuilder.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "InstrBuilder.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/MC/MCInst.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -33,6 +34,19 @@ static void initializeUsedResources(InstrDesc &ID, // Populate resources consumed. using ResourcePlusCycles = std::pair; std::vector Worklist; + + // Track cycles contributed by resources that are in a "Super" relationship. + // This is required if we want to correctly match the behavior of method + // SubtargetEmitter::ExpandProcResource() in Tablegen. When computing the set + // of "consumed" processor resources and resource cycles, the logic in + // ExpandProcResource() doesn't update the number of resource cycles + // contributed by a "Super" resource to a group. + // We need to take this into account when we find that a processor resource is + // part of a group, and it is also used as the "Super" of other resources. + // This map stores the number of cycles contributed by sub-resources that are + // part of a "Super" resource. The key value is the "Super" resource mask ID. + DenseMap SuperResources; + for (unsigned I = 0, E = SCDesc.NumWriteProcResEntries; I < E; ++I) { const MCWriteProcResEntry *PRE = STI.getWriteProcResBegin(&SCDesc) + I; const MCProcResourceDesc &PR = *SM.getProcResource(PRE->ProcResourceIdx); @@ -41,6 +55,10 @@ static void initializeUsedResources(InstrDesc &ID, ID.Buffers.push_back(Mask); CycleSegment RCy(0, PRE->Cycles, false); Worklist.emplace_back(ResourcePlusCycles(Mask, ResourceUsage(RCy))); + if (PR.SuperIdx) { + uint64_t Super = ProcResourceMasks[PR.SuperIdx]; + SuperResources[Super] += PRE->Cycles; + } } // Sort elements by mask popcount, so that we prioritize resource units over @@ -80,7 +98,7 @@ static void initializeUsedResources(InstrDesc &ID, for (unsigned J = I + 1; J < E; ++J) { ResourcePlusCycles &B = Worklist[J]; if ((NormalizedMask & B.first) == NormalizedMask) { - B.second.CS.Subtract(A.second.size()); + B.second.CS.Subtract(A.second.size() - SuperResources[A.first]); if (countPopulation(B.first) > 1) B.second.NumUnits++; } -- cgit v1.2.3