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

Generated by: LCOV version 1.13