From: Lang Hames Date: Thu, 23 Jul 2009 04:34:03 +0000 (+0000) Subject: Added PHI Def & Kill tracking to PHIElimination pass. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a77a3c378228de0d00998d76a937662fa97ca802;p=platform%2Fupstream%2Fllvm.git Added PHI Def & Kill tracking to PHIElimination pass. llvm-svn: 76849 --- diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp index dc799e8..1cbe798 100644 --- a/llvm/lib/CodeGen/PHIElimination.cpp +++ b/llvm/lib/CodeGen/PHIElimination.cpp @@ -182,6 +182,10 @@ void llvm::PHIElimination::LowerAtomicPHINode( TII->copyRegToReg(MBB, AfterPHIsIt, DestReg, IncomingReg, RC, RC); } + // Record PHI def. + //assert(!hasPHIDef(DestReg) && "Vreg has multiple phi-defs?"); + //PHIDefs[DestReg] = &MBB; + // Update live variable information if there is any. LiveVariables *LV = getAnalysisIfAvailable(); if (LV) { @@ -223,6 +227,13 @@ void llvm::PHIElimination::LowerAtomicPHINode( assert(TargetRegisterInfo::isVirtualRegister(SrcReg) && "Machine PHI Operands must all be virtual registers!"); + // Get the MachineBasicBlock equivalent of the BasicBlock that is the source + // path the PHI. + MachineBasicBlock &opBlock = *MPhi->getOperand(i*2+2).getMBB(); + + // Record the kill. + //PHIKills[SrcReg].insert(&opBlock); + // If source is defined by an implicit def, there is no need to insert a // copy. MachineInstr *DefMI = MRI->getVRegDef(SrcReg); @@ -231,10 +242,6 @@ void llvm::PHIElimination::LowerAtomicPHINode( continue; } - // Get the MachineBasicBlock equivalent of the BasicBlock that is the source - // path the PHI. - MachineBasicBlock &opBlock = *MPhi->getOperand(i*2+2).getMBB(); - // Check to make sure we haven't already emitted the copy for this block. // This can happen because PHI nodes may have multiple entries for the same // basic block. diff --git a/llvm/lib/CodeGen/PHIElimination.h b/llvm/lib/CodeGen/PHIElimination.h index 26a3731..b06435f 100644 --- a/llvm/lib/CodeGen/PHIElimination.h +++ b/llvm/lib/CodeGen/PHIElimination.h @@ -10,6 +10,8 @@ #ifndef LLVM_CODEGEN_PHIELIMINATION_HPP #define LLVM_CODEGEN_PHIELIMINATION_HPP +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Target/TargetInstrInfo.h" @@ -21,8 +23,17 @@ namespace llvm { /// Lower PHI instructions to copies. class PHIElimination : public MachineFunctionPass { MachineRegisterInfo *MRI; // Machine register information + private: + + typedef SmallSet PHIKillList; + typedef DenseMap PHIKillMap; + typedef DenseMap PHIDefMap; public: + + typedef PHIKillList::iterator phi_kill_iterator; + typedef PHIKillList::const_iterator const_phi_kill_iterator; + static char ID; // Pass identification, replacement for typeid PHIElimination() : MachineFunctionPass(&ID) {} @@ -30,6 +41,38 @@ namespace llvm { virtual void getAnalysisUsage(AnalysisUsage &AU) const; + /// Return true if the given vreg was defined by a PHI intsr prior to + /// lowering. + bool hasPHIDef(unsigned vreg) const { + return PHIDefs.count(vreg); + } + + /// Returns the block in which the PHI instruction which defined the + /// given vreg used to reside. + MachineBasicBlock* getPHIDefBlock(unsigned vreg) { + PHIDefMap::iterator phiDefItr = PHIDefs.find(vreg); + assert(phiDefItr != PHIDefs.end() && "vreg has no phi-def."); + return phiDefItr->second; + } + + /// Returns true if the given vreg was killed by a PHI instr. + bool hasPHIKills(unsigned vreg) const { + return PHIKills.count(vreg); + } + + /// Returns an iterator over the BasicBlocks which contained PHI + /// kills of this register prior to lowering. + phi_kill_iterator phiKillsBegin(unsigned vreg) { + PHIKillMap::iterator phiKillItr = PHIKills.find(vreg); + assert(phiKillItr != PHIKills.end() && "vreg has no phi-kills."); + return phiKillItr->second.begin(); + } + phi_kill_iterator phiKillsEnd(unsigned vreg) { + PHIKillMap::iterator phiKillItr = PHIKills.find(vreg); + assert(phiKillItr != PHIKills.end() && "vreg has no phi-kills."); + return phiKillItr->second.end(); + } + private: /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions /// in predecessor basic blocks. @@ -70,6 +113,8 @@ namespace llvm { typedef std::map VRegPHIUse; VRegPHIUse VRegPHIUseCount; + PHIDefMap PHIDefs; + PHIKillMap PHIKills; // Defs of PHI sources which are implicit_def. SmallPtrSet ImpDefs;