LLVM  7.0.0svn
Public Types | Public Member Functions | Public Attributes | List of all members
llvm::LegalizerHelper Class Reference

#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"

Collaboration diagram for llvm::LegalizerHelper:
Collaboration graph

Public Types

enum  LegalizeResult { AlreadyLegal, Legalized, UnableToLegalize }

Public Member Functions

 LegalizerHelper (MachineFunction &MF)
LegalizeResult legalizeInstrStep (MachineInstr &MI)
 Replace MI by a sequence of legal instructions that can implement the same operation. More...
LegalizeResult libcall (MachineInstr &MI)
 Legalize an instruction by emiting a runtime library call instead. More...
LegalizeResult narrowScalar (MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
 Legalize an instruction by reducing the width of the underlying scalar type. More...
LegalizeResult widenScalar (MachineInstr &MI, unsigned TypeIdx, LLT WideTy)
 Legalize an instruction by performing the operation on a wider scalar type (for example a 16-bit addition can be safely performed at 32-bits precision, ignoring the unused bits). More...
LegalizeResult lower (MachineInstr &MI, unsigned TypeIdx, LLT Ty)
 Legalize an instruction by splitting it into simpler parts, hopefully understood by the target. More...
LegalizeResult fewerElementsVector (MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
 Legalize a vector instruction by splitting into multiple components, each acting on the same scalar type as the original but with fewer elements. More...
LegalizeResult moreElementsVector (MachineInstr &MI, unsigned TypeIdx, LLT WideTy)
 Legalize a vector instruction by increasing the number of vector elements involved and ignoring the added elements later. More...
const LegalizerInfogetLegalizerInfo () const
 Expose LegalizerInfo so the clients can re-use. More...

Public Attributes

MachineIRBuilder MIRBuilder
 Expose MIRBuilder so clients can set their own RecordInsertInstruction functions. More...

Detailed Description

Definition at line 36 of file LegalizerHelper.h.

Member Enumeration Documentation

◆ LegalizeResult


Instruction was already legal and no change was made to the MachineFunction.


Instruction has been legalized and the MachineFunction changed.


Some kind of error has occurred and we could not legalize this instruction.

Definition at line 38 of file LegalizerHelper.h.

Constructor & Destructor Documentation

◆ LegalizerHelper()

LegalizerHelper::LegalizerHelper ( MachineFunction MF)

Definition at line 31 of file LegalizerHelper.cpp.

References MIRBuilder, and llvm::MachineIRBuilderBase::setMF().

Member Function Documentation

◆ fewerElementsVector()

LegalizerHelper::LegalizeResult LegalizerHelper::fewerElementsVector ( MachineInstr MI,
unsigned  TypeIdx,
LLT  NarrowTy 

◆ getLegalizerInfo()

const LegalizerInfo& llvm::LegalizerHelper::getLegalizerInfo ( ) const

Expose LegalizerInfo so the clients can re-use.

Definition at line 93 of file LegalizerHelper.h.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, llvm::createLibcall(), MI, MIRBuilder, and Reg.

Referenced by llvm::Legalizer::runOnMachineFunction().

◆ legalizeInstrStep()

LegalizerHelper::LegalizeResult LegalizerHelper::legalizeInstrStep ( MachineInstr MI)

Replace MI by a sequence of legal instructions that can implement the same operation.

Note that this means MI may be deleted, so any iterator steps should be performed before calling this function. Helper should be initialized to the MachineFunction containing MI.

Considered as an opaque blob, the legal code will use and define the same registers as MI.

Definition at line 37 of file LegalizerHelper.cpp.

References AlreadyLegal, llvm::MachineIRBuilderBase::buildUnmerge(), llvm::MachineRegisterInfo::createGenericVirtualRegister(), llvm::LegalizeActions::Custom, llvm::dbgs(), llvm::LegalizeActions::FewerElements, fewerElementsVector(), llvm::LegalizerInfo::getAction(), llvm::LegalizeActions::Legal, llvm::LegalizerInfo::legalizeCustom(), Legalized, libcall(), LLVM_DEBUG, llvm::Lower, lower(), MIRBuilder, llvm::LegalizeActions::NarrowScalar, narrowScalar(), llvm::MachineInstr::print(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), Reg, UnableToLegalize, VRegs, llvm::LegalizeActions::WidenScalar, and widenScalar().

Referenced by llvm::Legalizer::runOnMachineFunction().

◆ libcall()

LegalizerHelper::LegalizeResult LegalizerHelper::libcall ( MachineInstr MI)

◆ lower()

LegalizerHelper::LegalizeResult LegalizerHelper::lower ( MachineInstr MI,
unsigned  TypeIdx,
LLT  Ty 

◆ moreElementsVector()

LegalizeResult llvm::LegalizerHelper::moreElementsVector ( MachineInstr MI,
unsigned  TypeIdx,
LLT  WideTy 

Legalize a vector instruction by increasing the number of vector elements involved and ignoring the added elements later.

◆ narrowScalar()

LegalizerHelper::LegalizeResult LegalizerHelper::narrowScalar ( MachineInstr MI,
unsigned  TypeIdx,
LLT  NarrowTy 

Legalize an instruction by reducing the width of the underlying scalar type.

Definition at line 266 of file LegalizerHelper.cpp.

References assert(), llvm::MachineIRBuilderBase::buildConstant(), llvm::MachineIRBuilderBase::buildExtract(), llvm::MachineIRBuilderBase::buildInsert(), llvm::MachineIRBuilder::buildInstr(), llvm::MachineIRBuilderBase::buildLoad(), llvm::MachineIRBuilderBase::buildMerge(), llvm::FoldableInstructionsBuilder< Base >::buildOr(), llvm::MachineIRBuilderBase::buildStore(), llvm::MachineIRBuilderBase::buildUAdde(), llvm::MachineIRBuilderBase::buildUndef(), llvm::MachineIRBuilderBase::buildUnmerge(), llvm::MachineRegisterInfo::createGenericVirtualRegister(), llvm::MachineInstr::eraseFromParent(), llvm::ConstantInt::get(), llvm::MachineOperand::getCImm(), llvm::Function::getContext(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getImm(), llvm::MachineIRBuilderBase::getInsertPt(), llvm::MachineFunction::getMachineMemOperand(), llvm::MachineIRBuilderBase::getMBB(), llvm::MachineIRBuilderBase::getMF(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::LLT::getSizeInBits(), llvm::getSizeInBits(), llvm::MachineRegisterInfo::getType(), llvm::ConstantInt::getValue(), Legalized, llvm::APInt::lshr(), llvm::MachineIRBuilderBase::materializeGEP(), llvm::MachineInstr::memoperands_begin(), MI, MIRBuilder, llvm::NotAtomic, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::LLT::scalar(), llvm::MachineIRBuilderBase::setInsertPt(), llvm::MachineIRBuilderBase::setInstr(), llvm::MachineOperand::setReg(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::APInt::trunc(), and UnableToLegalize.

Referenced by legalizeInstrStep().

◆ widenScalar()

LegalizerHelper::LegalizeResult LegalizerHelper::widenScalar ( MachineInstr MI,
unsigned  TypeIdx,
LLT  WideTy 

Member Data Documentation

◆ MIRBuilder

MachineIRBuilder llvm::LegalizerHelper::MIRBuilder

Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.

Definition at line 90 of file LegalizerHelper.h.

Referenced by fewerElementsVector(), getLegalizerInfo(), legalizeInstrStep(), LegalizerHelper(), libcall(), lower(), narrowScalar(), llvm::Legalizer::runOnMachineFunction(), and widenScalar().

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