File: IsaVerification.h

package info (click to toggle)
intel-graphics-compiler2 2.24.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 113,504 kB
  • sloc: cpp: 812,849; lisp: 288,219; ansic: 102,423; python: 4,010; yacc: 2,588; lex: 1,666; pascal: 318; sh: 162; makefile: 38
file content (107 lines) | stat: -rw-r--r-- 3,810 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) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

#pragma once

#include "BuildIR.h" // capability check
#include "Common_ISA.h"
#include <map>
#include <string>
#include <vector>
#include <optional>

// forward declaration
class VISAKernelImpl;
class VISAKernel_format_provider;

namespace vISA {
class IR_Builder;
}

class vISAVerifier {
  const VISAKernel_format_provider *header;
  Options *options;
  const vISA::IR_Builder *irBuilder = nullptr; // for capability check

  std::vector<std::string> kerror_list;
  std::vector<std::string> error_list;

  // true -- a label (referred to by its id) is defined in the kernel
  // false -- a label is used in the kernel but not yet defined
  std::map<int, bool> labelDefs;

public:
  vISAVerifier(const VISAKernel_format_provider *kernelHeader, Options *opt,
               const vISA::IR_Builder *ir_Builder)
      : header(kernelHeader), options(opt), irBuilder(ir_Builder) {}

  virtual ~vISAVerifier() = default;

  void run(VISAKernelImpl *kernel);

  int verifyInstruction(const CISA_INST *inst);

  bool hasErrors() const { return kerror_list.size() + error_list.size() > 0; }
  size_t getNumErrors() const { return kerror_list.size() + error_list.size(); }

  void writeReport(const char *filename);

  std::optional<std::string> getLastErrorFound() const {
    if (error_list.empty())
      return std::nullopt;
    return error_list.back();
  }

private:
  void verifyKernelHeader();

  // checks that can only be done once the whole kernel is processed.
  void finalize();

  void verifyVariableDecl(unsigned declID);
  void verifyPredicateDecl(unsigned declID);
  void verifyAddressDecl(unsigned declID);
  void verifyRegion(const CISA_INST *inst, unsigned i);
  void verifyRawOperandType(const CISA_INST *inst, const raw_opnd &opnd,
                            bool (*typeFunc)(VISA_Type));
  void verifyRawOperand(const CISA_INST *inst, unsigned i);
  void verifyVectorOperand(const CISA_INST *inst, unsigned i);
  void verifyOperand(const CISA_INST *inst, unsigned i);
  void verifyInstructionSVM(const CISA_INST *inst);
  void verifyInstructionMove(const CISA_INST *inst);
  void verifyInstructionSync(const CISA_INST *inst);
  void verifyInstructionControlFlow(const CISA_INST *inst);
  void verifyInstructionMisc(const CISA_INST *inst);
  void verifyInstructionArith(const CISA_INST *inst);
  void verifyInstructionLogic(const CISA_INST *inst);
  void verifyInstructionCompare(const CISA_INST *inst);
  void verifyInstructionAddress(const CISA_INST *inst);
  void verifyInstructionSampler(const CISA_INST *inst);
  void verifyInstructionSIMDFlow(const CISA_INST *inst);
  void verifyInstructionDataport(const CISA_INST *inst);
  void verifyKernelAttributes();

  bool checkImmediateIntegerOpnd(const vector_opnd &opnd,
                                 VISA_Type expected_type);

  // Feature-based verifier
  //     additional verification beside generic verification.
  void verifyBFMixedMode(const CISA_INST *inst);

  // Return Operand visa type. Return ISA_TYPE_NUM if unknown.
  VISA_Type getOperandVISAType(const CISA_INST *I, unsigned Ix) const;
  // Check if I's operands use the given type, if so, return true.
  bool useGivenVISAType(const CISA_INST *I, VISA_Type givenType) const;
  // If region is available, return true; otherwise, return false.
  bool getRegion(const vector_opnd &VecOpnd, uint16_t &row_offset,
                 uint16_t &col_offset, uint16_t &v_stride, uint16_t &width,
                 uint16_t &h_stride) const;

  void verifyInstructionLsc(const CISA_INST *inst);
  void verifyInstructionSrnd(const CISA_INST *inst);
};