1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2017-2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #pragma once 10 11 #include <vector> 12 #include <string> 13 #include <map> 14 #include "Common_ISA.h" 15 #include "BuildIR.h" // capability check 16 17 //forward declaration 18 class VISAKernelImpl; 19 namespace vISA 20 { 21 class IR_Builder; 22 } 23 24 class vISAVerifier 25 { 26 const common_isa_header& isaHeader; 27 const print_format_provider_t* header; 28 Options* options; 29 30 std::vector<std::string> kerror_list; 31 std::vector<std::string> error_list; 32 33 // true -- a label (referred to by its id) is defined in the kernel 34 // false -- a label is used in the kernel but not yet defined 35 std::map<int, bool> labelDefs; 36 37 const vISA::IR_Builder* irBuilder = nullptr; // for capability check 38 39 public: 40 vISAVerifier(const common_isa_header & vISAHeader,const print_format_provider_t * kernelHeader,Options * opt)41 vISAVerifier(const common_isa_header& vISAHeader, const print_format_provider_t* kernelHeader, Options* opt) : 42 isaHeader(vISAHeader), header(kernelHeader), options(opt) {} 43 44 virtual ~vISAVerifier() = default; 45 46 void run(VISAKernelImpl* kernel); 47 hasErrors()48 bool hasErrors() const { return kerror_list.size() + error_list.size() > 0; } getNumErrors()49 size_t getNumErrors() const { return kerror_list.size() + error_list.size(); } 50 51 void writeReport(const char* filename); 52 53 private: 54 55 void verifyKernelHeader(); 56 void verifyInstruction(const CISA_INST* inst); 57 58 // checks that can only be done once the whole kernel is processed. 59 void finalize(); 60 61 void verifyVariableDecl( 62 unsigned declID); 63 void verifyPredicateDecl( 64 unsigned declID); 65 void verifyAddressDecl( 66 unsigned declID); 67 void verifyRegion( 68 const CISA_INST* inst, 69 unsigned i); 70 void verifyRawOperandType( 71 const CISA_INST* inst, 72 const raw_opnd& opnd, 73 bool (*typeFunc)(VISA_Type)); 74 void verifyRawOperand( 75 const CISA_INST* inst, unsigned i); 76 void verifyVectorOperand( 77 const CISA_INST* inst, 78 unsigned i); 79 void verifyOperand( 80 const CISA_INST* inst, 81 unsigned i); 82 void verifyInstructionSVM( 83 const CISA_INST* inst); 84 void verifyInstructionMove( 85 const CISA_INST* inst); 86 void verifyInstructionSync( 87 const CISA_INST* inst); 88 void verifyInstructionControlFlow( 89 const CISA_INST* inst); 90 void verifyInstructionMisc( 91 const CISA_INST* inst); 92 void verifyInstructionArith( 93 const CISA_INST* inst); 94 void verifyInstructionLogic( 95 const CISA_INST* inst); 96 void verifyInstructionCompare( 97 const CISA_INST* inst); 98 void verifyInstructionAddress( 99 const CISA_INST* inst); 100 void verifyInstructionSampler( 101 const CISA_INST* inst); 102 void verifyInstructionSIMDFlow( 103 const CISA_INST* inst); 104 void verifyInstructionDataport( 105 const CISA_INST* inst); 106 void verifyKernelAttributes(); 107 108 bool checkImmediateIntegerOpnd( 109 const vector_opnd& opnd, 110 VISA_Type expected_type); 111 112 // Feature-based verifier 113 // additional verification beside generic verification. 114 void verifyBFMixedMode( 115 const CISA_INST* inst); 116 117 // Return Operand visa type. Return ISA_TYPE_NUM if unknown. 118 VISA_Type getOperandVISAType(const CISA_INST* I, unsigned Ix) const; 119 // Check if I's operands use the given type, if so, return true. 120 bool useGivenVISAType(const CISA_INST* I, VISA_Type givenType) const; 121 // If region is available, return true; otherwise, return false. 122 bool getRegion(const vector_opnd& VecOpnd, 123 uint16_t& row_offset, uint16_t& col_offset, 124 uint16_t& v_stride, uint16_t& width, uint16_t& h_stride) const; 125 126 void verifyInstructionLsc( 127 const CISA_INST* inst); 128 void verifyInstructionSrnd( 129 const CISA_INST* inst); 130 }; 131 132