LLVM API Documentation

Classes | Public Member Functions | Protected Member Functions | Protected Attributes
llvm::FastISel Class Reference

#include <FastISel.h>

Collaboration diagram for llvm::FastISel:
Collaboration graph
[legend]

List of all members.

Classes

struct  SavePoint

Public Member Functions

MachineInstrgetLastLocalValue ()
void setLastLocalValue (MachineInstr *I)
void startNewBlock ()
DebugLoc getCurDebugLoc () const
 getCurDebugLoc() - Return current debug location information.
bool LowerArguments ()
bool SelectInstruction (const Instruction *I)
bool SelectOperator (const User *I, unsigned Opcode)
unsigned getRegForValue (const Value *V)
unsigned lookUpRegForValue (const Value *V)
std::pair< unsigned, boolgetRegForGEPIndex (const Value *V)
bool tryToFoldLoad (const LoadInst *LI, const Instruction *FoldInst)
 We're checking to see if we can fold LI into FoldInst. Note that we could have a sequence where multiple LLVM IR instructions are folded into the same machineinstr. For example we could have: A: x = load i32 *P B: y = icmp A, 42 C: br y, ...
virtual bool tryToFoldLoadIntoMI (MachineInstr *, unsigned, const LoadInst *)
 The specified machine instr operand is a vreg, and that vreg is being provided by the specified load instruction. If possible, try to fold the load as an operand to the instruction, returning true if possible. This method should be implemented by targets.
void recomputeInsertPt ()
void removeDeadCode (MachineBasicBlock::iterator I, MachineBasicBlock::iterator E)
 removeDeadCode - Remove all dead instructions between the I and E.
SavePoint enterLocalValueArea ()
void leaveLocalValueArea (SavePoint Old)
 leaveLocalValueArea - Reset InsertPt to the given old insert position.
virtual ~FastISel ()

Protected Member Functions

 FastISel (FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
virtual bool TargetSelectInstruction (const Instruction *I)=0
virtual bool FastLowerArguments ()
virtual unsigned FastEmit_ (MVT VT, MVT RetVT, unsigned Opcode)
virtual unsigned FastEmit_r (MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0, bool Op0IsKill)
virtual unsigned FastEmit_rr (MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill)
virtual unsigned FastEmit_ri (MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0, bool Op0IsKill, uint64_t Imm)
virtual unsigned FastEmit_rf (MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0, bool Op0IsKill, const ConstantFP *FPImm)
virtual unsigned FastEmit_rri (MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill, uint64_t Imm)
unsigned FastEmit_ri_ (MVT VT, unsigned Opcode, unsigned Op0, bool Op0IsKill, uint64_t Imm, MVT ImmType)
virtual unsigned FastEmit_i (MVT VT, MVT RetVT, unsigned Opcode, uint64_t Imm)
virtual unsigned FastEmit_f (MVT VT, MVT RetVT, unsigned Opcode, const ConstantFP *FPImm)
unsigned FastEmitInst_ (unsigned MachineInstOpcode, const TargetRegisterClass *RC)
unsigned FastEmitInst_r (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill)
unsigned FastEmitInst_rr (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill)
unsigned FastEmitInst_rrr (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill, unsigned Op2, bool Op2IsKill)
unsigned FastEmitInst_ri (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, uint64_t Imm)
unsigned FastEmitInst_rii (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, uint64_t Imm1, uint64_t Imm2)
unsigned FastEmitInst_rf (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, const ConstantFP *FPImm)
unsigned FastEmitInst_rri (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill, uint64_t Imm)
unsigned FastEmitInst_rrii (unsigned MachineInstOpcode, const TargetRegisterClass *RC, unsigned Op0, bool Op0IsKill, unsigned Op1, bool Op1IsKill, uint64_t Imm1, uint64_t Imm2)
unsigned FastEmitInst_i (unsigned MachineInstrOpcode, const TargetRegisterClass *RC, uint64_t Imm)
unsigned FastEmitInst_ii (unsigned MachineInstrOpcode, const TargetRegisterClass *RC, uint64_t Imm1, uint64_t Imm2)
 FastEmitInst_ii - Emit a MachineInstr with a two immediate operands.
unsigned FastEmitInst_extractsubreg (MVT RetVT, unsigned Op0, bool Op0IsKill, uint32_t Idx)
unsigned FastEmitZExtFromI1 (MVT VT, unsigned Op0, bool Op0IsKill)
void FastEmitBranch (MachineBasicBlock *MBB, DebugLoc DL)
void UpdateValueMap (const Value *I, unsigned Reg, unsigned NumRegs=1)
unsigned createResultReg (const TargetRegisterClass *RC)
virtual unsigned TargetMaterializeConstant (const Constant *C)
virtual unsigned TargetMaterializeAlloca (const AllocaInst *C)
virtual unsigned TargetMaterializeFloatZero (const ConstantFP *CF)

Protected Attributes

DenseMap< const Value *, unsignedLocalValueMap
FunctionLoweringInfoFuncInfo
MachineRegisterInfoMRI
MachineFrameInfoMFI
MachineConstantPoolMCP
DebugLoc DL
const TargetMachineTM
const DataLayoutTD
const TargetInstrInfoTII
const TargetLoweringTLI
const TargetRegisterInfoTRI
const TargetLibraryInfoLibInfo
MachineInstrLastLocalValue
MachineInstrEmitStartPt

Detailed Description

FastISel - This is a fast-path instruction selection class that generates poor code and doesn't support illegal types or non-trivial lowering, but runs quickly.

Definition at line 48 of file FastISel.h.


Constructor & Destructor Documentation

FastISel::~FastISel ( ) [virtual]

Definition at line 1097 of file FastISel.cpp.

FastISel::FastISel ( FunctionLoweringInfo funcInfo,
const TargetLibraryInfo libInfo 
) [explicit, protected]

Definition at line 1083 of file FastISel.cpp.


Member Function Documentation

unsigned FastISel::createResultReg ( const TargetRegisterClass RC) [protected]
FastISel::SavePoint FastISel::enterLocalValueArea ( )

enterLocalValueArea - Prepare InsertPt to begin inserting instructions into the local value area and return the old insert position.

Definition at line 340 of file FastISel.cpp.

References DL, FuncInfo, llvm::FunctionLoweringInfo::InsertPt, and recomputeInsertPt().

Referenced by getRegForValue().

unsigned FastISel::FastEmit_ ( MVT  VT,
MVT  RetVT,
unsigned  Opcode 
) [protected, virtual]

FastEmit_r - This method is called by target-independent code to request that an instruction with the given type and opcode be emitted.

Definition at line 1103 of file FastISel.cpp.

unsigned FastISel::FastEmit_f ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
const ConstantFP FPImm 
) [protected, virtual]

FastEmit_f - This method is called by target-independent code to request that an instruction with the given type, opcode, and floating-point immediate operand be emitted.

Definition at line 1125 of file FastISel.cpp.

unsigned FastISel::FastEmit_i ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
uint64_t  Imm 
) [protected, virtual]

FastEmit_i - This method is called by target-independent code to request that an instruction with the given type, opcode, and immediate operand be emitted.

Definition at line 1121 of file FastISel.cpp.

Referenced by FastEmit_ri_().

unsigned FastISel::FastEmit_r ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill 
) [protected, virtual]

FastEmit_r - This method is called by target-independent code to request that an instruction with the given type, opcode, and register operand be emitted.

Definition at line 1108 of file FastISel.cpp.

Referenced by getRegForGEPIndex().

unsigned FastISel::FastEmit_rf ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill,
const ConstantFP FPImm 
) [protected, virtual]

FastEmit_rf - This method is called by target-independent code to request that an instruction with the given type, opcode, and register and floating-point immediate operands be emitted.

Definition at line 1137 of file FastISel.cpp.

unsigned FastISel::FastEmit_ri ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill,
uint64_t  Imm 
) [protected, virtual]

FastEmit_ri - This method is called by target-independent code to request that an instruction with the given type, opcode, and register and immediate operands be emitted.

Definition at line 1130 of file FastISel.cpp.

Referenced by FastEmit_ri_(), and FastEmitZExtFromI1().

unsigned FastISel::FastEmit_ri_ ( MVT  VT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill,
uint64_t  Imm,
MVT  ImmType 
) [protected]

FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries to emit an instruction with an immediate operand using FastEmit_ri. If that fails, it materializes the immediate into a register and try FastEmit_rr instead.

Definition at line 1156 of file FastISel.cpp.

References llvm::ISD::Constant, FastEmit_i(), FastEmit_ri(), FastEmit_rr(), llvm::FunctionLoweringInfo::Fn, FuncInfo, llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::Function::getContext(), getRegForValue(), llvm::MVT::getSizeInBits(), llvm::isPowerOf2_64(), llvm::Log2_64(), llvm::ISD::MUL, llvm::ISD::SHL, llvm::ISD::SRA, llvm::ISD::SRL, and llvm::ISD::UDIV.

unsigned FastISel::FastEmit_rr ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill 
) [protected, virtual]

FastEmit_rr - This method is called by target-independent code to request that an instruction with the given type, opcode, and register operands be emitted.

Definition at line 1114 of file FastISel.cpp.

Referenced by FastEmit_ri_().

unsigned FastISel::FastEmit_rri ( MVT  VT,
MVT  RetVT,
unsigned  Opcode,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill,
uint64_t  Imm 
) [protected, virtual]

FastEmit_rri - This method is called by target-independent code to request that an instruction with the given type, opcode, and register and immediate operands be emitted.

Definition at line 1144 of file FastISel.cpp.

void FastISel::FastEmitBranch ( MachineBasicBlock MSucc,
DebugLoc  DL 
) [protected]

FastEmitBranch - Emit an unconditional branch to the given block, unless it is the immediate (fall-through) successor, and update the CFG.

Definition at line 865 of file FastISel.cpp.

References llvm::MachineBasicBlock::addSuccessor(), FuncInfo, llvm::MachineBasicBlock::getBasicBlock(), llvm::TargetInstrInfo::InsertBranch(), llvm::MachineBasicBlock::isLayoutSuccessor(), llvm::FunctionLoweringInfo::MBB, llvm::BasicBlock::size(), and TII.

Referenced by SelectOperator().

unsigned FastISel::FastEmitInst_ ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC 
) [protected]

FastEmitInst_ - Emit a MachineInstr with no operands and a result register in the given register class.

Definition at line 1198 of file FastISel.cpp.

References llvm::BuildMI(), createResultReg(), DL, FuncInfo, llvm::MCInstrInfo::get(), llvm::FunctionLoweringInfo::InsertPt, llvm::FunctionLoweringInfo::MBB, and TII.

unsigned FastISel::FastEmitInst_extractsubreg ( MVT  RetVT,
unsigned  Op0,
bool  Op0IsKill,
uint32_t  Idx 
) [protected]
unsigned FastISel::FastEmitInst_i ( unsigned  MachineInstrOpcode,
const TargetRegisterClass RC,
uint64_t  Imm 
) [protected]
unsigned FastISel::FastEmitInst_ii ( unsigned  MachineInstrOpcode,
const TargetRegisterClass RC,
uint64_t  Imm1,
uint64_t  Imm2 
) [protected]
unsigned FastISel::FastEmitInst_r ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill 
) [protected]
unsigned FastISel::FastEmitInst_rf ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
const ConstantFP FPImm 
) [protected]
unsigned FastISel::FastEmitInst_ri ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
uint64_t  Imm 
) [protected]
unsigned FastISel::FastEmitInst_rii ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
uint64_t  Imm1,
uint64_t  Imm2 
) [protected]
unsigned FastISel::FastEmitInst_rr ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill 
) [protected]
unsigned FastISel::FastEmitInst_rri ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill,
uint64_t  Imm 
) [protected]
unsigned FastISel::FastEmitInst_rrii ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill,
uint64_t  Imm1,
uint64_t  Imm2 
) [protected]
unsigned FastISel::FastEmitInst_rrr ( unsigned  MachineInstOpcode,
const TargetRegisterClass RC,
unsigned  Op0,
bool  Op0IsKill,
unsigned  Op1,
bool  Op1IsKill,
unsigned  Op2,
bool  Op2IsKill 
) [protected]
unsigned FastISel::FastEmitZExtFromI1 ( MVT  VT,
unsigned  Op0,
bool  Op0IsKill 
) [protected]

FastEmitZExtFromI1 - Emit MachineInstrs to compute the value of Op with all but the least significant bit set to zero.

Definition at line 1433 of file FastISel.cpp.

References llvm::ISD::AND, and FastEmit_ri().

bool FastISel::FastLowerArguments ( ) [protected, virtual]

