File: SplitAlignedScalars.h

package info (click to toggle)
intel-graphics-compiler2 2.28.4-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 792,656 kB
  • sloc: cpp: 5,761,745; ansic: 466,928; lisp: 312,143; python: 114,790; asm: 44,736; pascal: 10,930; sh: 8,033; perl: 7,914; ml: 3,625; awk: 3,523; yacc: 2,747; javascript: 2,667; lex: 1,898; f90: 1,028; cs: 573; xml: 474; makefile: 344; objc: 162
file content (94 lines) | stat: -rw-r--r-- 2,984 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*========================== begin_copyright_notice ============================

Copyright (C) 2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#ifndef __SPLITALIGNEDSCALARS_H__
#define __SPLITALIGNEDSCALARS_H__

#include "visa/GraphColor.h"

namespace vISA {
class SplitAlignedScalars {
private:
  // Constant trip count assume for each loop to estimate dynamic inst
  // count change due to splitting.
  const unsigned int EstimatedLoopTripCount = 4;
  // Minimum instruction distance required for splitting
  unsigned int MinOptDist = 0;
  // Threshold percent increase in estimated dynamic inst count allowed
  float BloatAllowed = 0.0f;

  unsigned int numDclsReplaced = 0;
  unsigned int numMovsAdded = 0;
  GlobalRA &gra;
  GraphColor &coloring;
  G4_Kernel &kernel;
  bool changesMade = false;

  class Data {
  public:
    unsigned int firstDef = 0;
    unsigned int lastUse = 0;
    bool allowed = true;
    unsigned int getDUMaxDist() {
      return std::abs((int)lastUse - (int)firstDef);
    };
    std::vector<std::pair<G4_BB *, G4_INST *>> defs;
    // store vector of <bb, inst, src#>
    std::vector<std::tuple<G4_BB *, G4_INST *, unsigned int>> uses;
  };

  std::unordered_map<G4_Declare *, Data> dclData;
  std::unordered_map<G4_Declare *, G4_Declare *> oldNewDcls;

  bool static canReplaceDst(G4_INST *inst);
  bool static canReplaceSrc(G4_INST *inst, unsigned int idx);

  bool heuristic(G4_Declare *dcl, Data &d);
  bool isDclCandidate(G4_Declare *dcl);
  std::vector<G4_Declare *> gatherCandidates();
  void pruneCandidates(std::vector<G4_Declare *> &candidates);
  unsigned int computeNumMovs(G4_Declare *dcl);

  template <class T> G4_Declare *getDclForRgn(T *rgn, G4_Declare *newTopDcl);

  // store set of dcls marked as spill in current RA iteration
  std::unordered_set<G4_Declare *> spilledDclSet;
  // store spill cost for each dcl
  std::unordered_map<G4_Declare *, float> dclSpillCost;
  // store dcls that have callee save bias
  std::unordered_set<G4_Declare *> calleeSaveBiased;

public:
  SplitAlignedScalars(GlobalRA &g, GraphColor &c)
      : gra(g), coloring(c), kernel(g.kernel) {
    MinOptDist =
        g.kernel.getOptions()->getuInt32Option(vISA_SplitAlignedScalarMinDist);
    BloatAllowed = g.kernel.getOptions()->getuInt32Option(
        vISA_SplitAlignedScalarBloatPPT) / 1000.0f;
    for (auto spill : coloring.getSpilledLiveRanges()) {
      spilledDclSet.insert(spill->getDcl());
    }
    auto numVars = coloring.getNumVars();
    auto lrs = coloring.getLiveRanges();
    for (unsigned int i = 0; i != numVars; ++i) {
      auto rootDcl = lrs[i]->getDcl();
      dclSpillCost[rootDcl] = lrs[i]->getSpillCost();
      if (lrs[i]->getCalleeSaveBias())
        calleeSaveBiased.insert(rootDcl);
    }
  }

  void run();

  bool getChangesMade() { return changesMade; }

  void dump(std::ostream &of = std::cerr);
};

} // namespace vISA
#endif