Skip to content

Instantly share code, notes, and snippets.

View gopi487krishna's full-sized avatar
🐧

Gopi Krishna Menon gopi487krishna

🐧
View GitHub Profile
@gopi487krishna
gopi487krishna / .Adding-Attributes-to-LLVM.md
Created September 28, 2022 13:21 — forked from colematt/.Adding-Attributes-to-LLVM.md
[Adding Attributes to LLVM] #llvm

Introduction

This post describes how to add a custom attribute to LLVM and Clang. Why would you want to do such a thing?

  • You have semantic information of which the front-end is aware, but the back-end discards in the Intermediate Representation (IR), and an existing attribute can't be used to retain this information. Adding the attribute using the front-end analysis preserves the information into the back-end generated IR.
  • You've considered using the GCC/LLVM annotate attribute to hold arbitrary strings, but you also need to add a parameter (or more!) to that annotation.

The Clang Internals Manual discusses how to do this, but not with the detail you might like to see. Its description is high-level, and only lists one file that needs to be modified. Tracking down all of the other files that must be changed is left as a frustrating exercise to the reader.

Conventions used i