Changeset View
Changeset View
Standalone View
Standalone View
llvm/include/llvm/Transforms/Utils/Local.h
Show All 18 Lines | |||||
#include "llvm/ADT/SmallPtrSet.h" | #include "llvm/ADT/SmallPtrSet.h" | ||||
#include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallVector.h" | ||||
#include "llvm/ADT/TinyPtrVector.h" | #include "llvm/ADT/TinyPtrVector.h" | ||||
#include "llvm/Analysis/AliasAnalysis.h" | #include "llvm/Analysis/AliasAnalysis.h" | ||||
#include "llvm/IR/CallSite.h" | #include "llvm/IR/CallSite.h" | ||||
#include "llvm/IR/Constant.h" | #include "llvm/IR/Constant.h" | ||||
#include "llvm/IR/Constants.h" | #include "llvm/IR/Constants.h" | ||||
#include "llvm/IR/DataLayout.h" | #include "llvm/IR/DataLayout.h" | ||||
#include "llvm/IR/DeferredDominance.h" | |||||
#include "llvm/IR/Dominators.h" | #include "llvm/IR/Dominators.h" | ||||
#include "llvm/IR/GetElementPtrTypeIterator.h" | #include "llvm/IR/GetElementPtrTypeIterator.h" | ||||
#include "llvm/IR/Operator.h" | #include "llvm/IR/Operator.h" | ||||
#include "llvm/IR/Type.h" | #include "llvm/IR/Type.h" | ||||
#include "llvm/IR/User.h" | #include "llvm/IR/User.h" | ||||
#include "llvm/IR/Value.h" | #include "llvm/IR/Value.h" | ||||
#include "llvm/Support/Casting.h" | #include "llvm/Support/Casting.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
/// If a terminator instruction is predicated on a constant value, convert it | /// If a terminator instruction is predicated on a constant value, convert it | ||||
/// into an unconditional branch to the constant destination. | /// into an unconditional branch to the constant destination. | ||||
/// This is a nontrivial operation because the successors of this basic block | /// This is a nontrivial operation because the successors of this basic block | ||||
/// must have their PHI nodes updated. | /// must have their PHI nodes updated. | ||||
/// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch | /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch | ||||
/// conditions and indirectbr addresses this might make dead if | /// conditions and indirectbr addresses this might make dead if | ||||
/// DeleteDeadConditions is true. | /// DeleteDeadConditions is true. | ||||
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false, | bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false, | ||||
const TargetLibraryInfo *TLI = nullptr); | const TargetLibraryInfo *TLI = nullptr, | ||||
DeferredDominance *DDT = nullptr); | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Local dead code elimination. | // Local dead code elimination. | ||||
// | // | ||||
/// Return true if the result produced by the instruction is not used, and the | /// Return true if the result produced by the instruction is not used, and the | ||||
/// instruction has no side effects. | /// instruction has no side effects. | ||||
bool isInstructionTriviallyDead(Instruction *I, | bool isInstructionTriviallyDead(Instruction *I, | ||||
Show All 37 Lines | |||||
/// | /// | ||||
/// Unlike the removePredecessor method, this attempts to simplify uses of PHI | /// Unlike the removePredecessor method, this attempts to simplify uses of PHI | ||||
/// nodes that collapse into identity values. For example, if we have: | /// nodes that collapse into identity values. For example, if we have: | ||||
/// x = phi(1, 0, 0, 0) | /// x = phi(1, 0, 0, 0) | ||||
/// y = and x, z | /// y = and x, z | ||||
/// | /// | ||||
/// .. and delete the predecessor corresponding to the '1', this will attempt to | /// .. and delete the predecessor corresponding to the '1', this will attempt to | ||||
/// recursively fold the 'and' to 0. | /// recursively fold the 'and' to 0. | ||||
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred); | void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, | ||||
DeferredDominance *DDT = nullptr); | |||||
/// BB is a block with one predecessor and its predecessor is known to have one | /// BB is a block with one predecessor and its predecessor is known to have one | ||||
/// successor (BB!). Eliminate the edge between them, moving the instructions in | /// successor (BB!). Eliminate the edge between them, moving the instructions in | ||||
/// the predecessor into BB. This deletes the predecessor block. | /// the predecessor into BB. This deletes the predecessor block. | ||||
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT = nullptr); | void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT = nullptr, | ||||
DeferredDominance *DDT = nullptr); | |||||
/// BB is known to contain an unconditional branch, and contains no instructions | /// BB is known to contain an unconditional branch, and contains no instructions | ||||
/// other than PHI nodes, potential debug intrinsics and the branch. If | /// other than PHI nodes, potential debug intrinsics and the branch. If | ||||
/// possible, eliminate BB by rewriting all the predecessors to branch to the | /// possible, eliminate BB by rewriting all the predecessors to branch to the | ||||
/// successor block and return true. If we can't transform, return false. | /// successor block and return true. If we can't transform, return false. | ||||
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB); | bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, | ||||
DeferredDominance *DDT = nullptr); | |||||
/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try | /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try | ||||
/// to be clever about PHI nodes which differ only in the order of the incoming | /// to be clever about PHI nodes which differ only in the order of the incoming | ||||
/// values, but instcombine orders them so it usually won't matter. | /// values, but instcombine orders them so it usually won't matter. | ||||
bool EliminateDuplicatePHINodes(BasicBlock *BB); | bool EliminateDuplicatePHINodes(BasicBlock *BB); | ||||
/// This function is used to do simplification of a CFG. For example, it | /// This function is used to do simplification of a CFG. For example, it | ||||
/// adjusts branches to branches to eliminate the extra hop, it eliminates | /// adjusts branches to branches to eliminate the extra hop, it eliminates | ||||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
/// Remove all instructions from a basic block other than it's terminator | /// Remove all instructions from a basic block other than it's terminator | ||||
/// and any present EH pad instructions. | /// and any present EH pad instructions. | ||||
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB); | unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB); | ||||
/// Insert an unreachable instruction before the specified | /// Insert an unreachable instruction before the specified | ||||
/// instruction, making it and the rest of the code in the block dead. | /// instruction, making it and the rest of the code in the block dead. | ||||
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, | unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, | ||||
bool PreserveLCSSA = false); | bool PreserveLCSSA = false, | ||||
DeferredDominance *DDT = nullptr); | |||||
/// Convert the CallInst to InvokeInst with the specified unwind edge basic | /// Convert the CallInst to InvokeInst with the specified unwind edge basic | ||||
/// block. This also splits the basic block where CI is located, because | /// block. This also splits the basic block where CI is located, because | ||||
/// InvokeInst is a terminator instruction. Returns the newly split basic | /// InvokeInst is a terminator instruction. Returns the newly split basic | ||||
/// block. | /// block. | ||||
BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI, | BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI, | ||||
BasicBlock *UnwindEdge); | BasicBlock *UnwindEdge); | ||||
/// Replace 'BB's terminator with one that does not have an unwind successor | /// Replace 'BB's terminator with one that does not have an unwind successor | ||||
/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind | /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind | ||||
/// successor. | /// successor. | ||||
/// | /// | ||||
/// \param BB Block whose terminator will be replaced. Its terminator must | /// \param BB Block whose terminator will be replaced. Its terminator must | ||||
/// have an unwind successor. | /// have an unwind successor. | ||||
void removeUnwindEdge(BasicBlock *BB); | void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT = nullptr); | ||||
/// Remove all blocks that can not be reached from the function's entry. | /// Remove all blocks that can not be reached from the function's entry. | ||||
/// | /// | ||||
/// Returns true if any basic block was removed. | /// Returns true if any basic block was removed. | ||||
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr); | bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr, | ||||
DeferredDominance *DDT = nullptr); | |||||
/// Combine the metadata of two instructions so that K can replace J | /// Combine the metadata of two instructions so that K can replace J | ||||
/// | /// | ||||
/// Metadata not listed as known via KnownIDs is removed | /// Metadata not listed as known via KnownIDs is removed | ||||
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs); | void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs); | ||||
/// Combine the metadata of two instructions so that K can replace J. This | /// Combine the metadata of two instructions so that K can replace J. This | ||||
/// specifically handles the case of CSE-like transformations. | /// specifically handles the case of CSE-like transformations. | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |