qiucf updated this revision to Diff 530843.
qiucf marked an inline comment as done.
qiucf edited the summary of this revision.
qiucf removed a reviewer: jsji.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116016/new/

https://reviews.llvm.org/D116016

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/CodeGenTypes.h
  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,17 @@
+// 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
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -DNOLDBL -o - | FileCheck %s --check-prefix=NOLDBL
+
+#ifndef NOLDBL
+long double foo(long double a, long double b) {
+  return a + b;
+}
+#endif
+
+int bar() { return 1; }
+
+// CHECK: ![[#]] = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: ![[#]] = !{i32 1, !"float-abi", !"ieeequad"}
+// LDBL64: ![[#]] = !{i32 1, !"float-abi", !"ieeedouble"}
+// NOLDBL-NOT: ![[#]] = !{i32 1, !"float-abi"
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5045,6 +5045,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 TargetCodeGenInfo {
@@ -5470,6 +5474,24 @@
                                      /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+    CodeGen::CodeGenModule &CGM,
+    const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+    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/lib/CodeGen/CodeGenTypes.h
===================================================================
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -90,6 +90,9 @@
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
+  /// True if any instance of long double types are used.
+  bool LongDoubleReferenced;
+
   SmallVector<const RecordDecl *, 8> DeferredRecords;
 
   /// This map keeps cache of llvm::Types and maps clang::Type to
@@ -306,6 +309,7 @@
   bool isRecordBeingLaidOut(const Type *Ty) const {
     return RecordsBeingLaidOut.count(Ty);
   }
+  bool isLongDoubleReferenced() const { return LongDoubleReferenced; }
   unsigned getTargetAddressSpace(QualType T) const;
 };
 
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -34,6 +34,7 @@
     Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
     TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
   SkippedLayout = false;
+  LongDoubleReferenced = false;
 }
 
 CodeGenTypes::~CodeGenTypes() {
@@ -529,10 +530,12 @@
           Context.getLangOpts().NativeHalfType ||
               !Context.getTargetInfo().useFP16ConversionIntrinsics());
       break;
+    case BuiltinType::LongDouble:
+      LongDoubleReferenced = true;
+      LLVM_FALLTHROUGH;
     case BuiltinType::BFloat16:
     case BuiltinType::Float:
     case BuiltinType::Double:
-    case BuiltinType::LongDouble:
     case BuiltinType::Float128:
     case BuiltinType::Ibm128:
       ResultType = getTypeForFormat(getLLVMContext(),
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to