Compiler Home Memory Allocation for Stack Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing compiler technologies face challenges in efficiently managing stack space for function calls, particularly when dealing with variadic functions and legacy ABIs, leading to increased memory usage and inefficiencies in parameter passing, especially in environments with restricted stack space such as Linux kernels or heavily multi-threaded applications.

Innovation Solution

A method is introduced where a compiler determines whether a caller allocates memory for a parameter passed to a callee, and inserts instructions to allocate a home memory location accordingly, optimizing stack frame allocation by only allocating a register save area when necessary, and using natural registers or memory locations for parameter passing based on data types.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Quantity of substance

If a fixed-size stack frame is allocated for all function calls, then stack space availability is improved, but memory usage efficiency deteriorates

Engineering Contradiction:
Improvestack space availabilityVSAvoidmemory usage efficiency
Core Design Contradiction:
Quantity of substanceVSLoss of energy

Solution Approach 1:

The patent implements dynamic stack frame allocation where the stack frame size is determined at runtime based on the actual number and types of parameters being passed. The compiler generates code that checks whether parameters are passed in registers or memory, and allocates stack frame space only when necessary. This dynamic approach allows the stack frame to adapt its size to the specific function call requirements, improving memory efficiency while ensuring sufficient stack space is always available.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent changes the parameter allocation strategy from a static fixed-size approach to a dynamic parameter-based approach. The stack frame allocation is adjusted based on parameter characteristics (whether they are passed in registers or memory). This parameter-driven allocation optimizes memory usage by allocating only the necessary stack space for each specific function call scenario.

Inventive Principle:
Principle #35Parameter changes

2Reliability

If stack frame is always allocated for parameter storage, then parameter passing reliability is improved, but stack space consumption increases

Engineering Contradiction:
Improveparameter passing reliabilityVSAvoidstack space consumption
Core Design Contradiction:
ReliabilityVSVolume of stationary object

Solution Approach 1:

The patent implements a self-service mechanism where the callee function automatically determines whether it needs to allocate stack frame space based on how parameters are passed to it. The generated code includes logic that checks parameter passing methods and allocates stack space only when the callee needs to access parameters in memory. This self-determining approach ensures reliable parameter passing while minimizing unnecessary stack space consumption.

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The patent makes stack frame allocation dynamic rather than static. The allocation decision is made at runtime based on the actual parameter passing scenario. When parameters are passed in registers, no stack frame is allocated. When parameters are passed in memory, the stack frame is allocated appropriately. This dynamic behavior maintains parameter passing reliability while optimizing stack space consumption.

Inventive Principle:
Principle #15Dynamics

3Adaptability or versatility

If home memory location is always provided for register parameters, then parameter access flexibility is improved, but memory allocation overhead increases

Engineering Contradiction:
Improveparameter access flexibilityVSAvoidmemory allocation overhead
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent applies preliminary action by pre-allocating home memory locations for register parameters only when the callee indicates it needs them. The compiler analyzes the callee's requirements and generates appropriate prologue code to allocate home memory locations in advance, but only for parameters that will actually be accessed in memory. This preliminary allocation provides parameter access flexibility when needed while avoiding unnecessary memory allocation overhead.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent changes the home memory location allocation from a universal default to a selective parameter-based approach. The allocation behavior changes based on the parameter's passing method and the callee's access requirements. Home memory locations are allocated for register parameters only when necessary, reducing memory allocation overhead while maintaining parameter access flexibility through conditional allocation.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS9760282B2Assigning home memory addresses to function call parameters
Publication Date: 2017.09.12 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US9760282B2 patent drawing
  • US9760282B2 patent drawing
  • US9760282B2 patent drawing

AI summary

Embodiments are directed to assigning a home memory location for a function call parameter. A method may include determining whether a caller is configured to allocate a memory location for a parameter passed to a callee. The caller is a module that includes a function call to the callee and the callee is a function. The method may include inserting instructions in the callee to allocate a home memory location for the parameter in response to determining that the caller is not configured to allocate a memory location for the parameter. In addition, the method may include inserting instructions in the callee to set the memory location as a home location for the parameter in response to determining that the caller is configured to allocate a memory location for the parameter.