Coverage Report

Created: 2018-09-17 19:50

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/MustExecute.h
Line
Count
Source
1
//===- MustExecute.h - Is an instruction known to execute--------*- 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
/// Contains a collection of routines for determining if a given instruction is
11
/// guaranteed to execute if a given point in control flow is reached.  The most
12
/// common example is an instruction within a loop being provably executed if we
13
/// branch to the header of it's containing loop.
14
///
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
18
#define LLVM_ANALYSIS_MUSTEXECUTE_H
19
20
#include "llvm/ADT/DenseMap.h"
21
#include "llvm/Analysis/EHPersonalities.h"
22
#include "llvm/Analysis/LoopInfo.h"
23
#include "llvm/IR/BasicBlock.h"
24
#include "llvm/IR/Dominators.h"
25
#include "llvm/IR/Instruction.h"
26
27
namespace llvm {
28
29
class Instruction;
30
class DominatorTree;
31
class Loop;
32
33
/// Captures loop safety information.
34
/// It keep information for loop blocks may throw exception or otherwise
35
/// exit abnormaly on any iteration of the loop which might actually execute
36
/// at runtime.  The primary way to consume this infromation is via
37
/// isGuaranteedToExecute below, but some callers bailout or fallback to
38
/// alternate reasoning if a loop contains any implicit control flow.
39
/// NOTE: LoopSafetyInfo contains cached information regarding loops and their
40
/// particular blocks. This information is only dropped on invocation of
41
/// computeLoopSafetyInfo. If the loop or any of its block is deleted, or if
42
/// any thrower instructions have been added or removed from them, or if the
43
/// control flow has changed, or in case of other meaningful modifications, the
44
/// LoopSafetyInfo needs to be recomputed. If a meaningful modifications to the
45
/// loop were made and the info wasn't recomputed properly, the behavior of all
46
/// methods except for computeLoopSafetyInfo is undefined.
47
class LoopSafetyInfo {
48
  bool MayThrow = false;       // The current loop contains an instruction which
49
                               // may throw.
50
  bool HeaderMayThrow = false; // Same as previous, but specific to loop header
51
52
  /// Collect all blocks from \p CurLoop which lie on all possible paths from
53
  /// the header of \p CurLoop (inclusive) to BB (exclusive) into the set
54
  /// \p Predecessors. If \p BB is the header, \p Predecessors will be empty.
55
  void collectTransitivePredecessors(
56
      const Loop *CurLoop, const BasicBlock *BB,
57
      SmallPtrSetImpl<const BasicBlock *> &Predecessors) const;
58
59
public:
60
  // Used to update funclet bundle operands.
61
  DenseMap<BasicBlock *, ColorVector> BlockColors;
62
63
  /// Returns true iff the header block of the loop for which this info is
64
  /// calculated contains an instruction that may throw or otherwise exit
65
  /// abnormally.
66
  bool headerMayThrow() const;
67
68
  /// Returns true iff any block of the loop for which this info is contains an
69
  /// instruction that may throw or otherwise exit abnormally.
70
  bool anyBlockMayThrow() const;
71
72
  /// Return true if we must reach the block \p BB under assumption that the
73
  /// loop \p CurLoop is entered and no instruction throws or otherwise exits
74
  /// abnormally.
75
  bool allLoopPathsLeadToBlock(const Loop *CurLoop, const BasicBlock *BB,
76
                               const DominatorTree *DT) const;
77
78
  /// Computes safety information for a loop checks loop body & header for
79
  /// the possibility of may throw exception, it takes LoopSafetyInfo and loop
80
  /// as argument. Updates safety information in LoopSafetyInfo argument.
81
  /// Note: This is defined to clear and reinitialize an already initialized
82
  /// LoopSafetyInfo.  Some callers rely on this fact.
83
  void computeLoopSafetyInfo(Loop *);
84
85
712k
  LoopSafetyInfo() = default;
86
};
87
88
/// Returns true if the instruction in a loop is guaranteed to execute at least
89
/// once (under the assumption that the loop is entered).
90
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT,
91
                           const Loop *CurLoop,
92
                           const LoopSafetyInfo *SafetyInfo);
93
94
}
95
96
#endif