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/DenseMap.h"
14 #include "llvm/ADT/SmallSet.h"
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/CodeGen/MachineBasicBlock.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
21 class MachineRegisterInfo;
22 class MachineLoopInfo;
24 /// Lower PHI instructions to copies.
25 class PHIElimination : public MachineFunctionPass {
26 MachineRegisterInfo *MRI; // Machine register information
29 static char ID; // Pass identification, replacement for typeid
30 PHIElimination() : MachineFunctionPass(ID) {
31 initializePHIEliminationPass(*PassRegistry::getPassRegistry());
34 virtual bool runOnMachineFunction(MachineFunction &Fn);
36 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
39 /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
40 /// in predecessor basic blocks.
42 bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
43 void LowerAtomicPHINode(MachineBasicBlock &MBB,
44 MachineBasicBlock::iterator AfterPHIsIt);
46 /// analyzePHINodes - Gather information about the PHI nodes in
47 /// here. In particular, we want to map the number of uses of a virtual
48 /// register which is used in a PHI node. We map that to the BB the
49 /// vreg is coming from. This is used later to determine when the vreg
50 /// is killed in the BB.
52 void analyzePHINodes(const MachineFunction& Fn);
54 /// Split critical edges where necessary for good coalescer performance.
55 bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
56 LiveVariables &LV, MachineLoopInfo *MLI);
58 /// SplitCriticalEdge - Split a critical edge from A to B by
59 /// inserting a new MBB. Update branches in A and PHI instructions
60 /// in B. Return the new block.
61 MachineBasicBlock *SplitCriticalEdge(MachineBasicBlock *A,
62 MachineBasicBlock *B);
64 /// FindCopyInsertPoint - Find a safe place in MBB to insert a copy from
65 /// SrcReg when following the CFG edge to SuccMBB. This needs to be after
66 /// any def of SrcReg, but before any subsequent point where control flow
67 /// might jump out of the basic block.
68 MachineBasicBlock::iterator FindCopyInsertPoint(MachineBasicBlock &MBB,
69 MachineBasicBlock &SuccMBB,
72 typedef std::pair<unsigned, unsigned> BBVRegPair;
73 typedef DenseMap<BBVRegPair, unsigned> VRegPHIUse;
75 VRegPHIUse VRegPHIUseCount;
77 // Defs of PHI sources which are implicit_def.
78 SmallPtrSet<MachineInstr*, 4> ImpDefs;
80 // Map reusable lowered PHI node -> incoming join register.
81 typedef DenseMap<MachineInstr*, unsigned,
82 MachineInstrExpressionTrait> LoweredPHIMap;
83 LoweredPHIMap LoweredPHIs;
88 #endif /* LLVM_CODEGEN_PHIELIMINATION_HPP */