LCOV - code coverage report
Current view: top level - include/llvm/Transforms/Scalar - JumpThreading.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 7 7 100.0 %
Date: 2017-09-14 15:23:50 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- JumpThreading.h - thread control through conditional BBs -*- 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             : //===----------------------------------------------------------------------===//
       9             : /// \file
      10             : /// See the comments on JumpThreadingPass.
      11             : ///
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_TRANSFORMS_SCALAR_JUMPTHREADING_H
      15             : #define LLVM_TRANSFORMS_SCALAR_JUMPTHREADING_H
      16             : 
      17             : #include "llvm/ADT/DenseSet.h"
      18             : #include "llvm/ADT/SmallPtrSet.h"
      19             : #include "llvm/ADT/SmallSet.h"
      20             : #include "llvm/Analysis/AliasAnalysis.h"
      21             : #include "llvm/Analysis/BlockFrequencyInfo.h"
      22             : #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
      23             : #include "llvm/Analysis/BranchProbabilityInfo.h"
      24             : #include "llvm/Analysis/LazyValueInfo.h"
      25             : #include "llvm/Analysis/TargetLibraryInfo.h"
      26             : #include "llvm/IR/Instructions.h"
      27             : #include "llvm/IR/IntrinsicInst.h"
      28             : #include "llvm/IR/ValueHandle.h"
      29             : 
      30             : namespace llvm {
      31             : 
      32             : /// A private "module" namespace for types and utilities used by
      33             : /// JumpThreading.
      34             : /// These are implementation details and should not be used by clients.
      35             : namespace jumpthreading {
      36             : // These are at global scope so static functions can use them too.
      37             : typedef SmallVectorImpl<std::pair<Constant *, BasicBlock *>> PredValueInfo;
      38             : typedef SmallVector<std::pair<Constant *, BasicBlock *>, 8> PredValueInfoTy;
      39             : 
      40             : // This is used to keep track of what kind of constant we're currently hoping
      41             : // to find.
      42             : enum ConstantPreference { WantInteger, WantBlockAddress };
      43             : }
      44             : 
      45             : /// This pass performs 'jump threading', which looks at blocks that have
      46             : /// multiple predecessors and multiple successors.  If one or more of the
      47             : /// predecessors of the block can be proven to always jump to one of the
      48             : /// successors, we forward the edge from the predecessor to the successor by
      49             : /// duplicating the contents of this block.
      50             : ///
      51             : /// An example of when this can occur is code like this:
      52             : ///
      53             : ///   if () { ...
      54             : ///     X = 4;
      55             : ///   }
      56             : ///   if (X < 3) {
      57             : ///
      58             : /// In this case, the unconditional branch at the end of the first if can be
      59             : /// revectored to the false side of the second if.
      60             : ///
      61        9121 : class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
      62             :   TargetLibraryInfo *TLI;
      63             :   LazyValueInfo *LVI;
      64             :   AliasAnalysis *AA;
      65             :   std::unique_ptr<BlockFrequencyInfo> BFI;
      66             :   std::unique_ptr<BranchProbabilityInfo> BPI;
      67             :   bool HasProfileData = false;
      68             :   bool HasGuards = false;
      69             : #ifdef NDEBUG
      70             :   SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
      71             : #else
      72             :   SmallSet<AssertingVH<const BasicBlock>, 16> LoopHeaders;
      73             : #endif
      74             :   DenseSet<std::pair<Value *, BasicBlock *>> RecursionSet;
      75             : 
      76             :   unsigned BBDupThreshold;
      77             : 
      78             :   // RAII helper for updating the recursion stack.
      79             :   struct RecursionSetRemover {
      80             :     DenseSet<std::pair<Value *, BasicBlock *>> &TheSet;
      81             :     std::pair<Value *, BasicBlock *> ThePair;
      82             : 
      83             :     RecursionSetRemover(DenseSet<std::pair<Value *, BasicBlock *>> &S,
      84             :                         std::pair<Value *, BasicBlock *> P)
      85      158628 :         : TheSet(S), ThePair(P) {}
      86             : 
      87      317256 :     ~RecursionSetRemover() { TheSet.erase(ThePair); }
      88             :   };
      89             : 
      90             : public:
      91             :   JumpThreadingPass(int T = -1);
      92             : 
      93             :   // Glue for old PM.
      94             :   bool runImpl(Function &F, TargetLibraryInfo *TLI_, LazyValueInfo *LVI_,
      95             :                AliasAnalysis *AA_, bool HasProfileData_,
      96             :                std::unique_ptr<BlockFrequencyInfo> BFI_,
      97             :                std::unique_ptr<BranchProbabilityInfo> BPI_);
      98             : 
      99             :   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
     100             : 
     101       67794 :   void releaseMemory() {
     102      135588 :     BFI.reset();
     103      135588 :     BPI.reset();
     104       67794 :   }
     105             : 
     106             :   void FindLoopHeaders(Function &F);
     107             :   bool ProcessBlock(BasicBlock *BB);
     108             :   bool ThreadEdge(BasicBlock *BB, const SmallVectorImpl<BasicBlock *> &PredBBs,
     109             :                   BasicBlock *SuccBB);
     110             :   bool DuplicateCondBranchOnPHIIntoPred(
     111             :       BasicBlock *BB, const SmallVectorImpl<BasicBlock *> &PredBBs);
     112             : 
     113             :   bool
     114             :   ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,
     115             :                                   jumpthreading::PredValueInfo &Result,
     116             :                                   jumpthreading::ConstantPreference Preference,
     117             :                                   Instruction *CxtI = nullptr);
     118             :   bool ProcessThreadableEdges(Value *Cond, BasicBlock *BB,
     119             :                               jumpthreading::ConstantPreference Preference,
     120             :                               Instruction *CxtI = nullptr);
     121             : 
     122             :   bool ProcessBranchOnPHI(PHINode *PN);
     123             :   bool ProcessBranchOnXOR(BinaryOperator *BO);
     124             :   bool ProcessImpliedCondition(BasicBlock *BB);
     125             : 
     126             :   bool SimplifyPartiallyRedundantLoad(LoadInst *LI);
     127             :   bool TryToUnfoldSelect(CmpInst *CondCmp, BasicBlock *BB);
     128             :   bool TryToUnfoldSelectInCurrBB(BasicBlock *BB);
     129             : 
     130             :   bool ProcessGuards(BasicBlock *BB);
     131             :   bool ThreadGuard(BasicBlock *BB, IntrinsicInst *Guard, BranchInst *BI);
     132             : 
     133             : private:
     134             :   BasicBlock *SplitBlockPreds(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
     135             :                               const char *Suffix);
     136             :   void UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB, BasicBlock *BB,
     137             :                                     BasicBlock *NewBB, BasicBlock *SuccBB);
     138             :   /// Check if the block has profile metadata for its outgoing edges.
     139             :   bool doesBlockHaveProfileData(BasicBlock *BB);
     140             : };
     141             : 
     142             : } // end namespace llvm
     143             : 
     144             : #endif

Generated by: LCOV version 1.13