[PATCH] D44861: [C-API] Add LLVMGetHostCPU{Name,Features}.

whitequark via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 15:46:34 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL329856: [LLVM-C] Add LLVMGetHostCPU{Name,Features}. (authored by whitequark, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44861?vs=139693&id=142085#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44861

Files:
  llvm/trunk/include/llvm-c/TargetMachine.h
  llvm/trunk/lib/Target/TargetMachineC.cpp


Index: llvm/trunk/lib/Target/TargetMachineC.cpp
===================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp
+++ llvm/trunk/lib/Target/TargetMachineC.cpp
@@ -18,6 +18,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
+#include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/Host.h"
@@ -237,6 +238,21 @@
   return strdup(sys::getDefaultTargetTriple().c_str());
 }
 
+char *LLVMGetHostCPUName(void) {
+  return strdup(sys::getHostCPUName().data());
+}
+
+char *LLVMGetHostCPUFeatures(void) {
+  SubtargetFeatures Features;
+  StringMap<bool> HostFeatures;
+
+  if (sys::getHostCPUFeatures(HostFeatures))
+    for (auto &F : HostFeatures)
+      Features.AddFeature(F.first(), F.second);
+
+  return strdup(Features.getString().c_str());
+}
+
 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) {
   unwrap(PM)->add(
       createTargetTransformInfoWrapperPass(unwrap(T)->getTargetIRAnalysis()));
Index: llvm/trunk/include/llvm-c/TargetMachine.h
===================================================================
--- llvm/trunk/include/llvm-c/TargetMachine.h
+++ llvm/trunk/include/llvm-c/TargetMachine.h
@@ -137,6 +137,14 @@
   disposed with LLVMDisposeMessage. */
 char* LLVMGetDefaultTargetTriple(void);
 
+/** Get the host CPU as a string. The result needs to be disposed with
+  LLVMDisposeMessage. */
+char* LLVMGetHostCPUName(void);
+
+/** Get the host CPU's features as a string. The result needs to be disposed
+  with LLVMDisposeMessage. */
+char* LLVMGetHostCPUFeatures(void);
+
 /** Adds the target-specific analysis passes to the pass manager. */
 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44861.142085.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180411/886ddd7c/attachment.bin>


More information about the llvm-commits mailing list