# New-in-Llvm-2.7

Published articles for New-in-Llvm-2.7.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## The Glasgow Haskell Compiler and LLVM

DevFeed: [The Glasgow Haskell Compiler and LLVM](<https://devfeed.tech/articles/the-glasgow-haskell-compiler-and-llvm-42851.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.html>)

Author: David Terei

Published: 2010-05-17T21:19:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [x86](<https://devfeed.tech/topics/x86.md>)

Tags: [code-generator](<https://devfeed.tech/tags/code-generator.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [ghc](<https://devfeed.tech/tags/ghc.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [linux](<https://devfeed.tech/tags/linux.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvm-users](<https://devfeed.tech/tags/llvm-users.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [x86](<https://devfeed.tech/tags/x86.md>)

### AI overview

This article describes the LLVM backend for the Glasgow Haskell Compiler, including its design, current Linux x86 support, existing compiler backends, and expected maintenance and optimization benefits.

### Source excerpt

If you read the LLVM 2.7 release notes carefully you would have noticed that one of the new external users is the Glasgow Haskell Compiler (GHC). As the author of the LLVM backend for GHC, I have been invited to write a post detailing the design of the backend and my experiences with using LLVM. This is that post :). I began work on the backend around July last year, undertaking it as part of an honours thesis for my bachelor of Computer Science. Currently the backend is quite stable and capable on Linux x86, able to bootstrap GHC itself. Other platforms haven't received any attention yet. What is GHC and Haskell GHC is a compiler for Haskell, a standardized, lazy, functional programming language. Haskell supports features such as static typing with type inference, lazy evaluation, pattern matching, list comprehension, type classes and type polymorphism. GHC is the most popular Haskell compiler, it compiles Haskell to native code and is supported of X86, PowerPC and SPARC. Existing pipelineBefore the LLVM backend was added, GHC already supported two backends, a C code generator and a native code generator (NCG). The C code generator was the first backend implemented and it works pretty well but is slow and fragile due to its use of many GCC specific extensions and need to post processes the assembly code produced by GCC to implement optimisations which aren't possible to do in the C code. The native code generator was started later to avoid these problems. It is around 2-3x quicker than the C backend and generally reduces the runtime of a Haskell program by around 5%. GHC developers are hoping to depreciate the C backend in the next major release. Why an LLVM backend? Offload work: Building a high performance compiler backend is a huge amount of work, LLVM for example was started around 10 years ago. Going forward, the LLVM backend should be a lot less work to maintain and extend than either the C backend or NCG. It will also benefit from any future improvements to

## Extensible Metadata in LLVM IR

DevFeed: [Extensible Metadata in LLVM IR](<https://devfeed.tech/articles/extensible-metadata-in-llvm-ir-42847.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html>)

Author: Chris Lattner

Published: 2010-04-14T00:23:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [C](<https://devfeed.tech/topics/c.md>), [side channel](<https://devfeed.tech/topics/side-channel.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [channel](<https://devfeed.tech/tags/channel.md>), [code-generator](<https://devfeed.tech/tags/code-generator.md>), [debug](<https://devfeed.tech/tags/debug.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvm-ir](<https://devfeed.tech/tags/llvm-ir.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [optimization](<https://devfeed.tech/tags/optimization.md>)

### AI overview

This post explains extensible metadata in LLVM IR, including its use for language-specific optimization, custom code generation, link-time optimization, and improved debugging information. It also describes how LLVM 2.6 represented debug metadata and the limitations of that approach.

### Source excerpt

A common request by front-end authors is to be able to add some sort of metadata to LLVM IR. This metadata could be used to influence language-specific optimization passes (for example, Type Based Alias Analysis in C), tag information for a custom code generator, or pass through information to link time optimization. LLVM 2.7 provides first-class support for this, and has switched debug information over to use it (improving debug info!). While the details of this feature can be found in the LLVM Language Reference manual, sometimes it is hard to distill the big picture from the low-level details. This post tries to fill the gap by explaining some history, motivation and example use cases for this new LLVM 2.7 feature. This post was written by Devang Patel and myself. Before we dive into how metadata works, it is useful to describe how debug information was represented in LLVM 2.6 and earlier: Debug Information in LLVM 2.6 Debugging information communicates source location information, type information and variable information to the debugger. This information is not used during the execution of program and does not result in executable code in the object file, but the code generator uses it to produce DWARF information. In this way, debug information is a sort of side channel from the front-end to the DWARF emitter in the code generator. For lack of a better mechanism, in LLVM 2.6 and earlier, debugging information is encoded using global variables tagged with a special "llvm.metadata" section. For example, we would generate something like this to describe C code like "int my_data;": @my_data = common global i32 0, align 4 @llvm.dbg.global_variable = internal constant %llvm.dbg.global_variable.type { i32 458804, {}* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.global_variables to { }*), {}* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([8 x i8]* @.str4, i32 0, i32 0), i8* getelementptr ([8 x i8]* @.str4, i32 0, i32 0), i8* nu

## The x86 Disassembler

DevFeed: [The x86 Disassembler](<https://devfeed.tech/articles/the-x86-disassembler-42842.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/01/x86-disassembler.html>)

Author: Spyffe

Published: 2010-01-06T13:34:00Z

Content type: tutorial

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [x86](<https://devfeed.tech/topics/x86.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [gdb](<https://devfeed.tech/topics/gdb.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [architecture](<https://devfeed.tech/tags/architecture.md>), [binary-analysis](<https://devfeed.tech/tags/binary-analysis.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [debugger](<https://devfeed.tech/tags/debugger.md>), [gdb](<https://devfeed.tech/tags/gdb.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [mc](<https://devfeed.tech/tags/mc.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [x86](<https://devfeed.tech/tags/x86.md>)

### AI overview

This technical article explains LLVM's x86 disassembler, including why disassemblers matter for binary analysis and debugging, the performance and memory properties they should have, and how LLVM MC represents and decodes instructions.

### Source excerpt

Disassemblers make binary analysis work. With a reliable disassembler, you can solve high-level problems like tracing back through a program's call stack or analyzing sample-based profiles to low-level problems like figuring out how your compiler unrolled a tight floating-point loop or what advantages declaring a variable const actually had at the other end of the optimization chain. A reliable disassembler, which takes sequences of bytes and prints human-readable instruction mnemonics, is a crucial part of any development platform. You're about to go on a whirlwind tour of the LLVM disassembler: why one should exist, what's great about this one, and how you can use it. The case for an LLVM-based disassemblerDisassemblers are all over the place. A disassembler you may well be familiar with is the disassembler from GNU gdb (source). In fact, any debugger needs one: Sun mdb has a disassembler too (source). Some specialized applications like Dtrace need disassemblers as well (source). So because this is well-traveled ground, there are several common properties you should expect from a disassembler: A large library can contain hundreds of thousands of instructions, so disassembly must be fast. A disassembler with a large memory footprint can steal memory and cache from analysis algorithms that need them more, so its code and data should be compact. Because disassemblers are used in a variety of applications, they should provide information about instructions in a generic, preferably even architecture-independent form. For the benefit of future code maintainers, disassemblers should be as table-driven as possible. Enter the LLVM MC architecture. In MC, instructions are represented using the architecture-independent MCInst class (include/llvm/MC/MCInst.h). The translation between MC instructions and machine code is specified by pre-existing TableGen tables (lib/Target/X86/X86.td for x86 platforms). Writing a disassembler inside the MC framework makes sense because it solv

## Address of Label and Indirect Branches in LLVM IR

DevFeed: [Address of Label and Indirect Branches in LLVM IR](<https://devfeed.tech/articles/address-of-label-and-indirect-branches-in-llvm-ir-42841.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.html>)

Author: Chris Lattner

Published: 2010-01-03T00:11:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [gcc](<https://devfeed.tech/topics/gcc.md>), [C](<https://devfeed.tech/topics/c.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [optimization](<https://devfeed.tech/tags/optimization.md>)

### AI overview

This post explains LLVM IR support introduced in LLVM 2.7 for taking the address of a label and jumping to it later. It compares the feature with GCC's "Label as Values" extension and describes how earlier LLVM versions lowered indirect gotos using integer IDs and switch instructions.

### Source excerpt

The GCC Compiler supports a useful "Label as Values" extension, which allows code to take the address of a label and then later do an unconditional branch to an address specified as a void*. This extension is particularly useful for building efficient interpreters. LLVM has long supported this extension by lowering it to a "correct" but extremely inefficient form. New in LLVM 2.7 is IR support for taking the address of a label and jumping to it later, which allows implementing this extension much more efficiently. This post describes this new LLVM IR feature and how it works. In this discussion, I limit the scope to only considering "local" jumps. We don't talk about non-local jumps in the GCC extension sense: jumps from a nested function to an outer one. The Address of Label Extension Before I dive into the new feature, I'll describe the GCC C extension along with how LLVM 2.6 and earlier used to compile it. Consider this code (from PR3120): static int fn(Opcodes opcodes) { static const void *codetable[] = { &&RETURN, &&INCREMENT, &&DECREMENT, &&DOUBLE, &&SWAPWORD }; int result = 0; goto *codetable[*(opcodes++)]; RETURN: return result; INCREMENT: result++; goto *codetable[*(opcodes++)]; DECREMENT: result--; goto *codetable[*(opcodes++)]; DOUBLE: result <<= 1; goto *codetable[*(opcodes++)]; SWAPWORD: result = (result << 16) | (result >> 16); goto *codetable[*(opcodes++)]; } As you can see, the code initializes the 'codetable' array with the addresses of 5 labels, and later jumps through a computed pointer. An interesting aspect about this extension is that the only thing you are allowed to do with an address taken label is to jump to it. While it is widely misused for other things (e.g. the BUG macro in the linux kernel, which prints the address of a label on error), you are really really only allowed jump to it. You are not allowed to use it in an inline asm, inspect the value, or do anything else. LLVM 2.6 and Earlier In LLVM 2.6 and earlier, LLVM took full advant

## Advanced Topics in Redundant Load Elimination with a Focus on PHI Translation

DevFeed: [Advanced Topics in Redundant Load Elimination with a Focus on PHI Translation](<https://devfeed.tech/articles/advanced-topics-in-redundant-load-elimination-with-a-focus-on-phi-translation-42835.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2009/12/advanced-topics-in-redundant-load.html>)

Author: Chris Lattner

Published: 2009-12-19T14:45:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [C](<https://devfeed.tech/topics/c.md>), [Code](<https://devfeed.tech/topics/code.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [optimize](<https://devfeed.tech/tags/optimize.md>)

### AI overview

This article explains PHI translation in LLVM's global value numbering and redundant load elimination. It describes why PHI translation is required for correctness and how LLVM 2.7 uses it to analyze predecessor blocks and eliminate redundant loads.

### Source excerpt

In our previous post on GVN we introduced some basics of load elimination. This post describes some advanced topics and focuses on PHI translation: what it is, why it is important, shows some nice things it can do, and describes the implementation in LLVM. What is PHI Translation All About? When performing redundancy elimination on SSA form, PHI translation is required when we are walking through the CFG and the value being analyzed has an operand defined in the block we're walking through. In the case of load elimination, the operand of the value being analyzed is the pointer we're loading from. This means that PHI translation happens when the pointer we're loading is defined in a block. For example, consider this C code: if (...) { *A = 5; P = A; } else { *B = 9; P = B; } use(*P); This compiles into LLVM IR that looks like this: BB1: store i32 5, i32* %A br label %Merge BB2: store i32 9, i32* %B br label %Merge Merge: %P = phi i32* [%A, %BB1], [%B, %BB2] %Y = load i32 *%P ... ... use %Y ... In this example, GVN starts looking at the %Y load to see if it can eliminate it. It scans backwards up the block, looking for other things that provide the value of the memory address at %P. Unlike in the example in the previous post, here we actually find a definition of %P: what do we do? In LLVM 2.6 and before, memory dependence analysis would just give up and act as though the memory had been clobbered, preventing the load from being analyzed further (and eventually being eliminated in this case). New in LLVM 2.7, GVN is able to translate %P into each predecessor. In this case, it sees that %P has the value of %A in %BB1 (and then sees that %A is available there) and that %P has the value of %B in %BB2 (where it is also available). This allows GVN to optimize this example into: BB1: store i32 5, i32* %A br label %Merge BB2: store i32 9, i32* %B br label %Merge Merge: %Y = phi i32 [5, %BB1], [9, %BB2] %P = phi i32* [%A, %BB1], [%B, %BB2] ... ... use %Y ... which eliminates