add a new MCInstPrinter class, move the (trivial) MCDisassmbler ctor inline.
[llvm/avr.git] / lib / CodeGen / BranchFolding.h
blob9763e3339a20a1128a33c554e6d0aefcdedc9bc0
1 //===-- BranchFolding.h - Fold machine code branch instructions --*- C++ -*===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CODEGEN_BRANCHFOLDING_HPP
11 #define LLVM_CODEGEN_BRANCHFOLDING_HPP
13 #include "llvm/CodeGen/MachineBasicBlock.h"
14 #include "llvm/CodeGen/MachineFunctionPass.h"
15 #include <vector>
17 namespace llvm {
18 class MachineFunction;
19 class MachineModuleInfo;
20 class RegScavenger;
21 class TargetInstrInfo;
22 class TargetRegisterInfo;
24 class BranchFolder {
25 public:
26 explicit BranchFolder(bool defaultEnableTailMerge);
28 bool OptimizeFunction(MachineFunction &MF,
29 const TargetInstrInfo *tii,
30 const TargetRegisterInfo *tri,
31 MachineModuleInfo *mmi);
32 private:
33 typedef std::pair<unsigned,MachineBasicBlock*> MergePotentialsElt;
34 typedef std::vector<MergePotentialsElt>::iterator MPIterator;
35 std::vector<MergePotentialsElt> MergePotentials;
37 typedef std::pair<MPIterator, MachineBasicBlock::iterator> SameTailElt;
38 std::vector<SameTailElt> SameTails;
40 bool EnableTailMerge;
41 const TargetInstrInfo *TII;
42 const TargetRegisterInfo *TRI;
43 MachineModuleInfo *MMI;
44 RegScavenger *RS;
46 bool TailMergeBlocks(MachineFunction &MF);
47 bool TryMergeBlocks(MachineBasicBlock* SuccBB,
48 MachineBasicBlock* PredBB);
49 void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
50 MachineBasicBlock *NewDest);
51 MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
52 MachineBasicBlock::iterator BBI1);
53 unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength);
54 void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB,
55 MachineBasicBlock* PredBB);
56 unsigned CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
57 unsigned maxCommonTailLength);
59 bool OptimizeBranches(MachineFunction &MF);
60 bool OptimizeBlock(MachineBasicBlock *MBB);
61 void RemoveDeadBlock(MachineBasicBlock *MBB);
62 bool OptimizeImpDefsBlock(MachineBasicBlock *MBB);
64 bool CanFallThrough(MachineBasicBlock *CurBB);
65 bool CanFallThrough(MachineBasicBlock *CurBB, bool BranchUnAnalyzable,
66 MachineBasicBlock *TBB, MachineBasicBlock *FBB,
67 const SmallVectorImpl<MachineOperand> &Cond);
71 /// BranchFolderPass - Wrap branch folder in a machine function pass.
72 class BranchFolderPass : public MachineFunctionPass,
73 public BranchFolder {
74 public:
75 static char ID;
76 explicit BranchFolderPass(bool defaultEnableTailMerge)
77 : MachineFunctionPass(&ID), BranchFolder(defaultEnableTailMerge) {}
79 virtual bool runOnMachineFunction(MachineFunction &MF);
80 virtual const char *getPassName() const { return "Control Flow Optimizer"; }
84 #endif /* LLVM_CODEGEN_BRANCHFOLDING_HPP */