METHOD AND COMPILER OF COMPILING A PROGRAM

Information

  • Patent Application
  • 20090049431
  • Publication Number
    20090049431
  • Date Filed
    August 01, 2008
    16 years ago
  • Date Published
    February 19, 2009
    16 years ago
Abstract
The present invention provides a method and a compiler of compiling a source program. According to an aspect of the present invention, there is provided a method of compiling a source program comprising: identifying a hint related to vector aligning when syntax analyzing said source program; and generating a simplified code based on said identified hint related to vector aligning when generating a code.
Description
CROSS-REFERENCE TO RELATED APPLICATIONS

The present application claims the benefit under 35 U.S.C. §119 of Switzerland; Application Serial Number 200710141856.0, filed Aug. 14, 2007 entitled “METHOD AND COMPILER OF COMPILING A PROGRAM,” which is incorporated herein by reference;


TECHNICAL FIELD

The present invention relates to technology of data processing, more particularly to technology of compiling a source program.


BACKGROUND

In recent years, highly specialized embedded microprocessors, e.g.□ Digital Signal Processors (DSPs), are required for real time processing of digitized analog signals, e.g.□ handling audio, video, graphics and communication etc. tasks.


A typical computing scenario involves executing the same or almost the same sequence of operations on different elements of a large data set, e.g. an array. In this situation, a traditional computing model, where a single instruction (such as load, store, or integer addition) operates on a single data element, is not very efficient.


Thereby, people design and develop a Single Instruction Multiple Data (SIMD) architecture, which improves the data processing performance of a program by executing the same type computing on different data elements of a parallel vector. Most of existing high performance processors support the SIMD architecture, and these processors include a plurality of function units, some of which are configured to process scalar data, and others are combined together to process structured SIMD vector data. The SIMD architecture is generally used to process vector data for high performance computing or multimedia data types, such as color information coded by using triple (r, g, b) format, or coordinate information coded by using quadruple (x, y, z, w) format and so on.


The detailed description about the SIMD architecture can be seen in the following references 1-4:



1. “Auto-Vectorization of Interleaved Data for SIMD”, Dorit Nuzman, Ira Rosen and Ayal Zaks, PLDI'06 Jun. 10-16, 2006, Ottawa, Ontario, Canada, p. 132-142 (reference 1);


2. “Vectorization for SIMD Architectures with Alignment Constraints”, Alexandre E. Eichenberger, Peng Wu and Kevin O'Brien, PLDI'04, Jun. 9-11, 2004, Washington, D.C., USA, p. 82-93 (reference 2);


3. “Compilation techniques for multimedia processors”, A. Krall and S. Lelait, International Journal of Parallel Programming, 28(4): 347-361, 2000 (reference 3); and


4. “Code Optimization Techniques for Embedded Processors, Methods, Algorithms, and Tools”, R. Leupers, Kluwer Academic Publisher, Boston, 2000 (reference 4), which are incorporated herein by reference.


Although the SIMD architecture improves the data processing performance hugely, the SIMD architecture requires a memory address of a vector operand to be vector aligned, that is to say, requires a vector pointer to be vector aligned. Thereby, in the process of compiling a source program, whether the pointer is vector aligned or not is required to be judged before the vector operand is loaded into a register, if the pointer is not vector aligned, the pointer is required to be aligned, and the register is required to be turned (shifted) before the register loaded with the operand is operated.


Actually, most of vector pointers of SIMD instructions are vector aligned, so it is not necessary to do the above-mentioned judgment, but for a compiler, it is very difficult to determine whether the vector pointer is vector aligned or not. Thereby, for the vector, the pointer of which is vector aligned itself, many fussy and useless codes are generated in the compiling process, the complexity of the code is increased and the data processing performance of the program is decreased consequently.


SUMMARY OF THE INVENTION

In order to solve the above-mentioned problems in the prior technology, the present invention provides a method and a compiler of compiling a source program.


According to an aspect of the present invention, there is provided a method of compiling a source program comprising: identifying a hint related to vector aligning when syntax analyzing the above-mentioned source program; and generating a simplified code based on the above-mentioned identified hint related to vector aligning when generating a code.


