blob: e97cc51430de12ed9adbcc56b607857ffb4bb452 [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///
11/// This file implements a few helper functions used by various backend
12/// 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}
51} // namespace mca