LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Utils/SimplifyCFG.cpp File Reference

#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/Type.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h"
#include <algorithm>
#include <functional>
#include <set>
#include <map>

Include dependency graph for Utils/SimplifyCFG.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "simplifycfg"

Functions

static bool PropagatePredecessorsForPHIs (BasicBlock *BB, BasicBlock *Succ)
static ValueGetIfCondition (BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
static bool DominatesMergePoint (Value *V, BasicBlock *BB, std::set< Instruction * > *AggressiveInsts)
static ValueGatherConstantSetEQs (Value *V, std::vector< ConstantInt * > &Values)
static ValueGatherConstantSetNEs (Value *V, std::vector< ConstantInt * > &Values)
static bool GatherValueComparisons (Instruction *Cond, Value *&CompVal, std::vector< ConstantInt * > &Values)
static void ErasePossiblyDeadInstructionTree (Instruction *I)
static bool SafeToMergeTerminators (TerminatorInst *SI1, TerminatorInst *SI2)
static void AddPredecessorToBlock (BasicBlock *Succ, BasicBlock *NewPred, BasicBlock *ExistPred)
static ValueisValueEqualityComparison (TerminatorInst *TI)
static BasicBlockGetValueEqualityComparisonCases (TerminatorInst *TI, std::vector< std::pair< ConstantInt *, BasicBlock * > > &Cases)
static bool FoldValueComparisonIntoPredecessors (TerminatorInst *TI)
static bool HoistThenElseCodeToIf (BranchInst *BI)
bool llvm::SimplifyCFG (BasicBlock *BB)


Define Documentation

#define DEBUG_TYPE   "simplifycfg"
 

Definition at line 14 of file Utils/SimplifyCFG.cpp.


Function Documentation

static void AddPredecessorToBlock BasicBlock Succ,
BasicBlock NewPred,
BasicBlock ExistPred
[static]
 

AddPredecessorToBlock - Update PHI nodes in Succ to indicate that there will now be entries in it from the 'NewPred' block. The values that will be flowing into the PHI nodes will be the same as those coming in from ExistPred, an existing predecessor of Succ.

Definition at line 365 of file Utils/SimplifyCFG.cpp.

References llvm::PHINode::addIncoming(), llvm::BasicBlock::begin(), llvm::PHINode::getIncomingValueForBlock(), I, llvm::succ_begin(), llvm::succ_end(), and V.

Referenced by FoldValueComparisonIntoPredecessors(), HoistThenElseCodeToIf(), and llvm::SimplifyCFG().

static bool DominatesMergePoint Value V,
BasicBlock BB,
std::set< Instruction * > *  AggressiveInsts
[static]
 

Definition at line 193 of file Utils/SimplifyCFG.cpp.

References Add(), llvm::ISD::And, llvm::BasicBlock::begin(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), I, llvm::ISD::Load, llvm::ISD::Or, llvm::Instruction::Shl, and llvm::ISD::Xor.

Referenced by llvm::SimplifyCFG().

static void ErasePossiblyDeadInstructionTree Instruction I  )  [static]
 

ErasePossiblyDeadInstructionTree - If the specified instruction is dead and has no side effects, nuke it. If it uses any instructions that become dead because the instruction is now gone, nuke them too.

Definition at line 325 of file Utils/SimplifyCFG.cpp.

References llvm::BasicBlock::getInstList(), llvm::Instruction::getParent(), llvm::isInstructionTriviallyDead(), llvm::User::op_begin(), and llvm::User::op_end().

Referenced by llvm::SimplifyCFG().

static bool FoldValueComparisonIntoPredecessors TerminatorInst TI  )  [static]
 

Definition at line 427 of file Utils/SimplifyCFG.cpp.

References llvm::SwitchInst::addCase(), AddPredecessorToBlock(), llvm::ISD::BasicBlock, E, first, llvm::BasicBlock::getInstList(), llvm::SwitchInst::getNumSuccessors(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), llvm::SwitchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), GetValueEqualityComparisonCases(), I, isValueEqualityComparison(), llvm::pred_begin(), llvm::pred_end(), llvm::BasicBlock::removePredecessor(), SafeToMergeTerminators(), second, and llvm::SwitchInst::setSuccessor().

Referenced by llvm::SimplifyCFG().

static Value* GatherConstantSetEQs Value V,
std::vector< ConstantInt * > &  Values
[static]
 

Definition at line 253 of file Utils/SimplifyCFG.cpp.

References C, llvm::ISD::Or, and llvm::ISD::SetEQ.

Referenced by GatherValueComparisons().