According to another aspect of the present invention, there is provided a compiler of compiling a source program comprising: a syntax analysis unit configured to identify a hint related to vector aligning when syntax analyzing the above-mentioned source program; and a code generating unit configured to generate a simplified code based on the above-mentioned identified hint related to vector aligning when generating a code.





BRIEF DESCRIPTION OF THE DRAWINGS

It is believed that through the following detailed description of the embodiments of the present invention, taken in conjunction with the drawings, the above-mentioned features, advantages, and objectives will be better understood.



FIG. 1 is a flowchart showing a method of compiling a source program according to an embodiment of the present invention; and



FIG. 2 is a block diagram showing a compiler of compiling a source program according to another embodiment of the present invention.





DETAILED DESCRIPTION OF THE INVENTION

Next, a detailed description of each embodiment of the present invention will be given in conjunction with the accompany drawings.


Method of Compiling a Source Program


FIG. 1 is a flowchart showing a method of compiling a source program according to an embodiment of the present invention. As shown in FIG. 1, first at Step 101, a source program is lexical analyzed. Specifically, the source program is any program written by using a high-level language. The high-level language has no relation with specific computer hardware and is a program design language problem-objected, the expression way of which is close to a natural language and a mathematical language and is easy to be accepted and mastered by people. In this embodiment, a language for writing the source program is required to support SIMD, such as GCC (GNU), Intel/C/C++, IBM XLC, MS Visual C++ and so on.


At Step 101, the source program is lexical analyzed. As one part of a compiling process, in lexical analysis, a term such as an identifier, a constant, a reserved word and an operator etc. in the source program is constructed and analyzed, and the term in the source program is transformed into an integer or an integer pair with an internal representation equaling to a certain degree, and then transmitted as the internal representation to others part of the compiling process, for example, syntax analysis etc. Any method known in the art or developed in the future can be used to perform lexical analyzing in Step 101, and the present invention has no special limitation on this.


Next, at Step 102, the source program is syntax analyzed. As one part of the compiling process, syntax analysis is a step to identify whether each of sentences of which the program is composed is correct in syntax or not after the process of lexical analyzing the source program is completed. For a syntax error found in the analysis, an indication will be given in a way of screen displaying or words printing etc., and it is required to be modified by a programmer.


In this embodiment, a hint related to vector aligning is identified when the source program is syntax analyzed. The above-mentioned hint related to vector aligning is introduced by the programmer when writing the above-mentioned source program, and the hint is used to indicate that the vector is vector aligned. Thereby, it can be definitely known in the compiling process of the source program that the vector is a vector aligned vector. For example, a modifier “_vec_align_” can be used as the hint. Detailed description will be given later by use of an example.


At Step 102, the identified hint related to vector aligning is recorded in order to provide the indication that the vector is vector aligned at later steps. Optionally, for example, the identified hint related to vector aligning can be recorded into a symbol table as an attribute of an identifier related to the vector. In the compiling process of the source program, the symbol table is used to record identifiers in the source program and their various attributes, and these attributes can provide memory allotment information, type information, and domain information and so on of the identifiers. For a process identifier, there is also parameter information, including the number and the type of the parameter, the combination way of the actual parameter and the formal parameter and so on. The structure of the symbol table is a kind of data structure containing records, one identifier occupies one record in the symbol table generally, and the record also has a domain of recording the attribute of the identifier besides the name domain of the identifier.


Next, at Step 103, the source program is semantic analyzed based on syntax analysis. Semantic analysis is used to check if the source program contains semantic errors or not, and collect types thereof to be used at the later code generating phase. Only the source program which is syntax and semantic correct can be translated into a target code. Any method known in the art or developed in the future can be used to perform semantic analyzing in Step 103, and the present invention has no special limitation on this.


At last, at Step 104, a simplified code is generated according to the identified hint related to vector aligning at Step 102 based on semantic analysis. At this step, for the vector having the hint related to vector aligning, the code used to judge if the vector is vector aligned or not in existing technology is not required to be generated, and the code used to turn a register is also not required to be generated, thereby the code generated is hugely simplified.


In this embodiment, an operand in the vector having the above-mentioned hint related to vector aligning is only required to be directly loaded into the register by use of the simplified code generated, and the above-mentioned register loaded with the operand is directly operated, thereby the processing performance of a program is hugely improved.


