mlir-script.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. import * as child_process from 'child_process';
  2. import * as fs from 'fs/promises';
  3. import * as os from 'os';
  4. import * as path from 'path';
  5. import * as process from 'process';
  6. import * as readline from 'readline';
  7. import * as tablegen from './tablegen.js';
  8. import * as url from 'url';
  9. const write = (message) => {
  10. if (process.stdout.write) {
  11. process.stdout.write(message);
  12. }
  13. };
  14. const writeLine = (message) => {
  15. write(message + os.EOL);
  16. };
  17. class Operator {
  18. constructor(def) {
  19. this.def = def;
  20. this.opName = def.getValueAsString('opName');
  21. const dialectDef = this.def.getValueAsDef('opDialect');
  22. if (dialectDef) {
  23. this.dialectName = dialectDef.getValueAsString('name');
  24. }
  25. }
  26. getDialectName() {
  27. return this.dialectName || '';
  28. }
  29. getOperationName() {
  30. return this.dialectName && this.opName ? `${this.dialectName}.${this.opName}` : null;
  31. }
  32. }
  33. const access = async (path) => {
  34. try {
  35. await fs.access(path);
  36. return true;
  37. } catch {
  38. return false;
  39. }
  40. };
  41. const schema = async () => {
  42. const dirname = path.dirname(url.fileURLToPath(import.meta.url));
  43. const source = path.join(dirname, '..', 'third_party', 'source', 'mlir');
  44. const paths = [
  45. path.join(source),
  46. path.join(source, 'llvm-project'),
  47. path.join(source, 'llvm-project', 'mlir', 'include'),
  48. path.join(source, 'llvm-project', 'mlir', 'test', 'lib', 'Dialect', 'Test'),
  49. path.join(source, 'llvm-project', 'mlir', 'test', 'lib', 'Dialect', 'Transform'),
  50. path.join(source, 'llvm-project', 'mlir', 'test', 'lib', 'Transforms'),
  51. path.join(source, 'llvm-project', 'mlir', 'include', 'mlir', 'Dialect', 'ArmNeon'),
  52. path.join(source, 'llvm-project', 'mlir', 'include', 'mlir', 'Dialect', 'ArmSME', 'IR'),
  53. path.join(source, 'llvm-project', 'mlir', 'include', 'mlir', 'Dialect', 'ArmSVE', 'IR'),
  54. path.join(source, 'llvm-project', 'mlir', 'examples', 'standalone', 'include'),
  55. path.join(source, 'llvm-project', 'mlir', 'examples', 'toy', 'Ch7', 'include'),
  56. path.join(source, 'llvm-project', 'mlir', 'examples', 'transform', 'Ch2', 'include'),
  57. path.join(source, 'llvm-project', 'mlir', 'examples', 'transform', 'Ch3', 'include'),
  58. path.join(source, 'llvm-project', 'mlir', 'examples', 'transform', 'Ch4', 'include'),
  59. path.join(source, 'stablehlo'),
  60. path.join(source, 'shardy'),
  61. path.join(source, 'xla', 'xla', 'mlir_hlo'),
  62. path.join(source, 'onnx-mlir'),
  63. path.join(source, 'torch-mlir', 'include'),
  64. path.join(source, 'triton', 'include'),
  65. path.join(source, 'triton', 'third_party'),
  66. path.join(source, 'triton', 'third_party', 'amd', 'include', 'Dialect', 'TritonAMDGPU', 'IR'),
  67. path.join(source, 'iree', 'compiler', 'src'),
  68. path.join(source, 'iree', 'compiler', 'src', 'iree', 'compiler', 'Codegen', 'Dialect', 'PCF', 'IR'),
  69. path.join(source, 'iree', 'compiler', 'src', 'iree', 'compiler', 'Modules', 'IO', 'Parameters', 'IR'),
  70. path.join(source, 'iree', 'llvm-external-projects', 'iree-dialects', 'include'),
  71. path.join(source, 'FlashTensor', 'include'),
  72. path.join(source, 'tpu-mlir', 'include'),
  73. path.join(source, 'tensorflow'),
  74. path.join(source, 'tensorflow', 'tensorflow', 'compiler', 'mlir', 'tfrt', 'ir'),
  75. path.join(source, 'runtime', 'include'),
  76. path.join(source, 'plaidml'),
  77. path.join(source, 'plaidml', 'pmlc', 'dialect', 'pxa', 'ir'),
  78. path.join(source, 'mlir-dace', 'include'),
  79. path.join(source, 'lltz', 'mlir', 'dialect', 'include', 'Michelson'),
  80. path.join(source, 'lagrad', 'include', 'LAGrad'),
  81. path.join(source, 'TensorRT-Incubator', 'mlir-tensorrt', 'tensorrt', 'include'),
  82. path.join(source, 'TensorRT-Incubator', 'mlir-tensorrt', 'executor', 'include'),
  83. path.join(source, 'TensorRT-Incubator', 'mlir-tensorrt', 'compiler', 'include'),
  84. path.join(source, 'TensorRT-Incubator', 'mlir-tensorrt', 'kernel', 'include'),
  85. path.join(source, 'TensorRT-Incubator', 'mlir-tensorrt', 'common', 'include'),
  86. path.join(source, 'triton', 'third_party', 'nvidia', 'include'),
  87. path.join(source, 'triton', 'third_party', 'nvidia', 'include', 'Dialect', 'NVGPU', 'IR'),
  88. path.join(source, 'triton', 'third_party', 'nvidia', 'include', 'Dialect', 'NVWS', 'IR'),
  89. path.join(source, 'clangir'),
  90. path.join(source, 'clangir', 'clang', 'include'),
  91. path.join(source, 'rocMLIR'),
  92. path.join(source, 'rocMLIR', 'mlir', 'include'),
  93. path.join(source, '_', 'llvm-project', 'mlir', 'include'),
  94. path.join(source, '_', 'mlir-hlo'),
  95. ];
  96. const dialects = [
  97. 'pmlc/dialect/tile/ir/ops.td',
  98. 'pmlc/dialect/stdx/ir/ops.td',
  99. 'pmlc/dialect/pxa/ir/ops.td',
  100. 'pmlc/dialect/linalgx/ir/ops.td',
  101. 'pmlc/dialect/xsmm/ir/ops.td',
  102. 'pmlc/dialect/layer/ir/ops.td',
  103. 'mlir/include/mlir/IR/BuiltinAttributeInterfaces.td',
  104. 'mlir/include/mlir/IR/BuiltinTypeInterfaces.td',
  105. 'mlir/include/mlir/IR/BuiltinLocationAttributes.td',
  106. 'mlir/include/mlir/IR/BuiltinDialect.td',
  107. 'mlir/include/mlir/IR/BuiltinOps.td',
  108. 'mlir/include/mlir/IR/BuiltinDialectBytecode.td',
  109. 'mlir/include/mlir/IR/BuiltinAttributes.td',
  110. 'mlir/include/mlir/IR/BuiltinTypes.td',
  111. 'mlir/include/mlir/Dialect/Affine/IR/AffineOps.td',
  112. 'mlir/include/mlir/Dialect/Affine/IR/AffineOps.td',
  113. 'mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td',
  114. 'mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td',
  115. 'mlir/include/mlir/Dialect/AMX/AMX.td',
  116. 'mlir/include/mlir/Dialect/Arith/IR/ArithOps.td',
  117. 'mlir/include/mlir/Dialect/ArmNeon/ArmNeon.td',
  118. 'mlir/include/mlir/Dialect/ArmNeon/TransformOps/ArmNeonVectorTransformOps.td',
  119. 'mlir/include/mlir/Dialect/ArmSME/IR/ArmSMEOps.td',
  120. 'mlir/include/mlir/Dialect/ArmSVE/IR/ArmSVE.td',
  121. 'mlir/include/mlir/Dialect/ArmSVE/TransformOps/ArmSVEVectorTransformOps.td',
  122. 'mlir/include/mlir/Dialect/Async/IR/AsyncOps.td',
  123. 'mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td',
  124. 'mlir/include/mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td',
  125. 'mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td',
  126. 'mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td',
  127. 'mlir/include/mlir/Dialect/DLTI/TransformOps/DLTITransformOps.td',
  128. 'mlir/include/mlir/Dialect/EmitC/IR/EmitC.td',
  129. 'mlir/include/mlir/Dialect/Func/IR/FuncOps.td',
  130. 'mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td',
  131. 'mlir/include/mlir/Dialect/GPU/IR/GPUOps.td',
  132. 'mlir/include/mlir/Dialect/GPU/TransformOps/GPUTransformOps.td',
  133. 'mlir/include/mlir/Dialect/Index/IR/IndexOps.td',
  134. 'mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td',
  135. 'mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td',
  136. 'mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td',
  137. 'mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td',
  138. 'mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgMatchOps.td',
  139. 'mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td',
  140. 'mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td',
  141. 'mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td',
  142. 'mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td',
  143. 'mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td',
  144. 'mlir/include/mlir/Dialect/LLVMIR/XeVMOps.td',
  145. 'mlir/include/mlir/Dialect/Math/IR/MathOps.td',
  146. 'mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td',
  147. 'mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td',
  148. 'mlir/include/mlir/Dialect/MLProgram/IR/MLProgramOps.td',
  149. 'mlir/include/mlir/Dialect/MPI/IR/MPIOps.td',
  150. 'mlir/include/mlir/Dialect/NVGPU/IR/NVGPUOps.td',
  151. 'mlir/include/mlir/Dialect/NVGPU/TransformOps/NVGPUTransformOps.td',
  152. 'mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td',
  153. 'mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td',
  154. 'mlir/include/mlir/Dialect/PDL/IR/PDLOps.td',
  155. 'mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td',
  156. 'mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td',
  157. 'mlir/include/mlir/Dialect/Quant/IR/QuantOps.td',
  158. 'mlir/include/mlir/Dialect/SCF/IR/SCFOps.td',
  159. 'mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td',
  160. 'mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td',
  161. 'mlir/include/mlir/Dialect/Shard/IR/ShardOps.td',
  162. 'mlir/include/mlir/Dialect/SMT/IR/SMTArrayOps.td',
  163. 'mlir/include/mlir/Dialect/SMT/IR/SMTBitVectorOps.td',
  164. 'mlir/include/mlir/Dialect/SMT/IR/SMTIntOps.td',
  165. 'mlir/include/mlir/Dialect/SMT/IR/SMTOps.td',
  166. 'mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td',
  167. 'mlir/include/mlir/Dialect/SparseTensor/TransformOps/SparseTensorTransformOps.td',
  168. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td',
  169. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAtomicOps.td',
  170. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBarrierOps.td',
  171. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBitOps.td',
  172. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCastOps.td',
  173. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td',
  174. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCompositeOps.td',
  175. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td',
  176. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td',
  177. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td',
  178. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGraphOps.td',
  179. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td',
  180. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td',
  181. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVIntegerDotProductOps.td',
  182. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVIntelExtOps.td',
  183. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVLogicalOps.td',
  184. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMatrixOps.td',
  185. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td',
  186. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMeshOps.td',
  187. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMiscOps.td',
  188. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td',
  189. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVPrimitiveOps.td',
  190. 'mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td',
  191. 'mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td',
  192. 'mlir/include/mlir/Dialect/Tensor/TransformOps/TensorTransformOps.td',
  193. 'mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td',
  194. 'mlir/include/mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.td',
  195. 'mlir/include/mlir/Dialect/Transform/IR/TransformOps.td',
  196. 'mlir/include/mlir/Dialect/Transform/IRDLExtension/IRDLExtensionOps.td',
  197. 'mlir/include/mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.td',
  198. 'mlir/include/mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.td',
  199. 'mlir/include/mlir/Dialect/Transform/SMTExtension/SMTExtensionOps.td',
  200. 'mlir/include/mlir/Dialect/Transform/TuneExtension/TuneExtensionOps.td',
  201. 'mlir/include/mlir/Dialect/UB/IR/UBOps.td',
  202. 'mlir/include/mlir/Dialect/Vector/IR/VectorOps.td',
  203. 'mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td',
  204. 'mlir/include/mlir/Dialect/WasmSSA/IR/WasmSSAOps.td',
  205. 'mlir/include/mlir/Dialect/X86Vector/X86Vector.td',
  206. 'mlir/include/mlir/Dialect/X86Vector/TransformOps/X86VectorTransformOps.td',
  207. 'mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td',
  208. 'mlir/include/mlir/Dialect/XeGPU/TransformOps/XeGPUTransformOps.td',
  209. 'mlir/examples/toy/Ch7/include/toy/Ops.td',
  210. 'mlir/examples/transform/Ch2/include/MyExtension.td',
  211. 'mlir/examples/transform/Ch3/include/MyExtension.td',
  212. 'mlir/examples/transform/Ch4/include/MyExtension.td',
  213. 'stablehlo/dialect/StablehloOps.td',
  214. 'stablehlo/dialect/ChloOps.td',
  215. 'stablehlo/dialect/VhloOps.td',
  216. 'stablehlo/reference/InterpreterOps.td',
  217. 'stablehlo/tests/CheckOps.td',
  218. 'shardy/dialect/sdy/ir/ops.td',
  219. 'shardy/dialect/mpmd/ir/ops.td',
  220. 'mhlo/IR/hlo_ops.td',
  221. 'thlo/IR/thlo_ops.td',
  222. 'src/Dialect/ONNX/ONNX.td',
  223. 'src/Dialect/ONNX/ONNXOps.td.inc',
  224. 'src/Dialect/ONNX/AdditionalONNXOps.td',
  225. 'src/Dialect/Krnl/Krnl.td',
  226. 'torch-mlir/Dialect/Torch/IR/TorchOps.td',
  227. 'torch-mlir/Dialect/TorchConversion/IR/TorchConversionOps.td',
  228. 'torch-mlir-dialects/Dialect/TMTensor/IR/TMTensorOps.td',
  229. 'tensorflow/compiler/mlir/lite/ir/tfl_ops.td',
  230. 'tensorflow/compiler/mlir/tensorflow/ir/tf_ops.td',
  231. 'tensorflow/compiler/mlir/tensorflow/ir/tf_saved_model_ops.td',
  232. 'tensorflow/compiler/mlir/tensorflow/ir/tf_device_ops.td',
  233. 'tensorflow/compiler/mlir/tensorflow/ir/tf_executor_ops.td',
  234. 'tensorflow/compiler/mlir/tools/kernel_gen/ir/tf_framework_ops.td',
  235. 'tensorflow/compiler/mlir/tfr/ir/tfr_ops.td',
  236. 'tensorflow/compiler/mlir/tfrt/ir/tfrt_fallback.td',
  237. 'tensorflow/compiler/mlir/tfrt/ir/tfrt_fallback_async.td',
  238. 'tensorflow/compiler/mlir/tfrt/ir/tfrt_fallback_sync.td',
  239. 'tensorflow/compiler/mlir/tfrt/ir/mlrt/tf_mlrt_ops.td',
  240. 'tensorflow/compiler/mlir/tensorflow/ir/host_runtime/tfrt_ops.td',
  241. 'tensorflow/compiler/mlir/tfrt/runtime_fallback/runtime_fallback_ops.td',
  242. 'tensorflow/compiler/mlir/tfrt/ir/mlrt/mlrt_ops.td',
  243. 'tfrt/core_runtime/opdefs/core_runtime.td',
  244. 'tfrt/core_runtime/opdefs/sync/core_runtime.td',
  245. 'tfrt/basic_kernels/opdefs/basic_kernels.td',
  246. 'tfrt/test_kernels/opdefs/test_kernels.td',
  247. 'tfrt/tensor/opdefs/tensor.td',
  248. 'tfrt/tensor/opdefs/dense_host_tensor.td',
  249. 'tfrt/tensor/opdefs/coo_host_tensor.td',
  250. 'tfrt/tensor/opdefs/tensor_shape.td',
  251. 'mlir/test/lib/Dialect/Test/TestOps.td',
  252. 'mlir/test/lib/Dialect/Test/TestOpsSyntax.td',
  253. 'mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td',
  254. 'mlir/test/lib/Interfaces/TilingInterface/TestTilingInterfaceTransformOps.td',
  255. 'mlir/test/lib/Transforms/TestTransformsOps.td',
  256. 'iree/compiler/Dialect/HAL/IR/HALOps.td',
  257. 'iree/compiler/Dialect/HAL/IR/HALTypes.td',
  258. 'iree/compiler/Modules/HAL/Loader/IR/HALLoaderOps.td',
  259. 'iree/compiler/Modules/HAL/Inline/IR/HALInlineOps.td',
  260. 'iree/compiler/Modules/IO/Parameters/IR/IOParametersOps.td',
  261. 'iree/compiler/Dialect/Flow/IR/FlowOps.td',
  262. 'iree/compiler/Dialect/Stream/IR/StreamOps.td',
  263. 'iree/compiler/Dialect/Util/TransformOps/UtilTransformOps.td',
  264. 'iree/compiler/Codegen/Dialect/GPU/TransformExtensions/IREEGPUExtensionsOps.td',
  265. 'iree/compiler/Codegen/Common/TransformExtensions/CommonExtensionsOps.td',
  266. 'iree/compiler/Codegen/LLVMGPU/TransformExtensions/LLVMGPUExtensionsOps.td',
  267. 'iree/compiler/Dialect/Flow/TransformExtensions/FlowExtensionsOps.td',
  268. 'iree/compiler/Dialect/LinalgExt/TransformExtensions/LinalgExtExtensionsOps.td',
  269. 'iree/compiler/Preprocessing/TransformExtensions/PreprocessingExtensionsOps.td',
  270. 'iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td',
  271. 'iree/compiler/Codegen/Dialect/PCF/IR/PCFOps.td',
  272. 'iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUOps.td',
  273. 'iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenOps.td',
  274. 'iree/compiler/Codegen/Dialect/Codegen/IR/UKernelOps.td',
  275. 'iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td',
  276. 'iree/compiler/Dialect/LinalgExt/IR/LinalgExtPureOps.td',
  277. 'iree/compiler/Dialect/TensorExt/IR/TensorExtOps.td',
  278. 'iree/compiler/Dialect/Util/IR/UtilOps.td',
  279. 'iree/compiler/Dialect/VM/IR/VMOps.td',
  280. 'iree/compiler/Dialect/VMVX/IR/VMVXOps.td',
  281. 'iree/compiler/Dialect/Encoding/IR/EncodingOps.td',
  282. 'iree/compiler/src/iree/compiler/Modules/Check/IR/CheckOps.td',
  283. 'iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.td',
  284. 'asuka/Dialect/Asuka/IR/AsukaOps.td',
  285. 'tpu_mlir/Dialect/Top/IR/TopOps.td',
  286. 'tpu_mlir/Dialect/Tpu/IR/TpuOps.td',
  287. 'SDFG/Dialect/Ops.td',
  288. 'lltz/mlir/dialect/include/Michelson/MichelsonOps.td',
  289. 'triton/Dialect/Triton/IR/TritonOps.td',
  290. 'triton/Dialect/TritonGPU/IR/TritonGPUOps.td',
  291. 'triton/Dialect/TritonInstrument/IR/TritonInstrumentOps.td',
  292. 'triton/Dialect/Gluon/IR/GluonOps.td',
  293. 'triton/Dialect/TritonNvidiaGPU/IR/TritonNvidiaGPUOps.td',
  294. 'triton/third_party/nvidia/include/Dialect/NVWS/IR/NVWSOps.td',
  295. 'amd/include/Dialect/TritonAMDGPU/IR/TritonAMDGPUOps.td',
  296. 'proton/Dialect/include/Dialect/Proton/IR/ProtonOps.td',
  297. 'proton/Dialect/include/Dialect/ProtonGPU/IR/ProtonGPUOps.td',
  298. 'lagrad/include/LAGrad/LAGradOps.td',
  299. 'mlir-tensorrt-dialect/TensorRT/IR/TensorRTOps.td',
  300. 'mlir-executor/Executor/IR/ExecutorOps.td',
  301. 'mlir-tensorrt/Dialect/CUDA/IR/CUDAOps.td',
  302. 'mlir-tensorrt/Dialect/TensorRTRuntime/IR/TensorRTRuntimeOps.td',
  303. 'mlir-tensorrt/Dialect/Plan/IR/PlanOps.td',
  304. 'mlir-kernel/Kernel/IR/Ops.td',
  305. 'mlir-kernel/Kernel/TransformOps/KernelTransformOps.td',
  306. 'Dialect/NVGPU/IR/NVGPUOps.td',
  307. 'Standalone/StandaloneOps.td',
  308. 'clang/include/clang/CIR/Dialect/IR/CIROps.td',
  309. 'mlir/include/mlir/Dialect/MIGraphX/IR/MIGraphX.td',
  310. ];
  311. const file = path.join(dirname, '..', 'source', 'mlir-metadata.json');
  312. const operations = new Map();
  313. const exists = await access(file);
  314. if (exists) {
  315. const content = await fs.readFile(file, 'utf-8');
  316. const json = JSON.parse(content);
  317. for (const op of json) {
  318. if (op.name.endsWith('.') || op.name.includes('..') || op.name.includes('#')) {
  319. throw new Error(`Invalid operation name '${op.name}'.`);
  320. }
  321. if (op.name && !op.name.endsWith('.')) {
  322. operations.set(op.name, op);
  323. }
  324. }
  325. }
  326. let count = 0;
  327. const parser = new tablegen.Reader();
  328. await parser.parse(dialects, paths);
  329. for (const def of parser.defs) {
  330. const op = new Operator(def);
  331. let operationName = op.getOperationName();
  332. if (!operationName) {
  333. continue;
  334. }
  335. if (operationName.endsWith('.') || operationName.includes('..') || operationName.includes('#')) {
  336. throw new Error(`Invalid operation name '${operationName}'.`);
  337. }
  338. // Workaround: Handle conflicting dialects from stablehlo and iree
  339. if (operationName.startsWith('check.')) {
  340. if (def.location.file.includes('stablehlo')) {
  341. operationName = operationName.replace(/^check./, 'check.<stablehlo>.');
  342. } else if (def.location.file.includes('iree')) {
  343. operationName = operationName.replace(/^check./, 'check.<iree>.');
  344. }
  345. }
  346. const operation = {
  347. name: operationName
  348. };
  349. if (operations.has(operationName)) {
  350. const existing = operations.get(operationName);
  351. if (existing.category) {
  352. operation.category = existing.category;
  353. }
  354. }
  355. let args = def.getValueAsDag('arguments');
  356. if (!args || !args.operands || args.operands.length === 0) {
  357. // Try to get from parent Arguments class
  358. for (const parent of def.parents) {
  359. if (parent.name === 'Arguments' && parent.args && parent.args.length > 0) {
  360. const [dagValue] = parent.args;
  361. if (dagValue && dagValue.type === 'dag') {
  362. args = dagValue.value;
  363. }
  364. break;
  365. }
  366. }
  367. }
  368. const name = operation.name.replace(/^(asuka|stablehlo|chlo|affine|linalg|memref|quant|vector|tosa|tfl|tf|onnx|torch\.aten|gpu)\./, '');
  369. if (['reshape', 'broadcast_in_dim', 'dynamic_reshape', 'Reshape', 'Shape', 'Size', 'ConstantOfShape'].includes(name)) {
  370. operation.category = 'Shape';
  371. } else if (['transpose', 'reverse', 'pad', 'Transpose', 'Pad'].includes(name)) {
  372. operation.category = 'Transform';
  373. } else if (['slice', 'split', 'dynamic_slice', 'gather', 'scatter', 'Slice', 'Gather', 'Scatter', 'concat', 'concatenate'].includes(name)) {
  374. operation.category = 'Tensor';
  375. } else if (['tanh', 'Sigmoid', 'Tanh', 'Relu', 'Softmax', 'softmax', 'sigmoid', 'relu', 'clamp'].includes(name)) {
  376. operation.category = 'Activation';
  377. } else if (['convolution', 'Conv', 'conv2d', 'conv3d', 'fully_connected', 'conv_2d'].includes(name)) {
  378. operation.category = 'Layer';
  379. } else if (['max_pool2d'].includes(name)) {
  380. operation.category = 'Pool';
  381. } else if (['batch_norm_inference'].includes(name)) {
  382. operation.category = 'Normalization';
  383. }
  384. if (def.getValue('summary')) {
  385. const summary = def.getValueAsString('summary').trim();
  386. if (summary) {
  387. operation.summary = summary;
  388. }
  389. }
  390. if (def.getValue('description')) {
  391. const description = def.getValueAsString('description');
  392. if (description) {
  393. operation.description = description;
  394. }
  395. }
  396. // Convert TableGen value to constraint string
  397. const toConstraintString = (value) => {
  398. if (!value) {
  399. return null;
  400. }
  401. if (value.type === 'def') {
  402. const defName = value.value;
  403. // Check if this is an enum attribute or property and add enum cases
  404. const attrDef = parser.getDef(defName) || parser.getClass(defName);
  405. // Resolve type aliases to their base forms for proper parser dispatch
  406. if (attrDef) {
  407. for (const parent of attrDef.parents) {
  408. // ConfinedAttr<BaseAttr, Constraints> -> ConfinedAttr<BaseAttr, Constraints>
  409. if (parent.name === 'ConfinedAttr' && parent.args && parent.args.length > 0) {
  410. const args = parent.args.map((arg) => toConstraintString(arg)).filter((x) => x !== null);
  411. return `ConfinedAttr<${args.join(', ')}>`;
  412. }
  413. // TypedArrayAttrBase<ElementType, ...> -> TypedArrayAttrBase<ElementType>
  414. if (parent.name === 'TypedArrayAttrBase' && parent.args && parent.args.length > 0) {
  415. const innerType = toConstraintString(parent.args[0]);
  416. return innerType ? `TypedArrayAttrBase<${innerType}>` : 'ArrayAttr';
  417. }
  418. // Variadic<Type> -> Variadic<Type>
  419. if (parent.name === 'Variadic' && parent.args && parent.args.length > 0) {
  420. const innerType = toConstraintString(parent.args[0]);
  421. return innerType ? `Variadic<${innerType}>` : 'Variadic';
  422. }
  423. // Optional<Type> -> Optional<Type>
  424. if (parent.name === 'Optional' && parent.args && parent.args.length > 0) {
  425. const innerType = toConstraintString(parent.args[0]);
  426. return innerType ? `Optional<${innerType}>` : 'Optional';
  427. }
  428. }
  429. }
  430. if (attrDef && (attrDef.isEnumAttr() || attrDef.isEnumProp())) {
  431. const cases = attrDef.getEnumCases();
  432. if (cases && cases.length > 0) {
  433. return `${defName}{${cases.join('|')}}`;
  434. }
  435. }
  436. return defName;
  437. }
  438. if (value.type === 'string' || value.type === 'code') {
  439. return value.value;
  440. }
  441. if (value.type === 'int') {
  442. return String(value.value);
  443. }
  444. if (value.type === 'list') {
  445. const items = value.value.map((item) => toConstraintString(item)).filter((x) => x !== null);
  446. return items.length > 0 ? `[${items.join(', ')}]` : null;
  447. }
  448. if (value.type === 'dag' && value.value) {
  449. const dag = value.value;
  450. // Unwrap Arg/Res wrappers - they just hold the type constraint plus metadata
  451. // The first operand is the actual type constraint
  452. if ((dag.operator === 'Arg' || dag.operator === 'Res') && dag.operands.length > 0) {
  453. return toConstraintString(dag.operands[0].value);
  454. }
  455. const args = dag.operands.map((op) => toConstraintString(op.value)).filter((x) => x !== null);
  456. if (args.length > 0) {
  457. return `${dag.operator}<${args.join(', ')}>`;
  458. }
  459. return dag.operator;
  460. }
  461. return null;
  462. };
  463. const attributes = [];
  464. const operands = [];
  465. const results = [];
  466. if (args && args.operator === 'ins') {
  467. for (const operand of args.operands) {
  468. if (operand.value && operand.name) {
  469. const type = toConstraintString(operand.value);
  470. // Check if this is an actual attribute/property constraint by looking up the def
  471. // and checking if it inherits from Attr or Property class (matches LLVM reference)
  472. const checkIsAttr = (record, visited = new Set()) => {
  473. if (!record || visited.has(record.name)) {
  474. return false;
  475. }
  476. visited.add(record.name);
  477. // Check for attribute base classes - both constraint and bytecode encoding types
  478. if (record.name === 'Attr' || record.name === 'AttributeKind' || record.name === 'DialectAttribute') {
  479. return true;
  480. }
  481. // Check for property base classes - properties are also attributes (compile-time metadata)
  482. if (record.name === 'Property' || record.name === 'PropConstraint' || record.name === 'EnumProp') {
  483. return true;
  484. }
  485. for (const parent of record.parents) {
  486. const parentClass = parser.getClass(parent.name);
  487. if (parentClass && checkIsAttr(parentClass, visited)) {
  488. return true;
  489. }
  490. }
  491. return false;
  492. };
  493. // Recursively check if a value represents an attribute type
  494. const checkValueIsAttr = (value) => {
  495. if (!value) {
  496. return false;
  497. }
  498. if (value.type === 'def') {
  499. // Simple def reference like StrAttr
  500. const constraintDef = parser.getDef(value.value) || parser.getClass(value.value);
  501. if (constraintDef) {
  502. return checkIsAttr(constraintDef);
  503. }
  504. // Fallback: if definition not found but name ends with "Attr", treat as attribute
  505. // This handles cases like CancellationConstructTypeAttr which are generated/external
  506. if (typeof value.value === 'string' && value.value.endsWith('Attr')) {
  507. return true;
  508. }
  509. return false;
  510. }
  511. if (value.type === 'dag' && value.value) {
  512. // DAG constraint like OptionalAttr<StrAttr> or Arg<OptionalAttr<ArrayAttr>, ...>
  513. const dag = value.value;
  514. // Check the operator (e.g., OptionalAttr, DefaultValuedAttr)
  515. const operatorDef = parser.getDef(dag.operator) || parser.getClass(dag.operator);
  516. if (operatorDef && checkIsAttr(operatorDef)) {
  517. return true;
  518. }
  519. // Fallback: if operator name ends with "Attr", treat as attribute
  520. if (typeof dag.operator === 'string' && dag.operator.endsWith('Attr')) {
  521. return true;
  522. }
  523. // For wrappers like Arg<...>, check the first operand recursively
  524. if (dag.operands && dag.operands.length > 0) {
  525. return checkValueIsAttr(dag.operands[0].value);
  526. }
  527. }
  528. return false;
  529. };
  530. const isAttribute = checkValueIsAttr(operand.value);
  531. if (isAttribute) {
  532. attributes.push({ name: operand.name, type });
  533. } else {
  534. operands.push({ name: operand.name, type });
  535. }
  536. }
  537. }
  538. }
  539. // If no attributes were found from 'arguments', try to extract from 'builders'
  540. // Some ops (like krnl.entry_point) define attributes only via builders
  541. if (attributes.length === 0) {
  542. const buildersField = def.getValue('builders');
  543. if (buildersField && buildersField.value && buildersField.value.type === 'list') {
  544. const buildersList = buildersField.value.value;
  545. if (buildersList && buildersList.length > 0) {
  546. // Try to get attribute name mappings from extraClassDeclaration
  547. const attrNameMap = new Map();
  548. const extraDecl = def.getValueAsString('extraClassDeclaration');
  549. if (extraDecl) {
  550. // Match patterns like: static StringRef getXxxAttrName() { return "yyy"; }
  551. const matches = extraDecl.matchAll(/get(\w+)AttrName\(\)\s*\{\s*return\s+"(\w+)"/g);
  552. for (const match of matches) {
  553. // Map parameter name (camelCase) to actual attribute name
  554. const paramName = match[1].charAt(0).toLowerCase() + match[1].slice(1);
  555. attrNameMap.set(paramName, match[2]);
  556. }
  557. }
  558. // Parse first OpBuilder<(ins ...)> to extract attributes
  559. for (const builder of buildersList) {
  560. if (builder.type === 'dag' && builder.value && builder.value.operator === 'OpBuilder') {
  561. const builderOperands = builder.value.operands;
  562. if (builderOperands && builderOperands.length > 0) {
  563. const [insArg] = builderOperands;
  564. if (insArg && insArg.value && insArg.value.type === 'dag' && insArg.value.value.operator === 'ins') {
  565. const insDag = insArg.value.value;
  566. for (const param of insDag.operands) {
  567. // Builder parameters have string types like "SymbolRefAttr":$name
  568. if (param.value && param.value.type === 'string' && param.name) {
  569. const cppType = param.value.value;
  570. // Only include Attr types (not Value or other C++ types)
  571. if (cppType.endsWith('Attr') || cppType.includes('Attr:')) {
  572. // Strip trailing Attr suffix variations and get base attr name
  573. const attrType = cppType.replace(/::$/, '').replace(/:.*$/, '');
  574. // Use the mapped name if available, otherwise derive from param name
  575. let attrName = param.name;
  576. // Remove common suffixes like 'Attr' from the parameter name
  577. const cleanParamName = attrName.replace(/Attr$/, '');
  578. if (attrNameMap.has(cleanParamName)) {
  579. attrName = attrNameMap.get(cleanParamName);
  580. } else if (attrNameMap.has(attrName)) {
  581. attrName = attrNameMap.get(attrName);
  582. } else {
  583. attrName = cleanParamName;
  584. }
  585. attributes.push({ name: attrName, type: attrType });
  586. }
  587. }
  588. }
  589. break; // Only process first builder
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. let resultsDag = def.getValueAsDag('results');
  598. if (!resultsDag || !resultsDag.operands || resultsDag.operands.length === 0) {
  599. // Try to get from parent Results class
  600. for (const parent of def.parents) {
  601. if (parent.name === 'Results' && parent.args && parent.args.length > 0) {
  602. const [dagValue] = parent.args;
  603. if (dagValue && dagValue.type === 'dag') {
  604. resultsDag = dagValue.value;
  605. }
  606. break;
  607. }
  608. }
  609. }
  610. if (resultsDag && resultsDag.operator === 'outs') {
  611. for (const operand of resultsDag.operands) {
  612. if (operand.value && operand.name) {
  613. const type = toConstraintString(operand.value);
  614. results.push({ name: operand.name, type });
  615. }
  616. }
  617. }
  618. if (operands.length > 0) {
  619. operation.operands = operands;
  620. }
  621. if (results.length > 0) {
  622. operation.results = results;
  623. }
  624. if (attributes.length > 0) {
  625. operation.attributes = attributes;
  626. }
  627. const successors = def.getValueAsDag('successors');
  628. if (successors && successors.operator === 'successor') {
  629. const list = [];
  630. for (const operand of successors.operands) {
  631. if (operand.name) {
  632. const type = toConstraintString(operand.value);
  633. list.push({ name: operand.name, type });
  634. }
  635. }
  636. if (list.length > 0) {
  637. operation.successors = list;
  638. }
  639. }
  640. const regions = def.getValueAsDag('regions');
  641. if (regions && regions.operator === 'region') {
  642. const list = [];
  643. for (const operand of regions.operands) {
  644. if (operand.name) {
  645. const type = toConstraintString(operand.value);
  646. list.push({ name: operand.name, type });
  647. }
  648. }
  649. if (list.length > 0) {
  650. operation.regions = list;
  651. }
  652. }
  653. if (def.getValue('assemblyFormat')) {
  654. const assemblyFormat = def.getValueAsString('assemblyFormat');
  655. if (assemblyFormat) {
  656. operation.assemblyFormat = assemblyFormat.trim();
  657. }
  658. }
  659. if (def.getValue('hasCustomAssemblyFormat') && def.getValueAsBit('hasCustomAssemblyFormat')) {
  660. operation.hasCustomAssemblyFormat = true;
  661. }
  662. if (def.getValue('parser')) {
  663. operation.parser = def.getValueAsString('parser');
  664. }
  665. // Extract defaultDialect from OpAsmOpInterface
  666. for (const parent of def.parents) {
  667. const possibleTraitArgs = parent.args && parent.args.length >= 2 ? [parent.args[1], parent.args[2]] : [];
  668. for (const traitsArg of possibleTraitArgs) {
  669. if (traitsArg && traitsArg.type === 'list' && traitsArg.value) {
  670. for (const trait of traitsArg.value) {
  671. const traitName = trait.type === 'def' ? trait.value : null;
  672. const traitDag = trait.type === 'dag' && trait.value?.operator ? trait.value.operator : null;
  673. if (traitName === 'OpAsmOpInterface' || traitDag === 'DeclareOpInterfaceMethods') {
  674. if (traitDag === 'DeclareOpInterfaceMethods' && trait.value?.operands) {
  675. if (trait.value.operands.some((operand) => operand.value && operand.value.type === 'list' && operand.value.value.some((method) => method.type === 'string' && method.value === 'getDefaultDialect'))) {
  676. const [dialectName] = operationName.split('.');
  677. operation.defaultDialect = dialectName;
  678. break;
  679. }
  680. }
  681. const extraClass = def.getValueAsString('extraClassDeclaration');
  682. if (extraClass) {
  683. const match = extraClass.match(/getDefaultDialect\(\)\s*\{\s*return\s+"(\w+)"/);
  684. if (match) {
  685. [, operation.defaultDialect] = match;
  686. break;
  687. }
  688. }
  689. }
  690. }
  691. if (operation.defaultDialect) {
  692. break;
  693. }
  694. }
  695. }
  696. if (operation.defaultDialect) {
  697. break;
  698. }
  699. }
  700. if (Object.keys(operation).length > 1) {
  701. operations.set(operationName, operation);
  702. count++;
  703. }
  704. }
  705. const sorted = Array.from(operations.values()).sort((a, b) => a.name.localeCompare(b.name));
  706. const output = JSON.stringify(sorted, null, 2);
  707. const formatted = output.replace(/\{\s+"name":\s+"([^"]+)",\s+"type":\s+"([^"]+)"\s+\}/g, '{ "name": "$1", "type": "$2" }');
  708. await fs.writeFile(file, formatted, 'utf-8');
  709. if (count < 6300) {
  710. throw new Error(`Unexpected operation count '${count}'.`);
  711. }
  712. };
  713. const test = async (pattern) => {
  714. pattern = pattern || './third_party/source/mlir/**/*.mlir';
  715. const errorTotals = new Map();
  716. const filesByError = new Map();
  717. const fileErrorDetails = new Map();
  718. let currentFile = null;
  719. const validFiles = new Set();
  720. const invalidFiles = new Set([
  721. 'third_party/source/mlir/iree/compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR/test/lowering_config_attr.mlir',
  722. 'third_party/source/mlir/iree/samples/compiler_plugins/simple_io_sample/test/print.mlir',
  723. 'third_party/source/mlir/lltz/mlir/dialect/irdl/michelson.irdl.mlir',
  724. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Builtin/ops.mlir',
  725. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/IRDL/regions-ops.irdl.mlir',
  726. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/IRDL/testd.irdl.mlir',
  727. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/IRDL/variadics.irdl.mlir',
  728. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Linalg/tile-to-forall.mlir',
  729. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/LLVMIR/func.mlir',
  730. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/LLVMIR/global.mlir',
  731. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir',
  732. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SMT/bitvector-errors.mlir',
  733. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/barrier-ops.mlir',
  734. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/composite-ops.mlir',
  735. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir',
  736. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir',
  737. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/khr-cooperative-matrix-ops.mlir',
  738. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/logical-ops.mlir',
  739. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir',
  740. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/misc-ops.mlir',
  741. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir',
  742. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir',
  743. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/SPIRV/IR/types.mlir',
  744. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Tosa/level_check.mlir',
  745. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Tosa/verifier.mlir',
  746. 'third_party/source/mlir/llvm-project/mlir/test/Dialect/Transform/test-pass-application.mlir',
  747. 'third_party/source/mlir/llvm-project/mlir/test/Examples/transform-opt/syntax-error.mlir',
  748. 'third_party/source/mlir/llvm-project/mlir/test/IR/attribute.mlir',
  749. 'third_party/source/mlir/llvm-project/mlir/test/IR/dynamic.mlir',
  750. 'third_party/source/mlir/llvm-project/mlir/test/IR/invalid-unregistered.mlir',
  751. 'third_party/source/mlir/llvm-project/mlir/test/IR/parser.mlir',
  752. 'third_party/source/mlir/llvm-project/mlir/test/IR/zero_whitespace.mlir',
  753. 'third_party/source/mlir/llvm-project/mlir/test/mlir-tblgen/attr-or-type-format.mlir',
  754. 'third_party/source/mlir/mlir-dace/design/mlir/map.mlir',
  755. 'third_party/source/mlir/mlir-dace/design/mlir/simple_sdfg.mlir',
  756. 'third_party/source/mlir/mlir-dace/design/mlir/symbol.mlir',
  757. 'third_party/source/mlir/mlir-dace/test/SDFG/Converter/toSDFG/llvm/load.mlir',
  758. 'third_party/source/mlir/mlir-dace/test/SDFG/Converter/toSDFG/llvm/store.mlir',
  759. 'third_party/source/mlir/mlir-dace/test/SDFG/Dialect/consume/too_many_params.mlir',
  760. 'third_party/source/mlir/mlir-dace/test/SDFG/Dialect/memlet/explicit_tile.mlir',
  761. 'third_party/source/mlir/mlir-dace/test/SDFG/Dialect/state/missing_identifier.mlir',
  762. 'third_party/source/mlir/mlir-dace/test/SDFG/Dialect/state/missing_region.mlir',
  763. 'third_party/source/mlir/mlir-dace/test/SDFG/Dialect/tasklet/missing_return_type.mlir',
  764. 'third_party/source/mlir/runtime/mlir_tests/bef_executor/tutorial.mlir',
  765. 'third_party/source/mlir/runtime/mlir_tests/core_runtime/basic_ops.mlir',
  766. 'third_party/source/mlir/shardy/shardy/dialect/mpmd/ir/test/memory_kind_parse_and_print.mlir',
  767. 'third_party/source/mlir/stablehlo/stablehlo/tests/ops_stablehlo.mlir',
  768. 'third_party/source/mlir/stablehlo/stablehlo/tests/print_types_invalid.mlir',
  769. 'third_party/source/mlir/stablehlo/stablehlo/tests/vhlo/invalid_vhlo_future.mlir',
  770. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/quantization/tensorflow/passes/quantized_function_library_tf_drq.mlir',
  771. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/quantization/tensorflow/passes/quantized_function_library_uniform_quantized.mlir',
  772. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/quantization/tensorflow/passes/quantized_function_library_xla_weight_only.mlir',
  773. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/quantization/tensorflow/passes/quantized_function_library.mlir',
  774. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/tensorflow/tests/compile_mlir_util/serialized-mlir-module-str-attr.mlir',
  775. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/tensorflow/tests/tf_executor_ops_invalid.mlir',
  776. 'third_party/source/mlir/tensorflow/tensorflow/compiler/mlir/tfr/tests/ops.mlir',
  777. ]);
  778. return new Promise((resolve, reject) => {
  779. const cmd = 'node';
  780. const args = ['--max-old-space-size=8192', './test/models.js', 'continue', pattern];
  781. const process = child_process.spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] });
  782. const stdout = readline.createInterface({ input: process.stdout, crlfDelay: Infinity });
  783. const stderr = readline.createInterface({ input: process.stderr, crlfDelay: Infinity });
  784. const processLine = (line) => {
  785. writeLine(line);
  786. const stripped = line.trim();
  787. if (!stripped) {
  788. return;
  789. }
  790. if (stripped.startsWith('third_party/')) {
  791. currentFile = stripped;
  792. if (stripped.toLowerCase().includes('invalid') || stripped.startsWith('third_party/source/mlir/mlir-dace/design')) {
  793. invalidFiles.add(currentFile);
  794. } else {
  795. validFiles.add(currentFile);
  796. }
  797. return;
  798. }
  799. if (currentFile && invalidFiles.has(currentFile)) {
  800. return;
  801. }
  802. if (currentFile && !invalidFiles.has(currentFile)) {
  803. // Skip summary lines (e.g., "123 / 456 = 78.9%")
  804. if (/^\s*\d+\s*\/\s*\d+\s*=\s*[\d.]+%\s*$/.test(stripped)) {
  805. return;
  806. }
  807. // Normalize error message
  808. const key = stripped.split(' at ', 1)[0].trim().replace(/\.$/, '').trim();
  809. if (key) {
  810. errorTotals.set(key, (errorTotals.get(key) || 0) + 1);
  811. if (!filesByError.has(key)) {
  812. filesByError.set(key, new Map());
  813. }
  814. const fileCounts = filesByError.get(key);
  815. fileCounts.set(currentFile, (fileCounts.get(currentFile) || 0) + 1);
  816. if (!fileErrorDetails.has(key)) {
  817. fileErrorDetails.set(key, new Map());
  818. }
  819. const details = fileErrorDetails.get(key);
  820. if (!details.has(currentFile)) {
  821. details.set(currentFile, []);
  822. }
  823. details.get(currentFile).push(stripped);
  824. }
  825. }
  826. };
  827. stdout.on('line', processLine);
  828. stderr.on('line', processLine);
  829. process.on('error', (error) => {
  830. reject(new Error(`Failed to start process: ${error.message}`));
  831. });
  832. process.on('close', (/* code */) => {
  833. const totalValid = validFiles.size;
  834. const filesWithErrors = new Set();
  835. for (const [, fileCounts] of filesByError) {
  836. for (const file of fileCounts.keys()) {
  837. filesWithErrors.add(file);
  838. }
  839. }
  840. writeLine('');
  841. writeLine('-'.repeat(75));
  842. if (errorTotals.size > 0) {
  843. const sortedErrors = Array.from(errorTotals.entries()).sort((a, b) => b[1] - a[1]).slice(0, 100);
  844. for (const [err, cnt] of sortedErrors) {
  845. const fileCounts = filesByError.get(err);
  846. const topFiles = Array.from(fileCounts.entries()).sort((a, b) => b[1] - a[1]).slice(0, 100);
  847. writeLine(`${cnt} | ${err}`);
  848. for (const [file,] of topFiles) {
  849. writeLine(` ${file}`);
  850. const details = fileErrorDetails.get(err).get(file);
  851. for (const specificError of details) {
  852. writeLine(` ${specificError}`);
  853. }
  854. }
  855. writeLine('');
  856. }
  857. }
  858. if (totalValid > 0) {
  859. const succeeded = totalValid - filesWithErrors.size;
  860. const percentage = (succeeded * 100.0) / totalValid;
  861. writeLine(` ${succeeded} / ${totalValid} = ${percentage.toPrecision(6)}% - skipped ${invalidFiles.size} files`);
  862. } else {
  863. writeLine(' No valid files processed');
  864. }
  865. writeLine('');
  866. resolve();
  867. });
  868. });
  869. };
  870. const main = async () => {
  871. const command = process.argv.length >= 3 ? process.argv[2] : 'schema';
  872. switch (command) {
  873. case 'test': {
  874. writeLine(process.argv);
  875. await test(process.argv.slice(3).join(' '));
  876. break;
  877. }
  878. case 'schema':
  879. default: {
  880. await schema();
  881. break;
  882. }
  883. }
  884. };
  885. await main();