CA2678767A1 - Optimization of meta-template instantiations - Google Patents

Optimization of meta-template instantiations Download PDF

Info

Publication number
CA2678767A1
CA2678767A1 CA002678767A CA2678767A CA2678767A1 CA 2678767 A1 CA2678767 A1 CA 2678767A1 CA 002678767 A CA002678767 A CA 002678767A CA 2678767 A CA2678767 A CA 2678767A CA 2678767 A1 CA2678767 A1 CA 2678767A1
Authority
CA
Canada
Prior art keywords
meta
template
identified
data structure
computer executable
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.)
Abandoned
Application number
CA002678767A
Other languages
French (fr)
Inventor
Sean Douglas Perry
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.)
IBM Canada Ltd
Original Assignee
IBM Canada Ltd
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 IBM Canada Ltd filed Critical IBM Canada Ltd
Priority to CA002678767A priority Critical patent/CA2678767A1/en
Publication of CA2678767A1 publication Critical patent/CA2678767A1/en
Priority to US12/894,642 priority patent/US8904370B2/en
Priority to US14/556,271 priority patent/US9436448B2/en
Priority to US15/205,794 priority patent/US9858055B2/en
Abandoned legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Abstract

An illustrative embodiment provides a computer-implemented method for an alternate type system for optimizing the evaluation and use of meta-template instantiations. The computer-implemented method obtains a source code, instantiates an element of the source code to form an instantiated element and identifies a meta-template within the instantiated element to form an identified meta-template. The computer-implemented method creates an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries, creates an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries, and uses the associated entry of the second data structure in combination with the entry of the first data structure.

Description

OPTIMIZATION OF META-TEMPLATE INSTANTIATIONS
BACKGROUND

1. Technical Field:
[0001] This disclosure relates generally to programming language optimization in a data processing system and more specifically alternate type system for optimizing the evaluation of meta-template instantiations in programming compilations.
2. Description of the Related Art:
[0002] Within the C++ programming language, programmers have created a functional programming language using various implementations of the template and the type system.
Current compiler implementations allow programmers to program complex problems using template instantiations enabling aspects of the problems to be solved at compile time rather than at run time. However, the type system of the compiler is not designed to handle the large number of template instantiations and types created while computing the results. As use of the type system increases the performance of the compiler degrades.
[0003] For example, in the following code snippet, the template class Fib<20>
will create Fib<19> and Fib<18>. This progressive instantiation continues until the specializations Fib<1>
and Fib<0> are used. The specializations provide termination of the recursive process.
[0004] template <int N>
[0005] struct Fib {
[0006] enum E {Result = Fib<N-1>::Result+Fib<N-2>::Result};
[0007] };
[0008]
[0009] template <> struct Fib<0> {enum {Result = 0};};
[0010] template <> struct Fib<1> {enum {Result = 0};};

[0012] int x = Fib<20>::Result;

100131 Although the user only used Fib<20>, other instantiations were required to compute the result. In this case the number of extra instantiations grows linearly with the value of the template argument. Use of Fib<21> will only require one more instantiation than Fib<20>.
[0014] As program complexity increases, so does the recursion thereby causing an overload of the regular type system. As the regular type system of the compiler becomes overloaded the compilation time increases due to the number of and size of entries to be processed as well as the time required performing the compilations.

BRIEF SUMMARY
[0015] According to one embodiment, a computer-implemented method for an alternate type system for optimizing the evaluation and use of meta-template instantiations obtains a source code, instantiates an element of the source code to form an instantiated element, identifies a meta-template within the instantiated element to form an identified meta-template, creates an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries, creates an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries, and uses the associated entry of the second data structure in combination with the entry of the first data structure.
[0016] According to another embodiment, a computer program product for an alternate type system for optimizing the evaluation and use of meta-template instantiations is presented. The computer program product comprises a computer recordable medium containing computer executable program code stored thereon, the computer executable program code comprising, computer executable program code for obtaining a source code, computer executable program code for instantiating an element of the source code to form an instantiated element, computer executable program code for identifying a meta-template within the instantiated element to form an identified meta-template, computer executable program code for creating an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries, computer executable program code for creating an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries, and computer executable program code for using the associated entry of the second data structure in combination with the entry of the first data structure.
[0017] According to another embodiment, an apparatus for an alternate type system for optimizing the evaluation and use of meta-template instantiations is presented. The apparatus comprises a communications fabric, a memory connected to the communications fabric, wherein the memory contains computer executable program code, a communications unit connected to the communications fabric, an input/output unit connected to the communications fabric, a display connected to the communications fabric, and a processor unit connected to the communications fabric, wherein the processor unit executes the computer executable program code to direct the apparatus to obtain a source code, instantiate an element of the source code to form an instantiated element, identify a meta-template within the instantiated element to form an identified meta-template, create an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries, create an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries, and use the associated entry of the second data structure in combination with the entry of the first data structure.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