Optionally, before the simplified code is generated at Step 104, a simplified intermediate code also can be generated according to the identified hint related to vector aligning at Step 102 based on semantic analysis. The intermediate code is a kind of intermediate language code between a source language and a target language. The intermediate code has various forms, for example, ternary form, quaternary form, converse Poland expression, tree structure and so on.


Further, after the simplified intermediate code is generated, the simplified intermediate code generated also can be processed and transformed in order to generate more effective target code (for example, saving time and saving space) at the last phase.


Further, optionally, in the method of compiling a source program of the embodiment, error handling also can be done. An error of the source program can be discovered at each phase of compiling the source program. After the error is discovered, there is specific processing on it generally, thus the compiling can be further continued to be executed, and the compiling will not be stopped as the error appears. For example, the word spelling error can be discovered in lexical analysis. The word string is checked if the syntax structure rule is satisfied or not in syntax analysis. The part which is syntax correct but contains meaningless operation is further found by the compiler in semantic analysis, such as adding two identifiers, one of which is array name and the other is process name, is allowed in syntax, but is not allowed in semantic. Various errors should be processed at the corresponding phase.


The method of compiling the source program of the embodiment will be further described by use of Example 1 and Comparative Example 1 in the following.


COMPARATIVE EXAMPLE 1

The source program as follows is provided to be compiled:

















Alloc.c



struct data_blk



{



 char *ptr;



 int size;



 int gid;



 int pad;



};



struct data_blk_list



{



 struct data_blk blks[4];



 unsigned int index;



 int pad;



};



void alloc_data_block(struct data_blk_list*blk_list,



 struct data_blk*blk, int blk_num)



{



 *blk = blk_list->blks[blk_list->index];



 blk_list->index++;



 blk_list->index %= blk_list->blk_num;



}



#spu-gcc-Os-S allow.c










In this source program, the vectors blk_List and blk exist, and whether these vectors are vector aligned or not is not known in the compiling process. Thus, the code used to judge if the vectors are vector aligned and the code used to turn a register must be generated, and the code finally generated will occupy 54 instructions.


EXAMPLE 1

The source program as follows is provided to be compiled:

















Alloc.c



struct data_blk



{



 char *ptr;



 int size;



 int gid;



 int pad;



};



struct data_blk_list



{



 struct data_blk blks[4];



 unsigned int index;



 int pad;



};



void alloc_data_block(struct data_blk_list*_vec_align_blk_list,



 strut data_blk*_vec_align_blk)



{



 *blk = blk_list->blks[blk_list->index];



 blk_list->index++;



 blk_list->index = 4;



}



#spu-gcc-Os-S allow.c










On the contrary with Comparative Example 1, a new modifier _vec_align_is introduced by the programmer to provide the hint related to vector aligning in the source program of Example 1. For the compiler, the vectors blk_list and blk are all 16 bytes aligned in Example 1, thus,

















void alloc_data_block(struct data_blk_list*_vec_align_blk_list,



 strut data_blk*_vec_align_blk)



{



 *blk = blk_list->blks[blk_list->index];



 blk_list->index++;



 blk_list->index = 4;



}



can be transformed into SIMD codes as follows:



void alloc_data_block(vector unsigned int *blk_list,



 vector unsigned int *blk)



{



 *blk = *(blk_list + spu_extract(blk_list[4], 0));



 blk_list [4] = spu_and(spu_add(blk_list[4], 1), 3);



}










Thus, the code used to judge if the vector is vector aligned and the code used to turn a register are not required to be generated, and the code finally generated will only occupy 10 instructions. Thereby the code generated is hugely simplified.


By use of the method of compiling a source program of the embodiment, a simplified target code can be generated by using the hint related to vector aligning provided in the source program, thereby the processing capability of the program is hugely improved, time and space are saved, and the efficiency is improved.


Compiler of Compiling a Source Program

Under the same inventive conception, FIG. 2 is a block diagram showing a compiler of compiling a source program according to another embodiment of the present invention. Next, the present embodiment will be described in conjunction with FIG. 2. For those same parts as the above embodiments, the description of which will be appropriately omitted.


