[PATCH] D112401: [Clang] Mutate printf bulitin names under IEEE128 on PPC64
Qiu Chaofan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 25 00:37:32 PDT 2021
qiucf updated this revision to Diff 381868.
qiucf added a reviewer: rjmccall.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112401/new/
https://reviews.llvm.org/D112401
Files:
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/ppc64-f128-builtins.c
Index: clang/test/CodeGen/ppc64-f128-builtins.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/ppc64-f128-builtins.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN: -mabi=ieeelongdouble | FileCheck --check-prefix=IEEE128 %s
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefix=PPC128 %s
+
+long double x;
+char buf[20];
+
+// IEEE128-LABEL: define dso_local void @test_printf
+// IEEE128: call signext i32 (i8*, ...) @__printfieee128
+// PPC128-LABEL: define dso_local void @test_printf
+// PPC128: call signext i32 (i8*, ...) @printf
+void test_printf() {
+ __builtin_printf("%.Lf", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsnprintf
+// IEEE128: call signext i32 @__vsnprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsnprintf
+// PPC128: call signext i32 @vsnprintf
+void test_vsnprintf(int n, ...) {
+ __builtin_va_list va;
+ __builtin_va_start(va, n);
+ __builtin_vsnprintf(buf, 20, "%.Lf", va);
+ __builtin_va_end(va);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsprintf
+// IEEE128: call signext i32 @__vsprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsprintf
+// PPC128: call signext i32 @vsprintf
+void test_vsprintf(int n, ...) {
+ __builtin_va_list va;
+ __builtin_va_start(va, n);
+ __builtin_vsprintf(buf, "%.Lf", va);
+ __builtin_va_end(va);
+}
+
+// IEEE128-LABEL: define dso_local void @test_sprintf
+// IEEE128: call signext i32 (i8*, i8*, ...) @__sprintfieee128
+// PPC128-LABEL: define dso_local void @test_sprintf
+// PPC128: call signext i32 (i8*, i8*, ...) @sprintf
+void test_sprintf() {
+ __builtin_sprintf(buf, "%.Lf", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_snprintf
+// IEEE128: call signext i32 (i8*, i64, i8*, ...) @__snprintfieee128
+// PPC128-LABEL: define dso_local void @test_snprintf
+// PPC128: call signext i32 (i8*, i64, i8*, ...) @snprintf
+void test_snprintf() {
+ __builtin_snprintf(buf, 20, "%.Lf", x);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -96,13 +96,30 @@
StringRef Name;
GlobalDecl D(FD);
+ static SmallDenseMap<unsigned, StringRef, 8> F128Builtins{
+ {Builtin::BI__builtin_printf, "__printfieee128"},
+ {Builtin::BI__builtin_vsnprintf, "__vsnprintfieee128"},
+ {Builtin::BI__builtin_vsprintf, "__vsprintfieee128"},
+ {Builtin::BI__builtin_sprintf, "__sprintfieee128"},
+ {Builtin::BI__builtin_snprintf, "__snprintfieee128"},
+ {Builtin::BI__builtin_fprintf, "__fprintfieee128"},
+ };
+
// If the builtin has been declared explicitly with an assembler label,
// use the mangled name. This differs from the plain label on platforms
// that prefix labels.
if (FD->hasAttr<AsmLabelAttr>())
Name = getMangledName(D);
- else
- Name = Context.BuiltinInfo.getName(BuiltinID) + 10;
+ else {
+ // TODO: This mutation should also be applied to other targets other than
+ // PPC, after backend supports IEEE 128-bit style libcalls.
+ if (getTriple().isPPC64() &&
+ &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() &&
+ F128Builtins.find(BuiltinID) != F128Builtins.end())
+ Name = F128Builtins[BuiltinID];
+ else
+ Name = Context.BuiltinInfo.getName(BuiltinID) + 10;
+ }
llvm::FunctionType *Ty =
cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112401.381868.patch
Type: text/x-patch
Size: 3607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211025/287359d6/attachment.bin>
More information about the cfe-commits
mailing list