https://github.com/koparasy updated 
https://github.com/llvm/llvm-project/pull/219078

>From f963fc08a2c7f86cf3a27b97ff382fdb8f3ad4a8 Mon Sep 17 00:00:00 2001
From: Konstantinos Parasyris <[email protected]>
Date: Wed, 26 Aug 2026 17:17:09 -0700
Subject: [PATCH 1/2] [CIR] Source LoweringPrepare target facts from the module

---
 .../CIR/Dialect/Transforms/LoweringPrepare.cpp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp 
b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
index f4ea135032493..c21a9fb7a181b 100644
--- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "PassDetail.h"
+#include "TargetLowering/LowerModule.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "mlir/IR/IRMapping.h"
@@ -248,7 +249,7 @@ struct LoweringPreparePass
     } else if (useARMGuardVarABI()) {
       // Guard variables are size width on ARM (32-bit AArch32, 64-bit 
AArch64).
       const unsigned sizeTypeSize =
-          astCtx->getTypeSize(astCtx->getSignedSizeType());
+          getTargetInfo().getTypeWidth(getTargetInfo().getSignedSizeType());
       guardTy =
           cir::IntType::get(&getContext(), sizeTypeSize, /*isSigned=*/true);
       guardAlignment =
@@ -276,7 +277,7 @@ struct LoweringPreparePass
       // for non-ELF and non-Wasm object formats, so only do it for ELF and
       // Wasm.
       bool hasComdat = globalOp.getComdat();
-      const llvm::Triple &triple = astCtx->getTargetInfo().getTriple();
+      const llvm::Triple &triple = getTargetInfo().getTriple();
       // TODO(cir): for now, we're just setting comdat to true, but it should
       // contain a comdat reference name here instead.
       if (!isLocalVarDecl && hasComdat &&
@@ -298,6 +299,14 @@ struct LoweringPreparePass
 
   clang::ASTContext *astCtx;
 
+  /// Target/ABI facts sourced from the module's own attributes.
+  std::unique_ptr<cir::LowerModule> lowerModule;
+
+  const clang::TargetInfo &getTargetInfo() const {
+    assert(lowerModule && "LoweringPrepare requires a module with a triple");
+    return lowerModule->getTarget();
+  }
+
   /// Tracks current module.
   mlir::ModuleOp mlirModule;
 
@@ -388,7 +397,7 @@ struct LoweringPreparePass
 
     llvm::StringLiteral nameAtExit = "__cxa_atexit";
     if (tls)
-      nameAtExit = astCtx->getTargetInfo().getTriple().isOSDarwin()
+      nameAtExit = getTargetInfo().getTriple().isOSDarwin()
                        ? llvm::StringLiteral("_tlv_atexit")
                        : llvm::StringLiteral("__cxa_thread_atexit");
 
@@ -3029,6 +3038,9 @@ void LoweringPreparePass::runOnOperation() {
   if (isa<::mlir::ModuleOp>(op))
     mlirModule = cast<::mlir::ModuleOp>(op);
 
+  if (mlirModule)
+    lowerModule = cir::createLowerModule(mlirModule);
+
   llvm::SmallVector<mlir::Operation *> opsToTransform;
 
   op->walk([&](mlir::Operation *op) {

>From f676cdec00c7a0da17a43376feb24c0a5121abf2 Mon Sep 17 00:00:00 2001
From: Konstantinos Parasyris <[email protected]>
Date: Fri, 11 Sep 2026 08:00:33 -0700
Subject: [PATCH 2/2] Fix comments

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
---
 clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp 
b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
index c21a9fb7a181b..2c4bd2f4ca3a8 100644
--- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
@@ -3035,11 +3035,12 @@ void 
LoweringPreparePass::buildCUDARegisterVars(cir::CIRBaseBuilderTy &builder,
 
 void LoweringPreparePass::runOnOperation() {
   mlir::Operation *op = getOperation();
-  if (isa<::mlir::ModuleOp>(op))
-    mlirModule = cast<::mlir::ModuleOp>(op);
+  assert(isa<::mlir::ModuleOp>(op) && "expected a ModuleOp");
+  mlirModule = cast<::mlir::ModuleOp>(op);
 
-  if (mlirModule)
-    lowerModule = cir::createLowerModule(mlirModule);
+  // CIRGen always sets the triple, so this cannot fail.
+  lowerModule = cir::createLowerModule(mlirModule);
+  assert(lowerModule && "requires a module with a triple");
 
   llvm::SmallVector<mlir::Operation *> opsToTransform;
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to