# GSoC 2024: ABI Lowering in ClangIR

DevFeed: [GSoC 2024: ABI Lowering in ClangIR](<https://devfeed.tech/articles/gsoc-2024-abi-lowering-in-clangir-43108.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2024-09-07-abi-lowering-in-clangir/>)

Author: Vinicius Espindola

Published: 2024-09-30T00:00:00Z

Content type: article

Language: en

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

Topics: [Compiler](<https://devfeed.tech/topics/compiler.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [mlir](<https://devfeed.tech/topics/mlir.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Code](<https://devfeed.tech/topics/code.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [architecture](<https://devfeed.tech/tags/architecture.md>), [architectures](<https://devfeed.tech/tags/architectures.md>), [ast](<https://devfeed.tech/tags/ast.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [build](<https://devfeed.tech/tags/build.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clangir](<https://devfeed.tech/tags/clangir.md>), [code](<https://devfeed.tech/tags/code.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [codegen](<https://devfeed.tech/tags/codegen.md>), [compile](<https://devfeed.tech/tags/compile.md>), [contribution](<https://devfeed.tech/tags/contribution.md>), [gsoc](<https://devfeed.tech/tags/gsoc.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [pipeline](<https://devfeed.tech/tags/pipeline.md>), [principles](<https://devfeed.tech/tags/principles.md>), [structs](<https://devfeed.tech/tags/structs.md>), [x86-64](<https://devfeed.tech/tags/x86-64.md>)

## AI overview

This article describes a Google Summer of Code project extending ClangIR with target-specific ABI and calling-convention lowering for X86-64 and additional architectures. It covers a modular TargetLowering library, lowering passes, feature guarding, and integration into the main pipeline.

## Source excerpt

ClangIR is an ongoing effort to build a high-level intermediate representation(IR) for C/C++ within the LLVM ecosystem. Its key advantage lies in its abilityto retain more source code information. While ClangIR is making progress, itstill lacks certain features, notably ABI handling. Currently, ClangIR lowersmost functions without accounting for ABI-specific calling convention details. Goals The "Build & Run SingleSource Benchmarks with ClangIR - Part 2" Google Summer ofCode 2024 builds on my contributions from GSoC 2023 by addressing one of themain issues I encountered: target-specific lowering. It focuses on extendingClangIR's code generation capabilities, particularly in ABI-lowering for X86-64.Several tests rely on operations and types (e.g., va_arg calls and complexdata types) that require target-specific information to compile correctly. The concrete steps to achieve this were: Implement foundational infrastructure that can scale to multiplearchitectures while adhering to ClangIR design principles such as CodeGenparity, feature guarding, and AST backreferences. Handle basic calling convention scenarios as a proof of concept tovalidate the foundational infrastructure. Add lowering for a second architecture to further validate theinfrastructure's extensibility to multiple architectures. Unify target-specific ClangIR lowering into the library, as there are afew isolated methods handling target-specific code lowering likecir.va_arg. Integrate calling convention lowering into the main pipeline to ensurefuture contributions and continued development of this infrastructure. Contributions The list of contribution (PRs) can be foundhere. Target Lowering Library The most significant contribution of this project was the development of amodular TargetLowering library.This ensures that target-specific MLIR lowering passes can leverage this sharedlibrary for lowering logic. The library also follows ClangIR's feature guardingprinciples, ensuring that any contributor can refe