[llvm] r335117 - [llvm-exegesis] Add mechanism to add target-specific passes.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 20 04:54:36 PDT 2018
Author: courbet
Date: Wed Jun 20 04:54:35 2018
New Revision: 335117
URL: http://llvm.org/viewvc/llvm-project?rev=335117&view=rev
Log:
[llvm-exegesis] Add mechanism to add target-specific passes.
Summary:
createX86FloatingPointStackifierPass is disabled until we handle
TracksLiveness correctly.
Reviewers: gchatelet
Subscribers: mgorny, tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D48360
Modified:
llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp
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/Target.cpp
llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Modified: llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp?rev=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp Wed Jun 20 04:54:35 2018
@@ -9,6 +9,7 @@
#include "Assembler.h"
+#include "Target.h"
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -139,6 +140,8 @@ void assembleToStream(std::unique_ptr<ll
auto &Properties = MF.getProperties();
Properties.set(llvm::MachineFunctionProperties::Property::NoVRegs);
Properties.reset(llvm::MachineFunctionProperties::Property::IsSSA);
+ // FIXME: Remove this when we assign all used registers as config step. This
+ // essentially disables checks that used registers are def'ed somewhere.
Properties.reset(llvm::MachineFunctionProperties::Property::TracksLiveness);
// prologue/epilogue pass needs the reserved registers to be frozen, this
// is usually done by the SelectionDAGISel pass.
@@ -158,6 +161,11 @@ void assembleToStream(std::unique_ptr<ll
PM.add(TPC);
PM.add(MMI.release());
TPC->printAndVerify("MachineFunctionGenerator::assemble");
+ // Add target-specific passes.
+ if (const auto *ET = ExegesisTarget::lookup(TM->getTargetTriple())) {
+ ET->addTargetSpecificPasses(PM);
+ TPC->printAndVerify("After ExegesisTarget::addTargetSpecificPasses");
+ }
// Adding the following passes:
// - machineverifier: checks that the MachineFunction is well formed.
// - prologepilog: saves and restore callee saved registers.
Modified: llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.cpp?rev=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.cpp Wed Jun 20 04:54:35 2018
@@ -14,10 +14,10 @@ ExegesisTarget::~ExegesisTarget() {} //
static ExegesisTarget* FirstTarget = nullptr;
-const ExegesisTarget* ExegesisTarget::lookup(llvm::StringRef TT) {
- const llvm::Triple::ArchType Arch = llvm::Triple(TT).getArch();
+const ExegesisTarget *ExegesisTarget::lookup(llvm::Triple TT) {
for (const ExegesisTarget* T = FirstTarget; T != nullptr; T = T->Next) {
- if (T->matchesArch(Arch)) return T;
+ if (T->matchesArch(TT.getArch()))
+ return T;
}
return nullptr;
}
Modified: llvm/trunk/tools/llvm-exegesis/lib/Target.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.h?rev=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.h Wed Jun 20 04:54:35 2018
@@ -18,14 +18,19 @@
#define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
#include "llvm/ADT/Triple.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/LegacyPassManager.h"
namespace exegesis {
class ExegesisTarget {
public:
+ // Targets can use this to add target-specific passes in assembleToStream();
+ virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
+
// Returns the ExegesisTarget for the given triple or nullptr if the target
// does not exist.
- static const ExegesisTarget* lookup(llvm::StringRef TT);
+ static const ExegesisTarget *lookup(llvm::Triple TT);
// Registers a target. Not thread safe.
static void registerTarget(ExegesisTarget *T);
Modified: 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=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/CMakeLists.txt Wed Jun 20 04:54:35 2018
@@ -1,3 +1,8 @@
+include_directories(
+ ${LLVM_MAIN_SRC_DIR}/lib/Target/X86
+ ${LLVM_BINARY_DIR}/lib/Target/X86
+ )
+
add_library(LLVMExegesisX86
STATIC
Target.cpp
Modified: 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=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp Wed Jun 20 04:54:35 2018
@@ -8,12 +8,20 @@
//===----------------------------------------------------------------------===//
#include "../Target.h"
+#include "X86.h"
+
namespace exegesis {
namespace {
class ExegesisX86Target : public ExegesisTarget {
-private:
+ void addTargetSpecificPasses(llvm::PassManagerBase &PM) const override {
+ // Lowers FP pseudo-instructions, e.g. ABS_Fp32 -> ABS_F.
+ // FIXME: Enable when the exegesis assembler no longer does
+ // Properties.reset(TracksLiveness);
+ // PM.add(llvm::createX86FloatingPointStackifierPass());
+ }
+
bool matchesArch(llvm::Triple::ArchType Arch) const override {
return Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::x86;
}
Modified: 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=335117&r1=335116&r2=335117&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp Wed Jun 20 04:54:35 2018
@@ -20,7 +20,8 @@ protected:
};
TEST_F(X86TargetTest, Lookup) {
- EXPECT_THAT(ExegesisTarget::lookup("x86_64-unknown-linux"), NotNull());
+ EXPECT_THAT(ExegesisTarget::lookup(llvm::Triple("x86_64-unknown-linux")),
+ NotNull());
}
} // namespace
More information about the llvm-commits
mailing list