summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetMachineC.cpp
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2018-04-11 22:40:42 +0000
committerwhitequark <whitequark@whitequark.org>2018-04-11 22:40:42 +0000
commit1ae61a612633331ba2bc6a13fc9703de5590fa29 (patch)
tree149ea6c8dc68e7bf2c5ea3d87711eedab9c77a41 /llvm/lib/Target/TargetMachineC.cpp
parenta557852719821f82025fe876607880058799c8af (diff)
downloadbcm5719-llvm-1ae61a612633331ba2bc6a13fc9703de5590fa29.tar.gz
bcm5719-llvm-1ae61a612633331ba2bc6a13fc9703de5590fa29.zip
[LLVM-C] Add LLVMGetHostCPU{Name,Features}.
Without these functions it's hard to create a TargetMachine for Orc JIT that creates efficient native code. It's not sufficient to just expose LLVMGetHostCPUName(), because for some CPUs there's fewer features actually available than the CPU name indicates (e.g. AVX might be missing on some CPUs identified as Skylake). Differential Revision: https://reviews.llvm.org/D44861 llvm-svn: 329856
Diffstat (limited to 'llvm/lib/Target/TargetMachineC.cpp')
-rw-r--r--llvm/lib/Target/TargetMachineC.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index d6016efa246..d43124d7123 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/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 @@ char *LLVMGetDefaultTargetTriple(void) {
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()));
OpenPOWER on IntegriCloud