X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FBranchFolding.h;h=3653a2ccd62375462bf2d1e911ae74c8c16ef9b4;hb=08f77a9f422e96110d8400e4caaf6a51be49a1f3;hp=648ec92b1eb60fc10f3378a96e4d0df01f08bf7f;hpb=72b2990a7495b9df89e151eb711c1e7abdd5f2e5;p=oota-llvm.git diff --git a/lib/CodeGen/BranchFolding.h b/lib/CodeGen/BranchFolding.h index 648ec92b1eb..3653a2ccd62 100644 --- a/lib/CodeGen/BranchFolding.h +++ b/lib/CodeGen/BranchFolding.h @@ -1,4 +1,4 @@ -//===-- BranchFolding.h - Fold machine code branch instructions --*- C++ -*===// +//===-- BranchFolding.h - Fold machine code branch instructions -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,23 +7,28 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CODEGEN_BRANCHFOLDING_HPP -#define LLVM_CODEGEN_BRANCHFOLDING_HPP +#ifndef LLVM_LIB_CODEGEN_BRANCHFOLDING_H +#define LLVM_LIB_CODEGEN_BRANCHFOLDING_H +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/Support/BlockFrequency.h" #include namespace llvm { + class MachineBlockFrequencyInfo; + class MachineBranchProbabilityInfo; class MachineFunction; class MachineModuleInfo; class RegScavenger; class TargetInstrInfo; class TargetRegisterInfo; - template class SmallVectorImpl; class BranchFolder { public: - explicit BranchFolder(bool defaultEnableTailMerge); + explicit BranchFolder(bool defaultEnableTailMerge, bool CommonHoist, + const MachineBlockFrequencyInfo &MBFI, + const MachineBranchProbabilityInfo &MBPI); bool OptimizeFunction(MachineFunction &MF, const TargetInstrInfo *tii, @@ -48,6 +53,7 @@ namespace llvm { }; typedef std::vector::iterator MPIterator; std::vector MergePotentials; + SmallPtrSet TriedMerging; class SameTailElt { MPIterator MPIter; @@ -85,39 +91,56 @@ namespace llvm { std::vector SameTails; bool EnableTailMerge; + bool EnableHoistCommonCode; const TargetInstrInfo *TII; const TargetRegisterInfo *TRI; MachineModuleInfo *MMI; RegScavenger *RS; + /// \brief This class keeps track of branch frequencies of newly created + /// blocks and tail-merged blocks. + class MBFIWrapper { + public: + MBFIWrapper(const MachineBlockFrequencyInfo &I) : MBFI(I) {} + BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const; + void setBlockFreq(const MachineBasicBlock *MBB, BlockFrequency F); + + private: + const MachineBlockFrequencyInfo &MBFI; + DenseMap MergedBBFreq; + }; + + MBFIWrapper MBBFreqInfo; + const MachineBranchProbabilityInfo &MBPI; + bool TailMergeBlocks(MachineFunction &MF); bool TryTailMergeBlocks(MachineBasicBlock* SuccBB, MachineBasicBlock* PredBB); + void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB); + void MaintainLiveIns(MachineBasicBlock *CurMBB, + MachineBasicBlock *NewMBB); void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst, MachineBasicBlock *NewDest); MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB, - MachineBasicBlock::iterator BBI1); + MachineBasicBlock::iterator BBI1, + const BasicBlock *BB); unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength, MachineBasicBlock *SuccBB, MachineBasicBlock *PredBB); void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB, MachineBasicBlock* PredBB); - unsigned CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB, - unsigned maxCommonTailLength); + bool CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB, + MachineBasicBlock *SuccBB, + unsigned maxCommonTailLength, + unsigned &commonTailIndex); - bool TailDuplicate(MachineBasicBlock *TailBB, - bool PrevFallsThrough, - MachineFunction &MF); - bool OptimizeBranches(MachineFunction &MF); bool OptimizeBlock(MachineBasicBlock *MBB); void RemoveDeadBlock(MachineBasicBlock *MBB); bool OptimizeImpDefsBlock(MachineBasicBlock *MBB); - - bool CanFallThrough(MachineBasicBlock *CurBB); - bool CanFallThrough(MachineBasicBlock *CurBB, bool BranchUnAnalyzable, - MachineBasicBlock *TBB, MachineBasicBlock *FBB, - const SmallVectorImpl &Cond); + + bool HoistCommonCode(MachineFunction &MF); + bool HoistCommonCodeInSuccs(MachineBasicBlock *MBB); }; }