[0018] For a more complete understanding of this disclosure, reference is now made to the following brief description, taken in conjunction with the accompanying drawings and detailed description, wherein like reference numerals represent like parts.
[0019] Figure 1 is a block diagram of an exemplary data processing system environment that may be operable for various embodiments of the disclosure;
[0020] Figure 2; is a block diagram of high level components of a compiler, in accordance with various embodiments of the disclosure;
[0021] Figure 3 is a flowchart of a high level process using the compiler of Figure 2 in accordance with one embodiment of the disclosure;
[0022] Figures 4 is a flowchart of a process for identifying a meta-template instantiation of Figure 3 in accordance with one embodiment of the disclosure;

[0023] Figure 5, is a flowchart of a portion of a transformation process of Figure 4 according to one embodiment of the disclosure; and [0024] Figure 6 is a flowchart of a process of handling static member functions according to one embodiment of the disclosure.
DETAILED DESCRIPTION

[0025] Although an illustrative implementation of one or more embodiments is provided below, the disclosed systems and/or methods may be implemented using any number of techniques.
This disclosure should in no way be limited to the illustrative implementations, drawings, and techniques illustrated below, including the exemplary designs and implementations illustrated and described herein, but may be modified within the scope of the appended claims along with their full scope of equivalents.
[0026] As will be appreciated by one skilled in the art, the present disclosure may be embodied as a system, method or computer program product. Accordingly, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a "circuit,"
"module," or "system." Furthermore, the present invention may take the form of a computer program product tangibly embodied in any medium of expression with computer usable program code embodied in the medium.
[0027] Computer program code for carrying out operations of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as JavaTM, Smalltalk, C++, or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc., in the United States, other countries or both. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server.
In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0028] The present disclosure is described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus, systems, and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions.
[0029] These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer program instructions may also be stored in a computer readable medium that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable medium produce an article of manufacture including instruction means which implement the function/act specified in the flowchart and/or block diagram block or blocks.
[0030] The computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
[0031] Turning now to Figure 1, a block diagram of an exemplary data processing system environment that may be operable for various embodiments of the disclosure is presented. In this illustrative example, data processing system 100 includes communications fabric 102, which provides communications between processor unit 104, memory 106, persistent storage 108, communications unit 110, input/output (UO) unit 112, and display 114.
[0032] Processor unit 104 serves to execute instructions for software that may be loaded into memory 106. Processor unit 104 may be a set of one or more processors or may be a multi-processor core, depending on the particular implementation. Further, processor unit 104 may be implemented using one or more heterogeneous processor systems in which a main processor is present with secondary processors on a single chip. As another illustrative example, processor unit 104 may be a symmetric multi-processor system containing multiple processors of the same type.
[0033] Memory 106 and persistent storage 108 are examples of storage devices 116. A storage device is any piece of hardware that is capable of storing information, such as, for example without limitation, data, program code in functional form, and/or other suitable information either on a temporary basis and/or a permanent basis. Memory 106, in these examples, may be, for example, a random access memory or any other suitable volatile or non-volatile storage device. Persistent storage 108 may take various forms depending on the particular implementation. For example, persistent storage 108 may contain one or more components or devices. For example, persistent storage 108 may be a hard drive, a flash memory, a rewritable optical disk, a rewritable magnetic tape, or some combination of the above.
The media used by persistent storage 108 also may be removable. For example, a removable hard drive may be used for persistent storage 108.
[0034] Communications unit 110, in these examples, provides for communications with other data processing systems or devices. In these examples, communications unit 110 is a network interface card. Communications unit 110 may provide communications through the use of either or both physical and wireless communications links.
[0035] Input/output unit 112 allows for input and output of data with other devices that may be connected to data processing system 100. For example, input/output unit 112 may provide a connection for user input through a keyboard, a mouse, and/or some other suitable input device.
Further, input/output unit 112 may send output to a printer. Display 114 provides a mechanism to display information to a user.
[0036] Instructions for the operating system, applications and/or programs may be located in storage devices 116, which are in communication with processor unit 104 through communications fabric 102. In these illustrative examples the instructions are in a functional forrn on persistent storage 108. These instructions may be loaded into memory 106 for execution by processor unit 104. The processes of the different embodiments may be performed by processor unit 104 using computer-implemented instructions, which may be located in a memory, such as memory 106.

