# 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