LLVM API Documentation

CodeGenPrepare.cpp File Reference

#include "llvm/Transforms/Scalar.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/PatternMatch.h"

Include dependency graph for CodeGenPrepare.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "codegenprepare"

Functions

FunctionPass * llvm::createCodeGenPreparePass (const TargetLowering *TLI=0)
static void SplitEdgeNicely (TerminatorInst *TI, unsigned SuccNum, SmallSet< std::pair< BasicBlock *, BasicBlock * >, 8 > &BackEdges, Pass *P)
static bool OptimizeNoopCopyExpression (CastInst *CI, const TargetLowering &TLI)
static bool OptimizeCmpExpression (CmpInst *CI)
static OStream & operator<< (OStream &OS, const ExtAddrMode &AM)
static bool MightBeFoldableInst (Instruction *I)
static bool IsOperandAMemoryOperand (CallInst *CI, InlineAsm *IA, Value *OpVal, const TargetLowering &TLI)
static bool FindAllMemoryUses (Instruction *I, SmallVectorImpl< std::pair< Instruction *, unsigned > > &MemoryUses, SmallPtrSet< Instruction *, 16 > &ConsideredInsts, const TargetLowering &TLI)
static bool IsNonLocalValue (Value *V, BasicBlock *BB)

Variables

static cl::opt< bool > FactorCommonPreds ("split-critical-paths-tweak", cl::init(false), cl::Hidden)
static RegisterPass
< CodeGenPrepare > 
X ("codegenprepare","Optimize for code generation")


Define Documentation

#define DEBUG_TYPE   "codegenprepare"

Definition at line 16 of file CodeGenPrepare.cpp.


Function Documentation

static bool FindAllMemoryUses ( Instruction *  I,
SmallVectorImpl< std::pair< Instruction *, unsigned > > &  MemoryUses,
SmallPtrSet< Instruction *, 16 > &  ConsideredInsts,
const TargetLowering &  TLI 
) [static]

FindAllMemoryUses - Recursively walk all the uses of I until we find a memory use. If we find an obviously non-foldable instruction, return true. Add the ultimately found memory instructions to MemoryUses.

Definition at line 1011 of file CodeGenPrepare.cpp.

References llvm::dyn_cast(), E, llvm::SmallPtrSet< PtrType, SmallSize >::insert(), IsOperandAMemoryOperand(), LI, MightBeFoldableInst(), llvm::Value::use_begin(), and llvm::Value::use_end().

static bool IsNonLocalValue ( Value *  V,
BasicBlock *  BB 
) [static]

IsNonLocalValue - Return true if the specified values are defined in a different basic block than BB.

Definition at line 1194 of file CodeGenPrepare.cpp.

References llvm::Instruction::getParent().

static bool IsOperandAMemoryOperand ( CallInst *  CI,
InlineAsm *  IA,
Value *  OpVal,
const TargetLowering &  TLI 
) [static]

IsOperandAMemoryOperand - Check to see if all uses of OpVal by the specified inline asm call are due to memory operands. If so, return true, otherwise return false.

Definition at line 969 of file CodeGenPrepare.cpp.

References llvm::TargetLowering::AsmOperandInfo::CallOperandVal, llvm::TargetLowering::ComputeConstraintToUse(), Constraints, llvm::TargetLowering::AsmOperandInfo::ConstraintType, llvm::User::getOperand(), llvm::InlineAsm::ConstraintInfo::isIndirect, llvm::InlineAsm::ParseConstraints(), and llvm::InlineAsm::ConstraintInfo::Type.

Referenced by FindAllMemoryUses().

static bool MightBeFoldableInst ( Instruction *  I  )  [static]

MightBeFoldableInst - This is a little filter, which returns true if an addressing computation involving I might be folded into a load/store accessing it. This doesn't need to be perfect, but needs to accept at least the set of instructions that MatchOperationAddr can.

Definition at line 712 of file CodeGenPrepare.cpp.

References Add(), BitCast, llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), and PtrToInt.

Referenced by FindAllMemoryUses().

static OStream& operator<< ( OStream &  OS,
const ExtAddrMode &  AM 
) [inline, static]

Definition at line 569 of file CodeGenPrepare.cpp.

static bool OptimizeCmpExpression ( CmpInst *  CI  )  [static]

OptimizeCmpExpression - sink the given CmpInst into user blocks to reduce the number of virtual registers that must be created and coalesced. This is a clear win except on targets with multiple condition code registers (PowerPC), where it might lose; some adjustment may be wanted there.

Return true if any changes are made.