As shown in FIG. 2, the compiler 200 of this embodiment comprises a lexical analysis unit 201 configured to lexical analyze the source program; a syntax analysis unit 202 configured to syntax analyze the source program; a semantic analysis unit 203 configured to semantic analyze the source program; and a code generating unit 204 configured to generate a target code.


In this embodiment, the source program is any program written by using a high-level language. The high-level language has no relation with specific computer hardware and is a program design language problem-objected, the expression way of which is close to a natural language and a mathematical language and is easy to be accepted and mastered by people. In this embodiment, a language for writing the source program is required to support SIMD, such as GCC (GNU), Intel/C/C++, IBM XLC, MS Visual C++ and so on.


In this embodiment, various characters such as identifiers, constants, reserved words and operands etc. in the source program are scanned from left to right by the lexical analysis unit 201, and symbols and terms forming the source program will be transmitted to the syntax analysis unit 202. In this embodiment, any lexical analysis unit known in the art or developed in the future can be used, and the present invention has no special limitation on this.


Whether each of the sentences of which the program is composed is correct in syntax or not□is identified by the syntax analysis unit 202 after the process of lexical analyzing the source program is completed by the lexical analysis unit 201. For a syntax error found in the analysis, an indication will be given in a way of screen displaying or words printing etc., and it is required to be modified by a programmer.


In this embodiment, a hint related to vector aligning is identified when the source program is syntax analyzed by the syntax analysis unit 202. The above-mentioned hint related to vector aligning is introduced by the programmer when writing the above-mentioned source program, and the hint is used to indicate that the vector is vector aligned. Thereby, it can be definitely known in the compiling process of the source program that the vector is a vector aligned vector. For example, a modifier “_vec_align_” can be used as the hint. The detailed description can be seen in the above-mentioned Example 1 in the embodiment of the method of compiling a source program of FIG. 1, which is omitted herein.


In this embodiment, the hint related to vector aligning identified by the syntax analysis unit 202 is recorded in order to provide the indication that the vector is vector aligned for other units. Optionally, for example, the identified hint related to vector aligning can be recorded into a symbol table as an attribute of an identifier related to the vector. In the process of compiling the source program by the compiler 200, the symbol table is used to record identifiers in the source program and their various attributes, and these attributes can provide memory allotment information, type information, domain information and so on of the identifiers. For a process identifier, there is also parameter information, including the number and the type of the parameter, the combination way of the actual parameter and the formal parameter and so on. The structure of the symbol table is a kind of data structure containing records, one identifier occupies one record in the symbol table generally, and the record also has a domain of recording the attribute of the identifier besides the name domain of the identifier.


Based on the source program syntax analyzed by the syntax analysis unit 202, the source program is semantic analyzed by the semantic analysis unit 203. The semantic analysis unit 203 is used to check if the source program contains semantic errors or not, and collect types thereof to be used at the later code generating phase. Only the source program which is syntax and semantic correct can be translated into a target code. In this embodiment, any semantic analysis unit known in the art or developed in the future can be used, and the present invention has no special limitation on this.


Based on the source program semantic analyzed by the semantic analysis unit 203, a simplified code is generated by the code generating unit 204 according to the hint related to vector aligning identified by the syntax analysis unit 202. In the process of generating the code by the code generating unit 204, for the vector having the hint related to vector aligning, the code used to judge if the vector is vector aligned or not in existing technology is not required to be generated, and the code used to turn a register is also not required to be generated, thereby the code generated is hugely simplified.


In this embodiment, an operand in the vector having the above-mentioned hint related to vector aligning is only required to be directly loaded into the register by use of the simplified code generated, and the above-mentioned register loaded with the operand is directly operated, thereby the processing performance of a program is hugely improved.


Optionally, the compiler 200 of this embodiment further comprises an intermediate code generating unit configured to generate a simplified intermediate code according to the hint related to vector aligning identified by the syntax analysis unit 202 based on the source program semantic analyzed by the semantic analysis unit 203 before the simplified code is generated by the code generating unit 204. The intermediate code is a kind of intermediate language code between a source language and a target language. The intermediate code has various forms, for example, ternary form, quaternary form, converse Poland expression, tree structure and so on.


