File: CustomUnsafeOptPass.hpp

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 (100 lines) | stat: -rw-r--r-- 3,672 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
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2022 Intel Corporation

SPDX-License-Identifier: MIT

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

#pragma once

#include "Compiler/CodeGenPublic.h"
#include "Compiler/MetaDataUtilsWrapper.h"

#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include <llvm/IR/InstVisitor.h>
#include "llvm/ADT/SetVector.h"
#include <llvm/Analysis/LoopInfo.h>
#include "common/LLVMWarningsPop.hpp"

namespace IGC {
llvm::FunctionPass *CreateEarlyOutPatternsPass();
llvm::FunctionPass *CreateLowerFmaPass(bool respectFastMathFlags);
llvm::FunctionPass *CreateHoistFMulInLoopPass();

class CustomUnsafeOptPass : public llvm::FunctionPass, public llvm::InstVisitor<CustomUnsafeOptPass> {
public:
  static char ID;

  CustomUnsafeOptPass();

  ~CustomUnsafeOptPass() {}

  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
    AU.setPreservesCFG();
    AU.addRequired<MetaDataUtilsWrapper>();
    AU.addRequired<CodeGenContextWrapper>();
  }

  virtual bool runOnFunction(llvm::Function &F) override;

  virtual llvm::StringRef getPassName() const override { return "Custom Unsafe Optimization Pass"; }

  void visitInstruction(llvm::Instruction &I);
  void visitPHINode(llvm::PHINode &I);
  void visitBinaryOperator(llvm::BinaryOperator &I);
  void visitFCmpInst(llvm::FCmpInst &FC);
  void visitSelectInst(llvm::SelectInst &I);
  void visitIntrinsicInst(llvm::IntrinsicInst &I);
  void visitFPToSIInst(llvm::FPToSIInst &I);

  bool visitBinaryOperatorPropNegate(llvm::BinaryOperator &I);
  bool visitBinaryOperatorNegateMultiply(llvm::BinaryOperator &I);
  bool visitBinaryOperatorTwoConstants(llvm::BinaryOperator &I);
  bool visitBinaryOperatorDivDivOp(llvm::BinaryOperator &I);
  bool visitBinaryOperatorDivRsq(llvm::BinaryOperator &I);
  bool visitBinaryOperatorAddDiv(llvm::BinaryOperator &I);
  bool visitBinaryOperatorFmulFaddPropagation(llvm::BinaryOperator &I);
  bool visitBinaryOperatorExtractCommonMultiplier(llvm::BinaryOperator &I);
  bool visitBinaryOperatorXor(llvm::BinaryOperator &I);
  bool removeCommonMultiplier(llvm::Value *I, llvm::Value *commonMultiplier);
  bool visitBinaryOperatorFmulToFmad(llvm::BinaryOperator &I);
  bool visitBinaryOperatorToFmad(llvm::BinaryOperator &I);
  bool visitBinaryOperatorAddSubOp(llvm::BinaryOperator &I);
  bool visitBinaryOperatorDivAddDiv(llvm::BinaryOperator &I);
  bool visitBinaryOperatorFDivFMulCancellation(llvm::BinaryOperator &I);
  bool isFDiv(llvm::Value *I, llvm::Value *&numerator, llvm::Value *&denominator);
  bool possibleForFmadOpt(llvm::Instruction *inst);
  bool visitFCmpInstFCmpFAddOp(llvm::FCmpInst &FC);
  bool visitFCmpInstFCmpSelOp(llvm::FCmpInst &FC);
  bool visitFMulFCmpOp(llvm::FCmpInst &FC);
  bool visitExchangeCB(llvm::BinaryOperator &I);
  void matchMixOperation(llvm::BinaryOperator &I);

  bool m_isChanged;
  bool m_disableReorderingOpt;
  IGC::CodeGenContext *m_ctx;
  IGCMD::MetaDataUtils *m_pMdUtils;

private:
  inline llvm::BinaryOperator *copyIRFlags(llvm::BinaryOperator *newOp, llvm::Value *oldOp) {
    newOp->copyIRFlags(oldOp);

    llvm::DebugLoc dbg = ((llvm::Instruction *)oldOp)->getDebugLoc();
    newOp->setDebugLoc(std::move(dbg));

    return newOp;
  }

  void reassociateMulAdd(llvm::Function &F);

  void strengthReducePowOrExpLog(llvm::IntrinsicInst *intrin, llvm::Value *base, llvm::Value *exponent, bool isPow);

  void collectForErase(llvm::Instruction &I, unsigned int operandsDepth = 0);
  void eraseCollectedInst();

  llvm::SetVector<llvm::Instruction *> m_instToErase;
};

} // namespace IGC