Compiler programming is a complex topic that requires a lot of expertise even for experienced software engineers.
NI LabVIEW software is a multi-disciplinary graphical programming environment that incorporates concepts including data flow, object-oriented, and event-driven programming. LabVIEW is also multi-platform and works well with a variety of operating systems (OSs), chipsets, embedded devices, and field programmable gate arrays (FPGAs). The LabVIEW compiler is a sophisticated system that has evolved dramatically over the past 20 years. Explore the NI LabVIEW compiler process and recent compiler innovations.
LabVIEW Compiler Process
The first step in compiling a VI is to expand the class, which is responsible for resolving implicit classes into types suitable for terminal output and checking for syntax errors. After class expansion, the VI is converted from the edit model to a dataflow intermediate representation (DFIR) graph that can be used by the compiler. The compiler performs several transformations, such as dead code removal, optimizations, and preparation for code generation during the decomposition of the DFIR graph. The DFIR is then converted into a low-level virtual machine (LLVM) intermediate representation (IR), and a series of scans are run on the IR to facilitate further optimization and throttling - ultimately - into machine code.
DFIR provides a high-level intermediate representation
DFIR is a hierarchical, block diagram code, graph-based IR. Similar to G-code, DFIR consists of many nodes with endpoints that can be connected to other endpoints. Some nodes, such as block diagrams, contain graphs, which can in turn contain other nodes.
Figure 1 shows the initial DFIR for a simple VI. When LabVIEW first creates a DFIR for a VI, it is a direct translation of the G-code, and the nodes in the DFIR graph have a one-to-one correspondence like the nodes in the G-code. As the compiler executes, DFIR nodes may be moved, partially separated, or added, yet the compiler will still preserve the original features, such as the inherent parallelism of the LabVIEW code.
Figure 1. Viewing the initial DFIR graph of a simple VI
DFIR provides two significant advantages to the LabVIEW compiler:
1. DFIR separates the editor from the compiler representation - Before DFIR, LabVIEW had a single VI representation that was shared by the editor and compiler. This prevented the compiler from modifying the representation during compilation and made it difficult to introduce compiler optimizations. DFIR introduces a series of optimizations and decompositions that can greatly improve the performance of LabVIEW code, requiring only that the block diagram nodes and wires be disconnected and moved.
2. DFIR as a common connection point between the front-end and back-end of multiple compilers - Today, LabVIEW can handle many distinct tasks. Similarly, LabVIEW also provides users with multiple algorithmic modes, such as LabVIEW MathScript, C integration, simulation diagrams, and statecharts. DFIR provides a common IR that is generated by the front-end and used by the back-end, making it easier to reuse different combinations.
DFIR decomposition and optimization
Once in the DFIR, the VI runs a series of decomposition transformations to reduce or normalize the DFIR graph. After the DFIR graph is fully decomposed, the DFIR optimization pass begins. There are more than 30 decompositions and optimizations that can improve the performance of LabVIEW code. Take a close look at the simple VI shown in Figures 2 and 3, which is called the Trim Whitespace VI (Trim Whitespace.vi) from vi.lib.
Figure 2. This is the VI before any DFIR decomposition.
Figure 3. The above is the definition of the Trim Whitespace.vi structure diagram
First, Trim Whitespace.vi is inlined into the calling VI, as shown in Figure 4. Now, the unreachable code and dead code removal operations can simplify the code. The first case structure will always execute the same branch because the input is a constant value. Therefore, the remaining branches can be moved along with the entire second case structure because they are never executed. Loop invariant code motion moves the Match Pattern primitive out of the loop box, ensuring that it is only executed once, as shown in Figure 5.
Figure 4. The subVI is inlined into the calling routine, resulting in a DFIR graph equivalent to this G-code.
Figure 5. DFIR graph generated by an optimized execution [page]
DFIR backend transformation
After the DFIR graph is decomposed and optimized, the back-end transforms are executed. These transforms evaluate and annotate the DFIR graph in preparation for the final reduction to LLVM IR. The clumping routine is responsible for grouping nodes into clusters that can be run in parallel. The substitution routine identifies when allocated data can be reused and when a copy must be made. After the substitution routine runs, the allocator reserves the memory space required for the VI to execute. Finally, the code generator is responsible for converting the DFIR graph into executable machine instructions for the target processor.
LLVM provides a low-level intermediate representation
LLVM is a general-purpose, high-performance, open-source framework originally invented as a research project at Illinois State University. LLVM is widely used in academic research and industry because of its flexibility, simple API, and lack of licensing restrictions. In LabVIEW 2010, the LabVIEW code generator uses LLVM to generate target machine code. After creating the code stream from the DFIR graph, LabVIEW visits each instruction and creates an equivalent LLVM representation. The software activates various optimization passes, and finally, the LLVM just-in-time (JIT) framework creates executable machine instructions in memory. LabVIEW can now use LLVM to perform instruction synthesis, jump threading, scalar replacement of aggregates, conditional expansion, tail call elimination, loop invariant code removal, dead code elimination, and loop unrolling.
DFIR works with LLVM
DFIR is a high-level IR with parallelism, while LLVM is a low-level IR with awareness of the characteristics of the target machine. The two work together to optimize the LabVIEW code written by developers for the processor architecture so that they can be executed on the processor.
– Chris Wood
Chris Wood is a sensor software engineer working in LabVIEW at National Instruments. He holds a bachelor's degree in computer engineering from Texas A&M University.
– Craig Smith
Craig Smith is a principal software engineer at National Instruments. He holds bachelor's and master's degrees in computer science from Texas A&M University.
Previous article:Design of Network Virtual Laboratory System Based on Virtual Instrument LabVIEW
Next article:Design of Engine Fuel Consumption Test System Based on LabVIEW
Recommended ReadingLatest update time:2024-11-17 04:33
- Popular Resources
- Popular amplifiers
- Modern Compiler Principles C Language Description (Ampel)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Arduino Nano collects temperature and humidity data through LabVIEW and DHT11
- Modern Testing Technology and System Integration (Liu Junhua)
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Tencent employees angrily criticized management for high-intensity overtime work, netizens: role models of our generation
- When using STM32 debugging, a hardware error occurs
- What problems have you encountered recently when using the forum? Feel free to comment!
- Intelligent LED lighting solution based on sensor and MCU
- What are the uses and characteristics of common pulse circuits?
- MSP430F5438a uses BSL downloader to download program
- [RISC-V MCU CH32V103 Review] PWM Adjustment of LED Lights
- 【mpy】The SD/MMC bus can be configured to 1 or 4 bits
- The microcontroller uses a dip switch to set the address
- 5G-specific terminology--it's technology