[PATCH] D95966: [AIX][support] Implement getHostCPUName

David Tenty via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 08:01:46 PST 2021


daltenty updated this revision to Diff 321433.
daltenty added a comment.

- Use systemcfg interfaces instead. Move the getsysttype call to the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95966

Files:
  llvm/lib/Support/Host.cpp
  llvm/unittests/Support/Host.cpp


Index: llvm/unittests/Support/Host.cpp
===================================================================
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -431,4 +431,25 @@
   ASSERT_EQ(std::tie(SystemMajor, SystemMinor),
             std::tie(TargetMajor, TargetMinor));
 }
+
+TEST_F(HostTest, AIXHostCPUDetect) {
+  // return a value base on the  current processor implementation mode.
+  const char *ExePath = "/usr/sbin/getsystype";
+  StringRef argv[] = {ExePath, "-i"};
+  std::unique_ptr<char[]> Buffer;
+  off_t Size;
+  ASSERT_EQ(runAndGetCommandOutput(ExePath, argv, Buffer, Size), true);
+  StringRef CPU(Buffer.get(), Size);
+  StringRef MCPU = StringSwitch<const char *>(CPU)
+                       .Case("POWER 4\n", "pwr4")
+                       .Case("POWER 5\n", "pwr5")
+                       .Case("POWER 6\n", "pwr6")
+                       .Case("POWER 7\n", "pwr7")
+                       .Case("POWER 8\n", "pwr8")
+                       .Case("POWER 9\n", "pwr9")
+                       .Case("POWER 10\n", "pwr10")
+                       .Default("unknown");
+
+  EXPECT_EQ(sys::getHostCPUName(), MCPU);
+}
 #endif
Index: llvm/lib/Support/Host.cpp
===================================================================
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/X86TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include <assert.h>
@@ -43,6 +44,9 @@
 #include <mach/mach_host.h>
 #include <mach/machine.h>
 #endif
+#ifdef _AIX
+#include <sys/systemcfg.h>
+#endif
 
 #define DEBUG_TYPE "host-detection"
 
@@ -1217,6 +1221,38 @@
 
   return "generic";
 }
+#elif defined(_AIX)
+namespace {
+enum PowerCPUImpl {
+  POWER4 = POWER_4,
+  POWER5 = POWER_5,
+  POWER6 = POWER_6,
+  POWER7 = POWER_7,
+  POWER8 = POWER_8,
+  POWER9 = POWER_9,
+  POWER10 = 0x40000
+};
+}
+StringRef sys::getHostCPUName() {
+  switch (_system_configuration.implementation) {
+  case PowerCPUImpl::POWER4:
+    return "pwr4";
+  case PowerCPUImpl::POWER5:
+    return "pwr5";
+  case PowerCPUImpl::POWER6:
+    return "pwr6";
+  case PowerCPUImpl::POWER7:
+    return "pwr7";
+  case PowerCPUImpl::POWER8:
+    return "pwr8";
+  case PowerCPUImpl::POWER9:
+    return "pwr9";
+  case PowerCPUImpl::POWER10:
+    return "pwr10";
+  default:
+    return "generic";
+  }
+}
 #else
 StringRef sys::getHostCPUName() { return "generic"; }
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95966.321433.patch
Type: text/x-patch
Size: 2585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/7a2c1188/attachment.bin>


More information about the llvm-commits mailing list