[go: up one dir, main page]

CN1920771A - Processing method for special register supporting regular record variables access - Google Patents

Processing method for special register supporting regular record variables access Download PDF

Info

Publication number
CN1920771A
CN1920771A CN 200510093279 CN200510093279A CN1920771A CN 1920771 A CN1920771 A CN 1920771A CN 200510093279 CN200510093279 CN 200510093279 CN 200510093279 A CN200510093279 A CN 200510093279A CN 1920771 A CN1920771 A CN 1920771A
Authority
CN
China
Prior art keywords
variable
compiler
tree structure
special register
attribute
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN 200510093279
Other languages
Chinese (zh)
Other versions
CN100559344C (en
Inventor
贾耀仓
桂剑
霍玮
谷晓铭
张兆庆
冯晓兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Hezhong Data Technology Co ltd
Original Assignee
Institute of Computing Technology of CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Institute of Computing Technology of CAS filed Critical Institute of Computing Technology of CAS
Priority to CNB2005100932793A priority Critical patent/CN100559344C/en
Publication of CN1920771A publication Critical patent/CN1920771A/en
Application granted granted Critical
Publication of CN100559344C publication Critical patent/CN100559344C/en
Anticipated expiration legal-status Critical
Expired - Lifetime legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

本发明公开了一种支持用规则记录变量访问专用寄存器组的处理方法。该方法包括:1)设计新的类型属性,以标识需要放入专用寄存器组的规则记录变量类型;2)设计规则记录变量的语法树结构,用递归算法实现计算规则记录变量各成员相对位置;3)设计规则记录变量的中间表示;4)生成利用规则记录变量访问专用寄存器组的代码。本发明的优点:1)保留高级语言开发的优点,又克服了高级语言难以对特殊硬件进行直接控制的缺点,提高编程效率,缩短开发周期;2)向程序员屏蔽了底层硬件的细节,能灵活的处理各种专用寄存器组的使用规范;3)向编译器暴露更多的优化机会,提高系统性能。The invention discloses a processing method supporting special register group access by rule record variable. The method includes: 1) designing a new type attribute to identify the type of the rule record variable that needs to be put into a special register group; 2) designing the syntax tree structure of the rule record variable, and using a recursive algorithm to realize the calculation of the relative position of each member of the rule record variable; 3) Design the intermediate representation of the rule record variable; 4) Generate the code for using the rule record variable to access the special register group. Advantages of the present invention: 1) retain the advantages of high-level language development, overcome the shortcoming that high-level language is difficult to directly control special hardware, improve programming efficiency, and shorten development cycle; 2) shield the details of underlying hardware from programmers, and can Flexible handling of usage specifications of various special-purpose register groups; 3) exposing more optimization opportunities to the compiler to improve system performance.

Description

一种支持用规则记录变量访问专用寄存器组的处理方法A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks

技术领域technical field

本发明涉及对于处理器中具有专用寄存器组的嵌入式软件开发,特别涉及一种支持用规则记录变量访问专用寄存器组的处理方法。The invention relates to the development of embedded software with special-purpose register groups in processors, in particular to a processing method for supporting access to special-purpose register groups by using rules to record variables.

背景技术Background technique

高级语言的设计目的是让程序按照人类的思维和语言习惯书写,它是面向程序员的。在嵌入式领域被广泛使用的高级语言是C语言。计算机能够直接识别和执行的不是高级语言,而是用二进制代码表示的机器指令的集合,即机器语言。汇编语言用助记符代替了二进制机器指令,但是仍然是硬件操作的控制信息,所以它和机器语言一样都是面向机器的低级语言。The purpose of high-level language design is to make programs written in accordance with human thinking and language habits, and it is oriented to programmers. The high-level language widely used in the embedded field is C language. What a computer can directly recognize and execute is not a high-level language, but a collection of machine instructions expressed in binary code, that is, machine language. Assembly language replaces binary machine instructions with mnemonics, but it is still control information for hardware operations, so it is a machine-oriented low-level language like machine language.

高级语言书写的源程序需要变换成机器语言目标代码才能在计算机上运行,这个变换通常包含两个阶段:前一个阶段是将源程序变换成汇编语言的表示,后一个阶段则是将汇编表示变换成机器语言目标代码。后一个阶段是由汇编器、链接器来完成的,与本发明无关。前一个阶段是由编译器来完成的,本发明的工作也都集中在这个阶段。后文中的编译,如果没有特别指明,表示的就是从高级语言的源程序变换到汇编语言表示的过程。The source program written in high-level language needs to be transformed into machine language object code to run on the computer. This transformation usually includes two stages: the first stage is to transform the source program into assembly language representation, and the latter stage is to transform the assembly representation into machine language object code. The latter stage is completed by assembler and linker, which has nothing to do with the present invention. The previous stage is completed by the compiler, and the work of the present invention also all concentrates on this stage. The compilation in the following, if not specified, refers to the process of transforming the source program of the high-level language into the assembly language representation.

