IP Library Granted Patent US 12,182,553
Granted Patent B2
US 12,182,553 · App. 17/665,830 · Granted Dec 31, 2024

User customizable compiler attributes for code optimization

Inventor: Ulrich Drepper (Grasbrunn, DE)
Assignee: Red Hat, Inc.
G06F8/443
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,182,553
App. No.
17/665,830
Granted
Dec 31, 2024
Kind
B2
Abstract

Disclosed herein is technology to use customized compiler attributes to enhance code optimizations. An example method may include: accessing, by a processing device executing a compiler, a source code comprising a compiler attribute, wherein the compiler attribute is defined by text in the source code; detecting, by the processing device, a call in the source code to a compiler function that processes the compiler attribute, wherein the source code includes logic to process the compiler attribute; executing, by the processing device, the compiler function at compile time, wherein the compiler function uses the logic to process the compiler attribute and generates attribute data; and using, by the compiler, the attribute data to optimize object code generated from the source code.

Claims (40)

1. A method comprising:

accessing, by a processing device executing a compiler, a source code comprising a compiler attribute, wherein the compiler attribute is defined by text in the source code;

detecting, by the processing device, a call in the source code to a first compiler function identified by function name in the source code that assigns a value to the compiler attribute in association with a variable declared in the source code, wherein the source code includes logic to process the compiler attribute;

executing, by the processing device, a second compiler function identified by function name in the source code at compile time to return a function result based on the value of the compiler attribute associated with the variable, wherein the compiler uses the logic to process the compiler attribute and, based on the function result generates an executable code segment that is a different executable code segment than would be generated based on a different value of the compiler attribute.

2. The method of claim 1 , wherein the text in the source code that defines the compiler attribute is provided by an author of the source code and comprises a call to a predefined compiler function and one or more user defined attribute values created by the author, wherein the user defined attribute values comprise at least one of a user defined attribute name or a user defined attribute type.

3. The method of claim 1 , wherein the logic is not included in object code and not evaluated at runtime, and wherein the logic comprises an if statement, a while loop, or a for loop.

4. The method of claim 1 , wherein the logic to process the compiler attribute is provided by an author of the source code and comprises attribute combining logic and attribute testing logic.

5. The method of claim 1 , further comprising:

generating, by the compiler, an intermediate representation that comprises multiple control flows that converge, wherein the multiple control flows each comprise the compiler attribute; and

using, by the compiler, attribute combining logic provided by the author to combine the compiler attributes of the multiple control flows into a combined attribute.

6. The method of claim 1 , further comprising:

detecting, by the compiler, that the compiler attribute defined in the source code is assigned to each of a plurality of descriptor variables;

evaluating, by the compiler, the compiler attributes at a location in the source code, wherein the compiler attributes indicate each of the descriptor variables comprise a target type that is a network socket; and

optimizing, by the compiler, the object code to include a call to a specific function that handles network sockets and to be absent a call to a generic function that handles multiple target types.

7. A system comprising:

a memory; and

a processing device communicably coupled to the memory, the processing device to:

access a source code comprising a compiler attribute, wherein the compiler attribute is defined by text in the source code;

detect a call in the source code to a first compiler function identified by function name in the source code that assigns a value to the compiler attribute in association with a variable declared in the source code, wherein the source code includes logic to process the compiler attribute;

execute a second compiler function identified by function name in the source code at compile time to return a function result based on the value of the compiler attribute associated with the variable, wherein the compiler uses the logic to process the compiler attribute and, based on the function result generates an executable code segment that is a different executable code segment than would be generated based on a different value of the compiler attribute.

8. The system of claim 7 , wherein the text in the source code that defines the compiler attribute is provided by an author of the source code and comprises a call to a predefined compiler function and one or more user defined attribute values created by the author, wherein the user defined attribute values comprise at least one of a user defined attribute name or a user defined attribute type.

9. The system of claim 7 , wherein the logic is not included in object code and not evaluated at runtime, and wherein the logic comprises an if statement, a while loop, or a for loop.

10. The system of claim 7 , wherein the logic to process the compiler attribute is provided by an author of the source code and comprises attribute combining logic and attribute testing logic.

11. The system of claim 7 , wherein the processing device is further to:

generate an intermediate representation that comprises multiple control flows that converge, wherein the multiple control flows each comprise the compiler attribute; and

use attribute combining logic provided by the author to combine the compiler attributes of the multiple control flows into a combined attribute.

12. The system of claim 7 , wherein the processing device is further to:

detect that the compiler attribute defined in the source code is assigned to each of a plurality of descriptor variables;

evaluate the compiler attributes at a location in the source code, wherein the compiler attributes indicate each of the descriptor variables comprise a target type that is a network socket; and

optimize the object code to include a call to a specific function that handles network sockets and to be absent a call to a generic function that handles multiple target types.

13. A non-transitory machine-readable storage medium storing instructions which, when executed, cause a processing device to perform operations comprising:

accessing a source code comprising a compiler attribute, wherein the compiler attribute is defined by text in the source code;

detecting a call in the source code to a first compiler function identified by function name in the source code that assigns a value to the compiler attribute in association with a variable declared in the source code, wherein the source code includes logic to process the compiler attribute;

executing a second compiler function identified by function name in the source code at compile time to return a function result based on the value of the compiler attribute associated with the variable, wherein the compiler uses the logic to process the compiler attribute and, based on the function result generates an executable code segment that is a different executable code segment than would be generated based on a different value of the compiler attribute.

14. The non-transitory machine-readable storage medium of claim 13 , wherein the text in the source code that defines the compiler attribute is provided by an author of the source code and comprises a call to a predefined compiler function and one or more user defined attribute values created by the author, wherein the user defined attribute values comprise at least one of a user defined attribute name or a user defined attribute type.

15. The non-transitory machine-readable storage medium of claim 13 , wherein the logic statement is not included in object code and not evaluated at runtime, and wherein the logic comprises an if statement, a while loop, or a for loop.

16. The non-transitory machine-readable storage medium of claim 13 , wherein the logic to process the compiler attribute is provided by an author of the source code and comprises attribute combining logic and attribute testing logic.

17. The non-transitory machine-readable storage medium of claim 13 , wherein the operations further comprise:

generating an intermediate representation that comprises multiple control flows that converge, wherein the multiple control flows each comprise the compiler attribute; and

using attribute combining logic provided by the author to combine the compiler attributes of the multiple control flows into a combined attribute.

Assignments (2)
CHANGE OF NAME Recorded Mar 3, 2026
From: RED HAT, INC.
To: RED HAT, LLC
Reel/Frame 074913/0759 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Feb 8, 2022
From: DREPPER, ULRICH
To: RED HAT, INC.
Reel/Frame 058930/0344 →
Continuity (1)
Related Publication 20230251838A1 · Aug 10, 2023