[clang] 9c56188 - [CIR] Add long_double_size to #cir.lowering_lang_options (#234946)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 01:56:24 PDT 2026


Author: Mariya Podchishchaeva
Date: 2026-10-26T09:56:19+01:00
New Revision: 9c56188287972addf513cfc7841f354dfb1854a9

URL: https://github.com/llvm/llvm-project/commit/9c56188287972addf513cfc7841f354dfb1854a9
DIFF: https://github.com/llvm/llvm-project/commit/9c56188287972addf513cfc7841f354dfb1854a9.diff

LOG: [CIR] Add long_double_size to #cir.lowering_lang_options (#234946)

It represents `LangOpts::LongDoubleSize` which is initialized if
`-mlong-double-*` command line option is present.

Relates to https://github.com/llvm/llvm-project/issues/227917 .

Added: 
    

Modified: 
    clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
    clang/lib/CIR/CodeGen/CIRGenModule.cpp
    clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
    clang/test/CIR/CodeGen/lowering-lang-options.cpp
    clang/test/CIR/IR/lowering-lang-options.cir
    clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
    clang/test/CIR/Transforms/lowering-prepare.cir

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 54158e5b77d84e..7c8bf6574b4dee 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -2690,13 +2690,14 @@ def CIR_LoweringLangOptionsAttr
     "bool":$gpu_rdc,
     "bool":$openmp,
     "bool":$openmp_is_target_device,
-    "int32_t":$clang_abi_compat
+    "int32_t":$clang_abi_compat,
+    "int32_t":$long_double_size
   );
 
   let assemblyFormat = [{
     `<` struct($exceptions, $threadsafe_statics, $cuda, $cuda_is_device, $hip,
                $hlsl, $gpu_rdc, $openmp, $openmp_is_target_device,
-               $clang_abi_compat) `>`
+               $clang_abi_compat, $long_double_size) `>`
   }];
 
   let canHaveIllegalCXXABIType = 0;

diff  --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 81b8c59ef90dc6..a9bd7a701f5ab0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -206,7 +206,8 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
           /*openmp=*/langOpts.OpenMP != 0,
           /*openmp_is_target_device=*/langOpts.OpenMPIsTargetDevice,
           /*clang_abi_compat=*/