InsertedCmp - Only insert a cmp in each block once.

Definition at line 502 of file CodeGenPrepare.cpp.

References llvm::CmpInst::Create(), E, llvm::Instruction::eraseFromParent(), llvm::BasicBlock::getFirstNonPHI(), llvm::CmpInst::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::Value::use_begin(), llvm::Value::use_empty(), and llvm::Value::use_end().

static bool OptimizeNoopCopyExpression ( CastInst *  CI,
const TargetLowering &  TLI 
) [static]

OptimizeNoopCopyExpression - If the specified cast instruction is a noop copy (e.g. it's casting from one pointer type to another, int->uint, or int->sbyte on PPC), sink it into user blocks to reduce the number of virtual registers that must be created and coalesced.

Return true if any changes are made.

InsertedCasts - Only insert a cast in each block once.

Definition at line 422 of file CodeGenPrepare.cpp.

References llvm::MVT::bitsLT(), llvm::CastInst::Create(), E, llvm::Instruction::eraseFromParent(), llvm::BasicBlock::getFirstNonPHI(), llvm::PHINode::getIncomingBlock(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::TargetLowering::getTypeAction(), llvm::TargetLowering::getTypeToTransformTo(), llvm::TargetLowering::getValueType(), llvm::MVT::isInteger(), llvm::TargetLowering::Promote, llvm::Value::use_begin(), llvm::Value::use_empty(), and llvm::Value::use_end().

static void SplitEdgeNicely ( TerminatorInst *  TI,
unsigned  SuccNum,
SmallSet< std::pair< BasicBlock *, BasicBlock * >, 8 > &  BackEdges,
Pass *  P 
) [static]

SplitEdgeNicely - Split the critical edge from TI to its specified successor if it will improve codegen. We only do this if the successor has phi nodes (otherwise critical edges are ok). If there is already another predecessor of the succ that is empty (and thus has no phi nodes), use it instead of introducing a new block.

TIPHIValues - This array is lazily computed to determine the values of PHIs in Dest that TI would provide.

Definition at line 320 of file CodeGenPrepare.cpp.

References BackEdges, llvm::BasicBlock::begin(), Dest, llvm::dyn_cast(), E, llvm::SmallVectorImpl< T >::empty(), FactorCommonPreds, llvm::BasicBlock::front(), llvm::Function::getEntryBlock(), llvm::PHINode::getIncomingValueForBlock(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), llvm::TerminatorInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::BranchInst::isUnconditional(), PI, llvm::pred_begin(), llvm::pred_end(), llvm::SmallVectorImpl< T >::push_back(), llvm::BasicBlock::removePredecessor(), llvm::TerminatorInst::setSuccessor(), llvm::SmallVectorImpl< T >::size(), llvm::SplitBlockPredecessors(), and llvm::SplitCriticalEdge().


Variable Documentation

const Type* AccessTy

AccessTy/MemoryInst - This is the type for the access (e.g. double) and the memory instruction that we're computing this address for.

Definition at line 607 of file CodeGenPrepare.cpp.

Referenced by llvm::FindAvailableLoadedValue(), and isObjectSmallerThan().

ExtAddrMode& AddrMode

AddrMode - This is the addressing mode that we're building up. This is part of the return value of this addressing mode matching stuff.

Definition at line 612 of file CodeGenPrepare.cpp.

Referenced by llvm::ARMInstrInfo::convertToThreeAddress(), llvm::ARMRegisterInfo::eliminateFrameIndex(), and llvm::ARMRegisterInfo::processFunctionBeforeCalleeSavedScan().

Definition at line 602 of file CodeGenPrepare.cpp.

BackEdges - Keep a set of all the loop back edges.

Definition at line 52 of file CodeGenPrepare.cpp.

Referenced by SplitEdgeNicely().

cl::opt<bool> FactorCommonPreds("split-critical-paths-tweak", cl::init(false), cl::Hidden) [static]

Referenced by SplitEdgeNicely().

char ID [static]

Definition at line 54 of file CodeGenPrepare.cpp.

IgnoreProfitability - This is set to true when we should not do profitability checks. When true, IsProfitableToFoldIntoAddressingMode always returns true.

Definition at line 617 of file CodeGenPrepare.cpp.

Definition at line 608 of file CodeGenPrepare.cpp.

Definition at line 559 of file CodeGenPrepare.cpp.

TLI - Keep a pointer of a TargetLowering to consult for determining transformation profitability.

Definition at line 48 of file CodeGenPrepare.cpp.

RegisterPass<CodeGenPrepare> X("codegenprepare","Optimize for code generation") [static]