[SystemZ] Automatically detect zEC12 and z196 hosts
authorRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Thu, 31 Oct 2013 12:14:17 +0000 (12:14 +0000)
committerRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Thu, 31 Oct 2013 12:14:17 +0000 (12:14 +0000)
As on other hosts, the CPU identification instruction is priveleged,
so we need to look through /proc/cpuinfo.  I copied the PowerPC way of
handling "generic".

Several tests were implicitly assuming z10 and so failed on z196.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193742 91177308-0d34-0410-b5e6-96231b3b80d8

23 files changed:
lib/Support/Host.cpp
lib/Target/SystemZ/SystemZProcessors.td
lib/Target/SystemZ/SystemZSubtarget.cpp
test/CodeGen/SystemZ/atomicrmw-minmax-03.ll
test/CodeGen/SystemZ/atomicrmw-minmax-04.ll
test/CodeGen/SystemZ/cond-store-01.ll
test/CodeGen/SystemZ/cond-store-02.ll
test/CodeGen/SystemZ/fp-cmp-01.ll
test/CodeGen/SystemZ/fp-cmp-02.ll
test/CodeGen/SystemZ/fp-cmp-03.ll
test/CodeGen/SystemZ/fp-move-02.ll
test/CodeGen/SystemZ/frame-13.ll
test/CodeGen/SystemZ/frame-14.ll
test/CodeGen/SystemZ/frame-15.ll
test/CodeGen/SystemZ/frame-16.ll
test/CodeGen/SystemZ/frame-18.ll
test/CodeGen/SystemZ/int-add-11.ll
test/CodeGen/SystemZ/int-conv-02.ll
test/CodeGen/SystemZ/int-conv-06.ll
test/CodeGen/SystemZ/risbg-01.ll
test/CodeGen/SystemZ/setcc-01.ll
test/CodeGen/SystemZ/setcc-02.ll
test/CodeGen/SystemZ/spill-01.ll

index 12df08c6c0c67a2226205090ea0671d05e783993..6a5d4d28a91d81b9b0a67b88bdcd24b51483050b 100644 (file)
@@ -535,6 +535,48 @@ std::string sys::getHostCPUName() {
 
   return "generic";
 }
 
   return "generic";
 }
