Files
archived-llvm/include/llvm/Transforms/Utils/ImplicitControlFlowTracking.h
Max Kazantsev bc569e6512 [NFC] Factor out implicit control flow logic from GVN
Logic for tracking implicit control flow instructions was added to GVN to
perform PRE optimizations correctly. It appears that GVN is not the only
optimization that sometimes does PRE, so this logic is required in other
places (such as Jump Threading).

This is an NFC patch that encapsulates all ICF-related logic in a dedicated
utility class separated from GVN.

Differential Revision: https://reviews.llvm.org/D40293


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339086 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-07 01:47:20 +00:00

63 lines
2.4 KiB
C++

//===-- ImplicitControlFlowTracking.h ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This class allows to keep track on instructions with implicit control flow.
// These are instructions that may not pass execution to their successors. For
// example, throwing calls and guards do not always do this. If we need to know
// for sure that some instruction is guaranteed to execute if the given block
// is reached, then we need to make sure that there is no implicit control flow
// instruction (ICFI) preceeding it. For example, this check is required if we
// perform PRE moving non-speculable instruction to other place.
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H
#define LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H
#include "llvm/IR/Dominators.h"
#include "llvm/Transforms/Utils/OrderedInstructions.h"
namespace llvm {
class ImplicitControlFlowTracking {
public:
ImplicitControlFlowTracking(DominatorTree *DT)
: OI(OrderedInstructions(DT)) {}
// Returns the topmost instruction with implicit control flow from the given
// basic block. Returns nullptr if there is no such instructions in the block.
const Instruction *getFirstICFI(const BasicBlock *BB);
// Returns true if at least one instruction from the given basic block has
// implicit control flow.
bool hasICF(const BasicBlock *BB);
// Returns true if the first ICFI of Insn's block exists and dominates Insn.
bool isDominatedByICFIFromSameBlock(const Instruction *Insn);
// Clears information about this particular block.
void invalidateBlock(const BasicBlock *BB);
// Invalidates all information from this tracking.
void clear();
private:
// Fills information about the given block's implicit control flow.
void fill(const BasicBlock *BB);
// Maps a block to the topmost instruction with implicit control flow in it.
DenseMap<const BasicBlock *, const Instruction *>
FirstImplicitControlFlowInsts;
OrderedInstructions OI;
// Blocks for which we have the actual information.
SmallPtrSet<const BasicBlock *, 8> KnownBlocks;
};
} // llvm
#endif // LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H