[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2023-09-25 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e97db89ae8e: [PowerPC] Emit IR module flag for current 
float abi (authored by qiucf).

Changed prior to commit:
  https://reviews.llvm.org/D116016?vs=530843=557298#toc

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/Targets/PPC.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/Targets/PPC.cpp
===
--- clang/lib/CodeGen/Targets/PPC.cpp
+++ clang/lib/CodeGen/Targets/PPC.cpp
@@ -620,6 +620,9 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
llvm::Value *Address) const override;
+  void emitTargetMetadata(CodeGen::CodeGenModule ,
+  const llvm::MapVector
+  ) const override;
 };
 
 class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -940,6 +943,24 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule ,
+const llvm::MapVector ) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+llvm::LLVMContext  = CGM.getLLVMContext();
+const auto *flt = ().getLongDoubleFormat();
+if (flt == ::APFloat::PPCDoubleDouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "doubledouble"));
+else if (flt == ::APFloat::IEEEquad())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeequad"));
+else if (flt == ::APFloat::IEEEdouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeedouble"));
+  }
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
 llvm::Value *Address) const {
Index: clang/lib/CodeGen/CodeGenTypes.h
===
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -84,6 +84,9 @@
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
+  /// True if any instance of long double types are used.
+  bool LongDoubleReferenced;
+
   /// This map keeps cache of llvm::Types and maps clang::Type to
   /// corresponding llvm::Type.
   llvm::DenseMap TypeCache;
@@ -289,6 +292,7 @@
   /// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
   bool isZeroInitializable(const RecordDecl *RD);
 
+  bool isLongDoubleReferenced() const { return LongDoubleReferenced; }
   bool isRecordLayoutComplete(const Type *Ty) const;
   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() {
@@ -406,10 +407,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(),

[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2023-09-21 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for reviving this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2023-09-19 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Gentle ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2023-06-13 Thread Qiu Chaofan via Phabricator via cfe-commits
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 ,
llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule ,
+  const llvm::MapVector
+  ) const override;
 };
 
 class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -5470,6 +5474,24 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule ,
+const llvm::MapVector ) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+llvm::LLVMContext  = CGM.getLLVMContext();
+const auto *flt = ().getLongDoubleFormat();
+if (flt == ::APFloat::PPCDoubleDouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "doubledouble"));
+else if (flt == ::APFloat::IEEEquad())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeequad"));
+else if (flt == ::APFloat::IEEEdouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeedouble"));
+  }
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
 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 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


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2022-01-04 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf updated this revision to Diff 397443.
qiucf added a comment.

Only emit the flags when any instance of `long double` is used.


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: !{{[0-9]+}} = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeequad"}
+// LDBL64: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeedouble"}
+// NOLDBL-NOT: !{{[0-9]+}} = !{i32 1, !"float-abi"
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5030,6 +5030,10 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule ,
+  const llvm::MapVector
+  ) const override;
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -5443,6 +5447,24 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule ,
+const llvm::MapVector ) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+llvm::LLVMContext  = CGM.getLLVMContext();
+const auto *flt = ().getLongDoubleFormat();
+if (flt == ::APFloat::PPCDoubleDouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "doubledouble"));
+else if (flt == ::APFloat::IEEEquad())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeequad"));
+else if (flt == ::APFloat::IEEEdouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeedouble"));
+  }
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
 llvm::Value *Address) const {
Index: clang/lib/CodeGen/CodeGenTypes.h
===
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -95,6 +95,9 @@
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
+  /// True if any instance of long double types are used.
+  bool LongDoubleReferenced;
+
   SmallVector DeferredRecords;
 
   /// This map keeps cache of llvm::Types and maps clang::Type to
@@ -310,6 +313,9 @@
 return RecordsBeingLaidOut.count(Ty);
   }
 
+  bool isLongDoubleReferenced() const {
+return LongDoubleReferenced;
+  }
 };
 
 }  // end namespace CodeGen
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -33,6 +33,7 @@
 Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
 TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
   SkippedLayout = false;
+  LongDoubleReferenced = false;
 }
 
 CodeGenTypes::~CodeGenTypes() {
@@ -507,10 +508,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


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2021-12-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D116016#3203005 , @nemanjai wrote:

> We should not be emitting the attribute in modules that do not have any use 
> of `long double`.

Right, otherwise it would be a bit unfortunate that a library not using long 
double has to be compiled differently to use ThinLTO with other programs, since 
the module flags metadata's behavior is `Error` (1).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2021-12-20 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

We should not be emitting the attribute in modules that do not have any use of 
`long double`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2021-12-19 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

In D116016#3202148 , @MaskRay wrote:

>> 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.
>
> How does .gnu_attribute work with the metadata?

Planned way to do is check the module flag in ASM printer, like

  if (flt == "doubledouble")
OutStreamer->emitGNUAttribute(4, 5);
  else if (flt == "ieeequad")
OutStreamer->emitGNUAttribute(4, 13);
  else if (flt == "ieeedouble")
OutStreamer->emitGNUAttribute(4, 9);

Currently this doesn't look like the most elegant way, and doesn't fully match 
behavior of GCC. (In GCC, if no floating operations exist, the attributes won't 
be generated) But since the floating abi option applies to the whole module, 
adding them to module flags are more reasonable than function attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2021-12-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> 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.

How does .gnu_attribute work with the metadata?




Comment at: clang/test/CodeGen/ppc64-float-abi-attr.c:9
+
+// CHECK: !{{[0-9]+}} = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: !{{[0-9]+}} = !{i32 1, !"float-abi", !"ieeequad"}

`![[#]]`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2021-12-19 Thread Qiu Chaofan via Phabricator via cfe-commits
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 ,
llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule ,
+  const llvm::MapVector
+  ) const override;
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -5443,6 +5447,22 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule ,
+const llvm::MapVector ) const {
+  llvm::LLVMContext  = CGM.getLLVMContext();
+  const auto *flt = ().getLongDoubleFormat();
+  if (flt == ::APFloat::PPCDoubleDouble())
+CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+  llvm::MDString::get(Ctx, "doubledouble"));
+  else if (flt == ::APFloat::IEEEquad())
+CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+  llvm::MDString::get(Ctx, "ieeequad"));
+  else if (flt == ::APFloat::IEEEdouble())
+CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+  llvm::MDString::get(Ctx, "ieeedouble"));
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
 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 ,
llvm::Value *Address) const override;
+
+  void emitTargetMetadata(CodeGen::CodeGenModule ,
+  const llvm::MapVector
+  ) const override;
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -5443,6 +5447,22 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule ,
+const llvm::MapVector ) const {
+  llvm::LLVMContext  =