File: VerificationPass.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 (104 lines) | stat: -rw-r--r-- 3,182 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
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

///=======================================================================================
/// This file contains types, enumerations, classes and other declarations used by
/// the IGC IR Verification Pass.
#pragma once

#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include <llvm/IR/InstVisitor.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/ArrayRef.h>
#include "llvm/Support/raw_ostream.h"
#include "common/LLVMWarningsPop.hpp"
#include "GenISAIntrinsics/GenIntrinsicInst.h"

#include <set>
#include <vector>

namespace IGC {
enum class IRSpecObjectClass { Instruction, GenISAIntrinsic, Intrinsic };

class VerificationPass : public llvm::ModulePass {
public:
  // Pass identification, replacement for typeid
  static char ID;

  /// @brief  Constructor
  VerificationPass();

  /// Destructor
  ~VerificationPass() {}

  /// @brief  Provides name of pass
  virtual llvm::StringRef getPassName() const override { return "VerificationPass"; }

  /// Entry point of the pass.
  virtual bool runOnModule(llvm::Module &M) override;

protected:
  // Module
  llvm::Module *m_Module;

  // String for collecting verification error messages.
  std::string m_str;

  // Stream interface for m_str
  llvm::raw_string_ostream m_messagesToDump;

  /// This structure contains sets of valid IGC IR objects
  /// such as types, intrinsic functions, etc.
  struct {
    std::set<unsigned int> FPTypeSizes;
    std::set<unsigned int> vectorTypeSizes;
    std::set<unsigned int> Instructions;
    std::set<llvm::Intrinsic::ID> IGCLLVMIntrinsics; // LLVM intrinsics supported by IGC
  } m_IGC_IR_spec;

  /// Initialization of the pass data
  void initVerificationPass();

  void addIRSpecObject(IRSpecObjectClass objClass, unsigned int ID);

  /// Verification of the function and its content.
  bool verifyFunction(llvm::Function &F);

  /// Verification of instruction.
  bool verifyInstruction(llvm::Instruction &inst);

  /// Common verification function that is executed
  /// for all types of instructions.
  bool verifyInstCommon(llvm::Instruction &inst);

  ///------------------------------------------------------
  /// Instruction verification functions for specific
  /// types of instructions should be declared here.
  ///------------------------------------------------------

  /// Specific verification function for Call instructions.
  bool verifyInstCall(llvm::Instruction &inst);
  /// Specific verification function for insert/extract instructions.
  bool verifyVectorInst(llvm::Instruction &inst);

  ///------------------------------------------------------

  /// Verification of values
  bool verifyValue(llvm::Value *val);

  /// Verification of type
  bool verifyType(llvm::Type *type, llvm::Value *val);

  /// Dumps the verification errors.
  void dumpMessages(llvm::Module &M);

  /// Prints the LLVM value into m_messagesToDump text stream.
  void printValue(llvm::Value *value);
};
} // namespace IGC