LLVM API Documentation

SelectionDAGISel.cpp File Reference

#include "llvm/CodeGen/SelectionDAGISel.h"
#include "llvm/CodeGen/ScheduleDAG.h"
#include "llvm/CallingConv.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/CodeGen/IntrinsicLowering.h"
#include "llvm/CodeGen/MachineDebugInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/CodeGen/SSARegMap.h"
#include "llvm/Target/MRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Visibility.h"
#include <map>
#include <set>
#include <iostream>
#include <algorithm>
#include "llvm/Instruction.def"
#include "llvm/Intrinsics.gen"

Include dependency graph for SelectionDAGISel.cpp:

Go to the source code of this file.

Namespaces

namespace  llvm

Classes

class  llvm::FunctionLoweringInfo
class  llvm::SelectionDAGLowering
struct  llvm::SelectionDAGLowering::CaseRec
struct  llvm::SelectionDAGLowering::CaseCmp
 The comparison function for sorting Case values.

Defines

#define DEBUG_TYPE   "isel"
#define HANDLE_INST(NUM, OPCODE, CLASS)   case Instruction::OPCODE:return visit##OPCODE((CLASS&)I);
#define GET_NO_MEMORY_INTRINSICS
#define GET_SIDE_EFFECT_INFO

Enumerations

enum  SchedHeuristics {
  defaultScheduling, noScheduling, simpleScheduling, simpleNoItinScheduling,
  listSchedulingBURR, listSchedulingTDRR, listSchedulingTD
}

Functions

static bool isUsedOutsideOfDefiningBlock (Instruction *I)
static bool isOnlyUsedInEntryBlock (Argument *A)
static bool IntrinsicCannotAccessMemory (unsigned IntrinsicID)
static bool IntrinsicOnlyReadsMemory (unsigned IntrinsicID)
static const TargetRegisterClassisAllocatableRegister (unsigned Reg, MachineFunction &MF, const TargetLowering &TLI, const MRegisterInfo *MRI)
static SDOperand getMemsetValue (SDOperand Value, MVT::ValueType VT, SelectionDAG &DAG)
static SDOperand getMemsetStringVal (MVT::ValueType VT, SelectionDAG &DAG, TargetLowering &TLI, std::string &Str, unsigned Offset)
static SDOperand getMemBasePlusOffset (SDOperand Base, unsigned Offset, SelectionDAG &DAG, TargetLowering &TLI)
 getMemBasePlusOffset - Returns base and offset node for the
static bool MeetsMaxMemopRequirement (std::vector< MVT::ValueType > &MemOps, unsigned Limit, uint64_t Size, unsigned Align, TargetLowering &TLI)
static bool OptimizeNoopCopyExpression (CastInst *CI)
static InstructionInsertGEPComputeCode (Instruction *&V, BasicBlock *BB, Instruction *GEPI, Value *Ptr, Value *PtrOffset)
static void ReplaceUsesOfGEPInst (Instruction *RepPtr, Value *Ptr, Constant *PtrOffset, BasicBlock *DefBB, GetElementPtrInst *GEPI, std::map< BasicBlock *, Instruction * > &InsertedExprs)
static bool OptimizeGEPExpression (GetElementPtrInst *GEPI, const TargetData *TD)

Variables

static cl::opt< bool > ViewISelDAGs ("view-isel-dags", cl::Hidden, cl::desc("Pop up a window to show isel dags as they are selected"))
static cl::opt< bool > ViewSchedDAGs ("view-sched-dags", cl::Hidden, cl::desc("Pop up a window to show sched dags as they are processed"))
cl::opt< SchedHeuristicsISHeuristic ("sched", cl::desc("Choose scheduling style"), cl::init(defaultScheduling), cl::values(clEnumValN(defaultScheduling,"default","Target preferred scheduling style"), clEnumValN(noScheduling,"none","No scheduling: breadth first sequencing"), clEnumValN(simpleScheduling,"simple","Simple two pass scheduling: minimize critical path ""and maximize processor utilization"), clEnumValN(simpleNoItinScheduling,"simple-noitin","Simple two pass scheduling: Same as simple ""except using generic latency"), clEnumValN(listSchedulingBURR,"list-burr","Bottom-up register reduction list scheduling"), clEnumValN(listSchedulingTDRR,"list-tdrr","Top-down register reduction list scheduling"), clEnumValN(listSchedulingTD,"list-td","Top-down list scheduler"), clEnumValEnd))


Define Documentation

#define DEBUG_TYPE   "isel"

Definition at line 14 of file SelectionDAGISel.cpp.

#define GET_NO_MEMORY_INTRINSICS

#define GET_SIDE_EFFECT_INFO

#define HANDLE_INST ( NUM,
OPCODE,
CLASS   )     case Instruction::OPCODE:return visit##OPCODE((CLASS&)I);


Enumeration Type Documentation

enum SchedHeuristics

Enumerator:
defaultScheduling 
noScheduling 
simpleScheduling 
simpleNoItinScheduling 
listSchedulingBURR 
listSchedulingTDRR 
listSchedulingTD 

Definition at line 64 of file SelectionDAGISel.cpp.


Function Documentation

static SDOperand getMemBasePlusOffset ( SDOperand  Base,
unsigned  Offset,
SelectionDAG DAG,
TargetLowering TLI 
) [static]

getMemBasePlusOffset - Returns base and offset node for the

Definition at line 2782 of file SelectionDAGISel.cpp.

References llvm::ISD::ADD, Base, DAG, llvm::SelectionDAG::getConstant(), and llvm::SelectionDAG::getNode().

Referenced by llvm::SelectionDAGLowering::visitMemIntrinsic().

static SDOperand getMemsetStringVal ( MVT::ValueType  VT,
SelectionDAG DAG,
TargetLowering TLI,
std::string &  Str,
unsigned  Offset 
) [static]

getMemsetStringVal - Similar to getMemsetValue. Except this is only used when a memcpy is turned into a memset when the source is a constant string ptr.

Definition at line 2766 of file SelectionDAGISel.cpp.

References DAG, llvm::SelectionDAG::getConstant(), llvm::MVT::getSizeInBits(), llvm::TargetLowering::isLittleEndian(), TLI, and Val.

Referenced by llvm::SelectionDAGLowering::visitMemIntrinsic().

static SDOperand getMemsetValue ( SDOperand  Value,
MVT::ValueType  VT,
SelectionDAG DAG 
) [static]

getMemsetValue - Vectorized representation of the memset value operand.

Definition at line 2735 of file SelectionDAGISel.cpp.

References DAG, llvm::SelectionDAG::getConstant(), llvm::SelectionDAG::getNode(), llvm::MVT::i8, llvm::ISD::OR, llvm::ISD::SHL, Val, and llvm::ISD::ZERO_EXTEND.

Referenced by llvm::SelectionDAGLowering::visitMemIntrinsic().

static Instruction* InsertGEPComputeCode ( Instruction *&  V,
BasicBlock BB,
Instruction GEPI,
Value Ptr,
Value PtrOffset 
) [static]

InsertGEPComputeCode - Insert code into BB to compute Ptr+PtrOffset, casting to the type of GEPI.

Definition at line 3020 of file SelectionDAGISel.cpp.

References BB, llvm::BasicBlock::begin(), llvm::Instruction::getParent(), llvm::Value::getType(), and V.

Referenced by ReplaceUsesOfGEPInst().

static bool IntrinsicCannotAccessMemory ( unsigned  IntrinsicID  )  [static]

IntrinsicCannotAccessMemory - Return true if the specified intrinsic cannot access memory and has no other side effects at all.

Definition at line 1395 of file SelectionDAGISel.cpp.

Referenced by llvm::SelectionDAGLowering::visitTargetIntrinsic().

static bool IntrinsicOnlyReadsMemory ( unsigned  IntrinsicID  )  [static]