编译器的工作可以分为若干阶段,通常划分为词法分析、语法分析、语义分析、中间代码生成、代码优化和代码生成阶段,参见文献1:《编译原理和技术(第二版)》,陈意云,1997年。编译器的这些阶段常常又被分为前端和后端。前端只依赖于源语言,通常包括前三个阶段,即词法分析、语法分析和语义分析。前端对源程序进行不同的分析,以解释源程序的结构和基本数据,决定它们的含义。其中,语义分析阶段检查程序的语义正确性,并为以后的代码生成阶段收集类型信息,它使用语法分析阶段确定的语法树来表示表达式和语句的算符和运算对象。编译器在中间代码生成阶段会产生源程序的中间表示。中间表示是一种抽象机的程序,易于产生,而且易于翻译成目标程序。编译器的后端是指编译器中依赖于目标机的部分,一般独立于源语言,而与中间语言相关,包括代码优化、代码生成等。代码优化阶段试图改进代码,产生执行较快的目标代码。代码生成阶段则将中间代码翻译成等价的机器指令序列。The work of a compiler can be divided into several stages, usually divided into lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and code generation stages, see Document 1: "Compiler Principles and Technologies (Second Edition)", Chen Yiyun ,1997. These phases of the compiler are often further divided into front-end and back-end. The front end only depends on the source language and usually includes the first three stages, namely lexical analysis, syntactic analysis and semantic analysis. The front end performs different analyzes on the source program to interpret the structure and basic data of the source program and determine their meaning. Among them, the semantic analysis stage checks the semantic correctness of the program and collects type information for the subsequent code generation stage. It uses the syntax tree determined in the syntax analysis stage to represent the operators and operands of expressions and statements. The compiler generates an intermediate representation of the source program during the intermediate code generation phase. The intermediate representation is a program of an abstract machine, which is easy to generate and translate into an object program. The backend of the compiler refers to the part of the compiler that depends on the target machine. It is generally independent of the source language and related to the intermediate language, including code optimization and code generation. The code optimization phase attempts to improve the code and produce object code that executes faster. The code generation stage translates the intermediate code into an equivalent sequence of machine instructions.

随着嵌入式处理器的大量应用,嵌入式软件的开发越来越来越重要。对于一款嵌入式处理器,能够有大量的应用程序支持是将之推向市场的前提。因此,缩短软件开发周期,提高软件开发质量,在整个开发过程中占有至关重要的作用。有些嵌入式处理器对性能有很高的要求,例如骨干网的路由器要求能够支持上G的分组转发速率。这一类嵌入式处理器中使用了特殊的技术来提高处理速度,其中的一种重要机制就是专用寄存器组。这些专用寄存器组用来存放关键数据,以克服访存瓶颈,加快数据存取,不能用于编译器的寄存器分配。在嵌入式软件中如何充分利用这些专用寄存器组是提高性能的关键之一。With the mass application of embedded processors, the development of embedded software becomes more and more important. For an embedded processor, being able to have a large number of application program support is the premise of pushing it to the market. Therefore, shortening the software development cycle and improving the quality of software development play a vital role in the entire development process. Some embedded processors have very high requirements on performance, for example, the routers of the backbone network are required to be able to support the packet forwarding rate of the upper G. Special techniques are used in this class of embedded processors to increase processing speed, one of which is the special purpose register set. These special-purpose register groups are used to store key data to overcome memory access bottlenecks and speed up data access, and cannot be used for compiler register allocation. How to make full use of these special-purpose register groups in embedded software is one of the keys to improve performance.

在目前的嵌入式软件开发中,访问专用寄存器组主要有两种方式:汇编语言编程和使用高级语言与汇编语言的混合编程。In the current embedded software development, there are two main ways to access the special register group: assembly language programming and mixed programming using high-level language and assembly language.

汇编语言编程的优点是运行效率高,可灵活的对专用寄存器组进行控制,但是缺点是要求程序员直接操作硬件,编程效率不高,难于调试,难于移植。The advantages of assembly language programming are high operating efficiency and flexible control of special register groups, but the disadvantages are that programmers are required to directly operate hardware, programming efficiency is not high, and it is difficult to debug and transplant.

混合编程是一种不得已的选择。高级语言克服了汇编语言的缺点,但是由于高级语言语法的局限,难以直接使用高级语言对嵌入式处理器提供的专用寄存器组进行操作,只能借助于内嵌到高级语言源程序中的汇编语句来操作硬件。如下面的C语言源程序片段所示:Hybrid programming is an option of last resort. High-level language overcomes the shortcomings of assembly language, but due to the limitation of high-level language syntax, it is difficult to directly use high-level language to operate the special register set provided by embedded processor, only by means of assembly statement embedded in high-level language source program to operate the hardware. As shown in the following C language source program fragment:

int a asm(%r18”);//将全局变量a指定放入寄存器%r18中int a asm(%r18");//put the global variable a into the register %r18

void function()void function()

{{

    int b asm(“%r22”);//局部变量b指定放入寄存器%r22中int b asm("%r22");//The local variable b is specified to be placed in the register %r22

    …...

}}

混合编程的一个缺点是同样难于移植,如果把某个专有寄存器的编号从%r18修改为%r17,就需要把源程序中所有出现的%r18修改一遍。另一个缺点是功能有限:1)是嵌入式汇编只能使用标量来访问专有寄存器,而不能使用结构、数组等规则记录变量,因此能够访问的寄存器个数受标量的最大宽度制约,通常不超过64位(即2个32位的专用寄存器);2)是标量只能作为一个整体来进行使用,当程序员需要对专用寄存器的一位或者某几位进行位域操作时,需要自己处理细节,增大了出错机会,降低了编程效率。One disadvantage of mixed programming is that it is also difficult to transplant. If you change the number of a specific register from %r18 to %r17, you need to modify all occurrences of %r18 in the source program. Another disadvantage is that the functions are limited: 1) Embedded assembly can only use scalars to access dedicated registers, but cannot use rules such as structures and arrays to record variables, so the number of registers that can be accessed is limited by the maximum width of scalars, usually not More than 64 bits (that is, two 32-bit special registers); 2) the scalar can only be used as a whole, when the programmer needs to perform bit field operations on one or several bits of the special register, he needs to handle it himself Details increase the chance of error and reduce programming efficiency.

因此,人们希望支持高级语言中用规则记录变量访问专用寄存器组的处理方法。Therefore, it is desirable to support the handling of variable access special-purpose register banks with rules in high-level languages.

发明内容Contents of the invention

本发明的目的是克服现有技术中的不足,提供一种支持在高级语言中用规则记录变量访问专用寄存器组的处理方法,能够在嵌入式软件开发中直接使用规则记录变量如结构、联合等访问处理器的专用寄存器组。The purpose of the present invention is to overcome the deficiencies in the prior art, provide a kind of processing method that supports to visit special-purpose register bank with rule record variable in high-level language, can directly use rule record variable such as structure, union etc. in embedded software development Access the processor's special register set.

