2009-07-22 07:47:33 +08:00
|
|
|
//===-- lib/CodeGen/PHIElimination.h ----------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_PHIELIMINATION_HPP
|
|
|
|
#define LLVM_CODEGEN_PHIELIMINATION_HPP
|
|
|
|
|
2009-07-23 12:34:03 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2009-07-22 07:47:33 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2010-02-10 03:54:29 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2009-07-22 07:47:33 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2010-02-10 03:54:29 +08:00
|
|
|
class LiveVariables;
|
|
|
|
|
2009-07-22 07:47:33 +08:00
|
|
|
/// Lower PHI instructions to copies.
|
|
|
|
class PHIElimination : public MachineFunctionPass {
|
|
|
|
MachineRegisterInfo *MRI; // Machine register information
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
PHIElimination() : MachineFunctionPass(&ID) {}
|
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &Fn);
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
|
|
|
|
/// in predecessor basic blocks.
|
|
|
|
///
|
|
|
|
bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
|
|
|
|
void LowerAtomicPHINode(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator AfterPHIsIt);
|
|
|
|
|
|
|
|
/// analyzePHINodes - Gather information about the PHI nodes in
|
|
|
|
/// here. In particular, we want to map the number of uses of a virtual
|
|
|
|
/// register which is used in a PHI node. We map that to the BB the
|
|
|
|
/// vreg is coming from. This is used later to determine when the vreg
|
|
|
|
/// is killed in the BB.
|
|
|
|
///
|
|
|
|
void analyzePHINodes(const MachineFunction& Fn);
|
|
|
|
|
2009-11-11 06:01:05 +08:00
|
|
|
/// Split critical edges where necessary for good coalescer performance.
|
2009-11-19 02:01:35 +08:00
|
|
|
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
LiveVariables &LV);
|
2009-11-11 06:01:05 +08:00
|
|
|
|
|
|
|
/// SplitCriticalEdge - Split a critical edge from A to B by
|
|
|
|
/// inserting a new MBB. Update branches in A and PHI instructions
|
|
|
|
/// in B. Return the new block.
|
|
|
|
MachineBasicBlock *SplitCriticalEdge(MachineBasicBlock *A,
|
|
|
|
MachineBasicBlock *B);
|
|
|
|
|
2009-11-14 05:56:15 +08:00
|
|
|
/// FindCopyInsertPoint - Find a safe place in MBB to insert a copy from
|
|
|
|
/// SrcReg when following the CFG edge to SuccMBB. This needs to be after
|
|
|
|
/// any def of SrcReg, but before any subsequent point where control flow
|
|
|
|
/// might jump out of the basic block.
|
2009-07-22 07:47:33 +08:00
|
|
|
MachineBasicBlock::iterator FindCopyInsertPoint(MachineBasicBlock &MBB,
|
2009-11-14 05:56:15 +08:00
|
|
|
MachineBasicBlock &SuccMBB,
|
2009-07-22 07:47:33 +08:00
|
|
|
unsigned SrcReg);
|
|
|
|
|
|
|
|
// SkipPHIsAndLabels - Copies need to be inserted after phi nodes and
|
|
|
|
// also after any exception handling labels: in landing pads execution
|
|
|
|
// starts at the label, so any copies placed before it won't be executed!
|
2010-02-16 09:57:28 +08:00
|
|
|
// We also deal with DBG_VALUEs, which are a bit tricky:
|
|
|
|
// PHI
|
|
|
|
// DBG_VALUE
|
|
|
|
// LABEL
|
|
|
|
// Here the DBG_VALUE needs to be skipped, and if it refers to a PHI it
|
|
|
|
// needs to be annulled or, better, moved to follow the label, as well.
|
|
|
|
// PHI
|
|
|
|
// DBG_VALUE
|
|
|
|
// no label
|
|
|
|
// Here it is not a good idea to skip the DBG_VALUE.
|
|
|
|
// FIXME: For now we skip and annul all DBG_VALUEs, maximally simple and
|
|
|
|
// maximally stupid.
|
2009-07-22 07:47:33 +08:00
|
|
|
MachineBasicBlock::iterator SkipPHIsAndLabels(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) {
|
|
|
|
// Rather than assuming that EH labels come before other kinds of labels,
|
|
|
|
// just skip all labels.
|
2010-02-16 09:57:28 +08:00
|
|
|
while (I != MBB.end() &&
|
|
|
|
(I->isPHI() || I->isLabel() || I->isDebugValue())) {
|
|
|
|
if (I->isDebugValue() && I->getNumOperands()==3 &&
|
|
|
|
I->getOperand(0).isReg())
|
|
|
|
I->getOperand(0).setReg(0U);
|
2009-07-22 07:47:33 +08:00
|
|
|
++I;
|
2010-02-16 09:57:28 +08:00
|
|
|
}
|
2009-07-22 07:47:33 +08:00
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2009-12-17 02:55:53 +08:00
|
|
|
typedef std::pair<unsigned, unsigned> BBVRegPair;
|
|
|
|
typedef DenseMap<BBVRegPair, unsigned> VRegPHIUse;
|
2009-07-22 07:47:33 +08:00
|
|
|
|
|
|
|
VRegPHIUse VRegPHIUseCount;
|
|
|
|
|
|
|
|
// Defs of PHI sources which are implicit_def.
|
|
|
|
SmallPtrSet<MachineInstr*, 4> ImpDefs;
|
2009-12-17 02:55:53 +08:00
|
|
|
|
|
|
|
// Map reusable lowered PHI node -> incoming join register.
|
2010-03-04 07:55:49 +08:00
|
|
|
typedef DenseMap<MachineInstr*, unsigned,
|
|
|
|
MachineInstrExpressionTrait> LoweredPHIMap;
|
2009-12-17 02:55:53 +08:00
|
|
|
LoweredPHIMap LoweredPHIs;
|
2009-07-22 07:47:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-04 15:46:30 +08:00
|
|
|
#endif /* LLVM_CODEGEN_PHIELIMINATION_HPP */
|