Skip to content

Advanced IR Generation and IT Certification Exams

  • Contact Us
Close Menu

Understanding the need for additional metadata – Advanced IR Generation-1

December 27, 2022December 27, 2022| Donna martinUnderstanding the need for additional metadata – Advanced IR Generation-1| 0 Comment| 03:36

Categories :
  • Adding debug metadata
  • Adding line numbers
  • Catching an exception
  • Exams of IT
  • ITCertification Exams

To demonstrate the problem, let’s look at the following function:
void doSomething(int *p, float *q) {
  *p = 42;
  *q = 3.1425;
}

The optimizer cannot decide if the pointers, p and q, point to the same memory cell or not. During optimization, an important analysis can be performed called alias analysis. If p and q point to the same memory cell, then they are aliases. Moreover, if the optimizer can prove that both pointers never alias each other, this enables additional optimization opportunities. For example, in the doSomething() function, the stores can be reordered without altering the result in this case.

In addition, it depends on the definition of the source language if a variable of one type can be an alias of another variable of a different type. Please note that languages may also contain expressions that break the type-based alias assumption – for example, type casts between unrelated types.

The solution chosen by the LLVM developers is to add metadata to the load and store instructions. The added metadata serves two purposes:

  • First, it defines the type hierarchy based on which type may alias another type
  • Second, it describes the memory access in a load or store instruction

Let’s have a look at the type hierarchy in C. Each type of hierarchy starts with a root node, either named or anonymous. LLVM assumes that root nodes with the same name describe the same type of hierarchy. You can use different type hierarchies in the same LLVM modules, and LLVM makes the safe assumption that these types may alias. Beneath the root node, there are the nodes for scalar types. Nodes for aggregate types are not attached to the root node, but they refer to scalar types and other aggregate types. Clang defines the hierarchy for C as follows:

  • The root node is called Simple C/C++ TBAA.
  • Beneath the root node is the node for the char types. This is a special type in C because all pointers can be converted into a pointer to char.
  • Beneath the char node are the nodes for the other scalar types and a type for all pointers, called any pointer.

In addition to this, aggregate types are defined as a sequence of member types and offsets.

These metadata definitions are used in access tags attached to the load and store instructions. An access tag is made up of three parts: a base type, an access type, and an offset. Depending on the base type, there are two possible ways the access tag describes memory access:

  1. If the base type is an aggregate type, then the access tag describes the memory access of a struct member with the necessary access type and is located at the given offset.
  2. If the base type is a scalar type, then the access type must be the same as the base type and the offset must be 0.

Post navigation

Previous page Integrating the exception handling code into the application – Advanced IR Generation
Next page Understanding the need for additional metadata – Advanced IR Generation-2

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Post

The LLVM pass manager – Optimizing IR

May 13, 2024May 13, 2024 Donna martinThe LLVM pass manager – Optimizing IR

The LLVM core libraries optimize the IR that your compiler creates and turn it into [...]

Read MoreRead More

Adding debug metadata – Advanced IR Generation-2

July 6, 2023July 6, 2023 Donna martinAdding debug metadata – Advanced IR Generation-2

The file is a module in tinylang, which makes it the compilation unit for LLVM. [...]

Read MoreRead More

Extending single inheritance with interfaces – IR Generation for High-Level Language Constructs

November 8, 2021November 8, 2021 Donna martinExtending single inheritance with interfaces – IR Generation for High-Level Language Constructs

Languages such as Java support interfaces. An interface is a collection of abstract methods, comparable [...]

Read MoreRead More

Search

Dropdown Categories

Archives

  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • December 2021
  • November 2021

Meta

  • Log in

Tag Cloud

Back to Top

Cookie Policy | Terms | Privacy | About Us | © Sherrieland