为了达到上述目的,本发明采取的技术方案如下:In order to achieve the above object, the technical scheme that the present invention takes is as follows:

支持用规则记录变量访问专用寄存器组的处理方法,通过扩展编译器的功能,对于嵌入式处理器中普遍存在的专用寄存器组,可以在高级语言源程序中将专用寄存器组定义为具有一定属性的规则记录变量来进行访问,具体内容包括如下四点:Supports the processing method of using rules to record variables to access special registers. By extending the functions of the compiler, for the special registers commonly found in embedded processors, the special registers can be defined in the high-level language source program as having certain attributes. Rules record variables for access, and the specific content includes the following four points:

1)设计新的类型属性,以标识需要放入专用寄存器组的规则记录变量类型。1) Design a new type attribute to identify the type of the rule record variable that needs to be placed in the special register bank.

2)设计规则记录变量的语法树结构,用递归算法实现计算规则记录变量各成员相对位置;其中变量的名称、类型、成员域、大小和一般的变量语法树结构类似,增加表示步骤1)所述类型属性的特征比特位,并忽视规则记录变量以及其成员域的对齐要求信息;这是因为常规的处理方法要求按照变量类型计算对齐以便编译器为变量分配存储位置,而本方法的规则记录变量会存储到专用寄存器组中,因此不需要计算对齐;规则记录变量的成员域在语法树结构中是用链表表示的,成员是除了联合变量之外的一般变量的语法树结构;所述递归算法在编译器分析到类型属性信息后遍历规则记录变量语法结构中的成员链,不考虑成员的类型和对齐要求计算成员在规则记录变量中的偏移,重置编译器在建立成员语法树结构时计算的位置信息。2) Design the grammatical tree structure of the rule record variable, and use a recursive algorithm to realize the calculation of the relative position of each member of the rule record variable; wherein the name, type, member field, and size of the variable are similar to the general variable grammatical tree structure. The feature bits of the above-mentioned type attributes, and ignore the alignment requirement information of the rule record variable and its field; Variables will be stored in special-purpose register groups, so there is no need to calculate alignment; the member fields of rule record variables are represented by linked lists in the syntax tree structure, and the members are syntax tree structures of general variables except joint variables; the recursive The algorithm traverses the member chain in the rule record variable syntax structure after the compiler analyzes the type attribute information, calculates the offset of the member in the rule record variable regardless of the type and alignment requirements of the member, and resets the compiler when building the member syntax tree structure The location information calculated at the time.

3)设计规则记录变量的中间表示;该结构包括规则记录变量和它每个成员域对应的专用寄存器编号、大小、起始比特和结束比特;生成规则记录变量的中间表示的算法包括:遍历规则记录变量语法树结构的成员链,根据成员的相对位置和大小计算所占用的专用寄存器编号、起始比特和结束比特,同时指示编译器专用寄存器不参与寄存器分配。3) Design the intermediate representation of the rule record variable; the structure includes the rule record variable and its special register number, size, start bit and end bit corresponding to each member field; the algorithm for generating the intermediate representation of the rule record variable includes: traversal rule Record the member chain of the variable syntax tree structure, calculate the occupied special register number, start bit and end bit according to the relative position and size of the member, and instruct the compiler that the special register does not participate in register allocation.

4)生成利用规则记录变量访问专用寄存器组的代码;所用算法分两模块:从专用寄存器组提取规则记录变量成员数据的数据提取模块和将规则记录变量成员数据存储到专用寄存器组的数据存储模块;其中,数据提取模块分3个过程:数据对齐、数据无关位屏蔽和专用寄存器读写;数据存储模块的过程为上述3个过程的逆过程;每个过程根据数据大小和位置选择合适的处理器指令或指令组合生成代码;一般的数据对齐通常选择移位指令,数据无关位屏蔽选择按位与或指令,而专用寄存器读写选择数据移动指令;对于单个成员数据占用多个专用寄存器的情况,算法根据寄存器边界将该数据分割多个部分,每个部分位于单个专用寄存器,经过提取或存储代码生成,最后再生成将各部分数据合并的代码。4) Generate the code that uses the rule record variable to access the special register group; the algorithm used is divided into two modules: the data extraction module that extracts the member data of the rule record variable from the special register group and the data storage module that stores the member data of the rule record variable to the special register group ; Among them, the data extraction module is divided into three processes: data alignment, data-independent bit masking and special register reading and writing; the process of the data storage module is the reverse process of the above three processes; each process selects the appropriate processing according to the data size and position The code is generated by register instruction or instruction combination; the shift instruction is usually selected for general data alignment, the bitwise AND or instruction is selected for data-independent bit masking, and the data movement instruction is selected for special register reading and writing; for the case where a single member data occupies multiple special registers , the algorithm divides the data into multiple parts according to the register boundaries, each part is located in a single special-purpose register, after extracting or storing code generation, and finally generating the code to combine the data of each part.

与现有技术相比,本发明提出的处理方法具有如下的优点:Compared with the prior art, the processing method proposed by the present invention has the following advantages:

1)保留了高级语言开发的优点,又克服了高级语言难以对特殊硬件进行直接控制的缺点,程序员像使用普通规则记录变量一样使用处理器提供的专用寄存器组,而不需要借助于汇编语句,既可以把专用寄存器组作为一个整体来存取,也可以单独存取单个寄存器的一位、几位或者跨寄存器边界存取,提高了编程效率,缩短了开发周期;1) It retains the advantages of high-level language development, and overcomes the disadvantage that high-level language is difficult to directly control special hardware. Programmers use the special register set provided by the processor like using ordinary rules to record variables, without resorting to assembly statements , it can not only access the special register group as a whole, but also access one bit, several bits of a single register or access across register boundaries, which improves programming efficiency and shortens the development cycle;

