Method of constructing a constant-folding mechanism in a multilanguage optimizing compiler
First Claim
1. A method executed in a computer system for producing an object module comprising a constant-folding routine, said method comprising the steps of:
- generating a flow graph that represents a constant-folding routine in an intermediate language using a compiler front end and an intermediate language input, said intermediate language being a universal language used by a plurality of compiler front ends to represent source code and including operators and data types used to describe said source code, each compiler front end corresponding to a different programming language, said intermediate language input describing said intermediate language and comprising said operators and said data types of said intermediate language, said constant-folding routine included in a code optimizer to evaluate a constant expression and to replace said constant expression with an equivalent expression yielding a same result as said constant expression, said constant expression being comprised of at least one of said operators or said data types; and
producing an object module that contains machine instructions of said constant-folding routine using said flow graph as an input to a code generator, said code generator being a common code generator used by each of said plurality of front ends to generate an object module using a flow graph.
3 Assignments
0 Petitions
Accused Products
Abstract
A compiler framework comprises a generic compiler back end which may be used by a plurality of front ends to generate object code for a target computer system. Each front end scans and parses a source module containing source code for a programming language, and generates an intermediate language representation that describes the source code. The intermediate language representation is input to the generic compiler back end which performs optimization and code generation for a plurality of target computer systems. "Constant folding" optimization is performed by the generic compiler back end, and comprises finding occurrences of expressions that can be reduced to a constant and calculated at compile time rather than at runtime. One mechanism for performing constant folding, also referred to as K-folding, uses a KFOLD routine that is built by the compiler framework. The KFOLD routine is constructed using a special front end that produces an intermediate language representation of the KFOLD routine which may be used by the generic back end to produce a corresponding object file for one of a plurality of target computer systems. The special front end produces the intermediate language representation for the KFOLD routine using as input the intermediate language comprising intermediate language operators.
289 Citations
19 Claims
-
1. A method executed in a computer system for producing an object module comprising a constant-folding routine, said method comprising the steps of:
-
generating a flow graph that represents a constant-folding routine in an intermediate language using a compiler front end and an intermediate language input, said intermediate language being a universal language used by a plurality of compiler front ends to represent source code and including operators and data types used to describe said source code, each compiler front end corresponding to a different programming language, said intermediate language input describing said intermediate language and comprising said operators and said data types of said intermediate language, said constant-folding routine included in a code optimizer to evaluate a constant expression and to replace said constant expression with an equivalent expression yielding a same result as said constant expression, said constant expression being comprised of at least one of said operators or said data types; and producing an object module that contains machine instructions of said constant-folding routine using said flow graph as an input to a code generator, said code generator being a common code generator used by each of said plurality of front ends to generate an object module using a flow graph. - View Dependent Claims (2, 3, 4)
-
-
5. A method performed in a host computer system having a memory for compiling source code and producing a corresponding object module, the method comprising the steps of:
-
generating a first flow graph that is stored in said memory by performing an execution flow analysis of said source code, said first flow graph representing said source code in an intermediate language, said intermediate language being a universal language used by a plurality of compiler front ends to represent source code and including operators and data types used to described said source code, each of said plurality of compiler front ends corresponding to a different programming language; generating a second flow graph that contains an optimized representation of said first flow graph by detecting a constant expression in said first flow graph and executing a constant-folding routine which evaluates said constant expression and replaces said constant expression with an equivalent expression yielding a same result as said constant expression, said constant expression including at least one of said operators or said data types, said second flow graph being stored in said memory; and producing said corresponding object module by using said second flow graph as input to a code generator that produces said corresponding object module for a target computer system, said corresponding object module including machine instructions for execution in said target computer system, said code generator being a common code generator used by a plurality of front ends to generate an object module using a flow graph; and wherein said constant-folding routine is produced by performing the steps of; generating, using a compiler front end and an intermediate language input to said compiler front end, a third flow graph that represents said constant-folding routine in said intermediate language, said intermediate language input describing said intermediate language and comprising said operators and said data types of said intermediate language, said compiler front end being one of said plurality of compiler front ends; and producing a constant-folding object module using said third flow graph as an input to said code generator. - View Dependent Claims (6, 7, 8, 9, 10, 11)
-
-
12. An apparatus for use in a host computer system having a memory for compiling source code and producing a corresponding object module, the apparatus comprising:
-
A) a first compiler front end performing an execution flow analysis of said source code and producing a first flow graph that is stored in said memory, said first flow graph representing said source code in an intermediate language including operators and data types used to describe said source code; B) a compiler back end, coupled to said first compiler front end, said compiler back-end comprising; i) optimizing means that uses said first flow graph as input for producing a second flow graph that contains an optimized representation of said first flow graph, said second flow graph representing said source code in said intermediate language and being stored in said memory; and ii) code generator means, coupled to said optimizing means, for generating said corresponding object module using said second flow graph as input;
said optimizing means comprising constant-folding means executing a constant-folding routine for detecting and evaluating a constant expression in said second flow graph and replacing said constant expression with an equivalent expression yielding a same result as said constant expression, said constant expression being comprised of at least one of said operators or said data types, said corresponding object module comprising machine instructions for execution in said target computer system; andC) means for generating said constant-folding routine comprising; i) a second compiler front end for generating a third flow graph that represents said constant-folding routine in said intermediate language, said third flow graph being generated using said operators of said intermediate language as input; and ii) said compiler back end, using said third flow graph as input and coupled to said second compiler front end, for generating an object file containing machine instructions for said constant-folding routine. - View Dependent Claims (13, 14, 15)
-
-
16. An apparatus used in a computer system for producing an object module comprising a constant-folding routine, said apparatus comprising:
-
generating means for generating a flow graph that represents said constant-folding routine in an intermediate language using a compiler front end and an intermediate language input, said intermediate language being a universal language used by a plurality of compiler front ends to represent source code and including operators and data types used to describe said source code, each compiler front end corresponding to a different programming language, said intermediate language input describing said intermediate language and comprising said operators and said data types of said intermediate language, said constant-folding routine included in a code optimizer to evaluate a constant expression and to replace said constant expression with an equivalent constant expression yielding a same result as said constant expression, said constant expression being comprised of at least one of said operators or said data types; and producing means for producing said object module using said flow graph as an input to a code generator, said code generator being a common code generator used by said plurality of compiler front ends to generate an object module using a flow graph. - View Dependent Claims (17, 18)
-
-
19. An apparatus for compiling source code in a host computer system with a memory and producing a corresponding object module, the apparatus comprising:
-
generating means for generating a first flow graph that is stored in said memory by performing an execution flow analysis of said source code, said first flow graph representing said source code in an intermediate language, said intermediate language being a universal language used by a plurality of compiler front ends to represent source code and including operators and data types used to described said source code, each of said plurality of compiler front ends corresponding to a different programming language; generating means for generating a second flow graph that contains an optimized representation of said first flow graph by detecting a constant expression in said first flow graph and executing a constant-folding routine which evaluates and replaces said constant expression with an equivalent expression yielding a same result as said constant expression, said constant expression being comprised of at least one of said operators or said data types, said third flow graph being stored in said memory; and producing means for producing said corresponding object module by using said second flow graph as input to a code generator that produces said corresponding object module for a target computer system, said corresponding object module including machine instructions for execution in said target computer system, said code generator being a common code generator used by a plurality of front ends to generate an object module using a flow graph; and wherein said constant-folding routine is produced using; a compiler front end and an intermediate language input to said compiler front end for generating a third flow graph that represents said constant-folding routine in said intermediate language, said intermediate language input describing said intermediate language and comprising said operators and said data types of said intermediate language; and said code generator, using said third flow graph as an input, for generating a constant-folding object module comprising machine instructions for said constant-folding routine.
-
Specification