File: GenXRawSendRipper.cpp

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (107 lines) | stat: -rw-r--r-- 2,625 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
99
100
101
102
103
104
105
106
107
/*========================== begin_copyright_notice ============================

Copyright (C) 2018-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

//
/// GenXRawSendRipper
/// -----------------
///
/// This pass tears down a series of raw send chained through the old value
/// operand when it's safe.
//===----------------------------------------------------------------------===//
//
#include "GenX.h"

#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"

#define DEBUG_TYPE "genx-raw-send-ripper"

using namespace llvm;
using namespace genx;

namespace {

class GenXRawSendRipper : public FunctionPass {

public:
  static char ID;
  explicit GenXRawSendRipper() : FunctionPass(ID) {}

  StringRef getPassName() const override {
    return "GenX RAW send ripper";
  }

  void getAnalysisUsage(AnalysisUsage &AU) const override {
    AU.setPreservesCFG();
  }

  bool runOnFunction(Function &F) override;
};

} // End anonymous namespace

namespace llvm {
void initializeGenXRawSendRipperPass(PassRegistry &);
} // End namespace llvm

char GenXRawSendRipper::ID = 0;
INITIALIZE_PASS(GenXRawSendRipper, "GenXRawSendRipper",
                "Rip chain of raw send", false, false)

FunctionPass *llvm::createGenXRawSendRipperPass() {
  initializeGenXRawSendRipperPass(*PassRegistry::getPassRegistry());
  return new GenXRawSendRipper();
}

bool GenXRawSendRipper::runOnFunction(Function &F) {
  bool Changed = false;

  for (auto &I : instructions(F)) {
    auto IID = vc::getAnyIntrinsicID(&I);
    int PredIdx = -1;
    int PassthruIdx = -1;

    switch (IID) {
    default:
      continue;
    case GenXIntrinsic::genx_raw_send:
      PredIdx = 1;
      PassthruIdx = 5;
      break;
    case GenXIntrinsic::genx_raw_sends:
      PredIdx = 1;
      PassthruIdx = 7;
      break;
    case GenXIntrinsic::genx_raw_send2:
      PredIdx = 2;
      PassthruIdx = 9;
      break;
    case GenXIntrinsic::genx_raw_sends2:
      PredIdx = 2;
      PassthruIdx = 11;
      break;
    }

    IGC_ASSERT_EXIT(PredIdx >= 0 && PassthruIdx >= 0);
    auto *Pred = dyn_cast<Constant>(I.getOperand(PredIdx));
    auto *Passthru = I.getOperand(PassthruIdx);

    if (!Pred || !Pred->getType()->isIntOrIntVectorTy(1) ||
        !Pred->isAllOnesValue() || isa<UndefValue>(Passthru))
      continue;

    I.setOperand(PassthruIdx, UndefValue::get(Passthru->getType()));
    Changed = true;
  }

  return Changed;
}