2)向程序员屏蔽了底层硬件的细节,能灵活的处理各种专用寄存器组的使用规范,当专用寄存器组使用规范变更的时候,只需要修改编译器中生成中间代码的映射过程,不需要对源程序程序作任何修改;2) The details of the underlying hardware are shielded from the programmer, and the use specifications of various special register sets can be flexibly handled. When the use specifications of special register sets change, only the mapping process of generating intermediate code in the compiler needs to be modified, and no Make any modification to the source program;

3)向编译器暴露了更多的优化机会,提高了系统性能。3) More optimization opportunities are exposed to the compiler, improving system performance.

具体实施方式Detailed ways

下面结合具体实施方式对本发明作进一步详细描述:Below in conjunction with specific embodiment the present invention is described in further detail:

支持用规则记录变量访问专用寄存器组的处理方法,处理流程如下:Supports the processing method of using rules to record variables to access special register groups, and the processing flow is as follows:

1)在编译器中增加对一种高级语言如C语言的类型属性的支持,对源程序中的规则记录变量进行检验,如果具有该类型属性,则编译器将其识别为需要放到专用寄存器组中;如果没有该类型属性,则编译器按照已知的方法进行处理;该步骤包括如下子步骤:1) Add support for the type attribute of a high-level language such as C language in the compiler, and check the rule record variable in the source program. If it has this type attribute, the compiler will recognize it as needing to be placed in a special register group; if there is no attribute of this type, the compiler will process it according to a known method; this step includes the following sub-steps:

步骤1.1:增加编译器内部的属性数组的长度,使其能够容纳新添的这种属性;Step 1.1: Increase the length of the attribute array inside the compiler so that it can accommodate the newly added attribute;

步骤1.2:修改属性数组的初始化函数,使得新添的这种属性参数能够被正确初始化,同时编译器在进行词法分析和语法分析时能够识别这种属性;Step 1.2: Modify the initialization function of the attribute array, so that the newly added attribute parameters can be correctly initialized, and the compiler can recognize this attribute when performing lexical analysis and syntax analysis;

2)编译器前端根据类型属性识别出需要放入专用寄存器组的规则记录变量,将为其建立语法树的结构,将语法树结构中对应与该属性的特征比特置1,并且根据变量的名称、类型、成员域、大小、对齐要求等设置语法树结构的对应域,除此以外,语法树结构和域信息的计算还由硬件设计者确定的专用寄存器组的使用规范(主要是数据排列方式)决定;该步骤包括如下子步骤:2) The front-end of the compiler recognizes the rule record variable that needs to be put into the special register group according to the type attribute, and builds a syntax tree structure for it, sets the feature bit corresponding to the attribute in the syntax tree structure to 1, and according to the name of the variable , type, member field, size, alignment requirements, etc. to set the corresponding fields of the syntax tree structure. In addition, the calculation of the syntax tree structure and field information is also determined by the hardware designer. ) decision; this step includes the following sub-steps:

步骤2.1:修改编译器内部对语法树结构的定义,增加和该属性对应的特征比特;Step 2.1: Modify the definition of the syntax tree structure inside the compiler, and add the feature bit corresponding to this attribute;

步骤2.2:编译器在进行语法分析时,对于变量定义将建立对应的语法树结构,并且将对应这种属性的标志比特置1;Step 2.2: When the compiler performs grammatical analysis, it will establish a corresponding grammatical tree structure for the variable definition, and set the flag bit corresponding to this attribute to 1;

步骤2.3:编译器对变量类型进行分析,根据变量的名称、类型、域,填充语法树结构,根据专用寄存器组使用规范递归计算规则记录变量各成员大小、对齐要求和起始位置。Step 2.3: The compiler analyzes the variable type, fills the syntax tree structure according to the variable name, type, and field, and records the size, alignment requirements, and starting position of each member of the variable according to the recursive calculation rules of the special register group usage specification.

3)编译器的中间代码生成阶段对于特征比特为0的语法树结构,按照普通变量进行处理,而对于步骤2中生成的语法树结构,将为变量和它每个子域建立对应的中间表示,包括其对应的专用寄存器编号、大小、起始比特和结束比特。该步骤包括如下子步骤:3) In the intermediate code generation stage of the compiler, for the syntax tree structure whose feature bit is 0, it is processed as an ordinary variable, and for the syntax tree structure generated in step 2, a corresponding intermediate representation will be established for the variable and each of its subfields, Including its corresponding special register number, size, start bit and end bit. This step includes the following sub-steps:

步骤3.1:如果语法树结构特征比特为0,则按照普通变量来进行处理,执行步骤4);Step 3.1: If the feature bit of the syntax tree structure is 0, then process it as a common variable, and perform step 4);

步骤3.2:对于步骤2.2中建立的特征比特为1的语法树结构,为变量和它的每个子域建立对应的中间表示,并初始化中间表示中变量的名称、类型等基本信息;Step 3.2: For the syntax tree structure with a feature bit of 1 established in step 2.2, establish a corresponding intermediate representation for the variable and each of its subfields, and initialize basic information such as the name and type of the variable in the intermediate representation;

步骤3.3:编译器根据步骤2.3中计算出来得各个位域的大小、起始位置和对齐方式信息,将各个位域映射到专用寄存器组中,设置其对应的中间代码,包括其对应的专用寄存器标号、大小、起始比特和结束比特。Step 3.3: According to the size, starting position and alignment information of each bit field calculated in step 2.3, the compiler maps each bit field to a special register group, and sets its corresponding intermediate code, including its corresponding special register Label, size, start bit and end bit.

4)编译器的后端利用步骤3)中生成的中间表示进行代码生成。该步骤包括如下子步骤:4) The backend of the compiler utilizes the intermediate representation generated in step 3) for code generation. This step includes the following sub-steps:

步骤4.1:编译器生成指令的中间代码;指令的操作数存储在专用寄存器组时,或者要用指令对专用寄存器组中的数据进行运算时,本专利支持数据可以跨越专用寄存器边界。对于这种占用多个物理寄存器的数据,要生成数据提取代码和数据合并代码;Step 4.1: The compiler generates the intermediate code of the instruction; when the operand of the instruction is stored in the special register group, or when the instruction is used to perform operations on the data in the special register group, this patent supports that the data can cross the boundary of the special register. For such data occupying multiple physical registers, data extraction code and data merging code should be generated;

步骤4.2:编译器根据现有技术提供的方法对指令的中间代码进行变换和优化,包括删除冗余的用于提取和合并数据的代码,最后输出汇编表示。Step 4.2: The compiler transforms and optimizes the intermediate code of the instruction according to the methods provided by the prior art, including deleting redundant codes for extracting and merging data, and finally outputs the assembly representation.

Claims (7)

1、一种支持用规则记录变量访问专用寄存器组的处理方法,通过扩展编译器的功能,对于嵌入式处理器中普遍存在的专用寄存器组,在高级语言源程序中将专用寄存器组定义为具有一定属性的规则记录变量来进行访问,具体包括如下四点:1, a kind of processing method that supports to record variables to visit special-purpose register group with the rule, by expanding the function of compiler, for the special-purpose register group commonly existing in the embedded processor, in high-level language source program, special-purpose register group is defined as having Certain attribute rules record variables for access, including the following four points: 1)定义一种类型属性,以标识需要放入专用寄存器组的规则记录变量类型;1) Define a type attribute to identify the rule record variable type that needs to be put into the special register group; 2)设计规则记录变量的语法树结构,用递归算法实现计算规则记录变量各成员相对位置;其中变量的名称、类型、成员域、大小和一般的变量语法树结构相同,增加表示步骤1)所述类型属性的特征比特位,并忽视规则记录变量以及其成员域的对齐要求信息;规则记录变量的成员域在语法树结构中用链表表示,成员是一般变量的语法树结构;2) Design the syntax tree structure of the rule record variable, and use a recursive algorithm to realize the calculation of the relative position of each member of the rule record variable; wherein the name, type, member field, and size of the variable are the same as the general variable syntax tree structure, and the increase indicates that step 1) The characteristic bit of the above-mentioned type attribute, and ignore the alignment requirement information of the rule record variable and its member field; the member field of the rule record variable is represented by a linked list in the syntax tree structure, and the members are the syntax tree structure of the general variable; 3)设计规则记录变量的中间表示;该结构包括规则记录变量和它每个成员域对应的专用寄存器编号、大小、起始比特和结束比特;生成规则记录变量的中间表示的算法包括:遍历规则记录变量语法树结构的成员链,根据成员的相对位置和大小计算所占用的专用寄存器编号、起始比特和结束比特,同时指示编译器专用寄存器不参与寄存器分配;3) Design the intermediate representation of the rule record variable; the structure includes the rule record variable and its special register number, size, start bit and end bit corresponding to each member field; the algorithm for generating the intermediate representation of the rule record variable includes: traversal rule Record the member chain of the variable syntax tree structure, calculate the occupied special register number, start bit and end bit according to the relative position and size of the member, and instruct the compiler that the special register does not participate in register allocation; 4)生成利用规则记录变量访问专用寄存器组的代码;所用算法分两模块:从专用寄存器组提取规则记录变量成员数据的数据提取模块和将规则记录变量成员数据存储到专用寄存器组的数据存储模块;其中,所述数据提取模块分三个过程:数据对齐、数据无关位屏蔽和专用寄存器读写;所述数据存储模块的过程为上述三个过程的逆过程;每个过程根据数据大小和位置选择合适的处理器指令或指令组合生成代码。4) Generate the code that uses the rule record variable to access the special register group; the algorithm used is divided into two modules: the data extraction module that extracts the member data of the rule record variable from the special register group and the data storage module that stores the member data of the rule record variable to the special register group ; Wherein, the data extraction module is divided into three processes: data alignment, data-independent bit masking and special register read and write; the process of the data storage module is the inverse process of the above three processes; each process is based on data size and position Select the appropriate processor instruction or combination of instructions to generate code. 2、根据权利要求1所述的支持用规则记录变量访问专用寄存器组的处理方法,其特征在于,步骤2)中的所述递归算法在编译器分析到类型属性信息后遍历规则记录变量语法结构中的成员链,不考虑成员的类型和对齐要求计算成员在规则记录变量中的偏移,重置编译器在建立成员语法树结构时计算的位置信息。2. The method according to claim 1, characterized in that, the recursive algorithm in step 2) traverses the grammatical structure of the rule record variable after the compiler analyzes the type attribute information In the member chain in , the offset of the member in the rule record variable is calculated regardless of the type and alignment requirements of the member, and the position information calculated by the compiler when building the member syntax tree structure is reset. 3、一种支持用规则记录变量访问专用寄存器组的处理方法,处理流程如下:3. A processing method that supports using rule record variables to access special register groups, the processing flow is as follows: 1)在编译器中增加对一种高级语言的类型属性的支持,对源程序中的规则记录变量进行检验,如果具有该类型属性,则编译器将其识别为需要放到专用寄存器组中;如果没有该类型属性,则编译器按照已知的方法进行处理;1) Add support for the type attribute of a high-level language in the compiler, and check the rule record variable in the source program. If it has the type attribute, the compiler will recognize it as needing to be placed in the special register group; If there is no such type attribute, the compiler will handle it according to the known method; 2)编译器前端根据类型属性识别出需要放入专用寄存器组的规则记录变量,将为其建立语法树的结构,将语法树结构中对应与该属性的特征比特置1,并且根据变量信息设置语法树结构的对应域;2) The front-end of the compiler recognizes the rule record variable that needs to be put into the special register group according to the type attribute, and will establish a syntax tree structure for it, set the feature bit corresponding to the attribute in the syntax tree structure to 1, and set it according to the variable information The corresponding domain of the syntax tree structure; 3)编译器的中间代码生成阶段对于特征比特为0的语法树结构,按照普通变量进行处理,而对于步骤2)中生成的语法树结构,将为变量和它每个子域建立对应的中间表示,包括其对应的专用寄存器编号、大小、起始比特和结束比特;3) In the intermediate code generation stage of the compiler, for the syntax tree structure with a feature bit of 0, it is processed as an ordinary variable, and for the syntax tree structure generated in step 2), a corresponding intermediate representation will be established for the variable and each of its subfields , including its corresponding special register number, size, start bit and end bit; 4)编译器的后端利用步骤3)中生成的中间表示进行代码生成。4) The backend of the compiler utilizes the intermediate representation generated in step 3) for code generation. 4、根据权利要求3所述的支持用规则记录变量访问专用寄存器组的处理方法,其特征在于,所述步骤1)包括如下子步骤:4. The method according to claim 3, characterized in that said step 1) includes the following sub-steps: 步骤1.1:增加编译器内部的属性数组的长度,使其能够容纳新添的这种属性;Step 1.1: Increase the length of the attribute array inside the compiler so that it can accommodate the newly added attribute; 步骤1.2:修改属性数组的初始化函数,使得新添的这种属性参数能够被正确初始化,同时编译器在进行词法分析和语法分析时能够识别这种属性。Step 1.2: Modify the initialization function of the attribute array, so that the newly added attribute parameter can be correctly initialized, and at the same time, the compiler can recognize this attribute when performing lexical analysis and syntax analysis. 5、根据权利要求3所述的支持用规则记录变量访问专用寄存器组的处理方法,其特征在于,所述步骤2)包括如下子步骤:5. The method according to claim 3, characterized in that said step 2) includes the following sub-steps: 步骤2.1:修改编译器内部对语法树结构的定义,增加和该属性对应的特征比特;Step 2.1: Modify the definition of the syntax tree structure inside the compiler, and add the feature bit corresponding to this attribute; 步骤2.2:编译器在进行语法分析时,对于变量定义将建立对应的语法树结构,并且将对应这种属性的标志比特置1;Step 2.2: When the compiler performs grammatical analysis, it will establish a corresponding grammatical tree structure for the variable definition, and set the flag bit corresponding to this attribute to 1; 步骤2.3:编译器对变量类型进行分析,根据变量的名称、类型、域,填充语法树结构,根据专用寄存器组使用规范递归计算规则记录变量各成员大小、对齐要求和起始位置;Step 2.3: The compiler analyzes the variable type, fills the syntax tree structure according to the name, type, and domain of the variable, and records the size, alignment requirements, and starting position of each member of the variable according to the recursive calculation rules of the special register group usage specification; 所述步骤3)包括如下子步骤:Described step 3) comprises following sub-step: 步骤3.1:如果语法树结构特征比特为0,则按照普通变量来进行处理,执行步骤4);Step 3.1: If the feature bit of the syntax tree structure is 0, then process it as a common variable, and perform step 4); 步骤3.2:对于步骤2.2中建立的特征比特为1的语法树结构,为变量和它的每个子域建立对应的中间表示,并初始化中间表示中关于变量的基本信息;Step 3.2: For the syntax tree structure with a feature bit of 1 established in step 2.2, establish a corresponding intermediate representation for the variable and each of its subfields, and initialize the basic information about the variable in the intermediate representation; 步骤3.3:编译器根据步骤2.3中计算出来得各个位域的大小、起始位置和对齐方式信息,将各个位域映射到专用寄存器组中,设置其对应的中间表示,包括其对应的专用寄存器标号、大小、起始比特和结束比特。Step 3.3: According to the size, starting position and alignment information of each bit field calculated in step 2.3, the compiler maps each bit field to a special register group, and sets its corresponding intermediate representation, including its corresponding special register Label, size, start bit and end bit. 6、根据权利要求3所述的支持用规则记录变量访问专用寄存器组的处理方法,其特征在于,所述步骤4)包括如下子步骤:6. The method according to claim 3, characterized in that said step 4) includes the following sub-steps: 步骤4.1:编译器生成指令的中间代码;指令的操作数存储在专用寄存器组时,或者要用指令对专用寄存器组中的数据进行运算时,数据可以跨越专用寄存器边界;对于这种占用多个物理寄存器的数据,要生成数据提取代码和数据合并代码;Step 4.1: The compiler generates the intermediate code of the instruction; when the operand of the instruction is stored in the special register group, or when the instruction is used to perform operations on the data in the special register group, the data can cross the boundary of the special register; For the data of physical registers, data extraction code and data merging code should be generated; 步骤4.2:编译器对指令的中间代码进行变换和优化,包括删除冗余的用于提取和合并数据的代码,最后输出汇编表示。Step 4.2: The compiler transforms and optimizes the intermediate code of the instruction, including deleting redundant codes for extracting and merging data, and finally outputs the assembly representation. 7、一种支持用规则记录变量访问专用寄存器组的处理方法,处理流程如下:7. A processing method that supports using rule record variables to access special register groups, the processing flow is as follows: 1)在编译器中增加对一种高级语言的类型属性的支持,对源程序中的规则记录变量进行检验,如果具有该类型属性,则编译器将其识别为需要放到专用寄存器组中;如果没有该类型属性,则编译器按照已知的方法进行处理;该步骤包括如下子步骤:1) Add support for the type attribute of a high-level language in the compiler, and check the rule record variable in the source program. If it has the type attribute, the compiler will recognize it as needing to be placed in the special register group; If there is no such type attribute, the compiler proceeds according to a known method; this step includes the following sub-steps: 步骤1.1:增加编译器内部的属性数组的长度,使其能够容纳新添的这种属性;Step 1.1: Increase the length of the attribute array inside the compiler so that it can accommodate the newly added attribute; 步骤1.2:修改属性数组的初始化函数,使得新添的这种属性参数能够被正确初始化,同时编译器在进行词法分析和语法分析时能够识别这种属性;Step 1.2: Modify the initialization function of the attribute array, so that the newly added attribute parameters can be correctly initialized, and the compiler can recognize this attribute when performing lexical analysis and syntax analysis; 2)编译器前端根据类型属性识别出需要放入专用寄存器组的规则记录变量,将为其建立语法树的结构,将语法树结构中对应与该属性的特征比特置1,并且根据变量信息设置语法树结构的对应域;该步骤包括如下子步骤:2) The front-end of the compiler recognizes the rule record variable that needs to be put into the special register group according to the type attribute, and will establish a syntax tree structure for it, set the feature bit corresponding to the attribute in the syntax tree structure to 1, and set it according to the variable information The corresponding domain of the syntax tree structure; this step includes the following sub-steps: 步骤2.1:修改编译器内部对语法树结构的定义,增加和该属性对应的特征比特;Step 2.1: Modify the definition of the syntax tree structure inside the compiler, and add the feature bit corresponding to this attribute; 步骤2.2:编译器在进行语法分析时,对于变量定义将建立对应的语法树结构,并且将对应这种属性的标志比特置1;Step 2.2: When the compiler performs grammatical analysis, it will establish a corresponding grammatical tree structure for the variable definition, and set the flag bit corresponding to this attribute to 1; 步骤2.3:编译器对变量类型进行分析,根据变量的名称、类型、域,填充语法树结构,根据专用寄存器组使用规范递归计算规则记录变量各成员大小、对齐要求和起始位置;Step 2.3: The compiler analyzes the variable type, fills the syntax tree structure according to the name, type, and domain of the variable, and records the size, alignment requirements, and starting position of each member of the variable according to the recursive calculation rules of the special register group usage specification; 3)编译器的中间代码生成阶段对于特征比特为0的语法树结构,按照普通变量进行处理,而对于步骤2中生成的语法树结构,将为变量和它每个子域建立对应的中间表示,包括其对应的专用寄存器编号、大小、起始比特和结束比特;该步骤包括如下子步骤:3) In the intermediate code generation stage of the compiler, for the syntax tree structure whose feature bit is 0, it is processed as an ordinary variable, and for the syntax tree structure generated in step 2, a corresponding intermediate representation will be established for the variable and each of its subfields, Including its corresponding special register number, size, start bit and end bit; this step includes the following sub-steps: 步骤3.1:如果语法树结构特征比特为0,则按照普通变量来进行处理,执行步骤4);Step 3.1: If the feature bit of the syntax tree structure is 0, then process it as a common variable, and perform step 4); 步骤3.2:对于步骤2.2中建立的特征比特为1的语法树结构,为变量和它的每个子域建立对应的中间代码,并初始化中间表示中关于变量的基本信息;Step 3.2: For the syntax tree structure with a feature bit of 1 established in step 2.2, create a corresponding intermediate code for the variable and each of its subfields, and initialize the basic information about the variable in the intermediate representation; 步骤3.3:编译器根据步骤2.3中计算出来得各个位域的大小、起始位置和对齐方式信息,将各个位域映射到专用寄存器组中,设置其对应的中间代码,包括其对应的专用寄存器标号、大小、起始比特和结束比特;Step 3.3: According to the size, starting position and alignment information of each bit field calculated in step 2.3, the compiler maps each bit field to a special register group, and sets its corresponding intermediate code, including its corresponding special register label, size, start bit and end bit; 4)编译器的后端利用步骤3)中生成的中间表示进行代码生成;该步骤包括如下子步骤:4) The backend of the compiler uses the intermediate representation generated in step 3) to generate code; this step includes the following sub-steps: 步骤4.1:编译器生成指令的中间代码;指令的操作数存储在专用寄存器组时,或者要用指令对专用寄存器组中的数据进行运算时,数据可以跨越专用寄存器边界;对于这种占用多个物理寄存器的数据,要生成数据提取代码和数据合并代码;Step 4.1: The compiler generates the intermediate code of the instruction; when the operand of the instruction is stored in the special register group, or when the instruction is used to perform operations on the data in the special register group, the data can cross the boundary of the special register; For the data of physical registers, data extraction code and data merging code should be generated; 步骤4.2:编译器根据现有技术提供的方法对指令的中间代码进行变换和优化,包括删除冗余的用于提取和合并数据的代码,最后输出汇编表示。Step 4.2: The compiler transforms and optimizes the intermediate code of the instruction according to the methods provided by the prior art, including deleting redundant codes for extracting and merging data, and finally outputs the assembly representation.
CNB2005100932793A 2005-08-23 2005-08-23 A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks Expired - Lifetime CN100559344C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005100932793A CN100559344C (en) 2005-08-23 2005-08-23 A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005100932793A CN100559344C (en) 2005-08-23 2005-08-23 A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks

