This invention discloses an automatic generation method for instruction matching templates based on LLVM intermediate representation, relating to the field of
computer technology. It includes the following steps: Step 1, obtaining and
parsing the LLVM IR instruction description file to generate a
directed acyclic graph (DAG) of instruction operation behavior; Step 2, performing instruction behavior
legalization processing on the DAG, analyzing types and operations incompatible with the target architecture in the DAG, and replacing them with operation sequences supported by the target architecture. This invention automatically generates
instruction selection rules matching the target
machine instruction set by analyzing the function semantic features,
operand dependencies, and target architecture
instruction set constraints of LLVM IR. These rules are used in the
code generation stage of the LLVM
compiler backend, solving the problems of low development efficiency, poor cross-hardware platform adaptability, and
compiler code performance degradation caused by manual coding errors in existing technologies that involve manually writing instruction matching templates.