[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-02-06 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb4b95dee3140: MIPS: fix build from IR files, nan2008 and 
FpAbi (authored by wzssyqa, committed by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,18 @@
+;; When we compile object with "-flto", the info of "-mnan=2008"
+;; and "-mfp32/-mfpxx/-mfp64" will be missing in the result IR file.
+;; Thus the asm/obj files will have wrong format.
+;; With D140270 we extract these info from the first function,
+;; and set it for the whole compile unit.
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -777,14 +777,18 @@
   // around it by re-initializing the PIC state here.
   TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
 
+  // Try to get target-features from the first function.
+  StringRef FS = TM.getTargetFeatureString();
+  Module::iterator F = M.begin();
+  if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
+FS = F->getFnAttribute("target-features").getValueAsString();
+
   // Compute MIPS architecture attributes based on the default subtarget
-  // that we'd have constructed. Module level directives aren't LTO
-  // clean anyhow.
+  // that we'd have constructed.
   // FIXME: For ifunc related functions we could iterate over and look
   // for a feature string that doesn't match the default one.
   const Triple  = TM.getTargetTriple();
   StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
-  StringRef FS = TM.getTargetFeatureString();
   const MipsTargetMachine  = static_cast(TM);
   const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
 
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as 

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-02-06 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

@MaskRay can you help to submit this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-30 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

I tested this against the kernel and left my feedback above (no issues) so this 
can be merged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D140270#4089857 , @wzssyqa wrote:

> ping

I don't know how to test this, so this will be up to @nathanchance ...
(Thanks for improving the mips port, though)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-30 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-02 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 485898.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,18 @@
+;; When we compile object with "-flto", the info of "-mnan=2008"
+;; and "-mfp32/-mfpxx/-mfp64" will be missing in the result IR file.
+;; Thus the asm/obj files will have wrong format.
+;; With D140270 we extract these info from the first function,
+;; and set it for the whole compile unit.
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -777,14 +777,18 @@
   // around it by re-initializing the PIC state here.
   TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
 
+  // Try to get target-features from the first function.
+  StringRef FS = TM.getTargetFeatureString();
+  Module::iterator F = M.begin();
+  if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
+FS = F->getFnAttribute("target-features").getValueAsString();
+
   // Compute MIPS architecture attributes based on the default subtarget
-  // that we'd have constructed. Module level directives aren't LTO
-  // clean anyhow.
+  // that we'd have constructed.
   // FIXME: For ifunc related functions we could iterate over and look
   // for a feature string that doesn't match the default one.
   const Triple  = TM.getTargetTriple();
   StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
-  StringRef FS = TM.getTargetFeatureString();
   const MipsTargetMachine  = static_cast(TM);
   const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
 
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: 

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-02 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 485897.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,13 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -777,14 +777,18 @@
   // around it by re-initializing the PIC state here.
   TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
 
+  // Try to get target-features from the first function.
+  StringRef FS = TM.getTargetFeatureString();
+  Module::iterator F = M.begin();
+  if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
+FS = F->getFnAttribute("target-features").getValueAsString();
+
   // Compute MIPS architecture attributes based on the default subtarget
-  // that we'd have constructed. Module level directives aren't LTO
-  // clean anyhow.
+  // that we'd have constructed.
   // FIXME: For ifunc related functions we could iterate over and look
   // for a feature string that doesn't match the default one.
   const Triple  = TM.getTargetTriple();
   StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
-  StringRef FS = TM.getTargetFeatureString();
   const MipsTargetMachine  = static_cast(TM);
   const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
 
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdsp"
+// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mdsp"
 //
 // RUN: %clang -target mips-linux-gnu -mdsp -mno-dsp -### \
 // RUN:   

[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-01 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

This does not show any issues with any of the MIPS configurations that I build 
in the Linux kernel, thanks for fixing the problems I reported!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll:1
+; RUN: llc %s -o - | FileCheck %s
+

Add `;; ` file-level comment what this test does. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

@nathanchance can you have a try this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-31 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 485793.
wzssyqa retitled this revision from "MIPS: emit .module and .nan directives 
only for first function" to "MIPS: fix build from IR files, nan2008 and FpAbi".
wzssyqa edited the summary of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,13 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -777,14 +777,18 @@
   // around it by re-initializing the PIC state here.
   TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
 
+  // Try to get target-features from the first function.
+  StringRef FS = TM.getTargetFeatureString();
+  Module::iterator F = M.begin();
+  if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
+FS = F->getFnAttribute("target-features").getValueAsString();
+
   // Compute MIPS architecture attributes based on the default subtarget
-  // that we'd have constructed. Module level directives aren't LTO
-  // clean anyhow.
+  // that we'd have constructed.
   // FIXME: For ifunc related functions we could iterate over and look
   // for a feature string that doesn't match the default one.
   const Triple  = TM.getTargetTriple();
   StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
-  StringRef FS = TM.getTargetFeatureString();
   const MipsTargetMachine  = static_cast(TM);
   const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
 
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: as{{(.exe)?}}"