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;
}
|