-          static_cast<int32_t>(langOpts.getClangABICompat())));
+          static_cast<int32_t>(langOpts.getClangABICompat()),
+          static_cast<int32_t>(langOpts.LongDoubleSize)));
 
   if (cgo.OptimizationLevel > 0 || cgo.OptimizeSize > 0)
     getModule()->setAttr(cir::CIRDialect::getOptInfoAttrName(),

diff  --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
index 2fda1c996ad5c3..0b9c88112509f9 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
@@ -114,6 +114,7 @@ std::unique_ptr<LowerModule> createLowerModule(mlir::ModuleOp module) {
     langOpts.OpenMPIsTargetDevice = loweringLangOpts.getOpenmpIsTargetDevice();
     langOpts.setClangABICompat(static_cast<clang::LangOptions::ClangABI>(
         loweringLangOpts.getClangAbiCompat()));
+    langOpts.LongDoubleSize = loweringLangOpts.getLongDoubleSize();
   }
   // Some langopts are still not lowered.
   assert(!cir::MissingFeatures::lowerModuleLangOpts());
@@ -133,6 +134,11 @@ std::unique_ptr<LowerModule> createLowerModule(mlir::ModuleOp module) {
     codeGenOpts.OptimizeSize = optInfo.getSize();
   }
 
+  clang::DiagnosticOptions diagOpts;
+  clang::DiagnosticsEngine diags(clang::DiagnosticIDs::create(), diagOpts,
+                                 new clang::IgnoringDiagConsumer());
+  targetInfo->adjust(diags, langOpts, /*Aux=*/nullptr);
+
   return std::make_unique<LowerModule>(std::move(langOpts),
                                        std::move(codeGenOpts), module,
                                        std::move(targetInfo));

diff  --git a/clang/test/CIR/CodeGen/lowering-lang-options.cpp b/clang/test/CIR/CodeGen/lowering-lang-options.cpp
index d547e3dce47810..3b3832ef0a334f 100644
--- a/clang/test/CIR/CodeGen/lowering-lang-options.cpp
+++ b/clang/test/CIR/CodeGen/lowering-lang-options.cpp
@@ -3,6 +3,8 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir \
 // RUN:   -fexceptions -fcxx-exceptions -emit-cir %s -o - \
 // RUN:   | FileCheck %s --check-prefix=EXC
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir \
+// RUN: -mlong-double-128 -emit-cir %s -o - | FileCheck %s --check-prefix=LD
 
 // CIRGen serializes the LangOptions facts that post-CIRGen lowering consumes
 // onto the ModuleOp as a #cir.lowering_lang_options attribute, unconditionally, so
@@ -24,7 +26,8 @@ int x;
 // PLAIN-SAME: gpu_rdc = false
 // PLAIN-SAME: openmp = false
 // PLAIN-SAME: openmp_is_target_device = false
-// PLAIN-SAME: clang_abi_compat = {{[0-9]+}}>
+// PLAIN-SAME: clang_abi_compat = {{[0-9]+}}
+// PLAIN-SAME: long_double_size = 0>
 
 // -fexceptions -fcxx-exceptions flips exceptions. (OpenMP is exercised in the
 // #cir.lowering_lang_options round-trip test, since -fopenmp on a global here hits
@@ -34,4 +37,7 @@ int x;
 // EXC-SAME: threadsafe_statics = true
 // EXC-SAME: openmp = false
 // EXC-SAME: openmp_is_target_device = false
-// EXC-SAME: clang_abi_compat = {{[0-9]+}}>
+// EXC-SAME: clang_abi_compat = {{[0-9]+}}
+
+// LD: cir.lowering_lang_options = #cir.lowering_lang_options<
+// LD-SAME: long_double_size = 128>

diff  --git a/clang/test/CIR/IR/lowering-lang-options.cir b/clang/test/CIR/IR/lowering-lang-options.cir
index cb1c82eb3d1019..a801376fff8244 100644
--- a/clang/test/CIR/IR/lowering-lang-options.cir
+++ b/clang/test/CIR/IR/lowering-lang-options.cir
@@ -7,10 +7,10 @@
 module attributes {cir.lowering_lang_options = #cir.lowering_lang_options<
   exceptions = true, threadsafe_statics = false, cuda = true,
   cuda_is_device = true, hip = true, hlsl = true, gpu_rdc = true, openmp = true,
-  openmp_is_target_device = true, clang_abi_compat = 9>} {
+  openmp_is_target_device = true, clang_abi_compat = 9, long_double_size = 80>} {
 }
 
 // CHECK: cir.lowering_lang_options = #cir.lowering_lang_options<
 // CHECK-SAME: exceptions = true, threadsafe_statics = false, cuda = true,
 // CHECK-SAME: cuda_is_device = true, hip = true, hlsl = true, gpu_rdc = true, openmp = true,
-// CHECK-SAME: openmp_is_target_device = true, clang_abi_compat = 9>
+// CHECK-SAME: openmp_is_target_device = true, clang_abi_compat = 9, long_double_size = 80>

diff  --git a/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir b/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
index ba35c4bc74b475..74a26e584b8a39 100644
--- a/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
@@ -13,7 +13,8 @@ module attributes {
   cir.lowering_lang_options = #cir.lowering_lang_options<
     exceptions = false, threadsafe_statics = true, cuda = true,
     cuda_is_device = true, hip = true, hlsl = false, gpu_rdc = false,
-    openmp = false, openmp_is_target_device = false, clang_abi_compat = 17>
+    openmp = false, openmp_is_target_device = false, clang_abi_compat = 17,
+    long_double_size = 0>
 } {
 
   // The kernel casts the incoming global pointer back to generic before the

diff  --git a/clang/test/CIR/Transforms/lowering-prepare.cir b/clang/test/CIR/Transforms/lowering-prepare.cir
index d535eb0df67687..ba317d2756da1d 100644
--- a/clang/test/CIR/Transforms/lowering-prepare.cir
+++ b/clang/test/CIR/Transforms/lowering-prepare.cir
@@ -12,7 +12,7 @@ module attributes {
   cir.lowering_lang_options = #cir.lowering_lang_options<
     exceptions = false, threadsafe_statics = true, cuda = false,
     cuda_is_device = false, hip = false, hlsl = false, gpu_rdc = false, openmp = false,
-    openmp_is_target_device = false, clang_abi_compat = 16>
+    openmp_is_target_device = false, clang_abi_compat = 16, long_double_size = 0>
 } {
   cir.global "private" internal dso_local dynamic_init_guard<"_ZGVZ1gvE1x"> @_ZZ1gvE1x = #cir.int<0> : !s32i align(4) dynamic_init_info<local = true, tls = none, is_inline = false, tsk = undeclared>
 


        


More information about the cfe-commits mailing list