Publications (2)

Publication Number Publication Date
CN1920771A true CN1920771A (en) 2007-02-28
CN100559344C CN100559344C (en) 2009-11-11

Family

ID=37778501

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005100932793A Expired - Lifetime CN100559344C (en) 2005-08-23 2005-08-23 A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks

Country Status (1)

Country Link
CN (1) CN100559344C (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957772A (en) * 2009-07-16 2011-01-26 北京中电华大电子设计有限责任公司 Compiler for generating lightweight comparison instruction
CN106201641A (en) * 2015-04-29 2016-12-07 龙芯中科技术有限公司 The memory access co mpiler optimization method and apparatus of function
CN107341372A (en) * 2017-07-25 2017-11-10 北京深思数盾科技股份有限公司 A kind of method for protecting software and device
CN112035040A (en) * 2020-08-31 2020-12-04 北京润科通用技术有限公司 Interface variable information processing method and device
CN114127684A (en) * 2020-09-29 2022-03-01 深圳市汇顶科技股份有限公司 Compiler for RISC processor with special purpose registers
CN115617400A (en) * 2022-12-20 2023-01-17 杭州加速科技有限公司 Register matching method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2857600B2 (en) * 1995-05-11 1999-02-17 松下電器産業株式会社 Processor and program translator

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957772A (en) * 2009-07-16 2011-01-26 北京中电华大电子设计有限责任公司 Compiler for generating lightweight comparison instruction
CN101957772B (en) * 2009-07-16 2013-01-02 北京中电华大电子设计有限责任公司 Compiler for generating lightweight comparison instruction
CN106201641A (en) * 2015-04-29 2016-12-07 龙芯中科技术有限公司 The memory access co mpiler optimization method and apparatus of function
CN107341372A (en) * 2017-07-25 2017-11-10 北京深思数盾科技股份有限公司 A kind of method for protecting software and device
CN107341372B (en) * 2017-07-25 2018-12-07 北京深思数盾科技股份有限公司 A kind of method for protecting software and device
CN112035040A (en) * 2020-08-31 2020-12-04 北京润科通用技术有限公司 Interface variable information processing method and device
CN112035040B (en) * 2020-08-31 2023-04-07 北京润科通用技术有限公司 Interface variable information processing method and device
CN114127684A (en) * 2020-09-29 2022-03-01 深圳市汇顶科技股份有限公司 Compiler for RISC processor with special purpose registers
CN115617400A (en) * 2022-12-20 2023-01-17 杭州加速科技有限公司 Register matching method and device
CN115617400B (en) * 2022-12-20 2023-03-21 杭州加速科技有限公司 Register matching method and device

Also Published As

Publication number Publication date
CN100559344C (en) 2009-11-11

Similar Documents

Publication Publication Date Title
CN110187885B (en) Intermediate code generation method and device for quantum program compiling
Alfred et al. Compilers Principles, Techniques
CN1802632B (en) Method and apparatus for performing interpreter optimization during program code transformation
US7536682B2 (en) Method and apparatus for performing interpreter optimizations during program code conversion
US8505002B2 (en) Translation of SIMD instructions in a data processing system
US7543284B2 (en) Partial dead code elimination optimizations for program code conversion
US8813047B2 (en) Yet another transformation language (YATL)
US20080178149A1 (en) Inferencing types of variables in a dynamically typed language
CN102385524B (en) Method for replacing compiling chain order based on mixed-compiling order set
Aho Compilers: Principles, Techniques and Tools (for VTU)
Blindell Instruction selection
US20100250564A1 (en) Translating a comprehension into code for execution on a single instruction, multiple data (simd) execution
US7200841B2 (en) Method and apparatus for performing lazy byteswapping optimizations during program code conversion
US8914782B2 (en) Optimization of declarative queries
CN102360306A (en) Method for extracting and optimizing information of cyclic data flow charts in high-level language codes
CN100559344C (en) A Processing Method Supporting Using Rules to Record Variables to Access Special Register Banks
Metcalf The seven ages of Fortran
Stitt et al. Techniques for synthesizing binaries to an advanced register/memory structure
WO2024222455A1 (en) Hardware acceleration instruction determination method and system, and electronic device and storage medium
CN112579059B (en) Compiling method supporting finite field data type and operator
Gill A Haskell hosted DSL for writing transformation systems
US20040045018A1 (en) Using address space bridge in postoptimizer to route indirect calls at runtime
Bose Instruction set design for support of high-level languages
Carpenter et al. Translation Schemes for the HPJava Parallel Programming Language
Nöcker Efficient functional programming: Compilation and programming techniques

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: HANGZHOU UNIMAS INFORMATION TECHNOLOGY CO., LTD.

Free format text: FORMER OWNER: INSTITUTE OF COMPUTING TECHNOLOGY, CHINESE ACADEMY OF SCIENCES

Effective date: 20121224

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 100080 HAIDIAN, BEIJING TO: 310052 HANGZHOU, ZHEJIANG PROVINCE

TR01 Transfer of patent right

Effective date of registration: 20121224

Address after: Hangzhou City, Zhejiang province Binjiang District 310052 shore road 1180 building 3 layer 1-3

Patentee after: HANGZHOU UNIMAS INFORMATION ENGINEERING Co.,Ltd.

Address before: 100080 Haidian District, Zhongguancun Academy of Sciences, South Road, No. 6, No.

Patentee before: Institute of Computing Technology, Chinese Academy of Sciences

C56 Change in the name or address of the patentee

Owner name: HANGZHOU UNIMASSYSTEM DATA TECHNOLOGY CO., LTD.

Free format text: FORMER NAME: HANGZHOU UNIMAS INFORMATION TECHNOLOGY CO., LTD.

CP01 Change in the name or title of a patent holder

Address after: Hangzhou City, Zhejiang province Binjiang District 310052 shore road 1180 building 3 layer 1-3

Patentee after: HANGZHOU HEZHONG DATA TECHNOLOGY Co.,Ltd.

Address before: Hangzhou City, Zhejiang province Binjiang District 310052 shore road 1180 building 3 layer 1-3

Patentee before: HANGZHOU UNIMAS INFORMATION ENGINEERING Co.,Ltd.

CP03 Change of name, title or address

Address after: 310052 floors 5-8, building 3, No. 399, Danfeng Road, Xixing street, Binjiang District, Hangzhou City, Zhejiang Province (self declaration)

Patentee after: HANGZHOU HEZHONG DATA TECHNOLOGY Co.,Ltd.

Address before: 310052 1-3 / F, building 3, 1180 Bin'an Road, Binjiang District, Hangzhou City, Zhejiang Province

Patentee before: HANGZHOU UNIMAS INFORMATION ENGINEERING Co.,Ltd.

CP03 Change of name, title or address
CX01 Expiry of patent term
CX01 Expiry of patent term

Granted publication date: 20091111