forked from OSchip/llvm-project
[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:
parent
bd1077e2bc
commit
6fd00e32e5
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue