[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp PPCInstrInfo.h
Chris Lattner
sabre at nondot.org
Fri Oct 13 14:21:31 PDT 2006
Changes in directory llvm/lib/Target/PowerPC:
PPCInstrInfo.cpp updated: 1.23 -> 1.24
PPCInstrInfo.h updated: 1.16 -> 1.17
---
Log message:
implement branch inspection/modification methods.
---
Diffs of the changes: (+106 -0)
PPCInstrInfo.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
PPCInstrInfo.h | 13 +++++++
2 files changed, 106 insertions(+)
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
diff -u llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:1.23 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:1.24
--- llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:1.23 Mon Jul 10 19:48:23 2006
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.cpp Fri Oct 13 16:21:17 2006
@@ -162,3 +162,96 @@
MachineBasicBlock::iterator MI) const {
BuildMI(MBB, MI, PPC::NOP, 0);
}
+
+
+// Branch analysis.
+bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
+ MachineBasicBlock *&FBB,
+ std::vector<MachineOperand> &Cond) const {
+ // If the block has no terminators, it just falls into the block after it.
+ MachineBasicBlock::iterator I = MBB.end();
+ if (I == MBB.begin() || !isTerminatorInstr((--I)->getOpcode()))
+ return false;
+
+ // Get the last instruction in the block.
+ MachineInstr *LastInst = I;
+
+ // If there is only one terminator instruction, process it.
+ if (I == MBB.begin() || !isTerminatorInstr((--I)->getOpcode())) {
+ if (LastInst->getOpcode() == PPC::B) {
+ TBB = LastInst->getOperand(0).getMachineBasicBlock();
+ return false;
+ } else if (LastInst->getOpcode() == PPC::COND_BRANCH) {
+ // Block ends with fall-through condbranch.
+ TBB = LastInst->getOperand(2).getMachineBasicBlock();
+ Cond.push_back(LastInst->getOperand(0));
+ Cond.push_back(LastInst->getOperand(1));
+ return true;
+ }
+ // Otherwise, don't know what this is.
+ return true;
+ }
+
+ // Get the instruction before it if it's a terminator.
+ MachineInstr *SecondLastInst = I;
+
+ // If there are three terminators, we don't know what sort of block this is.
+ if (SecondLastInst && I != MBB.begin() &&
+ isTerminatorInstr((--I)->getOpcode()))
+ return true;
+
+ // If the block ends with PPC::B and PPC:COND_BRANCH, handle it.
+ if (SecondLastInst->getOpcode() == PPC::COND_BRANCH &&
+ LastInst->getOpcode() == PPC::B) {
+ TBB = SecondLastInst->getOperand(2).getMachineBasicBlock();
+ Cond.push_back(SecondLastInst->getOperand(0));
+ Cond.push_back(SecondLastInst->getOperand(1));
+ FBB = LastInst->getOperand(0).getMachineBasicBlock();
+ return false;
+ }
+
+ // Otherwise, can't handle this.
+ return true;
+}
+
+void PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
+ MachineBasicBlock::iterator I = MBB.end();
+ if (I == MBB.begin()) return;
+ --I;
+ if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::COND_BRANCH)
+ return;
+
+ // Remove the branch.
+ I->eraseFromParent();
+
+ I = MBB.end();
+
+ if (I == MBB.begin()) return;
+ --I;
+ if (I->getOpcode() != PPC::COND_BRANCH)
+ return;
+
+ // Remove the branch.
+ I->eraseFromParent();
+}
+
+void PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
+ MachineBasicBlock *FBB,
+ const std::vector<MachineOperand> &Cond) const {
+ // Fall through?
+ if (TBB == 0 && FBB == 0) return;
+
+ assert(Cond.size() == 2 && "PPC branch conditions have two components!");
+
+ // Conditional branch
+ BuildMI(&MBB, PPC::COND_BRANCH, 3)
+ .addReg(Cond[0].getReg()).addImm(Cond[1].getImm()).addMBB(TBB);
+
+ if (FBB) // Two-way branch.
+ BuildMI(&MBB, PPC::B, 1).addMBB(FBB);
+}
+
+bool PPCInstrInfo::
+ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
+ return true;
+}
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.h
diff -u llvm/lib/Target/PowerPC/PPCInstrInfo.h:1.16 llvm/lib/Target/PowerPC/PPCInstrInfo.h:1.17
--- llvm/lib/Target/PowerPC/PPCInstrInfo.h:1.16 Fri Jun 16 19:01:04 2006
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.h Fri Oct 13 16:21:17 2006
@@ -94,6 +94,19 @@
virtual void insertNoop(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const;
+
+ // Branch analysis.
+ virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
+ MachineBasicBlock *&FBB,
+ std::vector<MachineOperand> &Cond) const;
+ virtual void RemoveBranch(MachineBasicBlock &MBB) const;
+ virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
+ MachineBasicBlock *FBB,
+ const std::vector<MachineOperand> &Cond) const;
+ virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
+
+
+
static unsigned invertPPCBranchOpcode(unsigned Opcode) {
switch (Opcode) {
default: assert(0 && "Unknown PPC branch opcode!");
More information about the llvm-commits
mailing list