Definition at line 1404 of file SelectionDAGISel.cpp.

Referenced by llvm::SelectionDAGLowering::visitTargetIntrinsic().

static const TargetRegisterClass* isAllocatableRegister ( unsigned  Reg,
MachineFunction MF,
const TargetLowering TLI,
const MRegisterInfo MRI 
) [static]

isAllocatableRegister - If the specified register is safe to allocate, i.e. it isn't a stack pointer or some other special register, return the register class for the register. Otherwise, return null.

Definition at line 1855 of file SelectionDAGISel.cpp.

References E, llvm::MVT::getSizeInBits(), llvm::TargetLowering::isTypeLegal(), MF, MRI, llvm::MVT::Other, RC, llvm::MRegisterInfo::regclass_begin(), llvm::MRegisterInfo::regclass_end(), and TLI.

Referenced by llvm::SelectionDAGLowering::GetRegistersForValue().

static bool isOnlyUsedInEntryBlock ( Argument A  )  [static]

isOnlyUsedInEntryBlock - If the specified argument is only used in the entry block, return true. This includes arguments used by switches, since the switch may expand into multiple basic blocks.

Definition at line 207 of file SelectionDAGISel.cpp.

References A, and E.

Referenced by llvm::FunctionLoweringInfo::FunctionLoweringInfo().

static bool isUsedOutsideOfDefiningBlock ( Instruction I  )  [static]

isUsedOutsideOfDefiningBlock - Return true if this instruction is used by PHI nodes or outside of the basic block that defines it, or used by a switch instruction, which may expand to multiple basic blocks.

Definition at line 194 of file SelectionDAGISel.cpp.

References BB, E, and llvm::BasicBlock::getParent().

Referenced by llvm::FunctionLoweringInfo::FunctionLoweringInfo().

static bool MeetsMaxMemopRequirement ( std::vector< MVT::ValueType > &  MemOps,
unsigned  Limit,
uint64_t  Size,
unsigned  Align,
TargetLowering TLI 
) [static]

MeetsMaxMemopRequirement - Determines if the number of memory ops required to replace the memset / memcpy is below the threshold. It also returns the types of the sequence of memory ops to perform memset / memcpy.

Definition at line 2791 of file SelectionDAGISel.cpp.

References llvm::TargetLowering::allowsUnalignedMemoryAccesses(), llvm::MVT::getSizeInBits(), llvm::MVT::i16, llvm::MVT::i32, llvm::MVT::i64, llvm::MVT::i8, llvm::MVT::isInteger(), llvm::TargetLowering::isTypeLegal(), and TLI.

Referenced by llvm::SelectionDAGLowering::visitMemIntrinsic().

static bool OptimizeGEPExpression ( GetElementPtrInst GEPI,
const TargetData TD 
) [static]

OptimizeGEPExpression - Since we are doing basic-block-at-a-time instruction selection, we want to be a bit careful about some things. In particular, if we have a GEP instruction that is used in a different block than it is defined, the addressing expression of the GEP cannot be folded into loads or stores that use it. In this case, decompose the GEP and move constant indices into blocks that use it.

Definition at line 3103 of file SelectionDAGISel.cpp.

References E, llvm::Instruction::eraseFromParent(), llvm::ConstantUInt::get(), llvm::TargetData::getIntPtrType(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Type::getPrimitiveSizeInBits(), llvm::TargetData::getStructLayout(), llvm::Value::getType(), llvm::GetElementPtrInst::getType(), llvm::TargetData::getTypeSize(), Idx, llvm::StructLayout::MemberOffsets, OI, llvm::User::op_begin(), llvm::User::op_end(), llvm::Value::replaceAllUsesWith(), ReplaceUsesOfGEPInst(), TD, Ty, UIntPtrTy, llvm::Value::use_begin(), and llvm::Value::use_end().

Referenced by llvm::SelectionDAGISel::runOnFunction().

static bool OptimizeNoopCopyExpression ( CastInst CI  )  [static]

OptimizeNoopCopyExpression - We have determined that 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.

Return true if any changes are made.

InsertedCasts - Only insert a cast in each block once.

Definition at line 2969 of file SelectionDAGISel.cpp.

References llvm::BasicBlock::begin(), E, llvm::Instruction::eraseFromParent(), llvm::UnaryInstruction::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), MadeChange, llvm::Value::use_begin(), llvm::Value::use_empty(), llvm::Value::use_end(), and User.