+#elif defined(__linux__) && defined(__s390x__)
+std::string sys::getHostCPUName() {
+  // STIDP is a privileged operation, so use /proc/cpuinfo instead.
+  // Note: We cannot mmap /proc/cpuinfo here and then process the resulting
+  // memory buffer because the 'file' has 0 size (it can be read from only
+  // as a stream).
+
+  std::string Err;
+  DataStreamer *DS = getDataFileStreamer("/proc/cpuinfo", &Err);
+  if (!DS) {
+    DEBUG(dbgs() << "Unable to open /proc/cpuinfo: " << Err << "\n");
+    return "generic";
+  }
+
+  // The "processor 0:" line comes after a fair amount of other information,
+  // including a cache breakdown, but this should be plenty.
+  char buffer[2048];
+  size_t CPUInfoSize = DS->GetBytes((unsigned char*) buffer, sizeof(buffer));
+  delete DS;
+
+  StringRef Str(buffer, CPUInfoSize);
+  SmallVector<StringRef, 32> Lines;
+  Str.split(Lines, "\n");
+  for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
+    if (Lines[I].startswith("processor ")) {
+      size_t Pos = Lines[I].find("machine = ");
+      if (Pos != StringRef::npos) {
+        Pos += sizeof("machine = ") - 1;
+        unsigned int Id;
+        if (!Lines[I].drop_front(Pos).getAsInteger(10, Id)) {
+          if (Id >= 2827)
+            return "zEC12";
+          if (Id >= 2817)
+            return "z196";
+        }
+      }
+      break;
+    }
+  }
+  
+  return "generic";
+}
 #else
 std::string sys::getHostCPUName() {
   return "generic";
 #else
 std::string sys::getHostCPUName() {
   return "generic";
index 00d4338af55b0dfd21b7c7dd92ac9c8222d5d629..f241fb0c22227f08160865149a98ce4d5e3498ec 100644 (file)
@@ -36,8 +36,9 @@ def FeatureFPExtension : SystemZFeature<
   "Assume that the floating-point extension facility is installed"
 >;
 
   "Assume that the floating-point extension facility is installed"
 >;
 
-def : Processor<"z10",   NoItineraries, []>;
-def : Processor<"z196",  NoItineraries,
+def : Processor<"generic", NoItineraries, []>;
+def : Processor<"z10", NoItineraries, []>;
+def : Processor<"z196", NoItineraries,
                 [FeatureDistinctOps, FeatureLoadStoreOnCond, FeatureHighWord,
                  FeatureFPExtension]>;
 def : Processor<"zEC12", NoItineraries,
                 [FeatureDistinctOps, FeatureLoadStoreOnCond, FeatureHighWord,
                  FeatureFPExtension]>;
 def : Processor<"zEC12", NoItineraries,
index b6a63923cf5c863bf65ce686a8843a292c2df89c..474192099f22fc6120e2d8d3b9ef36d9643a8b10 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SystemZSubtarget.h"
 #include "llvm/IR/GlobalValue.h"
 
 #include "SystemZSubtarget.h"
 #include "llvm/IR/GlobalValue.h"
+#include "llvm/Support/Host.h"
 #include "MCTargetDesc/SystemZMCTargetDesc.h"
 
 #define GET_SUBTARGETINFO_TARGET_DESC
 #include "MCTargetDesc/SystemZMCTargetDesc.h"
 
 #define GET_SUBTARGETINFO_TARGET_DESC
@@ -25,7 +26,11 @@ SystemZSubtarget::SystemZSubtarget(const std::string &TT,
     TargetTriple(TT) {
   std::string CPUName = CPU;
   if (CPUName.empty())
     TargetTriple(TT) {
   std::string CPUName = CPU;
   if (CPUName.empty())
-    CPUName = "z10";
+    CPUName = "generic";
+#if defined(__linux__) && defined(__s390x__)
+  if (CPUName == "generic")
+    CPUName = sys::getHostCPUName();
+#endif
 
   // Parse features string.
   ParseSubtargetFeatures(CPUName, FS);
 
   // Parse features string.
   ParseSubtargetFeatures(CPUName, FS);
index 418f156b24aec6983d2d0395e0317bd8a7f6118e..f2152c6f28bc9ef542b027d27a2189f4ee4a2343 100644 (file)
@@ -1,6 +1,7 @@
-; Test 32-bit atomic minimum and maximum.
+; Test 32-bit atomic minimum and maximum.  Here we match the z10 versions,
+; which can't use LOCR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Check signed minium.
 define i32 @f1(i32 %dummy, i32 *%src, i32 %b) {
 
 ; Check signed minium.
 define i32 @f1(i32 %dummy, i32 *%src, i32 %b) {
index 9d26d28bc1df4e8f8684b89e1052e411f20271ab..037eb1aa9367c37a374d692da0f03e07d08884bc 100644 (file)
@@ -1,6 +1,7 @@
-; Test 64-bit atomic minimum and maximum.
+; Test 64-bit atomic minimum and maximum.  Here we match the z10 versions,
+; which can't use LOCGR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Check signed minium.
 define i64 @f1(i64 %dummy, i64 *%src, i64 %b) {
 
 ; Check signed minium.
 define i64 @f1(i64 %dummy, i64 *%src, i64 %b) {
index 5b559340198f05db50d0b2751a5d8dd17fae93ac..d55ea2133e8f40041dca9278fe260b36876e1a83 100644 (file)
@@ -1,6 +1,7 @@
-; Test 8-bit conditional stores that are presented as selects.
+; Test 8-bit conditional stores that are presented as selects.  The volatile
+; tests require z10, which use a branch instead of a LOCR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare void @foo(i8 *)
 
 
 declare void @foo(i8 *)
 
index 9e188437a5f9726a713d4135cda6d06c37e245b6..91bc4860b384840439d0fca1ef6a3e44ea9b5235 100644 (file)
@@ -1,6 +1,7 @@
-; Test 16-bit conditional stores that are presented as selects.
+; Test 16-bit conditional stores that are presented as selects.  The volatile
+; tests require z10, which use a branch instead of a LOCR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare void @foo(i16 *)
 
 
 declare void @foo(i16 *)
 
index 7f194014f92b686f32895e3b61d5957b4d0d2964..d7c0cce9c2a5a193bafe865f8066e19c2b2f389b 100644 (file)
@@ -1,6 +1,7 @@
-; Test 32-bit floating-point comparison.
+; Test 32-bit floating-point comparison.  The tests assume a z10 implementation
+; of select, using conditional branches rather than LOCGR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare float @foo()
 
 
 declare float @foo()
 
index 1cd6da8c770852c74969fce1e13655c7040cb9c3..c61f04ed244e3b971dfda8341a3f5031fc0940d9 100644 (file)
@@ -1,6 +1,7 @@
-; Test 64-bit floating-point comparison.
+; Test 64-bit floating-point comparison.  The tests assume a z10 implementation
+; of select, using conditional branches rather than LOCGR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare double @foo()
 
 
 declare double @foo()
 
index 0f71f4e3a921d266a4ee466821102987b656f82c..e777d00c968734f4532cd630ecafa0ca3a5aa88a 100644 (file)
@@ -1,6 +1,7 @@
-; Test 128-bit floating-point comparison.
+; Test 128-bit floating-point comparison.  The tests assume a z10 implementation
+; of select, using conditional branches rather than LOCGR.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; There is no memory form of 128-bit comparison.
 define i64 @f1(i64 %a, i64 %b, fp128 *%ptr, float %f2) {
 
 ; There is no memory form of 128-bit comparison.
 define i64 @f1(i64 %a, i64 %b, fp128 *%ptr, float %f2) {
index 6f9da9ab69d46113d49caa65dcf6ee1a457e5a24..505ee8d37a4ebfea5a06c6cc1b0168442e35383a 100644 (file)
@@ -1,6 +1,7 @@
-; Test moves between FPRs and GPRs.
+; Test moves between FPRs and GPRs.  The 32-bit cases test the z10
+; implementation, which has no high-word support.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare i64 @foo()
 declare double @bar()
 
 declare i64 @foo()
 declare double @bar()
index 60bff508d93a795f7fd83d414d2b0e72ff5f9608..393850fbf6179483006d8f50ccd2fdd4a0eddf8b 100644 (file)
@@ -1,8 +1,11 @@
 ; Test the handling of base + 12-bit displacement addresses for large frames,
 ; Test the handling of base + 12-bit displacement addresses for large frames,
-; in cases where no 20-bit form exists.
+; in cases where no 20-bit form exists.  The tests here assume z10 register
+; pressure, without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefix=CHECK-NOFP %s
-; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | \
+; RUN:   FileCheck -check-prefix=CHECK-NOFP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -disable-fp-elim | \
+; RUN:   FileCheck -check-prefix=CHECK-FP %s
 
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
 
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
index 22a45eecf300087f81b4946dd9ed76d7e1d74278..3b48179c40b6ec9b9e7bb2cfaae71119c5a465cb 100644 (file)
@@ -1,9 +1,13 @@
 ; Test the handling of base + displacement addresses for large frames,
 ; in cases where both 12-bit and 20-bit displacements are allowed.
 ; Test the handling of base + displacement addresses for large frames,
 ; in cases where both 12-bit and 20-bit displacements are allowed.
+; The tests here assume z10 register pressure, without the high words
+; being available.
+;
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | \
+; RUN:   FileCheck -check-prefix=CHECK-NOFP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -disable-fp-elim | \
+; RUN:   FileCheck -check-prefix=CHECK-FP %s
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefix=CHECK-NOFP %s
-; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
-
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
 ; the frame itself.  In some cases the test is only possible if two
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
 ; the frame itself.  In some cases the test is only possible if two
index d8b291d01784763d1199765e1884f079dbcd74e2..b3c95e73c1af6036a64f62c83a9a2ea9f653996d 100644 (file)
@@ -1,8 +1,11 @@
 ; Test the handling of base + index + 12-bit displacement addresses for
 ; Test the handling of base + index + 12-bit displacement addresses for
-; large frames, in cases where no 20-bit form exists.
+; large frames, in cases where no 20-bit form exists.  The tests here
+; assume z10 register pressure, without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefix=CHECK-NOFP %s
-; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | \
+; RUN:   FileCheck -check-prefix=CHECK-NOFP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -disable-fp-elim | \
+; RUN:   FileCheck -check-prefix=CHECK-FP %s
 
 declare void @foo(float *%ptr1, float *%ptr2)
 
 
 declare void @foo(float *%ptr1, float *%ptr2)
 
index 9f43b4947f09892c3f11e8a8b768f8959623eb35..f7e2dfa3514947ee7cf2d951b062631919a9c06e 100644 (file)
@@ -1,8 +1,12 @@
 ; Test the handling of base + index + displacement addresses for large frames,
 ; in cases where both 12-bit and 20-bit displacements are allowed.
 ; Test the handling of base + index + displacement addresses for large frames,
 ; in cases where both 12-bit and 20-bit displacements are allowed.
+; The tests here assume z10 register pressure, without the high words
+; being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefix=CHECK-NOFP %s
-; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | \
+; RUN:   FileCheck -check-prefix=CHECK-NOFP %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -disable-fp-elim | \
+; RUN:   FileCheck -check-prefix=CHECK-FP %s
 
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
 
 ; This file tests what happens when a displacement is converted from
 ; being relative to the start of a frame object to being relative to
index 57d6f7d4db278d9777120a4cd543c4b7e5a7d417..21dfc1238a13a7a9caf54f3c29f1517b654cea25 100644 (file)
@@ -1,6 +1,7 @@
-; Test spilling of GPRs.
+; Test spilling of GPRs.  The tests here assume z10 register pressure,
+; without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; We need to allocate a 4-byte spill slot, rounded to 8 bytes.  The frame
 ; size should be exactly 160 + 8 = 168.
 
 ; We need to allocate a 4-byte spill slot, rounded to 8 bytes.  The frame
 ; size should be exactly 160 + 8 = 168.
index 212334e83c0acabd0b1c19e59a6dd19d7d583eca..679c206094f3bf3e07f27a87c83e94ea6f9b3220 100644 (file)
@@ -1,6 +1,7 @@
-; Test 32-bit additions of constants to memory.
+; Test 32-bit additions of constants to memory.  The tests here
+; assume z10 register pressure, without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Check additions of 1.
 define void @f1(i32 *%ptr) {
 
 ; Check additions of 1.
 define void @f1(i32 *%ptr) {
index 18cfd4a87faf5429b86078fc3c2e51d52fbd128c..dd7760d08cf53a6d80500896852347270e0e11ec 100644 (file)
@@ -1,6 +1,7 @@
-; Test zero extensions from a byte to an i32.
+; Test zero extensions from a byte to an i32.    The tests here
+; assume z10 register pressure, without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Test register extension, starting with an i32.
 define i32 @f1(i32 %a) {
 
 ; Test register extension, starting with an i32.
 define i32 @f1(i32 %a) {
index 9c95badb2c097431126fdeb48100f8416d64ce0b..33860d12270fd78b091337359b38bb074cedf9a0 100644 (file)
@@ -1,6 +1,7 @@
-; Test zero extensions from a halfword to an i32.
+; Test zero extensions from a halfword to an i32.  The tests here
+; assume z10 register pressure, without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Test register extension, starting with an i32.
 define i32 @f1(i32 %a) {
 
 ; Test register extension, starting with an i32.
 define i32 @f1(i32 %a) {
index 85de6dc6af2c2c9af186b0305725d8556c8b1df8..8a5d4874f686dcf3b48e67de5c7f45f9ae55e3b4 100644 (file)
@@ -1,6 +1,7 @@
 ; Test sequences that can use RISBG with a zeroed first operand.
 ; Test sequences that can use RISBG with a zeroed first operand.
+; The tests here assume that RISBLG isn't available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Test an extraction of bit 0 from a right-shifted value.
 define i32 @f1(i32 %foo) {
 
 ; Test an extraction of bit 0 from a right-shifted value.
 define i32 @f1(i32 %foo) {
index 5313215f118f1d78ea159a893879a98c07115324..4626760fa25bce7e848e808b329a7934062d5557 100644 (file)
@@ -1,6 +1,7 @@
-; Test SETCC for every integer condition.
+; Test SETCC for every integer condition.  The tests here assume that
+; RISBLG isn't available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Test CC in { 0 }, with 3 don't care.
 define i32 @f1(i32 %a, i32 %b) {
 
 ; Test CC in { 0 }, with 3 don't care.
 define i32 @f1(i32 %a, i32 %b) {
index 178822277d1ac7285309aa6c8c85f6984c4204ba..6a7be47a92b7c9471e9590e9f6c78b822767e6f1 100644 (file)
@@ -1,6 +1,7 @@
-; Test SETCC for every floating-point condition.
+; Test SETCC for every floating-point condition.  The tests here assume that
+; RISBLG isn't available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 ; Test CC in { 0 }
 define i32 @f1(float %a, float %b) {
 
 ; Test CC in { 0 }
 define i32 @f1(float %a, float %b) {
index 9de89d69b993a9aa171925ffee8ded2727e1f897..ca64a88f2a0d6f1e47d212f7256deb0c336a0955 100644 (file)
@@ -1,6 +1,7 @@
-; Test spilling using MVC.
+; Test spilling using MVC.  The tests here assume z10 register pressure,
+; without the high words being available.
 ;
 ;
-; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 
 declare void @foo()
 
 
 declare void @foo()