File: CrossingAnalysis.h

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (98 lines) | stat: -rw-r--r-- 3,168 bytes parent folder | download
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
95
96
97
98
/*========================== begin_copyright_notice ============================

Copyright (C) 2021 Intel Corporation

SPDX-License-Identifier: MIT

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

//===- CoroFrame.cpp - Builds and manipulates coroutine frame -------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once
#include "Probe/Assertion.h"
#include "Compiler/CodeGenPublic.h"
#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/Function.h>
#include <llvm/ADT/BitVector.h>
#include <llvm/IR/CFG.h>
#include "common/LLVMWarningsPop.hpp"

#include <vector>

namespace IGC {

void splitAround(llvm::Instruction *I, const llvm::Twine &Name);

class BlockToIndexMapping {
  llvm::SmallVector<llvm::BasicBlock *, 32> V;

public:
  size_t size() const { return V.size(); }

  BlockToIndexMapping(llvm::Function &F) {
    for (llvm::BasicBlock &BB : F)
      V.push_back(&BB);
    llvm::sort(V);
  }

  size_t blockToIndex(llvm::BasicBlock *BB) const {
    auto *I = llvm::lower_bound(V, BB);
    IGC_ASSERT_MESSAGE(I != V.end(), "BasicBlockNumberng: Unknown block");
    IGC_ASSERT_MESSAGE(*I == BB, "BasicBlockNumberng: Unknown block");
    return I - V.begin();
  }

  llvm::BasicBlock *indexToBlock(unsigned Index) const { return V[Index]; }
};

// The SuspendCrossingInfo maintains data that allows to answer a question
// whether given two BasicBlocks A and B there is a path from A to B that
// passes through a suspend point.
//
// For every basic block 'i' it maintains a BlockData that consists of:
//   Consumes:  a bit vector which contains a set of indices of blocks that can
//              reach block 'i'
//   Kills: a bit vector which contains a set of indices of blocks that can
//          reach block 'i', but one of the path will cross a suspend point
//   Suspend: a boolean indicating whether block 'i' contains a suspend point.
//

class SuspendCrossingInfo {
  BlockToIndexMapping Mapping;

  struct BlockData {
    llvm::BitVector Consumes;
    llvm::BitVector Kills;
    bool Suspend = false;
  };
  llvm::SmallVector<BlockData, 32> Block;

  llvm::iterator_range<llvm::succ_iterator> successors(BlockData const &BD) const;

  BlockData &getBlockData(llvm::BasicBlock *BB);

public:
  void print(llvm::raw_ostream &OS) const;
  void print(llvm::raw_ostream &OS, llvm::StringRef Label, llvm::BitVector const &BV) const;

  void dump() const;
  void dumpToFile(const CodeGenContext *Ctx) const;

  SuspendCrossingInfo(llvm::Function &F, const std::vector<llvm::Instruction *> &SuspendPoints);

  bool hasPathCrossingSuspendPoint(llvm::BasicBlock *DefBB, llvm::BasicBlock *UseBB) const;

  bool isDefinitionAcrossSuspend(llvm::BasicBlock *DefBB, llvm::User *U) const;

  bool isDefinitionAcrossSuspend(llvm::Argument &A, llvm::User *U) const;

  bool isDefinitionAcrossSuspend(llvm::Instruction &I, llvm::User *U) const;
};

} // namespace IGC