Further, the compiler 200 of this embodiment further comprises a code optimizing unit configured to process and transform the simplified intermediate code in order to generate more effective target code (for example, saving time and saving space) at the last phase after the simplified intermediate code is generated by the intermediate code generating unit.


Further, optionally, the compiler 200 of this embodiment further comprises an error handling unit configured to do error handling in the process of compiling the source program by the compiler 200 of the embodiment. An error of the source program can be discovered at each phase of compiling the source program by the compiler 200. After the error is discovered, there is specific processing on it generally, thus the compiling can be further continued to be executed, and the compiling will not be stopped as the error appears. For example, the word spelling error can be discovered in lexical analysis of the lexical analysis unit 201. The word string is checked if the syntax structure rule is satisfied or not in syntax analysis of the syntax analysis unit 202. The part which is syntax correct but contains meaningless operation is further found by the compiler in semantic analysis of the semantic analysis unit 203, such as adding two identifiers, one of which is array name and the other is process name, is allowed in syntax, but is not allowed in semantic. Various errors should be processed at the corresponding phase.


The detailed description of the compiling process of the compiler 200 can be seen in the above-mentioned embodiment of the method of compiling a source program of FIG. 1, which is omitted herein.


Further, the compiler 200 of compiling a source program of the embodiment also can be obtained by improving an existing compiler including but not limiting to GCC (GNU C Compiler), C/C++ Compiler of Intel, XLC Compiler of IBM, Visual C++ Compiler of MS and so on based on the above.


By use of the compiler 200 of compiling a source program of the embodiment, a simplified target code can be generated by using the hint related to vector aligning provided in the source program, thereby the processing capability of the program is improved hugely, time and space are saved, and the efficiency is improved.


Though a method of compiling a source program and a compiler of compiling a source program have been described in details with some exemplary embodiments, these above embodiments are not exhaustive. Those skilled in the art can make various variations and modifications within the spirit and the scope of the present invention. Therefore, the present invention is not limited to these embodiments; rather, the scope of the present invention is only defined by the appended claims.

Claims
  • 1. A method of compiling a source program comprising: identifying a hint related to vector aligning when syntax analyzing said source program; andgenerating a simplified code based on said identified hint related to vector aligning when generating a code.
  • 2. The method according to claim 1, further comprising: recording said identified hint related to vector aligning.
  • 3. The method according to claim 2, further comprising: recording said identified hint related to vector aligning into a symbol table as an attribute of an identifier related to a vector.
  • 4. The method according to claim 1, wherein, said hint related to vector aligning is introduced by a programmer when writing said source program.
  • 5. The method according to claim 1, wherein, said generated simplified code is used to: directly load an operand in a vector having said hint related to vector aligning into a register.
  • 6. The method according to claim 5, wherein, said generated simplified code is further used to: directly operate said register loaded with said operand.
  • 7. The method according to claims 1, further comprising: lexical analyzing said source program before syntax analyzing said source program.
  • 8. The method according to claim 1, further comprising: semantic analyzing said source program after syntax analyzing said source program.
  • 9. A compiler of compiling a source program comprising: a syntax analysis unit configured to identify a hint related to vector aligning when syntax analyzing said source program; anda code generating unit configured to generate a simplified code based on said identified hint related to vector aligning when generating a code.
  • 10. The compiler according to claim 9, wherein said identified hint related to vector aligning is recorded.
  • 11. The compiler according to claim 10, wherein said identified hint related to vector aligning is recorded into a symbol table as an attribute of an identifier related to a vector.
  • 12. The compiler according to claim 9, wherein said hint related to vector aligning is introduced by a programmer when writing said source program.
  • 13. The compiler according to claims 9, wherein said simplified code generated by said code generating unit is used to directly load an operand in a vector having said hint related to vector aligning into a register.
  • 14. The compiler according to claim 13, wherein said simplified code generated by said code generating unit is further used to directly operate said register loaded with said operand.
  • 15. The compiler according to a claim 9, further comprising: a lexical analysis unit configured to lexical analyze said source program before syntax analyzing said source program.
  • 16. The compiler according to claims 9, further comprising: a semantic analysis unit configured to semantic analyze said source program after syntax analyzing said source program.
Priority Claims (1)
Number Date Country Kind
200710141856.0 Aug 2007 CH national