static Value* GatherConstantSetNEs Value V,
std::vector< ConstantInt * > &  Values
[static]
 

Definition at line 275 of file Utils/SimplifyCFG.cpp.

References llvm::ISD::And, llvm::Type::BoolTy, C, llvm::Instruction::Cast, llvm::ConstantInt::get(), and llvm::ISD::SetNE.

Referenced by GatherValueComparisons().

static bool GatherValueComparisons Instruction Cond,
Value *&  CompVal,
std::vector< ConstantInt * > &  Values
[static]
 

GatherValueComparisons - If the specified Cond is an 'and' or 'or' of a bunch of comparisons of one value against constants, return the value and the constants being compared.

Definition at line 304 of file Utils/SimplifyCFG.cpp.

References llvm::ISD::And, GatherConstantSetEQs(), GatherConstantSetNEs(), llvm::Instruction::getOpcode(), and llvm::ISD::Or.

Referenced by llvm::SimplifyCFG().

static Value* GetIfCondition BasicBlock BB,
BasicBlock *&  IfTrue,
BasicBlock *&  IfFalse
[static]
 

GetIfCondition - Given a basic block (BB) with two predecessors (and presumably PHI nodes in it), check to see if the merge at this block is due to an "if condition". If so, return the boolean condition that determines which entry into BB will be taken. Also, return by references the block that will be entered from if the condition is true, and the block that will be entered if the condition is false.

Definition at line 102 of file Utils/SimplifyCFG.cpp.

References llvm::BranchInst::getCondition(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::BranchInst::isConditional(), llvm::pred_begin(), and llvm::pred_end().

Referenced by llvm::SimplifyCFG().

static BasicBlock* GetValueEqualityComparisonCases TerminatorInst TI,
std::vector< std::pair< ConstantInt *, BasicBlock * > > &  Cases
[static]
 

Definition at line 403 of file Utils/SimplifyCFG.cpp.

References llvm::BranchInst::getCondition(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::BranchInst::getSuccessor(), llvm::ISD::SetEQ, and llvm::ISD::SetNE.

Referenced by FoldValueComparisonIntoPredecessors().

static bool HoistThenElseCodeToIf BranchInst BI  )  [static]
 

HoistThenElseCodeToIf - Given a conditional branch that codes to BB1 and BB2, hoist any common code in the two blocks up into the branch block. The caller of this function guarantees that BI's block dominates BB1 and BB2.

Definition at line 550 of file Utils/SimplifyCFG.cpp.

References AddPredecessorToBlock(), llvm::BasicBlock::begin(), llvm::Instruction::clone(), E, llvm::Instruction::eraseFromParent(), llvm::BranchInst::getCondition(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValueForBlock(), llvm::BasicBlock::getInstList(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::Instruction::getParent(), llvm::BranchInst::getSuccessor(), llvm::Value::getType(), llvm::Instruction::isIdenticalTo(), llvm::Value::replaceAllUsesWith(), llvm::PHINode::setIncomingValue(), llvm::Instruction::setName(), llvm::succ_begin(), llvm::succ_end(), and llvm::Type::VoidTy.

Referenced by llvm::SimplifyCFG().

static Value* isValueEqualityComparison TerminatorInst TI  )  [static]
 

Definition at line 380 of file Utils/SimplifyCFG.cpp.

References llvm::pred_begin(), llvm::pred_end(), llvm::ISD::SetEQ, and llvm::ISD::SetNE.

Referenced by FoldValueComparisonIntoPredecessors(), and llvm::SimplifyCFG().

static bool PropagatePredecessorsForPHIs BasicBlock BB,
BasicBlock Succ
[static]
 

Definition at line 36 of file Utils/SimplifyCFG.cpp.

References llvm::PHINode::addIncoming(), llvm::BasicBlock::begin(), llvm::BasicBlock::front(), llvm::PHINode::getBasicBlockIndex(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), I, llvm::pred_begin(), llvm::pred_end(), llvm::PHINode::removeIncomingValue(), and llvm::succ_begin().

Referenced by llvm::SimplifyCFG().

static bool SafeToMergeTerminators TerminatorInst SI1,
TerminatorInst SI2
[static]
 

SafeToMergeTerminators - Return true if it is safe to merge these two terminator instructions together.

Definition at line 338 of file Utils/SimplifyCFG.cpp.

References E, llvm::PHINode::getIncomingValueForBlock(), llvm::Instruction::getParent(), I, llvm::succ_begin(), and llvm::succ_end().

Referenced by FoldValueComparisonIntoPredecessors(), and llvm::SimplifyCFG().