Referenced by llvm::SelectionDAGISel::runOnFunction().

static void ReplaceUsesOfGEPInst ( Instruction RepPtr,
Value Ptr,
Constant PtrOffset,
BasicBlock DefBB,
GetElementPtrInst GEPI,
std::map< BasicBlock *, Instruction * > &  InsertedExprs 
) [static]

ReplaceUsesOfGEPInst - Replace all uses of RepPtr with inserted code to compute its value. The RepPtr value can be computed with Ptr+PtrOffset. One trivial way of doing this would be to evaluate Ptr+PtrOffset in RepPtr's block, then ReplaceAllUsesWith'ing everything. However, we would prefer to sink PtrOffset into user blocks where doing so will likely allow us to fold the constant add into a load or store instruction. Additionally, if a user is a pointer-pointer cast, we look through it to find its users.

Definition at line 3055 of file SelectionDAGISel.cpp.

References llvm::UndefValue::get(), llvm::GetElementPtrInst::getType(), llvm::Value::getType(), InsertGEPComputeCode(), llvm::User::replaceUsesOfWith(), llvm::Value::use_back(), and llvm::Value::use_empty().

Referenced by OptimizeGEPExpression().


Variable Documentation

cl::opt<SchedHeuristics> ISHeuristic("sched", cl::desc("Choose scheduling style"), cl::init(defaultScheduling), cl::values(clEnumValN(defaultScheduling,"default","Target preferred scheduling style"),clEnumValN(noScheduling,"none","No scheduling: breadth first sequencing"),clEnumValN(simpleScheduling,"simple","Simple two pass scheduling: minimize critical path ""and maximize processor utilization"),clEnumValN(simpleNoItinScheduling,"simple-noitin","Simple two pass scheduling: Same as simple ""except using generic latency"),clEnumValN(listSchedulingBURR,"list-burr","Bottom-up register reduction list scheduling"),clEnumValN(listSchedulingTDRR,"list-tdrr","Top-down register reduction list scheduling"),clEnumValN(listSchedulingTD,"list-td","Top-down list scheduler"),clEnumValEnd)) [static]

Referenced by llvm::SelectionDAGISel::ScheduleAndEmitDAG().

std::vector<unsigned> Regs

Regs - This list hold the register (for legal and promoted values) or register set (for expanded values) that the value should be assigned to.

Definition at line 109 of file SelectionDAGISel.cpp.

Referenced by llvm::SelectionDAGLowering::GetRegistersForValue(), llvm::LiveVariables::removeVirtualRegistersDead(), llvm::LiveVariables::removeVirtualRegistersKilled(), and llvm::SelectionDAGLowering::visitInlineAsm().

MVT::ValueType RegVT

RegVT - The value type of each register.

Definition at line 113 of file SelectionDAGISel.cpp.

MVT::ValueType ValueVT

ValueVT - The value type of the LLVM value, which may be promoted from RegVT or made from merging the two expanded parts.

Definition at line 117 of file SelectionDAGISel.cpp.

Referenced by llvm::SelectionDAGLowering::GetRegistersForValue().

cl::opt<bool> ViewISelDAGs("view-isel-dags", cl::Hidden, cl::desc("Pop up a window to show isel dags as they are selected")) [static]

cl::opt<bool> ViewSchedDAGs("view-sched-dags", cl::Hidden, cl::desc("Pop up a window to show sched dags as they are processed")) [static]

Referenced by llvm::SelectionDAGISel::ScheduleAndEmitDAG().