summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-06-19 11:28:59 +0000
committerClement Courbet <courbet@google.com>2018-06-19 11:28:59 +0000
commit44b4c54e2698657d57ffcbbd9c26cb88c1a2cce9 (patch)
treeb4c67389f321642047335b0e4d21f352d9c3e664 /llvm/tools/llvm-exegesis/lib
parent46751785ee474bedf6e607913beb9e5104783237 (diff)
downloadbcm5719-llvm-44b4c54e2698657d57ffcbbd9c26cb88c1a2cce9.tar.gz
bcm5719-llvm-44b4c54e2698657d57ffcbbd9c26cb88c1a2cce9.zip
Re-land r335038 "[llvm-exegesis] A mechanism to add target-specific functionality.""
Fix typo: LLVM_NATIVE_ARCH -> LLVM_EXEGESIS_NATIVE_ARCH. llvm-svn: 335041
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib')
-rw-r--r--llvm/tools/llvm-exegesis/lib/CMakeLists.txt5
-rw-r--r--llvm/tools/llvm-exegesis/lib/Target.cpp36
-rw-r--r--llvm/tools/llvm-exegesis/lib/Target.h41
-rw-r--r--llvm/tools/llvm-exegesis/lib/Uops.cpp3
-rw-r--r--llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt13
-rw-r--r--llvm/tools/llvm-exegesis/lib/X86/LLVMBuild.txt22
-rw-r--r--llvm/tools/llvm-exegesis/lib/X86/Target.cpp33
7 files changed, 151 insertions, 2 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
index 10cf16af95e..96c6c91ece8 100644
--- a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,3 +1,7 @@
+if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
+ add_subdirectory(X86)
+endif()
+
add_library(LLVMExegesis
STATIC
Analysis.cpp
@@ -10,6 +14,7 @@ add_library(LLVMExegesis
MCInstrDescView.cpp
PerfHelper.cpp
RegisterAliasing.cpp
+ Target.cpp
Uops.cpp
X86.cpp
)
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
new file mode 100644
index 00000000000..1b11f93e353
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -0,0 +1,36 @@
+//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "Target.h"
+
+namespace exegesis {
+
+ExegesisTarget::~ExegesisTarget() {} // anchor.
+
+static ExegesisTarget* FirstTarget = nullptr;
+
+const ExegesisTarget* ExegesisTarget::lookup(llvm::StringRef TT) {
+ const llvm::Triple::ArchType Arch = llvm::Triple(TT).getArch();
+ for (const ExegesisTarget* T = FirstTarget; T != nullptr; T = T->Next) {
+ if (T->matchesArch(Arch)) return T;
+ }
+ return nullptr;
+}
+
+void ExegesisTarget::registerTarget(ExegesisTarget *Target){
+ if (FirstTarget == nullptr) {
+ FirstTarget = Target;
+ return;
+ }
+ assert(Target->Next == nullptr && "target has already been registered");
+ if (Target->Next != nullptr)
+ return;
+ Target->Next = FirstTarget;
+ FirstTarget = Target;
+}
+} // namespace exegesis
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
new file mode 100644
index 00000000000..3db495276b4
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -0,0 +1,41 @@
+//===-- Target.h ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+///
+/// Classes that handle the creation of target-specific objects. This is
+/// similar to llvm::Target/TargetRegistry.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
+#define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
+
+#include "llvm/ADT/Triple.h"
+
+namespace exegesis {
+
+class ExegesisTarget {
+public:
+ // Returns the ExegesisTarget for the given triple or nullptr if the target
+ // does not exist.
+ static const ExegesisTarget* lookup(llvm::StringRef TT);
+ // Registers a target. Not thread safe.
+ static void registerTarget(ExegesisTarget *T);
+
+ ~ExegesisTarget();
+
+private:
+ virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
+ const ExegesisTarget* Next = nullptr;
+};
+
+} // namespace exegesis
+
+#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
diff --git a/llvm/tools/llvm-exegesis/lib/Uops.cpp b/llvm/tools/llvm-exegesis/lib/Uops.cpp
index 4c6edaad32a..581b855cadf 100644
--- a/llvm/tools/llvm-exegesis/lib/Uops.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Uops.cpp
@@ -97,8 +97,7 @@ UopsBenchmarkRunner::isInfeasible(const llvm::MCInstrDesc &MCInstrDesc) const {
return llvm::make_error<BenchmarkFailure>(
"Infeasible : has unknown operands");
if (llvm::any_of(MCInstrDesc.operands(), hasMemoryOperand))
- return llvm::make_error<BenchmarkFailure>(
- "Infeasible : has memory operands");
+ return llvm::make_error<BenchmarkFailure>("Infeasible : has memory operands");
return llvm::Error::success();
}
diff --git a/llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt b/llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
new file mode 100644
index 00000000000..28dcff50ed7
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_library(LLVMExegesisX86
+ STATIC
+ Target.cpp
+ )
+
+llvm_update_compile_flags(LLVMExegesisX86)
+llvm_map_components_to_libnames(libs
+ X86
+ Exegesis
+ )
+
+target_link_libraries(LLVMExegesisX86 ${libs})
+set_target_properties(LLVMExegesisX86 PROPERTIES FOLDER "Libraries")
diff --git a/llvm/tools/llvm-exegesis/lib/X86/LLVMBuild.txt b/llvm/tools/llvm-exegesis/lib/X86/LLVMBuild.txt
new file mode 100644
index 00000000000..2a7ddca81e7
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/X86/LLVMBuild.txt
@@ -0,0 +1,22 @@
+;===- ./tools/llvm-exegesis/lib/X86LLVMBuild.txt ---------------*- Conf -*--===;
+;
+; The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Library
+name = ExegesisX86
+parent = Libraries
+required_libraries = X86
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
new file mode 100644
index 00000000000..a37387bf5e7
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -0,0 +1,33 @@
+//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "../Target.h"
+
+namespace exegesis {
+
+namespace {
+
+class ExegesisX86Target : public ExegesisTarget {
+private:
+ bool matchesArch(llvm::Triple::ArchType Arch) const override {
+ return Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::x86;
+ }
+};
+
+} // namespace
+
+static ExegesisTarget* getTheExegesisX86Target() {
+ static ExegesisX86Target Target;
+ return &Target;
+}
+
+void InitializeX86ExegesisTarget() {
+ ExegesisTarget::registerTarget(getTheExegesisX86Target());
+}
+
+} // namespace exegesis
OpenPOWER on IntegriCloud