[0037] These instructions are referred to as program code, computer usable program code, or computer readable program code that may be read and executed by a processor in processor unit 104. The program code in the different embodiments may be embodied on different physical or tangible computer readable media, such as memory 106 or persistent storage 108.
[00381 Program code 118 is located in a functional form on computer readable media 120 that is selectively removable and may be loaded onto or transferred to data processing system 100 for execution by processor unit 104. Program code 118 and computer readable media 120 form computer program product 122 in these examples. In one example, computer readable media 120 may be in a tangible form, such as, for example, an optical or magnetic disc that is inserted or placed into a drive or other device that is part of persistent storage 108 for transfer onto a storage device, such as a hard drive that is part of persistent storage 108.
In a tangible form, computer readable media 120 also may take the form of a persistent storage, such as a hard drive, a thumb drive, or a flash memory that is connected to data processing system 100. The tangible form of computer readable media 120 is also referred to as computer recordable storage media.
In some instances, computer readable media 120 may not be removable.
[0039] Alternatively, program code 118 may be transferred to data processing system 100 from computer readable media 120 through a communications link to communications unit 110 and/or through a connection to input/output unit 112. The communications link and/or the connection may be physical or wireless in the illustrative examples. The computer readable media also may take the form of non-tangible media, such as communications links or wireless transmissions containing the program code.
[0040] In some illustrative embodiments, program code 118 may be downloaded over a network to persistent storage 108 from another device or data processing system for use within data processing system 100. For instance, program code stored in a computer readable storage medium in a server data processing system may be downloaded over a network from the server to data processing system 100. The data processing system providing program code 118 may be a server computer, a client computer, or some other device capable of storing and transmitting program code 118.
[0041] The different components illustrated for data processing system 100 are not meant to provide architectural limitations to the manner in which different embodiments may be implemented. The different illustrative embodiments may be implemented in a data processing system including components in addition to or in place of those illustrated for data processing system 100. Other components shown in Figure 1 can be varied from the illustrative examples shown. The different embodiments may be implemented using any hardware device or system capable of executing program code. As one example, the data processing system may include organic components integrated with inorganic components and/or may be comprised entirely of organic components excluding a human being. For example, a storage device may be comprised of an organic semiconductor.
[0042] As another example, a storage device in data processing system 100 may be any hardware apparatus that may store data. Memory 106, persistent storage 108 and computer readable media 120 are examples of storage devices in a tangible form.
[0043] In another example, a bus system may be used to implement communications fabric 102 and may be comprised of one or more buses, such as a system bus or an input/output bus. Of course, the bus system may be implemented using any suitable type of architecture that provides for a transfer of data between different components or devices attached to the bus system.
Additionally, a communications unit may include one or more devices used to transmit and receive data, such as a modem or a network adapter. Further, a memory may be, for example, memory 106 or a cache such as found in an interface and memory controller hub that may be present in communications fabric 102.
[0044] Illustrative embodiments thus provide examples of identifying meta-templates within instantiated source code elements. Dependent functions instantiated from the meta-template are mapped into an alternate type system. Each entry in the alternate type system is smaller than a similar entry in a regular type system. The number of entries in the alternate type system is fewer than the number of entries in the regular type system. The use of the alternate type system typically allows the compiler to perform more efficiently than when using the regular type system without the alternate type system.
[0045] Using data processing system 100 of Figure las an example, an illustrative embodiment provides a computer-implemented method for an alternate type system for optimizing the evaluation and use of meta-template instantiations. The computer-implemented method using processor unit 104 to obtain a source code from storage devices 116 through communications fabric 102, instantiates an element of the source code to form an instantiated element and identifies a meta-template within the instantiated element to form an identified meta-template.

The computer-implemented method creates an entry for the identified meta-template in a first data structure, which may reside in memory 106 or persistent storage 108, wherein the entry comprises a set of mapped entries, creates an associated entry in a second data structure, which also may reside in memory 106 or persistent storage 108, linked to the set of mapped entries, wherein the associated entry represents the set of mapped entries; and uses the associated entry of the second data structure in combination with the entry of the first data structure. The computer-implemented method thus provides an alternate type system of the first data structure to optimize use of meta-template instantiations in programming compilations.
The computer-implemented method may be stored in storage devices 116 until used or installed as program code 118 from computer readable media 120 in the form of program product 122.
100461 With reference to Figure 2, a block diagram of high-level components of a compiler, in accordance with various embodiments of the disclosure is presented. Compiler 200 comprises a number of components for the compilation of source code 202 into compiled code 204.
Components of compiler 200 include, but are not limited to, instantiation process 206, template analyzer 208, regular type system 210, template mapper 212 and alternate type system 214.
100471 Source code 202 may contain various templates embedded within a set of instructions.
Source code 202 is provided as input for parsing to compiler 200. In conjunction with parsing, instantiation process 206 determines whether a template is located within the source code being processed. When a determination is made that a template of some form is present, template analyzer 208 determines whether the template is of a form known as a meta-template.
[0048] When the template, as determined by template analyzer 208, is not a meta-template, the template is processed to generate the required entries associated with the template into regular type system 210. When the template as determined by template analyzer 208 is a meta-template, template mapper 212 further processes the meta-template to evaluate the meta-template by creating a set of entries in a first data structure comprising an alternate type system 214. The set of entries for the meta-template, comprising one or more entries, stored in alternate type system 214, are smaller in size than associated entries created for a second data structure of a regular type system 210. The number of entries created in alternate type system 214 is also fewer than the number of entries created and stored in regular type system 210. The smaller size of each entry and fewer entries, contained within, allow alternate type system 214 to typically be more efficient and responsive than regular type system 210. Alternate type system 214 therefore provides a compact type system and includes a link from the set of entries for the meta-template to regular type system 210. The reduced size of each entry and fewer entries in alternate type system 214 enables efficient processing in conjunction with regular type system 210 and thus provides an optimization of the evaluation and use of the meta-template when compared to an implementation with only the use of regular type system 210.
[0049] For example, a set of entries for a meta-template may have five entries in alternate type system 214. The five entries are dependent entries used within the context of the identified meta-template. There is one link from the set of five entries of the meta-template to an associated entry in regular type system 210. Regular type system 210, in illustrative embodiments, does not include the dependent entries, as maintained in a compact form, of the alternate type system 214. The regular type system, in illustrative embodiments, therefore does not expand as rapidly as in previous implementations.
[0050] With reference to Figure 3 a flowchart of a high-level process using the compiler of Figure 2 in accordance with one embodiment of the disclosure is presented.
Process 300 is an example of using compiler 200 of Figure 2 in a C++ programming environment. A
meta-template can be recognized within source code 202 by compiler 200 of Figure 2.
A meta-template is a template that has no data members and therefore contains only enums or static data members and only static member functions. A meta-template typically has one or more of constant static data members, enums, typedefs and static member functions, for example, class scope constants.
100511 A user typically instantiates one meta-template to get an answer while the compiler needs to instantiate a large number of other meta-templates to compute the answer.
All of the instantiations take place in regular type system 210 that compiler 200 of Figure 2 uses for user declared types. The many instantiations in regular type system 210 bloat the type system and slow down compilation. Another effect of the previous implementations is to constrain the size of problems that can be solved using meta-templates. The ability to resolve problems is therefore limited by the size of and time that is required to use regular type system 210 of Figure 2.
[0052] In the illustrative embodiment of Figure 3 process 300 starts (step 302) and obtains a source code, such as source code 202 of Figure 2 (step 304). Instantiation of source code elements is performed (step 306). As each source code element is instantiated an identification of templates within the source code is performed (step 308). The identification operation of process 300 determines whether there are templates and whether the identified templates are meta-templates. Each instantiation of the identified meta-templates is placed in a separate entry of alternate type system 214 of compiler 200 of Figure 2. The alternate type system will be smaller and faster than the regular type system. The compiler can use the alternate type system for a template if a set of predefined conditions is met: A first condition requires the template to be a meta-template. A second condition requires the template to have one or more explicit (or partial) specializations. The specializations act as terminating conditions that will stop the recursive template instantiations associated with the processing of the meta-template.
[0053] Having identified a template as a meta-template in step 308, process 300 creates for each of these templates a mapping to map the C++ data structure into a small data structure, within the compiler (step 310). When the meta-template is evaluated other instantiations may be required.
The recursive behaviour of meta-templates, for example where a function Fib<20> instantiates function Fib<19> and function Fib<18>, and other functions in sequence, will create a graph in the alternate type system that is used to evaluate the result of the instantiation done by the program. Each node in the graph represents one instantiation. Each node contains the values assigned to static data members, and enums and typedefs to non-meta-template types. The edges between the nodes represent the typedefs to other meta-templates.
[0054] When the compiler encounters an instantiation for a template within the user code that satisfies the criteria for a meta-template, compiler 200 of Figure 2 will first create a mapping for the instantiation in the meta-template instantiation graph, alternate type system 214 of Figure 2.
That mapping will then be used to create an associated entry in regular type system 210 of Figure 2 representing the instantiation associated with the meta-template (step 312). The associated entry contains the results of the evaluation. Regular type system 210 of Figure 2 then only increases by one entry instead of the large number of entries required to compute the results for the instantiation associated with the meta-template. The set of entries, in the alternate type system, from the source code is processed to resolve the problem (step 314) with process 300 terminating thereafter (step 316).
[0055] Static member functions for meta-templates are also handled specially to minimize the numbers that are generated. Typically a static member function will use some of the instantiations only found in the alternate type system. The source code of a static member function needs to be transformed so the instantiations that were only created in alternate type system 214 of Figure 2 are replaced with the results. This is done by generating the code for the static member functions of the meta-template instantiations that are actually used by the different mechanisms of process 300 rather than a process for regular functions.
[0056] With reference to Figure 4 a flowchart of a process for identifying a meta-template instantiation of Figure 3 in accordance with one embodiment of the disclosure is presented.
Process 400 is an example of the identification process used in step 308 of process 300 of Figure 3.
100571 Process 400 begins (step 402) and determines whether the reference is a static member function within the identified meta-template to forrn an identified static member function (step 404). When a determination is made that the reference is a static member function within the identified meta-template, a "yes" result is obtained. When a determination is made that the reference is not a static member function within the identified meta-template, a "no" result is obtained. When a "no" result is obtained in step 404, process 400 skips to step 410. When a "yes" is obtained in step 404, process 400 determines whether the identified static member function is a member of a dependent meta-template instantiation (step 406).
Identifiers used within the static member function can be categorized as either references to members of dependent meta-template instantiations or references to members of non-dependent meta-template instantiations.
[0058] When a determination is made that the identified static member function is a member of a dependent meta-template instantiation, a "yes" result is obtained. When a determination is made that the identified static member function is not a member of a dependent meta-template instantiation, a "no" result is obtained. When a "yes" result is obtained in step 406, transform the dependent meta-template instantiations to use an alternate type system (step 408) with process 400 terminating thereafter (step 412). The transformation ensures the identifiers used in the static member function that use instantiations only instantiated in the alternate type system do not create an instantiation in the regular type system.
100591 When a "no" result is obtained in step 406, the identified static member function is a member of a non-dependent meta-template instantiation; and process 400 generates the non-dependent meta-template instantiations as a regular function in the regular type system (step 410), with process 400 terminating thereafter (step 412).

100601 With reference to Figure 5, a flowchart of a portion of a transfonnation process of Figure 4 according to one embodiment of the disclosure is presented. Process 500 is an example of replacing a reference of the transformation process of step 408 of process 400 of Figure 4.
The user code in the static member functions, provided as input to process 500, may contain references to meta-templates (including members and teplate arguments). The replacement performed in process 500 is designed to eliminate references in the function body that are not defined in the regular type system. Thus process 500 provides a capability to process static member functions and replace references to elements in the alternate type system with values or types from the regular type system.
[00611 Process 500 starts (step 502) and locates a first name used in the body of the static member function to form a located name (step 504). Process 500 determines whether the located name is qualified (step 506). When a determination is made that the name is qualified, a "yes"
result is obtained. When a determination is made that the located name is not qualified, a"no"
response is obtained.
[0062] When a "no" is obtained in step 506, determine whether the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template (step 508). When a determination is made that the located name represents a meta-template instantiation, a member of the meta-template or a template argument, a "yes"
result is obtained in step 508. When a "yes" result is obtained in step 508, process 500 replaces the located name with a result stored in the alternate type system (step 512). When a determination is made that the located name does not represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template, a"no" result is obtained in step 508. When a "no"
result is obtained in step 508, no replacement is done and process 500 skips to step 516.
100631 When a "yes" is obtained in step 506, determine whether leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template (step 510). When a determination is made that the leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template, a "yes" result is obtained in step 510. When a determination is made that leading qualifiers of the located name do not represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template a"no" result is obtained in step 510. When a "no" result is obtained in step 510, no replacement is done and process 500 skips to step 516.
[0064] When a "yes" result is obtained in step 510, process 500 replaces the leading qualifiers of the located name with a corresponding result stored in the alternate type system (step 514). The replacement of the leading qualifiers transforms the qualified name to only use the identifiers and types available in the regular type system.
[0065] Process 500 then determines whether more names exist (step 516). When a determination is made that more names exist, "yes" result is obtained. When a determination is made that no more names exist, "no" result is obtained. When a "no" result is obtained, process 500 terminates (step 520). When a "yes" result is obtained, process 500 locates a next name (step 518), with process 5001ooping back to step 506.
[0066] With reference to Figure 6 a flowchart of a process of handling static member functions according to one embodiment of the disclosure is presented. Process 600 is an example of a portion of transformation step 408 of process 400 of Figure 4.
100671 Process 600 starts (step 602) and identifies an enum or a static data member to form an identified enum or an identified static data member (step 604). Replace the reference for the identified enum or the reference for the identified static data member with a value for the identified enum or another value for the identified static data member (step 606). A
determination is made as to whether a typedef is not part of a scope chain that ends in a reference to the identified enum or the identified static data member function (step 608).
[0068] When a determination is made that the typedef is part of a scope chain that ends in a reference to the identified enum or the identified static data member function a "yes" result is obtained. When a determination is made that the typedef is no part of a scope chain that ends in a reference to the identified enum or the identified static data member function a "no" result is obtained. Responsive to a "no" result in step 608 that represents a determination that the typedef is not part of a scope chain that ends in the reference to the identified enum or the identified static data member, add the type of the last typedef in the scope chain to the regular type system (step 610). Responsive receiving a "yes" in step 608, process 600 terminates (step 618).
[0069] A determination is made as to whether the identified static member function is a call to a dependent meta-template member function is performed (step 612). When a determination is made that the identified static member function is a call to the dependent meta-template member function, a "yes" result is obtained. When a determination is made that the identified static member function is not a call to the dependent meta-template member function, a "no" result is obtained.
[0070] Responsive to the identified static member function is a call to a dependent meta-template member function, obtaining a "yes" result in step 612; generate code for the static member function to form generated code (step 614). Process 600 places the generated code inline (step 616), terminating thereafter (step 618). When the reference to the static member function takes the address of the static member function then the static member function has to be generated just as though the user instantiated the template. When a "no"
result is obtained in step 612, process 600 terminates thereafter (step 618).
[0071] Illustrative embodiments thus provide examples of identifying meta-templates within instantiated source code elements. Dependent functions instantiated from the meta-template are mapped into an alternate type system. Each entry in the alternate type system is smaller than a similar entry in a regular type system, however each entry represents a collection of entries that would have otherwise been made in the regular type system. The number of entries in the alternate type system is fewer than the number of entries in the regular type system. The use of the alternate type system in combination with the regular type system typically allows the compiler to perform more efficiently than when using the regular type system without the alternate type system.
[0072] An illustrative embodiment provides a computer-implemented method for an alternate type system for optimizing evaluation and use of ineta-template instantiations. The computer-implemented method obtains a source code, instantiates an element of the source code to form an instantiated element and identifies a meta-template within the instantiated element to form an identified meta-template. The computer-implemented method creates an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries, creates an associated entry in a second data structure, a regular type system, linked to the set of mapped entries, wherein the associated entry represents the set of mapped entries; and uses the associated entry of the second data structure in combination with the entry of the first data structure. The computer-implemented method thus provides an alternate type system, the form of a first data structure to optimize evaluation and use of meta-template instantiations in program compilations.

[0073] The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing a specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the block might occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
[0074] The corresponding structures, materials, acts, and equivalents of all means or step plus function elements in the claims below are intended to include any structure, material, or act for performing the function in combination with other claimed elements as specifically claimed.
The description of the present invention has been presented for purposes of illustration and description, but is not intended to be exhaustive or limited to the invention in the form disclosed.
Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the invention. The embodiment was chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.
[00100]The invention can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment containing both hardware and software elements. In a preferred embodiment, the invention is implemented in software, which includes but is not limited to firmware, resident software, microcode, and other software media that may be recognized by one skilled in the art.
[00101]It is important to note that while the present invention has been described in the context of a fully functioning data processing system, those of ordinary skill in the art will appreciate that the processes of the present invention are capable of being distributed in the form of a computer readable medium of instructions and a variety of forms and that the present invention applies equally regardless of the particular type of signal bearing media actually used to carry out the distribution. Examples of computer readable media include recordable-type media, such as a floppy disk, a hard disk drive, a RAM, CD-ROMs, DVD-ROMs, and transmission-type media, such as digital and analog communications links, wired or wireless communications links using transmission forms, such as, for example, radio frequency and light wave transmissions. The computer readable media may take the form of coded formats that are decoded for actual use in a particular data processing system.
[00102]A data processing system suitable for storing and/or executing program code will include at least one processor coupled directly or indirectly to memory elements through a system bus.
The memory elements can include local memory employed during actual execution of the program code, bulk storage, and cache memories which provide temporary storage of at least some program code in order to reduce the number of times code must be retrieved from bulk storage during execution.
[00103]Input/output or I/O devices (including but not limited to keyboards, displays, pointing devices, etc.) can be coupled to the system either directly or through intervening UO controllers.
[00104]Network adapters may also be coupled to the system to enable the data processing system to become coupled to other data processing systems or remote printers or storage devices through intervening private or public networks. Modems, cable modems, and Ethernet cards are just a few of the currently available types of network adapters.
[00105]The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention, the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.

Claims (20)

CLAIMS:
What is claimed is:
1. A computer-implemented method for an alternate type system for optimizing evaluation and use of meta-template instantiations, the method comprising:
obtaining a source code;
instantiating an element of the source code to form an instantiated element;
identifying a meta-template within the instantiated element to form an identified meta-template;
creating an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries;
creating an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries; and using the associated entry of the second data structure in combination with the entry of the first data structure.
2. The computer-implemented method of claim 1, wherein the identifying a meta-template further comprises:
identifying a static member function within the identified meta-template to form an identified static member function; and determining whether the identified static member function is a member of a dependent meta-template instantiation.
3. The computer-implemented method of claim 2, further comprises:
responsive to a determination that the identified static member function is a member of the dependent meta-template instantiation, transforming the identified static member function to use the first data structure, wherein the first data structure is an alternate type system and the second data structure is a regular type system.
4. The computer-implemented method of claim 1, wherein each entry in the set of mapped entries is smaller than the associated entry in the second data structure.
5. The computer-implemented method of claim 1, creating an entry for the identified meta-template in a first data structure further comprises:
locating a first name to form a located name;
determining whether the located name is qualified;
responsive to a determination the located name is qualified, determining whether leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
responsive to a determination the leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
replacing the leading qualifiers of the located name with a result stored in the first data structure;
responsive to a determination the located name is not qualified, determining whether the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
responsive to a determination the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template; replacing the located name with a result in the first data structure;
determining whether more names exist; and locating a next name.
6. The computer-implemented method of claim 2, further comprising:
responsive to a determination that the identified static member function is a member of a non-dependent meta-template instantiation, generating a regular function to use the second data structure.
7. The computer-implemented method of claim 1, wherein creating an entry for the identified meta-template in the first data structure further comprises:
identifying an enum or a static data member to form an identified enum or an identified static data member;
replacing a reference to the identified enum with a value and replacing a reference to the identified static data member with another value;
determining whether a typedef is part of a scope chain that ends in a reference to an enum or a static data member function;
responsive to a determination that the typedef is not part of a scope chain that ends in the reference to an enum or the reference to the static data member, adding the type of the last typedef in the scope chain to the regular type system;
determining whether the identified static member function is a call to the dependent meta-template member function;
responsive to a determination the identified static member function is a call to the dependent meta-template member function; generating code for the static member function to form generated code; and placing the generated code inline.
8. A computer program product for an alternate type system for optimizing evaluation and use of meta-template instantiations, the computer program product comprising:
a computer recordable-type media containing computer executable program code stored thereon, the computer executable program code comprising computer executable program code for obtaining a source code;
computer executable program code for instantiating an element of the source code to form an instantiated element;
computer executable program code for identifying a meta-template within the instantiated element to form an identified meta-template;
computer executable program code for creating an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries;

computer executable program code for creating an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries; and computer executable program code for using the associated entry of the second data structure in combination with the entry of the first data structure.
9. The computer program product of claim 8, wherein computer executable program code for identifying a meta-template further comprises:
computer executable program code for identifying a static member function within the identified meta-template to form an identified static member function; and computer executable program code for determining whether the identified static member function is a member of a dependent meta-template instantiation.
10. The computer program product of claim 9, wherein the computer executable program code further comprises:
responsive to a determination that the identified static member function is a member of the dependent meta-template instantiation, transforming the identified static member function to use the first data structure, wherein the first data structure is an alternate type system and the second data structure is a regular type system.
11. The computer program product of claim 8, wherein each entry in the set of mapped entries is smaller than the associated entry in the second data structure.
12. The computer program product of claim 8, wherein computer executable program code for creating an entry for the identified meta-template in a first data structure further comprises:
computer executable program code for locating a first name to form a located name;
computer executable program code for determining whether the located name is qualified;
computer executable program code responsive to a determination the located name is qualified, for determining whether leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template;

computer executable program code responsive to a determination the leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template; for replacing the leading qualifiers of the located name with a result stored in the first data structure;
computer executable program code responsive to a determination the located name is not qualified, for determining whether the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
computer executable program code responsive to a determination the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template; for replacing the located name with a result stored in a first data structure;
computer executable program code for determining whether more names exist; and computer executable program code for locating a next name.
13. The computer program product of claim 9, wherein the computer executable program code further comprises:
computer executable program code responsive to a determination that the identified static member function is a member of a non-dependent meta-template instantiation, for generating a regular function to use the second data structure.
14. The computer program product of claim 8, wherein computer executable program code for creating an entry for the identified meta-template in the first data structure further comprises:
computer executable program code for identifying an enum or a static data member to form an identified enum or an identified static data member;
computer executable program code for replacing a reference to the identified enum with a value and replacing a reference to the identified static data member with another value;
computer executable program code for determining whether a typedef is part of a scope chain that ends in a reference to an enum or a static data member;
computer executable program code responsive to a determination that the typedef is not part of a scope chain that ends in the reference to an enum or the reference to the static data member, for adding the type of the last typedef in the scope chain to the regular type system;

computer executable program code for determining whether the identified static member function is a call to the dependent meta-template member function;
computer executable program code responsive to a determination the identified static member function is a call to the dependent meta-template member function; for generating code for the static member function to form generated code; and computer executable program code for placing the generated code inline.
15. An apparatus for an alternate type system for optimizing evaluation and use of meta-template instantiations, the apparatus comprising:
a communications fabric;
a memory connected to the communications fabric, wherein the memory contains computer executable program code;
a communications unit connected to the communications fabric;
an input/output unit connected to the communications fabric;
a display connected to the communications fabric; and a processor unit connected to the communications fabric, wherein the processor unit executes the computer executable program code to direct the apparatus to:
obtain a source code;
instantiate an element of the source code to form an instantiated element;
identify a meta-template within the instantiated element to form an identified meta-template;
create an entry for the identified meta-template in a first data structure, wherein the entry comprises a set of mapped entries;
create an associated entry in a second data structure linked to the entry comprising the set of mapped entries, wherein the associated entry represents the set of mapped entries; and use the associated entry of the second data structure in combination with the entry of the first data structure.
16. The apparatus of claim 15, wherein the processor unit executes the computer executable instructions to identify the meta-template further comprises:
identify a static member function within the identified meta-template to form an identified static member function; and determine whether the identified static member function is a member of a dependent meta-template instantiation.
17. The apparatus of claim 16, wherein the processor unit executes the computer executable instructions to identify the meta-template further comprises:
responsive to a determination that the identified static member function is a member of the dependent meta-template instantiation, transform the identified static member function to use the first data structure, wherein the first data structure is is an alternate type system and the second data structure is a regular type system.
18. The apparatus of claim 15, wherein the processor unit executes the computer executable instructions to create an entry for the identified meta-template in a first data structure further comprises to:
locate a first name to form a located name;
determine whether the located name is qualified;
responsive to a determination the located name is qualified, determine whether leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
responsive to a determination the leading qualifiers of the located name represent a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
replace the leading qualifiers of the located name with a result stored in a first data structure;
responsive to a determination the located name is not qualified, determine whether the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template;
responsive to a determination the located name represents a meta-template instantiation, a member of the meta-template or an argument to the meta-template; replace the located name with a result stored in the first data structure;

determine whether more names exist; and locate a next name.
19. The apparatus of claim 16, wherein the processor further unit executes the computer executable instructions to determine that the identified static member function is a member of a non-dependent meta-template instantiation to:
generate a regular function to use the second data structure.
20. The apparatus of claim 15, wherein the processor unit further executes the computer executable instructions to create an entry for the identified meta-template in the first data structure to:
identify an enum or a static data member to form an identified enum or an identified static data member;
replace a reference to the identified enum with a value and replacing a reference to the identified static data member with another value;
determine whether a typedef is part of a scope chain that ends in a reference to an enum or a static data member;
responsive to a determination that the typedef is not part of a scope chain that ends in the reference to an enum or the reference to the static data member, add the type of the last typedef in the scope chain to the regular type system;
determine whether the identified static member function is a call to the dependent meta-template member function;
responsive to a determination the identified static member function is a call to the dependent meta-template member function; generate code for the static member function to form generated code; and place the generated code inline.
CA002678767A 2009-09-30 2009-09-30 Optimization of meta-template instantiations Abandoned CA2678767A1 (en)

Priority Applications (4)

Application Number Priority Date Filing Date Title
CA002678767A CA2678767A1 (en) 2009-09-30 2009-09-30 Optimization of meta-template instantiations
US12/894,642 US8904370B2 (en) 2009-09-30 2010-09-30 Optimization of meta-template instantiations
US14/556,271 US9436448B2 (en) 2009-09-30 2014-12-01 Optimization of meta-template instantiations
US15/205,794 US9858055B2 (en) 2009-09-30 2016-07-08 Optimization of meta-template instantiations

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CA002678767A CA2678767A1 (en) 2009-09-30 2009-09-30 Optimization of meta-template instantiations

Publications (1)

Publication Number Publication Date
CA2678767A1 true CA2678767A1 (en) 2009-12-09

Family

ID=41412316

Family Applications (1)

Application Number Title Priority Date Filing Date
CA002678767A Abandoned CA2678767A1 (en) 2009-09-30 2009-09-30 Optimization of meta-template instantiations

Country Status (2)

Country Link
US (3) US8904370B2 (en)
CA (1) CA2678767A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9684497B1 (en) * 2015-12-10 2017-06-20 International Business Machines Corporation Optimized compiling of a template function
US10331781B2 (en) * 2016-07-05 2019-06-25 Google Llc Template compilation using view transforms
CN110334010A (en) * 2019-05-30 2019-10-15 深圳壹账通智能科技有限公司 Sample data generation method, device, computer equipment and storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5900870A (en) * 1989-06-30 1999-05-04 Massachusetts Institute Of Technology Object-oriented computer user interface
US5835771A (en) 1995-06-07 1998-11-10 Rogue Wave Software, Inc. Method and apparatus for generating inline code using template metaprograms
CA2178898C (en) 1996-06-12 2000-02-01 David Joseph Streeter Sequencing and error detection of template instantiations during compilation of c++ programs
US5845103A (en) 1997-06-13 1998-12-01 Wisconsin Alumni Research Foundation Computer with dynamic instruction reuse
US6760905B1 (en) * 2000-09-21 2004-07-06 Curl Corporation Lazy compilation of template-generated classes in dynamic compilation execution environments
US6968541B1 (en) 2000-10-04 2005-11-22 International Business Machines Corporation Apparatus and method for template instantiation with a cross compiler
US8091071B2 (en) * 2006-08-21 2012-01-03 Sap, Ag Method and system for template-based code generation

Also Published As

Publication number Publication date
US20150186122A1 (en) 2015-07-02
US9858055B2 (en) 2018-01-02
US20110078671A1 (en) 2011-03-31
US20160321047A1 (en) 2016-11-03
US9436448B2 (en) 2016-09-06
US8904370B2 (en) 2014-12-02

Similar Documents

Publication Publication Date Title
EP3757761B1 (en) Methods and apparatus for intentional programming for heterogeneous systems
US20070061794A1 (en) Method and apparatus for classpath optimization in a Java runtime environment
US8959646B2 (en) Automated detection and validation of sanitizers
US8910180B2 (en) Interdependent task management by executing tasks based on the “for all” task attributes and existence of semaphore in a task dependency chain
US9021455B2 (en) Packed data objects
CA2759516A1 (en) Serialization of pre-initialized objects
US9858055B2 (en) Optimization of meta-template instantiations
CA2684348A1 (en) Algorithm complexity identification
CA2684441C (en) May-constant propagation
Vilk et al. BLeak: automatically debugging memory leaks in web applications
EP2181387A1 (en) A programming environment with support for handle and non-handle user-created classes
US9250936B2 (en) Enhanced array class
US20160147559A1 (en) Modification of context saving functions
US10649797B2 (en) Online method handle deduplication
EP4089527B1 (en) Deterministic memory allocation for real-time applications
US11442712B2 (en) Leveraging unspecified order of evaluation for compiler-based program optimization
US20130111329A1 (en) Hinting system at user interface design time
CA2687672A1 (en) Intelligent call graph generation
US20220414101A1 (en) Shifting left database degradation detection
US20240111518A1 (en) Embedding code from modules across versioning boundaries
CA2684353A1 (en) Identifying implicit services links using service usage information
US9152535B2 (en) Programmatic identification of root method
CN114385279A (en) Subprocess management method, device, equipment and medium
STARYNKEVITCH documentation of the BISMON static source code analyzer.

Legal Events

Date Code Title Description
EEER Examination request
FZDE Discontinued
FZDE Discontinued

Effective date: 20120229