LLVM  8.0.1
InstructionTables.cpp
Go to the documentation of this file.
1 //===--------------------- InstructionTables.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 the method InstructionTables::execute().
12 /// Method execute() prints a theoretical resource pressure distribution based
13 /// on the information available in the scheduling model, and without running
14 /// the pipeline.
15 ///
16 //===----------------------------------------------------------------------===//
17 
19 
20 namespace llvm {
21 namespace mca {
22 
24  const InstrDesc &Desc = IR.getInstruction()->getDesc();
25  UsedResources.clear();
26 
27  // Identify the resources consumed by this instruction.
28  for (const std::pair<uint64_t, ResourceUsage> Resource : 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(
34  Masks.begin(), std::find(Masks.begin(), Masks.end(), Resource.first));
35  const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
36  unsigned NumUnits = ProcResource.NumUnits;
37  if (!ProcResource.SubUnitsIdxBegin) {
38  // The number of cycles consumed by each unit.
39  for (unsigned I = 0, E = NumUnits; I < E; ++I) {
40  ResourceRef ResourceUnit = std::make_pair(Index, 1U << I);
41  UsedResources.emplace_back(
42  std::make_pair(ResourceUnit, ResourceCycles(Cycles, NumUnits)));
43  }
44  continue;
45  }
46 
47  // This is a group. Obtain the set of resources contained in this
48  // group. Some of these resources may implement multiple units.
49  // Uniformly distribute Cycles across all of the units.
50  for (unsigned I1 = 0; I1 < NumUnits; ++I1) {
51  unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1];
52  const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx);
53  // Compute the number of cycles consumed by each resource unit.
54  for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) {
55  ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2);
56  UsedResources.emplace_back(std::make_pair(
57  ResourceUnit, ResourceCycles(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
Instruction * getInstruction()
Definition: Instruction.h:488
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This file implements a custom stage to generate instruction tables.
Subclass of Error for the sole purpose of identifying the success path in the type system...
Definition: Error.h:325
const MCProcResourceDesc * getProcResource(unsigned ProcResourceIdx) const
Definition: MCSchedule.h:339
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:478
const InstrDesc & getDesc() const
Definition: Instruction.h:382
const unsigned * SubUnitsIdxBegin
Definition: MCSchedule.h:54
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error execute(InstRef &IR) override
The primary action that this stage performs on instruction IR.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
std::pair< uint64_t, uint64_t > ResourceRef
A resource unit identifier.
SmallVector< std::pair< uint64_t, ResourceUsage >, 4 > Resources
Definition: Instruction.h:328
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1207
Define a kind of processor resource that will be modeled by the scheduler.
Definition: MCSchedule.h:32
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:51
An instruction descriptor.
Definition: Instruction.h:322
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
#define I(x, y, z)
Definition: MD5.cpp:58
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Statically lint checks LLVM IR
Definition: Lint.cpp:193