Can anyone point me to a good definition of the term "lowering" in the context of compilers?
From what I can tell, it is the translation of a higher-level operation into an equivalent combination of lower-level operations, but I'm not really sure, and I can't find one after a few minutes of searching on Google. (There are a few usages of "lowering" e.g. in GCC or LLVM but no references to a definition.)
One semantic technique that is obvious in hindsight (but took Andrei Alexandrescu to point out to me) is called "lowering." It consists of, internally, rewriting more complex semantic constructs in terms of simpler ones. For example, while loops and foreach loops can be rewritten in terms of for loops.
In a lot of programming languages, there is an interesting stage that might take place (which happens in C# for example), such as code lowering, which means rewriting your high-level code in a lower level code in the same programming language (think of it as the opposite of syntax sugar).
A compiler is a special program that translates a programming language's source code into machine code, bytecode or another programming language. The source code is typically written in a high-level, human-readable language such as Java or C++.
In computer science, a compiler-compiler or compiler generator is a programming tool that creates a parser, interpreter, or compiler from some form of formal description of a programming language and machine. The most common type of compiler-compiler is more precisely called a parser generator.
Dr. Dobbs just published an article by Walter Bright (of dlang fame), where he mentions the term:
Lowering
One semantic technique that is obvious in hindsight (but took Andrei Alexandrescu to point out to me) is called "lowering." It consists of, internally, rewriting more complex semantic constructs in terms of simpler ones. For example,
while
loops andforeach
loops can be rewritten in terms offor
loops. Then, the rest of the code only has to deal withfor
loops. This turned out to uncover a couple of latent bugs in how while loops were implemented in D, and so was a nice win. It's also used to rewritescope guard
statements in terms oftry-finally
statements, etc. Every case where this can be found in the semantic processing will be win for the implementation.If it turns out that there are some special-case rules in the language that prevent this "lowering" rewriting, it might be a good idea to go back and revisit the language design.
Any time you can find commonality in the handling of semantic constructs, it's an opportunity to reduce implementation effort and bugs.
The Dragon Book doesn't use the term. Kennedy+Allen's Optimizing Compilers for Modern Architectures A Dependence-based Approach doesn't use the term. Steve Muchnick's Advanced Compiler Design and Implementation doesn't use the term.
Engineering A Compiler uses the term but doesn't define it. Bob Morgan's Building an Optimizing Compiler (1998) uses the term a lot and defines it.
Lowering : The instructions are lowered so that each operation in the flow graph represents a single instruction in the target machine.
It is a more general term and there is no single definition. My own understand is that a compiler lowers an operation from a higher abstraction layer to a lower, for example, in LLVM lowering from MachineInstr to MCInst.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With