[llvm] r335041 - Re-land r335038 "[llvm-exegesis] A mechanism to add target-specific functionality.""
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 19 04:28:59 PDT 2018
Author: courbet
Date: Tue Jun 19 04:28:59 2018
New Revision: 335041
URL: http://llvm.org/viewvc/llvm-project?rev=335041&view=rev
Log:
Re-land r335038 "[llvm-exegesis] A mechanism to add target-specific functionality.""
Fix typo: LLVM_NATIVE_ARCH -> LLVM_EXEGESIS_NATIVE_ARCH.
Added:
llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
llvm/trunk/tools/llvm-exegesis/lib/Target.h
llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt
llvm/trunk/tools/llvm-exegesis/lib/X86/LLVMBuild.txt
llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Modified:
llvm/trunk/tools/llvm-exegesis/CMakeLists.txt
llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt
llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
llvm/trunk/unittests/tools/llvm-exegesis/X86/CMakeLists.txt
Modified: llvm/trunk/tools/llvm-exegesis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/CMakeLists.txt?rev=335041&r1=335040&r2=335041&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-exegesis/CMakeLists.txt Tue Jun 19 04:28:59 2018
@@ -1,3 +1,4 @@
+
set(LLVM_LINK_COMPONENTS
Support
native
@@ -8,4 +9,18 @@ add_llvm_tool(llvm-exegesis
)
add_subdirectory(lib)
-target_link_libraries(llvm-exegesis PRIVATE LLVMExegesis)
+
+# Link the native exegesis target if compiled and on the right host.
+if ((LLVM_TARGETS_TO_BUILD MATCHES "X86") AND ("${LLVM_NATIVE_ARCH}" STREQUAL "X86"))
+ set(LLVM_EXEGESIS_NATIVE_ARCH "X86")
+endif()
+
+if (LLVM_EXEGESIS_NATIVE_ARCH)
+ set(LLVM_EXEGESIS_NATIVE_TARGET "LLVMExegesis${LLVM_EXEGESIS_NATIVE_ARCH}")
+ set_source_files_properties(llvm-exegesis.cpp PROPERTIES COMPILE_FLAGS "-DLLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET=Initialize${LLVM_EXEGESIS_NATIVE_ARCH}ExegesisTarget")
+endif()
+
+target_link_libraries(llvm-exegesis PRIVATE
+ LLVMExegesis
+ ${LLVM_EXEGESIS_NATIVE_TARGET}
+ )
Modified: llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt?rev=335041&r1=335040&r2=335041&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt Tue Jun 19 04:28:59 2018
@@ -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
)
Added: llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.cpp?rev=335041&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.cpp (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.cpp Tue Jun 19 04:28:59 2018
@@ -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
Added: llvm/trunk/tools/llvm-exegesis/lib/Target.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.h?rev=335041&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.h (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.h Tue Jun 19 04:28:59 2018
@@ -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
Modified: llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp?rev=335041&r1=335040&r2=335041&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp Tue Jun 19 04:28:59 2018
@@ -97,8 +97,7 @@ UopsBenchmarkRunner::isInfeasible(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();
}
Added: llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt?rev=335041&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt Tue Jun 19 04:28:59 2018
@@ -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")
Added: llvm/trunk/tools/llvm-exegesis/lib/X86/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/X86/LLVMBuild.txt?rev=335041&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/LLVMBuild.txt (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/LLVMBuild.txt Tue Jun 19 04:28:59 2018
@@ -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
Added: llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp?rev=335041&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp Tue Jun 19 04:28:59 2018
@@ -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
Modified: llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp?rev=335041&r1=335040&r2=335041&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp Tue Jun 19 04:28:59 2018
@@ -86,6 +86,10 @@ namespace exegesis {
static llvm::ExitOnError ExitOnErr;
+#ifdef LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET
+void LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET();
+#endif
+
static unsigned GetOpcodeOrDie(const llvm::MCInstrInfo &MCInstrInfo) {
if (OpcodeName.empty() && (OpcodeIndex == 0))
llvm::report_fatal_error(
@@ -120,6 +124,9 @@ void benchmarkMain() {
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
+#ifdef LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET
+ LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET();
+#endif
// FIXME: Target-specific filter.
X86Filter Filter;
Modified: llvm/trunk/unittests/tools/llvm-exegesis/X86/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/X86/CMakeLists.txt?rev=335041&r1=335040&r2=335041&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/CMakeLists.txt (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/CMakeLists.txt Tue Jun 19 04:28:59 2018
@@ -18,5 +18,8 @@ add_llvm_unittest(LLVMExegesisX86Tests
AnalysisTest.cpp
SnippetGeneratorTest.cpp
RegisterAliasingTest.cpp
+ TargetTest.cpp
)
-target_link_libraries(LLVMExegesisX86Tests PRIVATE LLVMExegesis)
+target_link_libraries(LLVMExegesisX86Tests PRIVATE
+ LLVMExegesis
+ LLVMExegesisX86)
Added: llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp?rev=335041&view=auto
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp (added)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp Tue Jun 19 04:28:59 2018
@@ -0,0 +1,27 @@
+#include "Target.h"
+
+#include <cassert>
+#include <memory>
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace exegesis {
+
+void InitializeX86ExegesisTarget();
+
+namespace {
+
+using testing::NotNull;
+
+class X86TargetTest : public ::testing::Test {
+protected:
+ static void SetUpTestCase() { InitializeX86ExegesisTarget(); }
+};
+
+TEST_F(X86TargetTest, Lookup) {
+ EXPECT_THAT(ExegesisTarget::lookup("x86_64-unknown-linux"), NotNull());
+}
+
+} // namespace
+} // namespace exegesis
More information about the llvm-commits
mailing list