[clang] [llvm] [CIR][CUDA][NFC] Add skeleton for NVPTX target lowering (PR #182645)
Ayokunle Amodu via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 21 14:34:57 PST 2026
https://github.com/ayokunle321 updated https://github.com/llvm/llvm-project/pull/182645
>From fd8662a0613e8165b221aacf69535741f0ab0adc Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Fri, 20 Feb 2026 19:35:27 -0700
Subject: [PATCH 1/6] add skeleton for nvptx target lowering
---
.gitignore | 1 +
clang/include/clang/CIR/MissingFeatures.h | 36 +++++++++
.../Transforms/TargetLowering/ABIInfo.cpp | 21 +++++
.../Transforms/TargetLowering/ABIInfo.h | 39 ++++++++++
.../TargetLowering/CIRLowerContext.cpp | 62 +++++++++++++++
.../TargetLowering/CIRLowerContext.h | 77 +++++++++++++++++++
.../Transforms/TargetLowering/CMakeLists.txt | 4 +
.../Transforms/TargetLowering/LowerModule.cpp | 18 ++++-
.../Transforms/TargetLowering/LowerModule.h | 11 ++-
.../Transforms/TargetLowering/LowerTypes.cpp | 24 ++++++
.../Transforms/TargetLowering/LowerTypes.h | 55 +++++++++++++
.../Transforms/TargetLowering/TargetInfo.h | 27 +++++++
.../TargetLowering/TargetLoweringInfo.cpp | 3 +
.../TargetLowering/TargetLoweringInfo.h | 7 ++
.../TargetLowering/Targets/NVPTX.cpp | 39 ++++++++++
15 files changed, 419 insertions(+), 5 deletions(-)
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
diff --git a/.gitignore b/.gitignore
index fa133b2d09834..f24f1599ed0f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@
# Nested build directory
/build*
+/llvm/build-release*
#==============================================================================#
# Explicit files to ignore (only matches one).
diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h
index 97c76df0bb0b9..388bfb81d53fb 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -15,6 +15,40 @@
#ifndef CLANG_CIR_MISSINGFEATURES_H
#define CLANG_CIR_MISSINGFEATURES_H
+constexpr bool cirCConvAssertionMode =
+ true; // Change to `false` to use llvm_unreachable
+
+#define CIR_CCONV_NOTE \
+ " Target lowering is now required. To workaround use " \
+ "-fno-clangir-call-conv-lowering. This flag is going to be removed at some" \
+ " point."
+
+// Special assertion to be used in the target lowering library.
+#define cir_cconv_assert(cond) \
+ do { \
+ if (!(cond)) \
+ llvm::errs() << CIR_CCONV_NOTE << "\n"; \
+ assert((cond)); \
+ } while (0)
+
+// Special version of llvm_unreachable to give more info to the user on how
+// to temporarily disable target lowering.
+#define cir_cconv_unreachable(msg) \
+ do { \
+ llvm_unreachable(msg CIR_CCONV_NOTE); \
+ } while (0)
+
+// Some assertions knowingly generate incorrect code. This macro allows us to
+// switch between using `assert` and `llvm_unreachable` for these cases.
+#define cir_cconv_assert_or_abort(cond, msg) \
+ do { \
+ if (cirCConvAssertionMode) { \
+ assert((cond) && msg CIR_CCONV_NOTE); \
+ } else { \
+ llvm_unreachable(msg CIR_CCONV_NOTE); \
+ } \
+ } while (0)
+
namespace cir {
// As a way to track features that haven't yet been implemented this class
@@ -189,6 +223,8 @@ struct MissingFeatures {
static bool lowerModuleCodeGenOpts() { return false; }
static bool lowerModuleLangOpts() { return false; }
static bool targetLoweringInfo() { return false; }
+ static bool extParamInfo() { return false; }
+ static bool qualifiedTypes() { return false; }
// Extra checks for lowerGetMethod in ItaniumCXXABI
static bool emitCFICheck() { return false; }
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp
new file mode 100644
index 0000000000000..75f0c33410cee
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp
@@ -0,0 +1,21 @@
+//===- ABIInfo.cpp --------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics clang/lib/CodeGen/ABIInfo.cpp. The queries are
+// adapted to operate on the CIR dialect, however.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ABIInfo.h"
+
+namespace cir {
+
+// Pin the vtable to this file.
+ABIInfo::~ABIInfo() = default;
+
+} // namespace cir
\ No newline at end of file
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h
new file mode 100644
index 0000000000000..3b0a40a0c80e4
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h
@@ -0,0 +1,39 @@
+//===----- ABIInfo.h - CIR's ABI information --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics the CodeGen/ABIInfo.h class. The main difference
+// is that this is adapted to operate on the CIR dialect.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_ABIINFO_H
+#define LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_ABIINFO_H
+
+#include "llvm/IR/CallingConv.h"
+
+namespace cir {
+
+// Forward declarations.
+class LowerTypes;
+
+/// Target specific hooks for defining how a type should be passed or returned
+/// from functions.
+/// FIXME(cir): this needs to be merged with clang/lib/CIR/CodeGen/ABIInfo.h
+class ABIInfo {
+protected:
+ LowerTypes <
+ llvm::CallingConv::ID RuntimeCC;
+
+public:
+ ABIInfo(LowerTypes <) : lt(lt), RuntimeCC(llvm::CallingConv::C) {}
+ virtual ~ABIInfo();
+};
+
+} // namespace cir
+
+#endif // LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_ABIINFO_H
\ No newline at end of file
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
new file mode 100644
index 0000000000000..c711c1c07aca0
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
@@ -0,0 +1,62 @@
+//===- CIRLowerContext.cpp ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics clang/lib/AST/ASTContext.cpp. The queries are
+// adapted to operate on the CIR dialect, however.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CIRLowerContext.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/CIR/Dialect/IR/CIRTypes.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "llvm/Support/ErrorHandling.h"
+
+namespace cir {
+
+CIRLowerContext::CIRLowerContext(mlir::ModuleOp module,
+ clang::LangOptions langOpts,
+ clang::CodeGenOptions codeGenOpts)
+ : mlirContext(module.getContext()), langOpts(std::move(langOpts)),
+ codeGenOpts(std::move(codeGenOpts)) {}
+
+CIRLowerContext::~CIRLowerContext() {}
+
+mlir::Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind builtinKind) {
+ mlir::Type ty;
+
+ // NOTE(cir): Clang does more stuff here. Not sure if we need to do the same.
+ cir_cconv_assert(!cir::MissingFeatures::qualifiedTypes());
+ switch (builtinKind) {
+ case clang::BuiltinType::Char_S:
+ ty = IntType::get(getMLIRContext(), 8, true);
+ break;
+ default:
+ cir_cconv_unreachable("NYI");
+ }
+
+ types.push_back(ty);
+ return ty;
+}
+
+void CIRLowerContext::initBuiltinTypes(const clang::TargetInfo &target,
+ const clang::TargetInfo *auxTarget) {
+ cir_cconv_assert((!this->target || this->target == &target) &&
+ "incorrect target reinitialization");
+ this->target = ⌖
+ this->auxTarget = auxTarget;
+
+ // C99 6.2.5p3.
+ if (langOpts.CharIsSigned)
+ charTy = initBuiltinType(clang::BuiltinType::Char_S);
+ else
+ cir_cconv_unreachable("NYI");
+}
+
+} // namespace cir
\ No newline at end of file
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
new file mode 100644
index 0000000000000..9ef0e617eaa08
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
@@ -0,0 +1,77 @@
+//===- CIRLowerContext.h - Context to lower CIR -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Partially mimics AST/ASTContext.h. The main difference is that this is
+// adapted to operate on the CIR dialect.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRLowerContext_H
+#define LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRLowerContext_H
+
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/Types.h"
+#include "mlir/Interfaces/DataLayoutInterfaces.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+
+namespace cir {
+
+// FIXME(cir): Most of this is type-related information that should already be
+// embedded into CIR. Maybe we can move this to an MLIR interface.
+class CIRLowerContext : public llvm::RefCountedBase<CIRLowerContext> {
+
+private:
+ mutable llvm::SmallVector<mlir::Type, 0> types;
+
+ const clang::TargetInfo *target = nullptr;
+ const clang::TargetInfo *auxTarget = nullptr;
+
+ /// MLIR context to be used when creating types.
+ mlir::MLIRContext *mlirContext;
+
+ /// The language options used to create the AST associated with
+ /// this ASTContext object.
+ clang::LangOptions langOpts;
+
+ /// Options for code generation.
+ clang::CodeGenOptions codeGenOpts;
+
+ //===--------------------------------------------------------------------===//
+ // Built-in Types
+ //===--------------------------------------------------------------------===//
+
+ mlir::Type charTy;
+
+public:
+ CIRLowerContext(mlir::ModuleOp module, clang::LangOptions langOpts,
+ clang::CodeGenOptions codeGenOpts);
+ ~CIRLowerContext();
+
+ /// Initialize built-in types.
+ ///
+ /// This routine may only be invoked once for a given ASTContext object.
+ /// It is normally invoked after ASTContext construction.
+ ///
+ /// \param Target The target
+ void initBuiltinTypes(const clang::TargetInfo &target,
+ const clang::TargetInfo *auxTarget = nullptr);
+
+private:
+ mlir::Type initBuiltinType(clang::BuiltinType::Kind builtinKind);
+
+public:
+ mlir::MLIRContext *getMLIRContext() const { return mlirContext; }
+
+};
+
+} // namespace cir
+
+#endif // LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRLowerContext_H
\ No newline at end of file
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
index 92148127424e9..7c94815ce3f26 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
@@ -1,8 +1,12 @@
add_clang_library(MLIRCIRTargetLowering
+ ABIInfo.cpp
CIRCXXABI.cpp
+ CIRLowerContext.cpp
LowerModule.cpp
+ LowerTypes.cpp
LowerItaniumCXXABI.cpp
TargetLoweringInfo.cpp
+ Targets/NVPTX.cpp
DEPENDS
clangBasic
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
index f2398e3105578..674440102acb3 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
@@ -13,6 +13,7 @@
#include "LowerModule.h"
#include "CIRCXXABI.h"
+#include "TargetInfo.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetInfo.h"
@@ -45,15 +46,26 @@ static std::unique_ptr<CIRCXXABI> createCXXABI(LowerModule &lm) {
static std::unique_ptr<TargetLoweringInfo>
createTargetLoweringInfo(LowerModule &lm) {
- assert(!cir::MissingFeatures::targetLoweringInfo());
- return std::make_unique<TargetLoweringInfo>();
+ const clang::TargetInfo &target = lm.getTarget();
+ const llvm::Triple &triple = target.getTriple();
+
+ switch (triple.getArch()) {
+ case llvm::Triple::nvptx:
+ case llvm::Triple::nvptx64:
+ return createNVPTXTargetLoweringInfo(lm);
+
+ default:
+ cir_cconv_unreachable("ABI NYI");
+ }
}
LowerModule::LowerModule(clang::LangOptions langOpts,
clang::CodeGenOptions codeGenOpts,
mlir::ModuleOp &module,
std::unique_ptr<clang::TargetInfo> target)
- : module(module), target(std::move(target)), abi(createCXXABI(*this)) {}
+ : context(module, std::move(langOpts), std::move(codeGenOpts)), module(module), target(std::move(target)), abi(createCXXABI(*this)), types(*this) {
+ context.initBuiltinTypes(*target);
+ }
const TargetLoweringInfo &LowerModule::getTargetLoweringInfo() {
if (!targetLoweringInfo)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.h
index ab3a648683279..f61f397f0bb9a 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.h
@@ -15,6 +15,7 @@
#define CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H
#include "CIRCXXABI.h"
+#include "LowerTypes.h"
#include "TargetLoweringInfo.h"
#include "mlir/IR/BuiltinOps.h"
#include "clang/Basic/CodeGenOptions.h"
@@ -27,11 +28,14 @@
namespace cir {
class LowerModule {
+ CIRLowerContext context;
mlir::ModuleOp module;
const std::unique_ptr<clang::TargetInfo> target;
std::unique_ptr<TargetLoweringInfo> targetLoweringInfo;
std::unique_ptr<CIRCXXABI> abi;
+ LowerTypes types;
+
public:
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts,
mlir::ModuleOp &module,
@@ -43,9 +47,12 @@ class LowerModule {
return target->getCXXABI().getKind();
}
- CIRCXXABI &getCXXABI() const { return *abi; }
- const clang::TargetInfo &getTarget() const { return *target; }
+ CIRLowerContext &getContext() { return context; }
mlir::MLIRContext *getMLIRContext() { return module.getContext(); }
+ mlir::ModuleOp &getModule() { return module; }
+ const clang::TargetInfo &getTarget() const { return *target; }
+ CIRCXXABI &getCXXABI() const { return *abi; }
+ LowerTypes &getTypes() { return types; }
const TargetLoweringInfo &getTargetLoweringInfo();
};
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp
new file mode 100644
index 0000000000000..62382f4e647ef
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp
@@ -0,0 +1,24 @@
+//===--- LowerTypes.cpp - Type translation to target-specific types -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics clang/lib/CodeGen/CodeGenTypes.cpp. The queries
+// are adapted to operate on the CIR dialect, however.
+//
+//===----------------------------------------------------------------------===//
+
+#include "LowerTypes.h"
+#include "LowerModule.h"
+#include "mlir/Support/LLVM.h"
+
+using namespace cir;
+
+LowerTypes::LowerTypes(LowerModule &lm)
+ : lm(lm), context(lm.getContext()), target(lm.getTarget()),
+ CXXABI(lm.getCXXABI()),
+ theABIInfo(lm.getTargetLoweringInfo().getABIInfo()),
+ mlirContext(lm.getMLIRContext()), dataLayout(lm.getModule()) {}
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
new file mode 100644
index 0000000000000..9ce0c7372e35c
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
@@ -0,0 +1,55 @@
+//===--- LowerTypes.cpp - Type lowering for CIR dialect -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics clang/lib/CodeGen/CodeGenTypes.cpp. The queries
+// are adapted to operate on the CIR dialect, however.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERTYPES_H
+#define LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERTYPES_H
+
+#include "ABIInfo.h"
+#include "CIRCXXABI.h"
+#include "CIRLowerContext.h"
+#include "mlir/IR/MLIRContext.h"
+#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
+
+namespace cir {
+
+// Forward declarations.
+class LowerModule;
+
+/// This class organizes lowering to ABI-specific types in CIR.
+class LowerTypes {
+ // FIXME(cir): This abstraction could likely be replaced by a MLIR interface
+ // or direct queries to CIR types. It's here mostly for code parity.
+
+private:
+ LowerModule &lm;
+ CIRLowerContext &context;
+ const clang::TargetInfo ⌖
+ CIRCXXABI &CXXABI;
+
+ // This should not be moved earlier, since its initialization depends on some
+ // of the previous reference members being already initialized
+ const ABIInfo &theABIInfo;
+
+ // Used to build types and other MLIR operations.
+ mlir::MLIRContext *mlirContext;
+
+ cir::CIRDataLayout dataLayout;
+
+public:
+ LowerTypes(LowerModule &lm);
+ ~LowerTypes() = default;
+};
+
+} // namespace cir
+
+#endif // LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERTYPES_H
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
new file mode 100644
index 0000000000000..011efa153c665
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
@@ -0,0 +1,27 @@
+//===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file partially mimics clang/lib/CodeGen/TargetInfo.h. The queries are
+// adapted to operate on the CIR dialect, however.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_TARGETINFO_H
+#define LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_TARGETINFO_H
+
+#include "LowerModule.h"
+#include "TargetLoweringInfo.h"
+
+namespace cir {
+
+std::unique_ptr<TargetLoweringInfo>
+createNVPTXTargetLoweringInfo(LowerModule &cgm);
+
+} // namespace cir
+
+#endif // LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_TARGETINFO_H
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
index 5ecdb8d587552..1abb770b64f9e 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
@@ -15,6 +15,9 @@
namespace cir {
+TargetLoweringInfo::TargetLoweringInfo(std::unique_ptr<ABIInfo> info)
+ : info(std::move(info)) {}
+
TargetLoweringInfo::~TargetLoweringInfo() = default;
cir::SyncScopeKind
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.h
index 760c3b0b7cc5e..4d3844af5d700 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.h
@@ -14,14 +14,21 @@
#ifndef LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_TARGETLOWERINGINFO_H
#define LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_TARGETLOWERINGINFO_H
+#include "ABIInfo.h"
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
namespace cir {
class TargetLoweringInfo {
+private:
+ std::unique_ptr<ABIInfo> info;
+
public:
+ TargetLoweringInfo(std::unique_ptr<ABIInfo> info);
virtual ~TargetLoweringInfo();
+ const ABIInfo &getABIInfo() const { return *info; }
+
virtual cir::SyncScopeKind
convertSyncScope(cir::SyncScopeKind syncScope) const;
};
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
new file mode 100644
index 0000000000000..35055ce5ee3d9
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
@@ -0,0 +1,39 @@
+//===- NVPTX.cpp - TargetInfo for NVPTX -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "LowerTypes.h"
+#include "TargetInfo.h"
+#include "TargetLoweringInfo.h"
+
+namespace cir {
+
+//===----------------------------------------------------------------------===//
+// NVPTX ABI Implementation
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+class NVPTXABIInfo : public ABIInfo {
+public:
+ NVPTXABIInfo(LowerTypes <) : ABIInfo(lt) {}
+};
+
+class NVPTXTargetLoweringInfo : public TargetLoweringInfo {
+public:
+ NVPTXTargetLoweringInfo(LowerTypes <)
+ : TargetLoweringInfo(std::make_unique<NVPTXABIInfo>(lt)) {}
+};
+
+} // namespace
+
+std::unique_ptr<TargetLoweringInfo>
+createNVPTXTargetLoweringInfo(LowerModule &lm) {
+ return std::make_unique<NVPTXTargetLoweringInfo>(lm.getTypes());
+}
+
+} // namespace cir
\ No newline at end of file
>From b59d938aab222ef90ae5cbfe0dcd37e190964bdf Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Fri, 20 Feb 2026 19:56:51 -0700
Subject: [PATCH 2/6] fix style
---
.gitignore | 1 +
.../Transforms/TargetLowering/CIRLowerContext.cpp | 3 ++-
.../Transforms/TargetLowering/CIRLowerContext.h | 1 -
.../Dialect/Transforms/TargetLowering/LowerModule.cpp | 10 ++++++----
.../Transforms/TargetLowering/TargetLoweringInfo.cpp | 2 +-
5 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index f24f1599ed0f6..f831f36d3ed7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@
# Nested build directory
/build*
+
/llvm/build-release*
#==============================================================================#
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
index c711c1c07aca0..fe32f0726d19b 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
@@ -28,7 +28,8 @@ CIRLowerContext::CIRLowerContext(mlir::ModuleOp module,
CIRLowerContext::~CIRLowerContext() {}
-mlir::Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind builtinKind) {
+mlir::Type
+CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind builtinKind) {
mlir::Type ty;
// NOTE(cir): Clang does more stuff here. Not sure if we need to do the same.
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
index 9ef0e617eaa08..02afbdf8de5ad 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.h
@@ -69,7 +69,6 @@ class CIRLowerContext : public llvm::RefCountedBase<CIRLowerContext> {
public:
mlir::MLIRContext *getMLIRContext() const { return mlirContext; }
-
};
} // namespace cir
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
index 674440102acb3..825aae8d0b119 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
@@ -48,7 +48,7 @@ static std::unique_ptr<TargetLoweringInfo>
createTargetLoweringInfo(LowerModule &lm) {
const clang::TargetInfo &target = lm.getTarget();
const llvm::Triple &triple = target.getTriple();
-
+
switch (triple.getArch()) {
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
@@ -63,9 +63,11 @@ LowerModule::LowerModule(clang::LangOptions langOpts,
clang::CodeGenOptions codeGenOpts,
mlir::ModuleOp &module,
std::unique_ptr<clang::TargetInfo> target)
- : context(module, std::move(langOpts), std::move(codeGenOpts)), module(module), target(std::move(target)), abi(createCXXABI(*this)), types(*this) {
- context.initBuiltinTypes(*target);
- }
+ : context(module, std::move(langOpts), std::move(codeGenOpts)),
+ module(module), target(std::move(target)), abi(createCXXABI(*this)),
+ types(*this) {
+ context.initBuiltinTypes(*target);
+}
const TargetLoweringInfo &LowerModule::getTargetLoweringInfo() {
if (!targetLoweringInfo)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
index 1abb770b64f9e..971a20ceca415 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.cpp
@@ -16,7 +16,7 @@
namespace cir {
TargetLoweringInfo::TargetLoweringInfo(std::unique_ptr<ABIInfo> info)
- : info(std::move(info)) {}
+ : info(std::move(info)) {}
TargetLoweringInfo::~TargetLoweringInfo() = default;
>From 99206ed5867f79d44644d70b6e180769a9baa645 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Fri, 20 Feb 2026 20:12:53 -0700
Subject: [PATCH 3/6] use lm to avoid CI error
---
.../lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
index 9ce0c7372e35c..b9569d84798e2 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
@@ -48,6 +48,13 @@ class LowerTypes {
public:
LowerTypes(LowerModule &lm);
~LowerTypes() = default;
+
+ LowerModule &getLm() const { return lm; }
+// CIRLowerContext &getContext() { return context; }
+// const clang::TargetInfo &getTarget() const { return target; }
+// const cir::CIRDataLayout &getDataLayout() const { return dataLayout; }
+// CIRCXXABI &getCXXABI() const { return CXXABI; }
+// mlir::MLIRContext *getMLIRContext() { return mlirContext; }
};
} // namespace cir
>From 8561473fae03c79224764cca8e7bea83c5e5bcb3 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Fri, 20 Feb 2026 20:29:59 -0700
Subject: [PATCH 4/6] remove commented getters
---
.../CIR/Dialect/Transforms/TargetLowering/LowerTypes.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
index b9569d84798e2..bcbd82b4747b5 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.h
@@ -50,11 +50,11 @@ class LowerTypes {
~LowerTypes() = default;
LowerModule &getLm() const { return lm; }
-// CIRLowerContext &getContext() { return context; }
-// const clang::TargetInfo &getTarget() const { return target; }
-// const cir::CIRDataLayout &getDataLayout() const { return dataLayout; }
-// CIRCXXABI &getCXXABI() const { return CXXABI; }
-// mlir::MLIRContext *getMLIRContext() { return mlirContext; }
+ // CIRLowerContext &getContext() { return context; }
+ // const clang::TargetInfo &getTarget() const { return target; }
+ // const cir::CIRDataLayout &getDataLayout() const { return dataLayout; }
+ // CIRCXXABI &getCXXABI() const { return CXXABI; }
+ // mlir::MLIRContext *getMLIRContext() { return mlirContext; }
};
} // namespace cir
>From e7735c5e3add0ba9ce661ed77f41bf57e310e946 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Sat, 21 Feb 2026 15:33:10 -0700
Subject: [PATCH 5/6] switch to x86_64 for foundation
---
clang/include/clang/CIR/MissingFeatures.h | 1 +
.../Transforms/TargetLowering/CMakeLists.txt | 1 +
.../Transforms/TargetLowering/LowerModule.cpp | 8 ++++
.../Transforms/TargetLowering/TargetInfo.h | 9 +++-
.../TargetLowering/Targets/NVPTX.cpp | 39 ------------------
.../Transforms/TargetLowering/Targets/X86.cpp | 41 +++++++++++++++++++
6 files changed, 59 insertions(+), 40 deletions(-)
delete mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
create mode 100644 clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp
diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h
index 388bfb81d53fb..08af05b188b62 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -225,6 +225,7 @@ struct MissingFeatures {
static bool targetLoweringInfo() { return false; }
static bool extParamInfo() { return false; }
static bool qualifiedTypes() { return false; }
+ static bool swift() { return false; }
// Extra checks for lowerGetMethod in ItaniumCXXABI
static bool emitCFICheck() { return false; }
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
index 7c94815ce3f26..c8b6e2c9d95ab 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
@@ -6,6 +6,7 @@ add_clang_library(MLIRCIRTargetLowering
LowerTypes.cpp
LowerItaniumCXXABI.cpp
TargetLoweringInfo.cpp
+ Targets/X86.cpp
Targets/NVPTX.cpp
DEPENDS
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
index 825aae8d0b119..85c830e1eb262 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
@@ -50,6 +50,14 @@ createTargetLoweringInfo(LowerModule &lm) {
const llvm::Triple &triple = target.getTriple();
switch (triple.getArch()) {
+ case llvm::Triple::x86_64: {
+ switch (triple.getOS()) {
+ case llvm::Triple::Win32:
+ cir_cconv_unreachable("Windows ABI NYI");
+ default:
+ return createX86_64TargetLoweringInfo(lm, X86AVXABILevel::None);
+ }
+ }
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
return createNVPTXTargetLoweringInfo(lm);
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
index 011efa153c665..e4d67a36d6165 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetInfo.h
@@ -19,8 +19,15 @@
namespace cir {
+/// The AVX ABI level for X86 targets.
+enum class X86AVXABILevel {
+ None,
+ AVX,
+ AVX512,
+};
+
std::unique_ptr<TargetLoweringInfo>
-createNVPTXTargetLoweringInfo(LowerModule &cgm);
+createX86_64TargetLoweringInfo(LowerModule &lm, X86AVXABILevel avxLevel);
} // namespace cir
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
deleted file mode 100644
index 35055ce5ee3d9..0000000000000
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//===- NVPTX.cpp - TargetInfo for NVPTX -----------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "LowerTypes.h"
-#include "TargetInfo.h"
-#include "TargetLoweringInfo.h"
-
-namespace cir {
-
-//===----------------------------------------------------------------------===//
-// NVPTX ABI Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class NVPTXABIInfo : public ABIInfo {
-public:
- NVPTXABIInfo(LowerTypes <) : ABIInfo(lt) {}
-};
-
-class NVPTXTargetLoweringInfo : public TargetLoweringInfo {
-public:
- NVPTXTargetLoweringInfo(LowerTypes <)
- : TargetLoweringInfo(std::make_unique<NVPTXABIInfo>(lt)) {}
-};
-
-} // namespace
-
-std::unique_ptr<TargetLoweringInfo>
-createNVPTXTargetLoweringInfo(LowerModule &lm) {
- return std::make_unique<NVPTXTargetLoweringInfo>(lm.getTypes());
-}
-
-} // namespace cir
\ No newline at end of file
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp
new file mode 100644
index 0000000000000..56c7d4184f840
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp
@@ -0,0 +1,41 @@
+//===- X86.cpp - TargetInfo for X86 -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "ABIInfo.h"
+#include "LowerModule.h"
+#include "LowerTypes.h"
+#include "TargetInfo.h"
+#include "clang/CIR/MissingFeatures.h"
+#include <memory>
+
+namespace cir {
+
+//===----------------------------------------------------------------------===//
+// X86 ABI Implementation
+//===----------------------------------------------------------------------===//
+
+class X86_64ABIInfo : public ABIInfo {
+
+public:
+ X86_64ABIInfo(LowerTypes <, X86AVXABILevel avxLevel) : ABIInfo(lt) {}
+};
+
+class X86_64TargetLoweringInfo : public TargetLoweringInfo {
+public:
+ X86_64TargetLoweringInfo(LowerTypes <, X86AVXABILevel avxLevel)
+ : TargetLoweringInfo(std::make_unique<X86_64ABIInfo>(lt, avxLevel)) {
+ assert(!cir::MissingFeatures::swift());
+ }
+};
+
+std::unique_ptr<TargetLoweringInfo>
+createX86_64TargetLoweringInfo(LowerModule &lm, X86AVXABILevel avxLevel) {
+ return std::make_unique<X86_64TargetLoweringInfo>(lm.getTypes(), avxLevel);
+}
+
+} // namespace cir
>From 61e26ddd77629ca9e4bdb4f1220de34720f7cfb9 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Sat, 21 Feb 2026 15:34:31 -0700
Subject: [PATCH 6/6] remove nvptx target from cmakelist
---
clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
index c8b6e2c9d95ab..023e6cfb6fe22 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt
@@ -7,8 +7,7 @@ add_clang_library(MLIRCIRTargetLowering
LowerItaniumCXXABI.cpp
TargetLoweringInfo.cpp
Targets/X86.cpp
- Targets/NVPTX.cpp
-
+
DEPENDS
clangBasic
More information about the cfe-commits
mailing list