FastLowerArguments - This method is called by target-independent code to do target specific argument lowering. It returns true if it was successful.

Definition at line 1099 of file FastISel.cpp.

Referenced by LowerArguments().

DebugLoc llvm::FastISel::getCurDebugLoc ( ) const [inline]

getCurDebugLoc() - Return current debug location information.

Definition at line 92 of file FastISel.h.

References DL.

MachineInstr* llvm::FastISel::getLastLocalValue ( ) [inline]

getLastLocalValue - Return the position of the last instruction emitted for materializing constants for use in the current block.

Definition at line 77 of file FastISel.h.

References LastLocalValue.

Referenced by recomputeInsertPt().

std::pair< unsigned, bool > FastISel::getRegForGEPIndex ( const Value V)

getRegForGEPIndex - This is a wrapper around getRegForValue that also takes care of truncating or sign-extending the given getelementptr index value.

Definition at line 290 of file FastISel.cpp.

References llvm::EVT::bitsGT(), llvm::EVT::bitsLT(), FastEmit_r(), llvm::EVT::getEVT(), llvm::TargetLoweringBase::getPointerTy(), getRegForValue(), llvm::EVT::getSimpleVT(), llvm::Value::getType(), llvm::ISD::SIGN_EXTEND, TLI, and llvm::ISD::TRUNCATE.

unsigned FastISel::getRegForValue ( const Value V)
void FastISel::leaveLocalValueArea ( SavePoint  Old)
unsigned FastISel::lookUpRegForValue ( const Value V)

lookUpRegForValue - Look up the value to see if its value is already cached in a register. It may be defined by instructions across blocks or defined locally.

Definition at line 254 of file FastISel.cpp.

References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT >::find(), FuncInfo, LocalValueMap, and llvm::FunctionLoweringInfo::ValueMap.

Referenced by getRegForValue().

bool FastISel::LowerArguments ( )
void FastISel::recomputeInsertPt ( )

recomputeInsertPt - Reset InsertPt to prepare for inserting instructions into the current block.

Definition at line 314 of file FastISel.cpp.

References llvm::ISD::EH_LABEL, llvm::MachineBasicBlock::end(), FuncInfo, llvm::MachineBasicBlock::getFirstNonPHI(), getLastLocalValue(), llvm::FunctionLoweringInfo::InsertPt, and llvm::FunctionLoweringInfo::MBB.

Referenced by enterLocalValueArea(), removeDeadCode(), and SelectInstruction().

void FastISel::removeDeadCode ( MachineBasicBlock::iterator  I,
MachineBasicBlock::iterator  E 
)

removeDeadCode - Remove all dead instructions between the I and E.

Definition at line 328 of file FastISel.cpp.

References llvm::RegState::Dead, llvm::MachineInstr::eraseFromParent(), llvm::ARM_PROC::I, and recomputeInsertPt().

Referenced by SelectInstruction().

bool FastISel::SelectInstruction ( const Instruction I)
bool FastISel::SelectOperator ( const User I,
unsigned  Opcode 
)
void llvm::FastISel::setLastLocalValue ( MachineInstr I) [inline]

setLastLocalValue - Update the position of the last instruction emitted for materializing constants for use in the current block.

Definition at line 81 of file FastISel.h.

References EmitStartPt, llvm::ARM_PROC::I, and LastLocalValue.

void FastISel::startNewBlock ( )

startNewBlock - Set the current block to which generated machine instructions will be appended, and clear the local CSE map.

Definition at line 75 of file FastISel.cpp.

