File: CheckInstrTypes.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 (106 lines) | stat: -rw-r--r-- 3,204 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
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

#pragma once

#include "Compiler/CodeGenContextWrapper.hpp"
#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include <llvm/IR/InstVisitor.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/LoopPass.h>
#include "common/LLVMWarningsPop.hpp"
#include "Compiler/IGCPassSupport.h"
#include "Compiler/CodeGenPublic.h"

namespace IGC {
// Forward declaration
struct SInstrTypes;

class CheckInstrTypes : public llvm::FunctionPass, public llvm::InstVisitor<CheckInstrTypes> {
  llvm::LoopInfo *LI = nullptr;

public:
  static char ID;

  CheckInstrTypes();
  CheckInstrTypes(bool afterOpts, bool metrics);

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

  void checkGlobalLocal(llvm::Instruction &I);

  virtual llvm::StringRef getPassName() const override { return "CheckInstrTypes"; }

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

  void visitInstruction(llvm::Instruction &I);

  void visitCallInst(llvm::CallInst &C);
  void visitBranchInst(llvm::BranchInst &I);
  void visitSwitchInst(llvm::SwitchInst &I);
  void visitIndirectBrInst(llvm::IndirectBrInst &I);
  void visitICmpInst(llvm::ICmpInst &I);
  void visitFCmpInst(llvm::FCmpInst &I);
  void visitAllocaInst(llvm::AllocaInst &I);
  void visitLoadInst(llvm::LoadInst &I);
  void visitStoreInst(llvm::StoreInst &I);
  void visitGetElementPtrInst(llvm::GetElementPtrInst &I);
  void visitPHINode(llvm::PHINode &PN);
  void visitSelectInst(llvm::SelectInst &I);
  void visitIntrinsicInst(llvm::IntrinsicInst &I);
  void SetLoopFlags(llvm::Function &F);

private:
  IGC::SInstrTypes g_InstrTypes = {};
  bool g_AfterOpts = false, g_metrics = false;
  CodeGenContext *context = nullptr;

  void print(llvm::raw_ostream &OS) const;
  void updateContext();
};

class InstrStatistic : public llvm::FunctionPass, public llvm::InstVisitor<InstrStatistic> {
public:
  static char ID;
  InstrStatistic()
      : FunctionPass(ID), m_ctx(nullptr), m_type(InstrStatTypes(0)), m_stage(InstrStatStage::BEGIN), m_threshold(0),
        m_LI(nullptr) {};
  InstrStatistic(CodeGenContext *ctx, InstrStatTypes type, InstrStatStage stage, int threshold);

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

  virtual llvm::StringRef getPassName() const override { return "InstrStatistic"; }

  void visitLoadInst(llvm::LoadInst &I);
  void visitStoreInst(llvm::StoreInst &I);

  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
    AU.addRequired<llvm::LoopInfoWrapperPass>();
    AU.setPreservesAll();
  }

private:
  CodeGenContext *m_ctx;
  IGC::InstrStatTypes m_type;
  InstrStatStage m_stage;
  int m_threshold;
  llvm::LoopInfo *m_LI;

  bool parseLoops();
  bool parseLoop(llvm::Loop *loop);

  void print(llvm::raw_ostream &OS) const;
};

} // namespace IGC