llvm::CSEMIRBuilder

Defines a builder that does CSE of MachineInstructions using GISelCSEInfo. Eg usage.

Synopsis

Declared in <llvm/CodeGen/GlobalISel/CSEMIRBuilder.h>

class CSEMIRBuilder
    : public MachineIRBuilder

Description


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.

Base Classes

NameDescription
MachineIRBuilderHelper for constructing MachineInstrs with a shared insertion point.

Member Functions

NameDescription
buildAShr Build and insert Dst = G_ASHR Src0, Src1.
buildAbds Build and insert Res = G_ABDS Op0, Op1
buildAbdu Build and insert Res = G_ABDU Op0, Op1
buildAbs Build and insert Dst = G_ABS Src
buildAdd Build and insert Res = G_ADD Op0, Op1
buildAddrSpaceCast Build and insert Dst = G_ADDRSPACE_CAST Src.
buildAnd Build and insert Res = G_AND Op0, Op1
buildAnyExt Build and insert Res = G_ANYEXT Op0
buildAnyExtOrTrunc Res = COPY Op depending on the differing sizes of Res and Op.
buildAssertAlign Build and insert Res = G_ASSERT_ALIGN Op, AlignVal
buildAssertInstr Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN
buildAssertSExt Build and insert Res = G_ASSERT_SEXT Op, Size
buildAssertZExt Build and insert Res = G_ASSERT_ZEXT Op, Size
buildAtomicCmpXchg Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal, MMO`.
buildAtomicCmpXchgWithSuccess Build and insert `OldValRes<def>, SuccessRes<def> = G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO`.
buildAtomicRMW Build and insert OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO.
buildAtomicRMWAdd Build and insert OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO.
buildAtomicRMWAnd Build and insert OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO.
buildAtomicRMWFAdd Build and insert OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO.
buildAtomicRMWFMax Build and insert OldValRes<def> = G_ATOMICRMW_FMAX Addr, Val, MMO.
buildAtomicRMWFMaximum Build and insert OldValRes<def> = G_ATOMICRMW_FMAXIMUM Addr, Val, MMO.
buildAtomicRMWFMin Build and insert OldValRes<def> = G_ATOMICRMW_FMIN Addr, Val, MMO.
buildAtomicRMWFMinimum Build and insert OldValRes<def> = G_ATOMICRMW_FMINIMUM Addr, Val, MMO.
buildAtomicRMWFSub Build and insert OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO.
buildAtomicRMWMax Build and insert OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO.
buildAtomicRMWMin Build and insert OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO.
buildAtomicRMWNand Build and insert OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO.
buildAtomicRMWOr Build and insert OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO.
buildAtomicRMWSub Build and insert OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO.
buildAtomicRMWUmax Build and insert OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO.
buildAtomicRMWUmin Build and insert OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO.
buildAtomicRMWXchg Build and insert OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO.
buildAtomicRMWXor Build and insert OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO.
buildBSwap Build and insert Dst = G_BSWAP Src0
buildBitReverse Build and insert Dst = G_BITREVERSE Src
buildBitcast Build and insert Dst = G_BITCAST Src
buildBlockAddress Build and insert Res = G_BLOCK_ADDR BA
buildBoolExt Build and insert a boolean extend of Op into Res.
buildBoolExtInReg Build and insert an in-register boolean extend of Op into Res.
buildBr Build and insert G_BR Dest
buildBrCond Build and insert G_BRCOND Tst, Dest
buildBrIndirect Build and insert G_BRINDIRECT Tgt
buildBrJT Build and insert G_BRJT TablePtr, JTI, IndexReg
buildBuildVector Build and insert Res = G_BUILD_VECTOR Op0, ...
buildBuildVectorConstant Build and insert Res = G_BUILD_VECTOR Op0, ... where each OpN is built with G_CONSTANT.
buildBuildVectorTrunc Build and insert Res = G_BUILD_VECTOR_TRUNC Op0, ...
buildCTLS Build and insert Res = G_CTLS Op0, Src0
buildCTLZ Build and insert Res = G_CTLZ Op0, Src0
buildCTLZ_ZERO_POISON Build and insert Res = G_CTLZ_ZERO_POISON Op0, Src0
buildCTPOP Build and insert Res = G_CTPOP Op0, Src0
buildCTTZ Build and insert Res = G_CTTZ Op0, Src0
buildCTTZ_ZERO_POISON Build and insert Res = G_CTTZ_ZERO_POISON Op0, Src0
buildCast Build and insert an appropriate cast between two registers of equal size.
buildConcatVectors Build and insert Res = G_CONCAT_VECTORS Op0, ...
buildConstDbgValue Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified by Expr).
buildConstant buildConstant overloads
buildConstantPool Build and insert Res = G_CONSTANT_POOL Idx
buildConstantPtrAuth Build and insert G_PTRAUTH_GLOBAL_VALUE
buildCopy Build and insert Res = COPY Op
buildDbgLabel Build and insert a DBG_LABEL instructions specifying that Label is given. Convert "llvm.dbg.label Label" to "DBG_LABEL Label".
buildDeleteTrailingVectorElements Build and insert a, b, ..., x, y, z = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a, b, ..., x
buildDirectDbgValue Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Reg (suitably modified by Expr).
buildDynStackAlloc Build and insert Res = G_DYN_STACKALLOC Size, Align
buildExtOrTrunc Build and insert Res = ExtOpc, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of Res and Op.
buildExtract Build and insert Res0, ... = G_EXTRACT Src, Idx0.
buildExtractSubvector Build and insert Res = G_EXTRACT_SUBVECTOR Src, Idx0.
buildExtractVectorElement Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx
buildExtractVectorElementConstant Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx
buildFAbs Build and insert Res = G_FABS Op0
buildFAdd Build and insert Res = G_FADD Op0, Op1
buildFCanonicalize Build and insert Dst = G_FCANONICALIZE Src0
buildFCmp Build and insert a Res = G_FCMP Pred, Op0, Op1.
buildFConstant buildFConstant overloads
buildFCopysign Build and insert Res = G_FCOPYSIGN Op0, Op1
buildFDiv Build and insert Res = G_FDIV Op0, Op1
buildFExp2 Build and insert Dst = G_FEXP2 Src
buildFFloor Build and insert Res = GFFLOOR Op0, Op1
buildFFrexp Build and insert Fract, Exp = G_FFREXP Src
buildFIDbgValue Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in the stack slot specified by FI (suitably modified by Expr).
buildFLdexp Build and insert Dst = G_FLDEXP Src0, Src1
buildFLog Build and insert Dst = G_FLOG Src
buildFLog2 Build and insert Dst = G_FLOG2 Src
buildFMA Build and insert Res = G_FMA Op0, Op1, Op2
buildFMAD Build and insert Res = G_FMAD Op0, Op1, Op2
buildFMaxNum Build and insert Dst = G_FMAXNUM Src0, Src1.
buildFMaxNumIEEE Build and insert Dst = G_FMAXNUM_IEEE Src0, Src1.
buildFMinNum Build and insert Dst = G_FMINNUM Src0, Src1.
buildFMinNumIEEE Build and insert Dst = G_FMINNUM_IEEE Src0, Src1.
buildFMul Build and insert Dst = G_FMUL Src0, Src1.
buildFNeg Build and insert Res = G_FNEG Op0
buildFPExt Build and insert Res = G_FPEXT Op
buildFPTOSI Build and insert Res = G_FPTOSI Src0
buildFPTOSI_SAT Build and insert Res = G_FPTOSI_SAT Src0
buildFPTOUI Build and insert Res = G_FPTOUI Src0
buildFPTOUI_SAT Build and insert Res = G_FPTOUI_SAT Src0
buildFPTrunc Build and insert Res = G_FPTRUNC Op
buildFPow Build and insert Dst = G_FPOW Src0, Src1
buildFRint Build and insert Dst = G_FRINT Src0
buildFSincos Build and insert Sin, Cos = G_FSINCOS Src
buildFSub Build and insert Res = G_FSUB Op0, Op1
buildFence Build and insert G_FENCE Ordering, Scope.
buildFrameIndex Build and insert Res = G_FRAME_INDEX Idx
buildFreeze Build and insert Dst = G_FREEZE Src
buildGetFPEnv Build and insert Dst = G_GET_FPENV
buildGetFPMode Build and insert Dst = G_GET_FPMODE
buildGetRounding Build and insert Dst = G_GET_ROUNDING
buildGlobalValue Build and insert Res = G_GLOBAL_VALUE GV
buildICmp Build and insert a Res = G_ICMP Pred, Op0, Op1.
buildIndirectDbgValue Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in memory at Reg (suitably modified by Expr).
buildInsert Build and insert Res = G_INSERT Src, Op, Index.
buildInsertSubvector Build and insert Res = G_INSERT_SUBVECTOR Src0, Src1, Idx.
buildInsertVectorElement Build and insert Res = G_INSERT_VECTOR_ELT Val, Elt, Idx.
buildInstr buildInstr overloads
buildInstrNoInsert Build but don't insert <empty> = Opcode <empty>.
buildIntToPtr Build and insert a G_INTTOPTR instruction.
buildIntrinsic buildIntrinsic overloads
buildIntrinsicRoundeven Build and insert Dst = G_INTRINSIC_ROUNDEVEN Src0, Src1
buildIntrinsicTrunc Build and insert Dst = G_INTRINSIC_TRUNC Src0
buildIsFPClass Build and insert a Res = G_IS_FPCLASS Src, Mask
buildJumpTable Build and insert Res = G_JUMP_TABLE JTI
buildLShr Build and insert Dst = G_LSHR Src0, Src1.
buildLoad buildLoad overloads
buildLoadFromOffset Helper to create a load from a constant offset given a base address. Load the type of Dst from Offset from the given base address and memory operand.
buildLoadInstr Build and insert Res = <opcode> Addr, MMO.
buildMaskLowPtrBits Build and insert Res = G_PTRMASK Op0, G_CONSTANT (1 << NumBits) - 1
buildMemCpy Build and insert a G_MEMCPY memory transfer.
buildMemTransferInst Build and insert G_MEMCPY or G_MEMMOVE
buildMergeLikeInstr buildMergeLikeInstr overloads
buildMergeValues Build and insert Res = G_MERGE_VALUES Op0, ...
buildModf Build and insert Fract, Int = G_FMODF Src
buildMul Build and insert Res = G_MUL Op0, Op1
buildNeg Build and insert integer negation Zero = G_CONSTANT 0 Res = G_SUB Zero, Op0
buildNot Build and insert a bitwise not, NegOne = G_CONSTANT -1 Res = G_OR Op0, NegOne
buildObjectPtrOffset Build a nuw inbounds G_PTR_ADD for an in-object pointer offset.
buildOr Build and insert Res = G_OR Op0, Op1
buildPadVectorWithUndefElements Build and insert a, b, ..., x = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a, b, ..., x, undef, ..., undef
buildPrefetch Build and insert G_PREFETCH Addr, RW, Locality, CacheType
buildPtrAdd Build and insert Res = G_PTR_ADD Op0, Op1
buildPtrMask Build and insert Res = G_PTRMASK Op0, Op1
buildPtrToInt Build and insert a G_PTRTOINT instruction.
buildResetFPEnv Build and insert G_RESET_FPENV
buildResetFPMode Build and insert G_RESET_FPMODE
buildRotateLeft Build and insert Dst = G_ROTL Src, Amt
buildRotateRight Build and insert Dst = G_ROTR Src, Amt
buildSAdde Build and insert Res, CarryOut = G_SADDE Op0, Op1, CarryInp
buildSAddo Build and insert Res, CarryOut = G_SADDO Op0, Op1
buildSCmp Build and insert a Res = G_SCMP Op0, Op1.
buildSExt Build and insert Res = G_SEXT Op
buildSExtInReg Build and insert Res = G_SEXT_INREG Op, ImmOp
buildSExtOrTrunc Build and insert Res = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of Res and Op.
buildSITOFP Build and insert Res = G_SITOFP Src0
buildSMax Build and insert Res = G_SMAX Op0, Op1
buildSMin Build and insert Res = G_SMIN Op0, Op1
buildSMulH Build and insert Dst = G_SMULH Src0, Src1.
buildSSube Build and insert Res, CarryOut = G_SSUBE Op0, Op1, CarryInp
buildSSubo Build and insert Res, CarryOut = G_SUBO Op0, Op1
buildSbfx Build and insert Dst = G_SBFX Src, LSB, Width.
buildSelect Build and insert a Res = G_SELECT Tst, Op0, Op1
buildSetFPEnv Build and insert G_SET_FPENV Src
buildSetFPMode Build and insert G_SET_FPMODE Src
buildSetRounding Build and insert G_SET_ROUNDING
buildShl Build and insert Dst = G_SHL Src0, Src1.
buildShuffleSplat Build and insert a vector splat of a scalar Src using a G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idiom.
buildShuffleVector Build and insert Res = G_SHUFFLE_VECTOR Src1, Src2, Mask
buildSplatBuildVector Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements
buildSplatVector Build and insert Res = G_SPLAT_VECTOR Val
buildStepVector Build and insert Res = G_STEP_VECTOR Step
buildStore buildStore overloads
buildStoreInstr Build and insert <opcode> Val, Addr, MMO.
buildStrictFAdd Build and insert Res = G_STRICT_FADD Op0, Op1
buildSub Build and insert Res = G_SUB Op0, Op1
buildTrap Build and insert G_TRAP or G_DEBUGTRAP
buildTrunc Build and insert Res = G_TRUNC Op
buildTruncSSatS Build and insert Res = G_TRUNC_SSAT_S Op
buildTruncSSatU Build and insert Res = G_TRUNC_SSAT_U Op
buildTruncUSatU Build and insert Res = G_TRUNC_USAT_U Op
buildUAdde Build and insert Res, CarryOut = G_UADDE Op0, Op1, CarryIn
buildUAddo Build and insert Res, CarryOut = G_UADDO Op0, Op1
buildUCmp Build and insert a Res = G_UCMP Op0, Op1.
buildUITOFP Build and insert Res = G_UITOFP Src0
buildUMax Build and insert Res = G_UMAX Op0, Op1
buildUMin Build and insert Res = G_UMIN Op0, Op1
buildUMulH Build and insert Dst = G_UMULH Src0, Src1.
buildURem Build and insert Res = G_UREM Op0, Op1
buildUSube Build and insert Res, CarryOut = G_USUBE Op0, Op1, CarryInp
buildUSubo Build and insert Res, CarryOut = G_USUBO Op0, Op1
buildUbfx Build and insert Dst = G_UBFX Src, LSB, Width.
buildUndef Build and insert Res = IMPLICIT_DEF.
buildUnmerge buildUnmerge overloads
buildVScale Build and insert Res = G_VSCALE MinElts
buildVecReduceAdd Build and insert Res = G_VECREDUCE_ADD Src
buildVecReduceAnd Build and insert Res = G_VECREDUCE_AND Src
buildVecReduceFAdd Build and insert Res = G_VECREDUCE_FADD Src
buildVecReduceFMax Build and insert Res = G_VECREDUCE_FMAX Src
buildVecReduceFMaximum Build and insert Res = G_VECREDUCE_FMAXIMUM Src
buildVecReduceFMin Build and insert Res = G_VECREDUCE_FMIN Src
buildVecReduceFMinimum Build and insert Res = G_VECREDUCE_FMINIMUM Src
buildVecReduceFMul Build and insert Res = G_VECREDUCE_FMUL Src
buildVecReduceMul Build and insert Res = G_VECREDUCE_MUL Src
buildVecReduceOr Build and insert Res = G_VECREDUCE_OR Src
buildVecReduceSMax Build and insert Res = G_VECREDUCE_SMAX Src
buildVecReduceSMin Build and insert Res = G_VECREDUCE_SMIN Src
buildVecReduceSeqFAdd Build and insert Res = G_VECREDUCE_SEQ_FADD ScalarIn, VecIn
buildVecReduceSeqFMul Build and insert Res = G_VECREDUCE_SEQ_FMUL ScalarIn, VecIn
buildVecReduceUMax Build and insert Res = G_VECREDUCE_UMAX Src
buildVecReduceUMin Build and insert Res = G_VECREDUCE_UMIN Src
buildVecReduceXor Build and insert Res = G_VECREDUCE_XOR Src
buildXor Build and insert Res = G_XOR Op0, Op1
buildZExt Build and insert Res = G_ZEXT Op
buildZExtInReg Build and inserts Res = G_AND Op, LowBitsSet(ImmOp) Since there is no G_ZEXT_INREG like G_SEXT_INREG, the instruction is emulated using G_AND.
buildZExtOrTrunc Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of Res and Op.
getBoolExtOp Return the opcode used to extend boolean values for this target.
getCSEInfo Return the CSE info associated with this builder, if any.
getContext Return the LLVM context of the function being built.
getDL Getter for DebugLoc
getDataLayout Return the data layout of the function being built.
getDeactivationSymbol Return the current deactivation symbol, if any.
getDebugLoc Get the current instruction's debug location.
getInsertPt Current insertion point for new instructions.
getMBB getMBB overloads
getMF getMF overloads
getMMRAMetadata Get the current instruction's MMRA metadata.
getMRI Return the machine register info for the current function.
getObserver Return the active change observer, or null if none is set.
getPCSections Get the current instruction's PC sections metadata.
getState Getter for the State
getTII Return the target instruction info for the current function.
insertInstr Insert an existing instruction at the insertion point.
isObservingChanges Return true if a change observer is currently installed.
materializeObjectPtrOffset Materialize a nuw inbounds G_PTR_ADD for an in-object constant offset.
materializePtrAdd Materialize and insert Res = G_PTR_ADD Op0, (G_CONSTANT Value)
setCSEInfo Set the CSE info consulted while building instructions.
setChangeObserver Install a change observer for newly created instructions.
setDeactivationSymbol Set the deactivation symbol for subsequently built instructions.
setDebugLoc Set the debug location to DL for all the next build instructions.
setInsertPt Set the insertion point before the specified position.
setInstr Set the insertion point to before MI.
setInstrAndDebugLoc Set the insertion point to before MI, and set the debug loc to MI's loc.
setMBB Set the insertion point to the end of MBB.
setMF @{ Set the MachineFunction where to build instructions.
setMMRAMetadata Set the MMRA metadata for all subsequently built instructions.
setPCSections Set the PC sections metadata to MD for all the next build instructions.
setState Replace the builder state with NewState.
stopObservingChanges Clear the active change observer.

Using Declarations

NameDescription
CSEMIRBuilder Pull in base class constructors.
buildConstant Bring in the other buildConstant overloads from the base class.
buildFConstant Bring in the other buildFConstant overloads from the base class.

Protected Member Functions

NameDescription
recordInsertion Notify the change observer that InsertedInstr was created.
validateBinaryOp Validate types for a binary operation.
validateSelectOp Validate types for a select operation.
validateShiftOp Validate types for a shift operation.
validateTruncExt Validate types for a truncate or extend between Dst and Src.
validateUnaryOp Validate types for a unary operation.