References llvm::MachineBasicBlock::begin(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT >::clear(), llvm::ISD::EH_LABEL, EmitStartPt, llvm::MachineBasicBlock::end(), FuncInfo, llvm::ARM_PROC::I, LastLocalValue, LocalValueMap, and llvm::FunctionLoweringInfo::MBB.

virtual unsigned llvm::FastISel::TargetMaterializeAlloca ( const AllocaInst C) [inline, protected, virtual]

TargetMaterializeAlloca - Emit an alloca address in a register using target-specific logic.

Definition at line 383 of file FastISel.h.

virtual unsigned llvm::FastISel::TargetMaterializeConstant ( const Constant C) [inline, protected, virtual]

TargetMaterializeConstant - Emit a constant in a register using target-specific logic, such as constant pool loads.

Definition at line 377 of file FastISel.h.

virtual unsigned llvm::FastISel::TargetMaterializeFloatZero ( const ConstantFP CF) [inline, protected, virtual]

Definition at line 387 of file FastISel.h.

virtual bool llvm::FastISel::TargetSelectInstruction ( const Instruction I) [protected, pure virtual]

TargetSelectInstruction - This method is called by target-independent code when the normal FastISel process fails to select an instruction. This gives targets a chance to emit code for anything that doesn't fit into FastISel's framework. It returns true if it was successful.

Referenced by SelectInstruction().

bool FastISel::tryToFoldLoad ( const LoadInst LI,
const Instruction FoldInst 
)

We're checking to see if we can fold LI into FoldInst. Note that we could have a sequence where multiple LLVM IR instructions are folded into the same machineinstr. For example we could have: A: x = load i32 *P B: y = icmp A, 42 C: br y, ...

In this scenario, LI is "A", and FoldInst is "C". We know about "B" (and any other folded instructions) because it is between A and C.

If we succeed folding, return true.

Definition at line 1509 of file FastISel.cpp.

References FuncInfo, llvm::MachineRegisterInfo::defusechain_iterator< ReturnUses, ReturnDefs, SkipDebug >::getOperandNo(), llvm::Instruction::getParent(), llvm::MachineInstr::getParent(), getRegForValue(), llvm::Value::hasOneUse(), llvm::MachineRegisterInfo::hasOneUse(), llvm::FunctionLoweringInfo::InsertPt, llvm::LoadInst::isVolatile(), LI, llvm::FunctionLoweringInfo::MBB, MRI, llvm::MachineRegisterInfo::reg_begin(), tryToFoldLoadIntoMI(), and llvm::Instruction::use_back().

virtual bool llvm::FastISel::tryToFoldLoadIntoMI ( MachineInstr ,
unsigned  ,
const LoadInst  
) [inline, virtual]

The specified machine instr operand is a vreg, and that vreg is being provided by the specified load instruction. If possible, try to fold the load as an operand to the instruction, returning true if possible. This method should be implemented by targets.

Definition at line 146 of file FastISel.h.

Referenced by tryToFoldLoad().

void FastISel::UpdateValueMap ( const Value I,
unsigned  Reg,
unsigned  NumRegs = 1 
) [protected]

UpdateValueMap - Update the value map to include the new mapping for this instruction, or insert an extra copy to get the result in a previous determined register. NOTE: This is only necessary because we might select a block that uses a value before we select the block that defines the value. It might be possible to fix this by selecting blocks in reverse postorder.

Definition at line 271 of file FastISel.cpp.

References FuncInfo, llvm::ARM_PROC::I, LocalValueMap, llvm::FunctionLoweringInfo::RegFixups, and llvm::FunctionLoweringInfo::ValueMap.

Referenced by SelectOperator().


Member Data Documentation

The top most instruction in the current block that is allowed for emitting local variables. LastLocalValue resets to EmitStartPt when it makes sense (for example, on function calls)

Definition at line 72 of file FastISel.h.

Referenced by setLastLocalValue(), and startNewBlock().

The position of the last instruction for materializing constants for use in the current block. It resets to EmitStartPt when it makes sense (for example, it's usually profitable to avoid function calls between the definition and the use)

Definition at line 67 of file FastISel.h.

Referenced by getLastLocalValue(), leaveLocalValueArea(), setLastLocalValue(), and startNewBlock().

Definition at line 61 of file FastISel.h.

Referenced by SelectInstruction().

Definition at line 50 of file FastISel.h.

Referenced by lookUpRegForValue(), LowerArguments(), startNewBlock(), and UpdateValueMap().

Definition at line 54 of file FastISel.h.

Definition at line 53 of file FastISel.h.

Definition at line 52 of file FastISel.h.

Referenced by createResultReg(), FastEmitInst_extractsubreg(), and tryToFoldLoad().

const DataLayout& llvm::FastISel::TD [protected]

Definition at line 57 of file FastISel.h.

const TargetLowering& llvm::FastISel::TLI [protected]
const TargetMachine& llvm::FastISel::TM [protected]

Definition at line 56 of file FastISel.h.

Definition at line 60 of file FastISel.h.

Referenced by FastEmitInst_extractsubreg().


The documentation for this class was generated from the following files: