mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-12 05:56:28 +00:00
AArch64DeadRegisterDefinitionsPass: Cleanup; NFC
- Fix doxygen file comment - reduce indentation in loop - Factor out some common subexpressions - Move independent helper function out of class - Fix Changed flag (this is not strictly NFC but a bugfix, but the flag seems ignored anyway) llvm-svn: 285488
This commit is contained in:
parent
ee986aa4c9
commit
6de13f8bcf
@ -6,9 +6,9 @@
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// When allowed by the instruction, replace a dead definition of a GPR with
|
||||
// the zero register. This makes the code a bit friendlier towards the
|
||||
// hardware's register renamer.
|
||||
/// \file When allowed by the instruction, replace a dead definition of a GPR
|
||||
/// with the zero register. This makes the code a bit friendlier towards the
|
||||
/// hardware's register renamer.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "AArch64.h"
|
||||
@ -32,12 +32,12 @@ namespace {
|
||||
class AArch64DeadRegisterDefinitions : public MachineFunctionPass {
|
||||
private:
|
||||
const TargetRegisterInfo *TRI;
|
||||
bool Changed;
|
||||
bool implicitlyDefinesOverlappingReg(unsigned Reg, const MachineInstr &MI);
|
||||
bool processMachineBasicBlock(MachineBasicBlock &MBB);
|
||||
bool usesFrameIndex(const MachineInstr &MI);
|
||||
void processMachineBasicBlock(MachineBasicBlock &MBB);
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid.
|
||||
explicit AArch64DeadRegisterDefinitions() : MachineFunctionPass(ID) {
|
||||
AArch64DeadRegisterDefinitions() : MachineFunctionPass(ID) {
|
||||
initializeAArch64DeadRegisterDefinitionsPass(
|
||||
*PassRegistry::getPassRegistry());
|
||||
}
|
||||
@ -71,16 +71,15 @@ bool AArch64DeadRegisterDefinitions::implicitlyDefinesOverlappingReg(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AArch64DeadRegisterDefinitions::usesFrameIndex(const MachineInstr &MI) {
|
||||
for (const MachineOperand &Op : MI.uses())
|
||||
if (Op.isFI())
|
||||
static bool usesFrameIndex(const MachineInstr &MI) {
|
||||
for (const MachineOperand &MO : MI.uses())
|
||||
if (MO.isFI())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AArch64DeadRegisterDefinitions::processMachineBasicBlock(
|
||||
void AArch64DeadRegisterDefinitions::processMachineBasicBlock(
|
||||
MachineBasicBlock &MBB) {
|
||||
bool Changed = false;
|
||||
for (MachineInstr &MI : MBB) {
|
||||
if (usesFrameIndex(MI)) {
|
||||
// We need to skip this instruction because while it appears to have a
|
||||
@ -95,14 +94,16 @@ bool AArch64DeadRegisterDefinitions::processMachineBasicBlock(
|
||||
DEBUG(dbgs() << " Ignoring, XZR or WZR already used by the instruction\n");
|
||||
continue;
|
||||
}
|
||||
for (int i = 0, e = MI.getDesc().getNumDefs(); i != e; ++i) {
|
||||
MachineOperand &MO = MI.getOperand(i);
|
||||
if (MO.isReg() && MO.isDead() && MO.isDef()) {
|
||||
const MCInstrDesc &Desc = MI.getDesc();
|
||||
for (int I = 0, E = Desc.getNumDefs(); I != E; ++I) {
|
||||
MachineOperand &MO = MI.getOperand(I);
|
||||
if (!MO.isReg() || !MO.isDead() || !MO.isDef())
|
||||
continue;
|
||||
assert(!MO.isImplicit() && "Unexpected implicit def!");
|
||||
DEBUG(dbgs() << " Dead def operand #" << i << " in:\n ";
|
||||
DEBUG(dbgs() << " Dead def operand #" << I << " in:\n ";
|
||||
MI.print(dbgs()));
|
||||
// Be careful not to change the register if it's a tied operand.
|
||||
if (MI.isRegTiedToUseOperand(i)) {
|
||||
if (MI.isRegTiedToUseOperand(I)) {
|
||||
DEBUG(dbgs() << " Ignoring, def is tied operand.\n");
|
||||
continue;
|
||||
}
|
||||
@ -115,7 +116,7 @@ bool AArch64DeadRegisterDefinitions::processMachineBasicBlock(
|
||||
// Make sure the instruction take a register class that contains
|
||||
// the zero register and replace it if so.
|
||||
unsigned NewReg;
|
||||
switch (MI.getDesc().OpInfo[i].RegClass) {
|
||||
switch (Desc.OpInfo[I].RegClass) {
|
||||
default:
|
||||
DEBUG(dbgs() << " Ignoring, register is not a GPR.\n");
|
||||
continue;
|
||||
@ -130,27 +131,25 @@ bool AArch64DeadRegisterDefinitions::processMachineBasicBlock(
|
||||
MO.setReg(NewReg);
|
||||
DEBUG(MI.print(dbgs()));
|
||||
++NumDeadDefsReplaced;
|
||||
Changed = true;
|
||||
// Only replace one dead register, see check for zero register above.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
// Scan the function for instructions that have a dead definition of a
|
||||
// register. Replace that register with the zero register when possible.
|
||||
bool AArch64DeadRegisterDefinitions::runOnMachineFunction(MachineFunction &MF) {
|
||||
TRI = MF.getSubtarget().getRegisterInfo();
|
||||
bool Changed = false;
|
||||
DEBUG(dbgs() << "***** AArch64DeadRegisterDefinitions *****\n");
|
||||
|
||||
if (skipFunction(*MF.getFunction()))
|
||||
return false;
|
||||
|
||||
TRI = MF.getSubtarget().getRegisterInfo();
|
||||
bool Changed = false;
|
||||
DEBUG(dbgs() << "***** AArch64DeadRegisterDefinitions *****\n");
|
||||
Changed = false;
|
||||
for (auto &MBB : MF)
|
||||
if (processMachineBasicBlock(MBB))
|
||||
Changed = true;
|
||||
processMachineBasicBlock(MBB);
|
||||
return Changed;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user