1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[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

llvm-svn: 335117
This commit is contained in:
Clement Courbet 2018-06-20 11:54:35 +00:00
parent 99ba2cc970
commit 5d00aadd9a
6 changed files with 33 additions and 6 deletions

View File

@ -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<llvm::LLVMTargetMachine> TM,
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<llvm::LLVMTargetMachine> TM,
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.

View File

@ -14,10 +14,10 @@ ExegesisTarget::~ExegesisTarget() {} // anchor.
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;
}

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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