From 6ae3626a4fda14e6250ac8d8ff487efb8952cdf7 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 18 May 2007 00:18:17 +0000 Subject: [PATCH] RemoveBranch() and InsertBranch() now returns number of instructions deleted / inserted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37193 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMInstrInfo.cpp | 16 +++++++++------- lib/Target/ARM/ARMInstrInfo.h | 8 ++++---- lib/Target/Sparc/SparcInstrInfo.cpp | 8 +++++--- lib/Target/Sparc/SparcInstrInfo.h | 6 +++--- lib/Target/X86/X86InstrInfo.cpp | 21 ++++++++++++--------- lib/Target/X86/X86InstrInfo.h | 8 ++++---- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/lib/Target/ARM/ARMInstrInfo.cpp b/lib/Target/ARM/ARMInstrInfo.cpp index 891ae558f3d..5f5806d27d2 100644 --- a/lib/Target/ARM/ARMInstrInfo.cpp +++ b/lib/Target/ARM/ARMInstrInfo.cpp @@ -349,33 +349,34 @@ bool ARMInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, } -void ARMInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { +unsigned ARMInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { MachineFunction &MF = *MBB.getParent(); ARMFunctionInfo *AFI = MF.getInfo(); int BOpc = AFI->isThumbFunction() ? ARM::tB : ARM::B; int BccOpc = AFI->isThumbFunction() ? ARM::tBcc : ARM::Bcc; MachineBasicBlock::iterator I = MBB.end(); - if (I == MBB.begin()) return; + if (I == MBB.begin()) return 0; --I; if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc) - return; + return 0; // Remove the branch. I->eraseFromParent(); I = MBB.end(); - if (I == MBB.begin()) return; + if (I == MBB.begin()) return 1; --I; if (I->getOpcode() != BccOpc) - return; + return 1; // Remove the branch. I->eraseFromParent(); + return 2; } -void ARMInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, +unsigned ARMInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, const std::vector &Cond) const { MachineFunction &MF = *MBB.getParent(); @@ -393,12 +394,13 @@ void ARMInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, BuildMI(&MBB, get(BOpc)).addMBB(TBB); else BuildMI(&MBB, get(BccOpc)).addMBB(TBB).addImm(Cond[0].getImm()); - return; + return 1; } // Two-way conditional branch. BuildMI(&MBB, get(BccOpc)).addMBB(TBB).addImm(Cond[0].getImm()); BuildMI(&MBB, get(BOpc)).addMBB(FBB); + return 2; } bool ARMInstrInfo::BlockHasNoFallThrough(MachineBasicBlock &MBB) const { diff --git a/lib/Target/ARM/ARMInstrInfo.h b/lib/Target/ARM/ARMInstrInfo.h index 33645b2d334..84663e75f72 100644 --- a/lib/Target/ARM/ARMInstrInfo.h +++ b/lib/Target/ARM/ARMInstrInfo.h @@ -96,10 +96,10 @@ public: virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, std::vector &Cond) const; - virtual void RemoveBranch(MachineBasicBlock &MBB) const; - virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, - MachineBasicBlock *FBB, - const std::vector &Cond) const; + virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; + virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, + MachineBasicBlock *FBB, + const std::vector &Cond) const; virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const; virtual bool ReverseBranchCondition(std::vector &Cond) const; diff --git a/lib/Target/Sparc/SparcInstrInfo.cpp b/lib/Target/Sparc/SparcInstrInfo.cpp index a5774bdd778..a8c822ae9ae 100644 --- a/lib/Target/Sparc/SparcInstrInfo.cpp +++ b/lib/Target/Sparc/SparcInstrInfo.cpp @@ -97,10 +97,12 @@ unsigned SparcInstrInfo::isStoreToStackSlot(MachineInstr *MI, return 0; } -void SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, - MachineBasicBlock *FBB, - const std::vector &Cond)const{ +unsigned +SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, + MachineBasicBlock *FBB, + const std::vector &Cond)const{ // Can only insert uncond branches so far. assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!"); BuildMI(&MBB, get(SP::BA)).addMBB(TBB); + return 1; } diff --git a/lib/Target/Sparc/SparcInstrInfo.h b/lib/Target/Sparc/SparcInstrInfo.h index 9df9bad1205..3fb50ff92ea 100644 --- a/lib/Target/Sparc/SparcInstrInfo.h +++ b/lib/Target/Sparc/SparcInstrInfo.h @@ -63,9 +63,9 @@ public: virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const; - virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, - MachineBasicBlock *FBB, - const std::vector &Cond) const; + virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, + MachineBasicBlock *FBB, + const std::vector &Cond) const; }; } diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index bd46cda376a..6018337b9d9 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -431,31 +431,33 @@ bool X86InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, return true; } -void X86InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { +unsigned X86InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { MachineBasicBlock::iterator I = MBB.end(); - if (I == MBB.begin()) return; + if (I == MBB.begin()) return 0; --I; if (I->getOpcode() != X86::JMP && GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID) - return; + return 0; // Remove the branch. I->eraseFromParent(); I = MBB.end(); - if (I == MBB.begin()) return; + if (I == MBB.begin()) return 1; --I; if (GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID) - return; + return 1; // Remove the branch. I->eraseFromParent(); + return 2; } -void X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, - MachineBasicBlock *FBB, - const std::vector &Cond) const { +unsigned +X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, + MachineBasicBlock *FBB, + const std::vector &Cond) const { // Shouldn't be a fall through. assert(TBB && "InsertBranch must not be told to insert a fallthrough"); assert((Cond.size() == 1 || Cond.size() == 0) && @@ -470,13 +472,14 @@ void X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm()); BuildMI(&MBB, get(Opc)).addMBB(TBB); } - return; + return 1; } // Two-way Conditional branch. unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm()); BuildMI(&MBB, get(Opc)).addMBB(TBB); BuildMI(&MBB, get(X86::JMP)).addMBB(FBB); + return 2; } bool X86InstrInfo::BlockHasNoFallThrough(MachineBasicBlock &MBB) const { diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h index aaf6f15e5ff..7f5a16b3e0d 100644 --- a/lib/Target/X86/X86InstrInfo.h +++ b/lib/Target/X86/X86InstrInfo.h @@ -263,10 +263,10 @@ public: virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, std::vector &Cond) const; - virtual void RemoveBranch(MachineBasicBlock &MBB) const; - virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, - MachineBasicBlock *FBB, - const std::vector &Cond) const; + virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; + virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, + MachineBasicBlock *FBB, + const std::vector &Cond) const; virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const; virtual bool ReverseBranchCondition(std::vector &Cond) const;