Source Code Generation via Intermediate Representation Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional methods for generating source code from block diagrams often result in inefficient code due to excessive buffer variables, particularly when dealing with parallel control flow branches and multi-component variables, leading to increased stack usage and runtime.

Innovation Solution

A method that transforms a block diagram into an intermediate representation, optimizes it by detecting and reproducing operations across parallel control flow branches based on a cost criterion, and translates the optimized representation into source code, thereby reducing stack usage and runtime.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Quantity of substance

If conventional code generation is used from block diagrams, then source code can be generated, but excessive buffer variables are created leading to increased stack usage

Engineering Contradiction:
Improvenumber of buffer variablesVSAvoidstack usage
Core Design Contradiction:
Quantity of substanceVSDevice complexity

Solution Approach 1:

The patent extracts and eliminates unnecessary buffer variables from the code generation process. By analyzing the block diagram structure and data flow, the system identifies and removes redundant buffer variables that are created in conventional approaches, thereby reducing stack usage while maintaining functional correctness.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent changes the parameters of variable usage by distinguishing between necessary and unnecessary buffer variables. Through static analysis and optimization passes, the system transforms the code to minimize buffer variable creation, changing the parameter count of variables that need to be allocated on the stack.

Inventive Principle:
Principle #35Parameter changes

2Productivity

If buffer variables are used in parallel control flow branches, then code can be generated, but runtime is lengthened due to copying operations

Engineering Contradiction:
Improveexecution speedVSAvoidruntime
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent removes unnecessary copying operations from parallel control flow branches by eliminating redundant buffer variables. Through optimization analysis, the system identifies copying operations that can be removed and replaces them with direct variable usage, thereby reducing runtime overhead.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent performs preliminary optimization analysis during the code generation phase to identify and eliminate future copying operations. By analyzing the control flow structure in advance, the system prepares optimized code that avoids unnecessary copying during execution, improving runtime performance.

Inventive Principle:
Principle #10Preliminary action

3Adaptability or versatility

If multi-component variables are used in parallel branches, then functionality is maintained, but stack usage increases significantly

Engineering Contradiction:
Improvefunctional correctnessVSAvoidstack usage
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent segments multi-component variables into smaller components only when necessary for specific operations. By analyzing which components are actually needed in each parallel branch, the system creates localized variable structures that reduce overall stack usage while maintaining the required functionality of multi-component data structures.

Inventive Principle:
Principle #1Segmentation

4Device complexity

If conventional optimization is applied, then some code size reduction is achieved, but code remains inefficient due to parallel control flow buffer variables

Engineering Contradiction:
Improvecode sizeVSAvoidcode efficiency
Core Design Contradiction:
Device complexityVSProductivity

Solution Approach 1:

The patent implements a feedback mechanism through multiple optimization passes that analyze the intermediate representation of the block diagram. The system continuously refines the generated code by detecting patterns in parallel control flow and applying targeted optimizations, using feedback from each analysis pass to improve subsequent optimization decisions.

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The patent combines multiple optimization techniques into a composite optimization process. By integrating buffer variable elimination, copying operation removal, and conventional optimizations into a unified multi-pass system, the approach achieves superior code efficiency that addresses both code size and execution performance simultaneously.

Inventive Principle:
Principle #40Composite materials

Data Source

PatentUS20250165232A1Method for generating source code
Publication Date: 2025.05.22 DSPACE SE & CO KG
  • US20250165232A1 patent drawing
  • US20250165232A1 patent drawing
  • US20250165232A1 patent drawing

AI summary

A method for generating source code includes: transforming, by a computing device, a block diagram into an intermediate representation; successively optimizing, by the computing device, the intermediate representation; and translating, by the computing device, the optimized intermediate representation into source code. Transforming a block comprises creating a reference to a block output variable. Creating the reference to the block output comprises: detecting at least two parallel control flow branches which read or write a variable; identifying an operation that accesses the variable; checking whether a cost criterion is satisfied; and reproducing the operation in the at least two parallel control flow branches based on the cost criterion being satisfied. Reproducing the operation comprises shifting the operation from an original position to positions where the variable is read or written.