From 98716f882cf08f521dc8e57693d224006e3f3b68 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 4 Oct 2017 23:38:46 -0700
Subject: [PATCH 2/6] [C-API] WIP: Add LLVMGetHostCPUName().

---
 include/llvm-c/TargetMachine.h | 4 ++++
 lib/Target/TargetMachineC.cpp  | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/llvm-c/TargetMachine.h b/include/llvm-c/TargetMachine.h
index f4f7f7698c4..44f6b8babd1 100644
--- a/include/llvm-c/TargetMachine.h
+++ b/include/llvm-c/TargetMachine.h
@@ -137,6 +137,10 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleR
   disposed with LLVMDisposeMessage. */
 char* LLVMGetDefaultTargetTriple(void);
 
+/** Get the host CPU as a string. The result needs to be disposed with
+  LLVMDisposeMessage. */
+char* LLVMGetHostCPUName(void);
+
 /** Adds the target-specific analysis passes to the pass manager. */
 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
 
diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp
index 210375ff828..63d0bbf74bc 100644
--- a/lib/Target/TargetMachineC.cpp
+++ b/lib/Target/TargetMachineC.cpp
@@ -238,6 +238,14 @@ char *LLVMGetDefaultTargetTriple(void) {
   return strdup(sys::getDefaultTargetTriple().c_str());
 }
 
+/** Get the host CPU as a string. The result needs to be disposed with
+  LLVMDisposeMessage. */
+char* LLVMGetHostCPUName(void)
+{
+  /* XXX: verify it's null terminated */
+  return strdup(sys::getHostCPUName().data());
+}
+
 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) {
   unwrap(PM)->add(
       createTargetTransformInfoWrapperPass(unwrap(T)->getTargetIRAnalysis()));
-- 
2.14.1.536.g6867272d5b.dirty

