class CSEMIRBuilder

Declaration

class CSEMIRBuilder : public MachineIRBuilder { /* full declaration omitted */ };

Description

Defines a builder that does CSE of MachineInstructions using GISelCSEInfo. Eg usage. GISelCSEInfo *Info = &getAnalysis <GISelCSEAnalysisWrapperPass >().getCSEInfo(); CSEMIRBuilder CB(Builder.getState()); CB.setCSEInfo(Info); auto A = CB.buildConstant(s32, 42); auto B = CB.buildConstant(s32, 42); assert(A == B); unsigned CReg = MRI.createGenericVirtualRegister(s32); auto C = CB.buildConstant(CReg, 42); assert(C->getOpcode() == TargetOpcode::COPY); Explicitly passing in a register would materialize a copy if possible. CSEMIRBuilder also does trivial constant folding for binary ops.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:32

Inherits from: MachineIRBuilder

Member Variables

Method Overview

  • public llvm::MachineInstrBuilder buildConstant(const llvm::DstOp & Res, const llvm::ConstantInt & Val)
  • public llvm::MachineInstrBuilder buildFConstant(const llvm::DstOp & Res, const llvm::ConstantFP & Val)
  • public llvm::MachineInstrBuilder buildInstr(unsigned int Opc, ArrayRef<llvm::DstOp> DstOps, ArrayRef<llvm::SrcOp> SrcOps, Optional<unsigned int> Flag = None)
  • private bool canPerformCSEForOpc(unsigned int Opc) const
  • private bool checkCopyToDefsPossible(ArrayRef<llvm::DstOp> DstOps)
  • private bool dominates(MachineBasicBlock::const_iterator A, MachineBasicBlock::const_iterator B) const
  • private llvm::MachineInstrBuilder generateCopiesIfRequired(ArrayRef<llvm::DstOp> DstOps, llvm::MachineInstrBuilder & MIB)
  • private llvm::MachineInstrBuilder getDominatingInstrForID(llvm::FoldingSetNodeID & ID, void *& NodeInsertPos)
  • private llvm::MachineInstrBuilder memoizeMI(llvm::MachineInstrBuilder MIB, void * NodeInsertPos)
  • private void profileDstOp(const llvm::DstOp & Op, llvm::GISelInstProfileBuilder & B) const
  • private void profileDstOps(ArrayRef<llvm::DstOp> Ops, llvm::GISelInstProfileBuilder & B) const
  • private void profileEverything(unsigned int Opc, ArrayRef<llvm::DstOp> DstOps, ArrayRef<llvm::SrcOp> SrcOps, Optional<unsigned int> Flags, llvm::GISelInstProfileBuilder & B) const
  • private void profileMBBOpcode(llvm::GISelInstProfileBuilder & B, unsigned int Opc) const
  • private void profileSrcOp(const llvm::SrcOp & Op, llvm::GISelInstProfileBuilder & B) const
  • private void profileSrcOps(ArrayRef<llvm::SrcOp> Ops, llvm::GISelInstProfileBuilder & B) const

Inherited from MachineIRBuilder:

Methods

llvm::MachineInstrBuilder buildConstant(
    const llvm::DstOp& Res,
    const llvm::ConstantInt& Val)

Description

Build and insert \p Res = G_CONSTANT \p Val G_CONSTANT is an integer constant with the specified size and value. \p Val will be extended or truncated to the size of \p Reg.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:100

Parameters

const llvm::DstOp& Res
const llvm::ConstantInt& Val

Returns

The newly created instruction.

llvm::MachineInstrBuilder buildFConstant(
    const llvm::DstOp& Res,
    const llvm::ConstantFP& Val)

Description

Build and insert \p Res = G_FCONSTANT \p Val G_FCONSTANT is a floating-point constant with the specified size and value.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:105

Parameters

const llvm::DstOp& Res
const llvm::ConstantFP& Val

Returns

The newly created instruction.

llvm::MachineInstrBuilder buildInstr(
    unsigned int Opc,
    ArrayRef<llvm::DstOp> DstOps,
    ArrayRef<llvm::SrcOp> SrcOps,
    Optional<unsigned int> Flag = None)

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:94

Parameters

unsigned int Opc
ArrayRef<llvm::DstOp> DstOps
ArrayRef<llvm::SrcOp> SrcOps
Optional<unsigned int> Flag = None

bool canPerformCSEForOpc(unsigned int Opc) const

Description

Simple check if we can CSE (we have the CSEInfo) or if this Opcode is safe to CSE.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:54

Parameters

unsigned int Opc

bool checkCopyToDefsPossible(
    ArrayRef<llvm::DstOp> DstOps)

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:88

Parameters

ArrayRef<llvm::DstOp> DstOps

bool dominates(
    MachineBasicBlock::const_iterator A,
    MachineBasicBlock::const_iterator B) const

Description

Returns true if A dominates B (within the same basic block). Both iterators must be in the same basic block.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:43

Parameters

MachineBasicBlock::const_iterator A
MachineBasicBlock::const_iterator B

llvm::MachineInstrBuilder
generateCopiesIfRequired(
    ArrayRef<llvm::DstOp> DstOps,
    llvm::MachineInstrBuilder& MIB)

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:82

Parameters

ArrayRef<llvm::DstOp> DstOps
llvm::MachineInstrBuilder& MIB

llvm::MachineInstrBuilder getDominatingInstrForID(
    llvm::FoldingSetNodeID& ID,
    void*& NodeInsertPos)

Description

For given ID, find a machineinstr in the CSE Map. If found, check if it dominates the current insertion point and if not, move it just before the current insertion point and return it. If not found, return Null MachineInstrBuilder.

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:50

Parameters

llvm::FoldingSetNodeID& ID
void*& NodeInsertPos

llvm::MachineInstrBuilder memoizeMI(
    llvm::MachineInstrBuilder MIB,
    void* NodeInsertPos)

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:78

Parameters

llvm::MachineInstrBuilder MIB
void* NodeInsertPos

void profileDstOp(
    const llvm::DstOp& Op,
    llvm::GISelInstProfileBuilder& B) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:56

Parameters

const llvm::DstOp& Op
llvm::GISelInstProfileBuilder& B

void profileDstOps(
    ArrayRef<llvm::DstOp> Ops,
    llvm::GISelInstProfileBuilder& B) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:58

Parameters

ArrayRef<llvm::DstOp> Ops
llvm::GISelInstProfileBuilder& B

void profileEverything(
    unsigned int Opc,
    ArrayRef<llvm::DstOp> DstOps,
    ArrayRef<llvm::SrcOp> SrcOps,
    Optional<unsigned int> Flags,
    llvm::GISelInstProfileBuilder& B) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:72

Parameters

unsigned int Opc
ArrayRef<llvm::DstOp> DstOps
ArrayRef<llvm::SrcOp> SrcOps
Optional<unsigned int> Flags
llvm::GISelInstProfileBuilder& B

void profileMBBOpcode(
    llvm::GISelInstProfileBuilder& B,
    unsigned int Opc) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:70

Parameters

llvm::GISelInstProfileBuilder& B
unsigned int Opc

void profileSrcOp(
    const llvm::SrcOp& Op,
    llvm::GISelInstProfileBuilder& B) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:63

Parameters

const llvm::SrcOp& Op
llvm::GISelInstProfileBuilder& B

void profileSrcOps(
    ArrayRef<llvm::SrcOp> Ops,
    llvm::GISelInstProfileBuilder& B) const

Declared at: llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h:65

Parameters

ArrayRef<llvm::SrcOp> Ops
llvm::GISelInstProfileBuilder& B