1 //===-- lib/CodeGen/PHIElimination.h ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CODEGEN_PHIELIMINATION_HPP
11 #define LLVM_CODEGEN_PHIELIMINATION_HPP
13 #include "llvm/ADT/SmallPtrSet.h"
14 #include "llvm/CodeGen/MachineFunctionPass.h"
15 #include "llvm/Target/TargetInstrInfo.h"
21 /// Lower PHI instructions to copies.
22 class PHIElimination : public MachineFunctionPass {
23 MachineRegisterInfo *MRI; // Machine register information
26 static char ID; // Pass identification, replacement for typeid
27 PHIElimination() : MachineFunctionPass(&ID) {}
29 virtual bool runOnMachineFunction(MachineFunction &Fn);
31 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
34 /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
35 /// in predecessor basic blocks.
37 bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
38 void LowerAtomicPHINode(MachineBasicBlock &MBB,
39 MachineBasicBlock::iterator AfterPHIsIt);
41 /// analyzePHINodes - Gather information about the PHI nodes in
42 /// here. In particular, we want to map the number of uses of a virtual
43 /// register which is used in a PHI node. We map that to the BB the
44 /// vreg is coming from. This is used later to determine when the vreg
45 /// is killed in the BB.
47 void analyzePHINodes(const MachineFunction& Fn);
49 // FindCopyInsertPoint - Find a safe place in MBB to insert a copy from
50 // SrcReg. This needs to be after any def or uses of SrcReg, but before
51 // any subsequent point where control flow might jump out of the basic
53 MachineBasicBlock::iterator FindCopyInsertPoint(MachineBasicBlock &MBB,
56 // SkipPHIsAndLabels - Copies need to be inserted after phi nodes and
57 // also after any exception handling labels: in landing pads execution
58 // starts at the label, so any copies placed before it won't be executed!
59 MachineBasicBlock::iterator SkipPHIsAndLabels(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator I) {
61 // Rather than assuming that EH labels come before other kinds of labels,
62 // just skip all labels.
63 while (I != MBB.end() &&
64 (I->getOpcode() == TargetInstrInfo::PHI || I->isLabel()))
69 typedef std::pair<const MachineBasicBlock*, unsigned> BBVRegPair;
70 typedef std::map<BBVRegPair, unsigned> VRegPHIUse;
72 VRegPHIUse VRegPHIUseCount;
74 // Defs of PHI sources which are implicit_def.
75 SmallPtrSet<MachineInstr*, 4> ImpDefs;
80 #endif /* PHIELIMINATION_H */