diff options
Diffstat (limited to 'lib/CodeGen/BranchFolding.h')
| -rw-r--r-- | lib/CodeGen/BranchFolding.h | 43 | 
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/CodeGen/BranchFolding.h b/lib/CodeGen/BranchFolding.h index fc48e484292d..4852721eea10 100644 --- a/lib/CodeGen/BranchFolding.h +++ b/lib/CodeGen/BranchFolding.h @@ -37,6 +37,9 @@ namespace llvm {                            // flag. Ignored for optsize.                            unsigned MinCommonTailLength = 0); +    /// Perhaps branch folding, tail merging and other CFG optimizations on the +    /// given function.  Block placement changes the layout and may create new +    /// tail merging opportunities.      bool OptimizeFunction(MachineFunction &MF, const TargetInstrInfo *tii,                            const TargetRegisterInfo *tri, MachineModuleInfo *mmi,                            MachineLoopInfo *mli = nullptr, @@ -122,6 +125,8 @@ namespace llvm {                                    const MachineBasicBlock *MBB) const;        raw_ostream &printBlockFreq(raw_ostream &OS,                                    const BlockFrequency Freq) const; +      void view(const Twine &Name, bool isSimple = true); +      uint64_t getEntryFreq() const;      private:        const MachineBlockFrequencyInfo &MBFI; @@ -137,26 +142,64 @@ namespace llvm {                         MachineBasicBlock* PredBB,                         unsigned MinCommonTailLength);      void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB); + +    /// Delete the instruction OldInst and everything after it, replacing it +    /// with an unconditional branch to NewDest.      void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,                                   MachineBasicBlock *NewDest); + +    /// Given a machine basic block and an iterator into it, split the MBB so +    /// that the part before the iterator falls into the part starting at the +    /// iterator.  This returns the new MBB.      MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,                                    MachineBasicBlock::iterator BBI1,                                    const BasicBlock *BB); + +    /// Look through all the blocks in MergePotentials that have hash CurHash +    /// (guaranteed to match the last element).  Build the vector SameTails of +    /// all those that have the (same) largest number of instructions in common +    /// of any pair of these blocks.  SameTails entries contain an iterator into +    /// MergePotentials (from which the MachineBasicBlock can be found) and a +    /// MachineBasicBlock::iterator into that MBB indicating the instruction +    /// where the matching code sequence begins.  Order of elements in SameTails +    /// is the reverse of the order in which those blocks appear in +    /// MergePotentials (where they are not necessarily consecutive).      unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength,                                MachineBasicBlock *SuccBB,                                MachineBasicBlock *PredBB); + +    /// Remove all blocks with hash CurHash from MergePotentials, restoring +    /// branches at ends of blocks as appropriate.      void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB,                                                  MachineBasicBlock* PredBB); + +    /// None of the blocks to be tail-merged consist only of the common tail. +    /// Create a block that does by splitting one.      bool CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,                                     MachineBasicBlock *SuccBB,                                     unsigned maxCommonTailLength,                                     unsigned &commonTailIndex); +    /// Create merged DebugLocs of identical instructions across SameTails and +    /// assign it to the instruction in common tail. +    void MergeCommonTailDebugLocs(unsigned commonTailIndex); +      bool OptimizeBranches(MachineFunction &MF); + +    /// Analyze and optimize control flow related to the specified block. This +    /// is never called on the entry block.      bool OptimizeBlock(MachineBasicBlock *MBB); + +    /// Remove the specified dead machine basic block from the function, +    /// updating the CFG.      void RemoveDeadBlock(MachineBasicBlock *MBB); +    /// Hoist common instruction sequences at the start of basic blocks to their +    /// common predecessor.      bool HoistCommonCode(MachineFunction &MF); + +    /// If the successors of MBB has common instruction sequence at the start of +    /// the function, move the instructions before MBB terminator if it's legal.      bool HoistCommonCodeInSuccs(MachineBasicBlock *MBB);    };  }  | 
