qiucf created this revision.
qiucf added reviewers: nemanjai, jsji, shchenz, PowerPC, uweigand, MaskRay.
Herald added subscribers: steven.zhang, kbarton.
qiucf requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This is part of the efforts adding `.gnu_attribute` support for PowerPC. In 
Clang, an extra metadata field will be added as `float-abi` to show current 
`long double` format. So backend can emit `.gnu_attribute` section data from 
this metadata.

Note: This patch will break 50+ more LIT tests in `clang/test/OpenMP`. They're 
all trivial changes since only the referenced metadata numbers are changed. 
They're not included in this review since it's quite large so that browser 
cannot load them easily.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116016

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/ppc64-float-abi-attr.c


Index: clang/test/CodeGen/ppc64-float-abi-attr.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/ppc64-float-abi-attr.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm 
-mabi=ieeelongdouble -o - | FileCheck %s --check-prefix=IEEE
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm 
-mlong-double-64 -o - | FileCheck %s --check-prefix=LDBL64
+
+long double foo(long double a, long double b) {
+  return a + b;
+}
+
+// CHECK: !{{[0-9]+}} = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeequad"}
+// LDBL64: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeedouble"}
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5030,6 +5030,10 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
+                          const llvm::MapVector<GlobalDecl, StringRef>
+                              &MangledDeclNames) const override;
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -5443,6 +5447,22 @@
                                      /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+    CodeGen::CodeGenModule &CGM,
+    const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  const auto *flt = &CGM.getTarget().getLongDoubleFormat();
+  if (flt == &llvm::APFloat::PPCDoubleDouble())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "doubledouble"));
+  else if (flt == &llvm::APFloat::IEEEquad())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "ieeequad"));
+  else if (flt == &llvm::APFloat::IEEEdouble())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "ieeedouble"));
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                                 llvm::Value *Address) const {


Index: clang/test/CodeGen/ppc64-float-abi-attr.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/ppc64-float-abi-attr.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mabi=ieeelongdouble -o - | FileCheck %s --check-prefix=IEEE
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mlong-double-64 -o - | FileCheck %s --check-prefix=LDBL64
+
+long double foo(long double a, long double b) {
+  return a + b;
+}
+
+// CHECK: !{{[0-9]+}} = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeequad"}
+// LDBL64: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeedouble"}
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5030,6 +5030,10 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
+                          const llvm::MapVector<GlobalDecl, StringRef>
+                              &MangledDeclNames) const override;
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -5443,6 +5447,22 @@
                                      /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+    CodeGen::CodeGenModule &CGM,
+    const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  const auto *flt = &CGM.getTarget().getLongDoubleFormat();
+  if (flt == &llvm::APFloat::PPCDoubleDouble())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "doubledouble"));
+  else if (flt == &llvm::APFloat::IEEEquad())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "ieeequad"));
+  else if (flt == &llvm::APFloat::IEEEdouble())
+    CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+                              llvm::MDString::get(Ctx, "ieeedouble"));
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                                 llvm::Value *Address) const {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to