From: Chris Lattner Date: Wed, 24 Aug 2005 00:09:33 +0000 (+0000) Subject: Implement LiveVariables.h change X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=657b4d1ac6a64d8751ed8c53d662201dab4438e1 Implement LiveVariables.h change git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22994 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/LiveVariables.cpp b/lib/CodeGen/LiveVariables.cpp index 42a07543d0d..cb034c017a8 100644 --- a/lib/CodeGen/LiveVariables.cpp +++ b/lib/CodeGen/LiveVariables.cpp @@ -34,6 +34,7 @@ #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Config/alloca.h" +#include using namespace llvm; static RegisterAnalysis X("livevars", "Live Variable Analysis"); @@ -51,6 +52,25 @@ LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) { return VirtRegInfo[RegIdx]; } +bool LiveVariables::KillsRegister(MachineInstr *MI, unsigned Reg) const { + std::map >::const_iterator I = + RegistersKilled.find(MI); + if (I == RegistersKilled.end()) return false; + + // Do a binary search, as these lists can grow pretty big, particularly for + // call instructions on targets with lots of call-clobbered registers. + return std::binary_search(I->second.begin(), I->second.end(), Reg); +} + +bool LiveVariables::RegisterDefIsDead(MachineInstr *MI, unsigned Reg) const { + std::map >::const_iterator I = + RegistersDead.find(MI); + if (I == RegistersDead.end()) return false; + + // Do a binary search, as these lists can grow pretty big, particularly for + // call instructions on targets with lots of call-clobbered registers. + return std::binary_search(I->second.begin(), I->second.end(), Reg); +} void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo, @@ -301,6 +321,16 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) { i + MRegisterInfo::FirstVirtualRegister); } + // Walk through the RegistersKilled/Dead sets, and sort the registers killed + // or dead. This allows us to use efficient binary search for membership + // testing. + for (std::map >::iterator + I = RegistersKilled.begin(), E = RegistersKilled.end(); I != E; ++I) + std::sort(I->second.begin(), I->second.end()); + for (std::map >::iterator + I = RegistersDead.begin(), E = RegistersDead.end(); I != E; ++I) + std::sort(I->second.begin(), I->second.end()); + // Check to make sure there are no unreachable blocks in the MC CFG for the // function. If so, it is due to a bug in the instruction selector or some // other part of the code generator if this happens.