LLVM 20.0.0git
InstructionTables.cpp
Go to the documentation of this file.
1//===--------------------- InstructionTables.cpp ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file implements the method InstructionTables::execute().
11/// Method execute() prints a theoretical resource pressure distribution based
12/// on the information available in the scheduling model, and without running
13/// the pipeline.
14///
15//===----------------------------------------------------------------------===//
16
18
19namespace llvm {
20namespace mca {
21
23 const InstrDesc &Desc = IR.getInstruction()->getDesc();
24 UsedResources.clear();
25
26 // Identify the resources consumed by this instruction.
27 for (const std::pair<uint64_t, ResourceUsage> &Resource :
28 Desc.Resources) {
29 // Skip zero-cycle resources (i.e., unused resources).
30 if (!Resource.second.size())
31 continue;
32 unsigned Cycles = Resource.second.size();
33 unsigned Index = std::distance(Masks.begin(), find(Masks, Resource.first));
34 const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
35 unsigned NumUnits = ProcResource.NumUnits;
36 if (!ProcResource.SubUnitsIdxBegin) {
37 // The number of cycles consumed by each unit.
38 for (unsigned I = 0, E = NumUnits; I < E; ++I) {
39 ResourceRef ResourceUnit = std::make_pair(Index, 1U << I);
40 UsedResources.emplace_back(
41 std::make_pair(ResourceUnit, ReleaseAtCycles(Cycles, NumUnits)));
42 }
43 continue;
44 }
45
46 // This is a group. Obtain the set of resources contained in this
47 // group. Some of these resources may implement multiple units.
48 // Uniformly distribute Cycles across all of the units.
49 for (unsigned I1 = 0; I1 < NumUnits; ++I1) {
50 unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1];
51 const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx);
52 // Compute the number of cycles consumed by each resource unit.
53 for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) {
54 ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2);
55 UsedResources.emplace_back(std::make_pair(
56 ResourceUnit,
57 ReleaseAtCycles(Cycles, NumUnits * SubUnit.NumUnits)));
58 }
59 }
60 }
61
62 // Send a fake instruction issued event to all the views.
63 HWInstructionIssuedEvent Event(IR, UsedResources);
64 notifyEvent<HWInstructionIssuedEvent>(Event);
65 return ErrorSuccess();
66}
67
68} // namespace mca
69} // namespace llvm
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file implements a custom stage to generate instruction tables.
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:81
#define I(x, y, z)
Definition: MD5.cpp:58
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition: Error.h:335
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:950
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:720
Error execute(InstRef &IR) override
The primary action that this stage performs on instruction IR.
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:51
std::pair< uint64_t, uint64_t > ResourceRef
A resource unit identifier.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1742
Description of the encoding of one expression Op.
Define a kind of processor resource that will be modeled by the scheduler.
Definition: MCSchedule.h:31
const unsigned * SubUnitsIdxBegin
Definition: MCSchedule.h:53
const MCProcResourceDesc * getProcResource(unsigned ProcResourceIdx) const
Definition: MCSchedule.h:353
An instruction descriptor.
Definition: Instruction.h:447