Skip to content

Commit

Permalink
[SystemZ] Properly register machine passes.
Browse files Browse the repository at this point in the history
Registering the passes enables use of -stop-before=/-stop-after
options.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D117823
  • Loading branch information
redstar committed Jan 21, 2022
1 parent 7e3bcae commit d5ae039
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
10 changes: 10 additions & 0 deletions llvm/lib/Target/SystemZ/SystemZ.h
Expand Up @@ -20,6 +20,7 @@
namespace llvm {
class SystemZTargetMachine;
class FunctionPass;
class PassRegistry;

namespace SystemZ {
// Condition-code mask values.
Expand Down Expand Up @@ -196,6 +197,15 @@ FunctionPass *createSystemZLDCleanupPass(SystemZTargetMachine &TM);
FunctionPass *createSystemZCopyPhysRegsPass(SystemZTargetMachine &TM);
FunctionPass *createSystemZPostRewritePass(SystemZTargetMachine &TM);
FunctionPass *createSystemZTDCPass();

void initializeSystemZElimComparePass(PassRegistry &);
void initializeSystemZShortenInstPass(PassRegistry &);
void initializeSystemZLongBranchPass(PassRegistry &);
void initializeSystemZLDCleanupPass(PassRegistry &);
void initializeSystemZCopyPhysRegsPass(PassRegistry &);
void initializeSystemZPostRewritePass(PassRegistry &);
void initializeSystemZTDCPassPass(PassRegistry &);

} // end namespace llvm

#endif
10 changes: 1 addition & 9 deletions llvm/lib/Target/SystemZ/SystemZCopyPhysRegs.cpp
Expand Up @@ -25,12 +25,6 @@

using namespace llvm;

#define SYSTEMZ_COPYPHYSREGS_NAME "SystemZ Copy Physregs"

namespace llvm {
void initializeSystemZCopyPhysRegsPass(PassRegistry&);
}

namespace {

class SystemZCopyPhysRegs : public MachineFunctionPass {
Expand All @@ -41,8 +35,6 @@ class SystemZCopyPhysRegs : public MachineFunctionPass {
initializeSystemZCopyPhysRegsPass(*PassRegistry::getPassRegistry());
}

StringRef getPassName() const override { return SYSTEMZ_COPYPHYSREGS_NAME; }

bool runOnMachineFunction(MachineFunction &MF) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;

Expand All @@ -59,7 +51,7 @@ char SystemZCopyPhysRegs::ID = 0;
} // end anonymous namespace

INITIALIZE_PASS(SystemZCopyPhysRegs, "systemz-copy-physregs",
SYSTEMZ_COPYPHYSREGS_NAME, false, false)
"SystemZ Copy Physregs", false, false)

FunctionPass *llvm::createSystemZCopyPhysRegsPass(SystemZTargetMachine &TM) {
return new SystemZCopyPhysRegs();
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/SystemZ/SystemZElimCompare.cpp
Expand Up @@ -65,11 +65,8 @@ class SystemZElimCompare : public MachineFunctionPass {
public:
static char ID;

SystemZElimCompare(const SystemZTargetMachine &tm)
: MachineFunctionPass(ID) {}

StringRef getPassName() const override {
return "SystemZ Comparison Elimination";
SystemZElimCompare() : MachineFunctionPass(ID) {
initializeSystemZElimComparePass(*PassRegistry::getPassRegistry());
}

bool processBlock(MachineBasicBlock &MBB);
Expand Down Expand Up @@ -106,6 +103,9 @@ char SystemZElimCompare::ID = 0;

} // end anonymous namespace

INITIALIZE_PASS(SystemZElimCompare, DEBUG_TYPE,
"SystemZ Comparison Elimination", false, false)

// Returns true if MI is an instruction whose output equals the value in Reg.
static bool preservesValueOf(MachineInstr &MI, unsigned Reg) {
switch (MI.getOpcode()) {
Expand Down Expand Up @@ -746,5 +746,5 @@ bool SystemZElimCompare::runOnMachineFunction(MachineFunction &F) {
}

FunctionPass *llvm::createSystemZElimComparePass(SystemZTargetMachine &TM) {
return new SystemZElimCompare(TM);
return new SystemZElimCompare();
}
12 changes: 6 additions & 6 deletions llvm/lib/Target/SystemZ/SystemZLDCleanup.cpp
Expand Up @@ -29,11 +29,8 @@ namespace {
class SystemZLDCleanup : public MachineFunctionPass {
public:
static char ID;
SystemZLDCleanup(const SystemZTargetMachine &tm)
: MachineFunctionPass(ID), TII(nullptr), MF(nullptr) {}

StringRef getPassName() const override {
return "SystemZ Local Dynamic TLS Access Clean-up";
SystemZLDCleanup() : MachineFunctionPass(ID), TII(nullptr), MF(nullptr) {
initializeSystemZLDCleanupPass(*PassRegistry::getPassRegistry());
}

bool runOnMachineFunction(MachineFunction &MF) override;
Expand All @@ -52,8 +49,11 @@ char SystemZLDCleanup::ID = 0;

} // end anonymous namespace

INITIALIZE_PASS(SystemZLDCleanup, "systemz-ld-cleanup",
"SystemZ Local Dynamic TLS Access Clean-up", false, false)

FunctionPass *llvm::createSystemZLDCleanupPass(SystemZTargetMachine &TM) {
return new SystemZLDCleanup(TM);
return new SystemZLDCleanup();
}

void SystemZLDCleanup::getAnalysisUsage(AnalysisUsage &AU) const {
Expand Down
12 changes: 7 additions & 5 deletions llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
Expand Up @@ -135,10 +135,9 @@ class SystemZLongBranch : public MachineFunctionPass {
public:
static char ID;

SystemZLongBranch(const SystemZTargetMachine &tm)
: MachineFunctionPass(ID) {}

StringRef getPassName() const override { return "SystemZ Long Branch"; }
SystemZLongBranch() : MachineFunctionPass(ID) {
initializeSystemZLongBranchPass(*PassRegistry::getPassRegistry());
}

bool runOnMachineFunction(MachineFunction &F) override;

Expand Down Expand Up @@ -174,6 +173,9 @@ const uint64_t MaxForwardRange = 0xfffe;

} // end anonymous namespace

INITIALIZE_PASS(SystemZLongBranch, DEBUG_TYPE, "SystemZ Long Branch", false,
false)

// Position describes the state immediately before Block. Update Block
// accordingly and move Position to the end of the block's non-terminator
// instructions.
Expand Down Expand Up @@ -481,5 +483,5 @@ bool SystemZLongBranch::runOnMachineFunction(MachineFunction &F) {
}

FunctionPass *llvm::createSystemZLongBranchPass(SystemZTargetMachine &TM) {
return new SystemZLongBranch(TM);
return new SystemZLongBranch();
}
10 changes: 1 addition & 9 deletions llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
Expand Up @@ -21,16 +21,10 @@
#include "llvm/CodeGen/MachineInstrBuilder.h"
using namespace llvm;

#define SYSTEMZ_POSTREWRITE_NAME "SystemZ Post Rewrite pass"

#define DEBUG_TYPE "systemz-postrewrite"
STATISTIC(MemFoldCopies, "Number of copies inserted before folded mem ops.");
STATISTIC(LOCRMuxJumps, "Number of LOCRMux jump-sequences (lower is better)");

namespace llvm {
void initializeSystemZPostRewritePass(PassRegistry&);
}

namespace {

class SystemZPostRewrite : public MachineFunctionPass {
Expand All @@ -44,8 +38,6 @@ class SystemZPostRewrite : public MachineFunctionPass {

bool runOnMachineFunction(MachineFunction &Fn) override;

StringRef getPassName() const override { return SYSTEMZ_POSTREWRITE_NAME; }

private:
void selectLOCRMux(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
Expand All @@ -70,7 +62,7 @@ char SystemZPostRewrite::ID = 0;
} // end anonymous namespace

INITIALIZE_PASS(SystemZPostRewrite, "systemz-post-rewrite",
SYSTEMZ_POSTREWRITE_NAME, false, false)
"SystemZ Post Rewrite pass", false, false)

/// Returns an instance of the Post Rewrite pass.
FunctionPass *llvm::createSystemZPostRewritePass(SystemZTargetMachine &TM) {
Expand Down
17 changes: 9 additions & 8 deletions llvm/lib/Target/SystemZ/SystemZShortenInst.cpp
Expand Up @@ -26,11 +26,7 @@ namespace {
class SystemZShortenInst : public MachineFunctionPass {
public:
static char ID;
SystemZShortenInst(const SystemZTargetMachine &tm);

StringRef getPassName() const override {
return "SystemZ Instruction Shortening";
}
SystemZShortenInst();

bool processBlock(MachineBasicBlock &MBB);
bool runOnMachineFunction(MachineFunction &F) override;
Expand All @@ -56,12 +52,17 @@ class SystemZShortenInst : public MachineFunctionPass {
char SystemZShortenInst::ID = 0;
} // end anonymous namespace

INITIALIZE_PASS(SystemZShortenInst, DEBUG_TYPE,
"SystemZ Instruction Shortening", false, false)

FunctionPass *llvm::createSystemZShortenInstPass(SystemZTargetMachine &TM) {
return new SystemZShortenInst(TM);
return new SystemZShortenInst();
}

SystemZShortenInst::SystemZShortenInst(const SystemZTargetMachine &tm)
: MachineFunctionPass(ID), TII(nullptr) {}
SystemZShortenInst::SystemZShortenInst()
: MachineFunctionPass(ID), TII(nullptr) {
initializeSystemZShortenInstPass(*PassRegistry::getPassRegistry());
}

// Tie operands if MI has become a two-address instruction.
static void tieOpsIfNeeded(MachineInstr &MI) {
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Target/SystemZ/SystemZTDC.cpp
Expand Up @@ -61,10 +61,6 @@

using namespace llvm;

namespace llvm {
void initializeSystemZTDCPassPass(PassRegistry&);
}

namespace {

class SystemZTDCPass : public FunctionPass {
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
Expand Up @@ -32,6 +32,14 @@ using namespace llvm;
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTarget() {
// Register the target.
RegisterTargetMachine<SystemZTargetMachine> X(getTheSystemZTarget());
auto &PR = *PassRegistry::getPassRegistry();
initializeSystemZElimComparePass(PR);
initializeSystemZShortenInstPass(PR);
initializeSystemZLongBranchPass(PR);
initializeSystemZLDCleanupPass(PR);
initializeSystemZShortenInstPass(PR);
initializeSystemZPostRewritePass(PR);
initializeSystemZTDCPassPass(PR);
}

// Determine whether we use the vector ABI.
Expand Down

0 comments on commit d5ae039

Please sign in to comment.