#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineInstrBundle.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/CodeGen/Register.h"
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/CodeGenTypes/LowLevelType.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Operator.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <utility>
usingnamespacellvm;
static const MachineFunction *getMFIfAvailable(const MachineInstr &MI) { … }
static void tryToGetTargetInfo(const MachineInstr &MI,
const TargetRegisterInfo *&TRI,
const MachineRegisterInfo *&MRI,
const TargetIntrinsicInfo *&IntrinsicInfo,
const TargetInstrInfo *&TII) { … }
void MachineInstr::addImplicitDefUseOperands(MachineFunction &MF) { … }
MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
DebugLoc DL, bool NoImp)
: … { … }
MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
: … { … }
void MachineInstr::setDesc(const MCInstrDesc &TID) { … }
void MachineInstr::moveBefore(MachineInstr *MovePos) { … }
MachineRegisterInfo *MachineInstr::getRegInfo() { … }
const MachineRegisterInfo *MachineInstr::getRegInfo() const { … }
void MachineInstr::removeRegOperandsFromUseLists(MachineRegisterInfo &MRI) { … }
void MachineInstr::addRegOperandsToUseLists(MachineRegisterInfo &MRI) { … }
void MachineInstr::addOperand(const MachineOperand &Op) { … }
static void moveOperands(MachineOperand *Dst, MachineOperand *Src,
unsigned NumOps, MachineRegisterInfo *MRI) { … }
void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) { … }
void MachineInstr::removeOperand(unsigned OpNo) { … }
void MachineInstr::setExtraInfo(MachineFunction &MF,
ArrayRef<MachineMemOperand *> MMOs,
MCSymbol *PreInstrSymbol,
MCSymbol *PostInstrSymbol,
MDNode *HeapAllocMarker, MDNode *PCSections,
uint32_t CFIType, MDNode *MMRAs) { … }
void MachineInstr::dropMemRefs(MachineFunction &MF) { … }
void MachineInstr::setMemRefs(MachineFunction &MF,
ArrayRef<MachineMemOperand *> MMOs) { … }
void MachineInstr::addMemOperand(MachineFunction &MF,
MachineMemOperand *MO) { … }
void MachineInstr::cloneMemRefs(MachineFunction &MF, const MachineInstr &MI) { … }
static bool hasIdenticalMMOs(ArrayRef<MachineMemOperand *> LHS,
ArrayRef<MachineMemOperand *> RHS) { … }
void MachineInstr::cloneMergedMemRefs(MachineFunction &MF,
ArrayRef<const MachineInstr *> MIs) { … }
void MachineInstr::setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol) { … }
void MachineInstr::setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol) { … }
void MachineInstr::setHeapAllocMarker(MachineFunction &MF, MDNode *Marker) { … }
void MachineInstr::setPCSections(MachineFunction &MF, MDNode *PCSections) { … }
void MachineInstr::setCFIType(MachineFunction &MF, uint32_t Type) { … }
void MachineInstr::setMMRAMetadata(MachineFunction &MF, MDNode *MMRAs) { … }
void MachineInstr::cloneInstrSymbols(MachineFunction &MF,
const MachineInstr &MI) { … }
uint32_t MachineInstr::mergeFlagsWith(const MachineInstr &Other) const { … }
uint32_t MachineInstr::copyFlagsFromInstruction(const Instruction &I) { … }
void MachineInstr::copyIRFlags(const Instruction &I) { … }
bool MachineInstr::hasPropertyInBundle(uint64_t Mask, QueryType Type) const { … }
bool MachineInstr::isIdenticalTo(const MachineInstr &Other,
MICheckType Check) const { … }
bool MachineInstr::isEquivalentDbgInstr(const MachineInstr &Other) const { … }
const MachineFunction *MachineInstr::getMF() const { … }
MachineInstr *MachineInstr::removeFromParent() { … }
MachineInstr *MachineInstr::removeFromBundle() { … }
void MachineInstr::eraseFromParent() { … }
void MachineInstr::eraseFromBundle() { … }
bool MachineInstr::isCandidateForCallSiteEntry(QueryType Type) const { … }
bool MachineInstr::shouldUpdateCallSiteInfo() const { … }
unsigned MachineInstr::getNumExplicitOperands() const { … }
unsigned MachineInstr::getNumExplicitDefs() const { … }
void MachineInstr::bundleWithPred() { … }
void MachineInstr::bundleWithSucc() { … }
void MachineInstr::unbundleFromPred() { … }
void MachineInstr::unbundleFromSucc() { … }
bool MachineInstr::isStackAligningInlineAsm() const { … }
InlineAsm::AsmDialect MachineInstr::getInlineAsmDialect() const { … }
int MachineInstr::findInlineAsmFlagIdx(unsigned OpIdx,
unsigned *GroupNo) const { … }
const DILabel *MachineInstr::getDebugLabel() const { … }
const MachineOperand &MachineInstr::getDebugVariableOp() const { … }
MachineOperand &MachineInstr::getDebugVariableOp() { … }
const DILocalVariable *MachineInstr::getDebugVariable() const { … }
const MachineOperand &MachineInstr::getDebugExpressionOp() const { … }
MachineOperand &MachineInstr::getDebugExpressionOp() { … }
const DIExpression *MachineInstr::getDebugExpression() const { … }
bool MachineInstr::isDebugEntryValue() const { … }
const TargetRegisterClass*
MachineInstr::getRegClassConstraint(unsigned OpIdx,
const TargetInstrInfo *TII,
const TargetRegisterInfo *TRI) const { … }
const TargetRegisterClass *MachineInstr::getRegClassConstraintEffectForVReg(
Register Reg, const TargetRegisterClass *CurRC, const TargetInstrInfo *TII,
const TargetRegisterInfo *TRI, bool ExploreBundle) const { … }
const TargetRegisterClass *MachineInstr::getRegClassConstraintEffectForVRegImpl(
unsigned OpIdx, Register Reg, const TargetRegisterClass *CurRC,
const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const { … }
const TargetRegisterClass *MachineInstr::getRegClassConstraintEffect(
unsigned OpIdx, const TargetRegisterClass *CurRC,
const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const { … }
unsigned MachineInstr::getBundleSize() const { … }
bool MachineInstr::hasRegisterImplicitUseOperand(Register Reg) const { … }
int MachineInstr::findRegisterUseOperandIdx(Register Reg,
const TargetRegisterInfo *TRI,
bool isKill) const { … }
std::pair<bool,bool>
MachineInstr::readsWritesVirtualRegister(Register Reg,
SmallVectorImpl<unsigned> *Ops) const { … }
int MachineInstr::findRegisterDefOperandIdx(Register Reg,
const TargetRegisterInfo *TRI,
bool isDead, bool Overlap) const { … }
int MachineInstr::findFirstPredOperandIdx() const { … }
const unsigned TiedMax = …;
void MachineInstr::tieOperands(unsigned DefIdx, unsigned UseIdx) { … }
unsigned MachineInstr::findTiedOperandIdx(unsigned OpIdx) const { … }
void MachineInstr::clearKillInfo() { … }
void MachineInstr::substituteRegister(Register FromReg, Register ToReg,
unsigned SubIdx,
const TargetRegisterInfo &RegInfo) { … }
bool MachineInstr::isSafeToMove(bool &SawStore) const { … }
bool MachineInstr::wouldBeTriviallyDead() const { … }
static bool MemOperandsHaveAlias(const MachineFrameInfo &MFI, AAResults *AA,
bool UseTBAA, const MachineMemOperand *MMOa,
const MachineMemOperand *MMOb) { … }
bool MachineInstr::mayAlias(AAResults *AA, const MachineInstr &Other,
bool UseTBAA) const { … }
bool MachineInstr::hasOrderedMemoryRef() const { … }
bool MachineInstr::isDereferenceableInvariantLoad() const { … }
unsigned MachineInstr::isConstantValuePHI() const { … }
bool MachineInstr::hasUnmodeledSideEffects() const { … }
bool MachineInstr::isLoadFoldBarrier() const { … }
bool MachineInstr::allDefsAreDead() const { … }
bool MachineInstr::allImplicitDefsAreDead() const { … }
void MachineInstr::copyImplicitOps(MachineFunction &MF,
const MachineInstr &MI) { … }
bool MachineInstr::hasComplexRegisterTies() const { … }
LLT MachineInstr::getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes,
const MachineRegisterInfo &MRI) const { … }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void MachineInstr::dump() const {
dbgs() << " ";
print(dbgs());
}
LLVM_DUMP_METHOD void MachineInstr::dumprImpl(
const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const {
if (Depth >= MaxDepth)
return;
if (!AlreadySeenInstrs.insert(this).second)
return;
if (Depth)
fdbgs().PadToColumn(Depth * 2);
print(fdbgs());
for (const MachineOperand &MO : operands()) {
if (!MO.isReg() || MO.isDef())
continue;
Register Reg = MO.getReg();
if (Reg.isPhysical())
continue;
const MachineInstr *NewMI = MRI.getUniqueVRegDef(Reg);
if (NewMI == nullptr)
continue;
NewMI->dumprImpl(MRI, Depth + 1, MaxDepth, AlreadySeenInstrs);
}
}
LLVM_DUMP_METHOD void MachineInstr::dumpr(const MachineRegisterInfo &MRI,
unsigned MaxDepth) const {
SmallPtrSet<const MachineInstr *, 16> AlreadySeenInstrs;
dumprImpl(MRI, 0, MaxDepth, AlreadySeenInstrs);
}
#endif
void MachineInstr::print(raw_ostream &OS, bool IsStandalone, bool SkipOpers,
bool SkipDebugLoc, bool AddNewLine,
const TargetInstrInfo *TII) const { … }
void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
bool IsStandalone, bool SkipOpers, bool SkipDebugLoc,
bool AddNewLine, const TargetInstrInfo *TII) const { … }
bool MachineInstr::addRegisterKilled(Register IncomingReg,
const TargetRegisterInfo *RegInfo,
bool AddIfNotFound) { … }
void MachineInstr::clearRegisterKills(Register Reg,
const TargetRegisterInfo *RegInfo) { … }
bool MachineInstr::addRegisterDead(Register Reg,
const TargetRegisterInfo *RegInfo,
bool AddIfNotFound) { … }
void MachineInstr::clearRegisterDeads(Register Reg) { … }
void MachineInstr::setRegisterDefReadUndef(Register Reg, bool IsUndef) { … }
void MachineInstr::addRegisterDefined(Register Reg,
const TargetRegisterInfo *RegInfo) { … }
void MachineInstr::setPhysRegsDeadExcept(ArrayRef<Register> UsedRegs,
const TargetRegisterInfo &TRI) { … }
unsigned
MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) { … }
void MachineInstr::emitError(StringRef Msg) const { … }
MachineInstrBuilder llvm::BuildMI(MachineFunction &MF, const DebugLoc &DL,
const MCInstrDesc &MCID, bool IsIndirect,
Register Reg, const MDNode *Variable,
const MDNode *Expr) { … }
MachineInstrBuilder llvm::BuildMI(MachineFunction &MF, const DebugLoc &DL,
const MCInstrDesc &MCID, bool IsIndirect,
ArrayRef<MachineOperand> DebugOps,
const MDNode *Variable, const MDNode *Expr) { … }
MachineInstrBuilder llvm::BuildMI(MachineBasicBlock &BB,
MachineBasicBlock::iterator I,
const DebugLoc &DL, const MCInstrDesc &MCID,
bool IsIndirect, Register Reg,
const MDNode *Variable, const MDNode *Expr) { … }
MachineInstrBuilder llvm::BuildMI(MachineBasicBlock &BB,
MachineBasicBlock::iterator I,
const DebugLoc &DL, const MCInstrDesc &MCID,
bool IsIndirect,
ArrayRef<MachineOperand> DebugOps,
const MDNode *Variable, const MDNode *Expr) { … }
static const DIExpression *computeExprForSpill(
const MachineInstr &MI,
const SmallVectorImpl<const MachineOperand *> &SpilledOperands) { … }
static const DIExpression *computeExprForSpill(const MachineInstr &MI,
Register SpillReg) { … }
MachineInstr *llvm::buildDbgValueForSpill(MachineBasicBlock &BB,
MachineBasicBlock::iterator I,
const MachineInstr &Orig,
int FrameIndex, Register SpillReg) { … }
MachineInstr *llvm::buildDbgValueForSpill(
MachineBasicBlock &BB, MachineBasicBlock::iterator I,
const MachineInstr &Orig, int FrameIndex,
const SmallVectorImpl<const MachineOperand *> &SpilledOperands) { … }
void llvm::updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex,
Register Reg) { … }
void MachineInstr::collectDebugValues(
SmallVectorImpl<MachineInstr *> &DbgValues) { … }
void MachineInstr::changeDebugValuesDefReg(Register Reg) { … }
MMOList;
static LocationSize getSpillSlotSize(const MMOList &Accesses,
const MachineFrameInfo &MFI) { … }
std::optional<LocationSize>
MachineInstr::getSpillSize(const TargetInstrInfo *TII) const { … }
std::optional<LocationSize>
MachineInstr::getFoldedSpillSize(const TargetInstrInfo *TII) const { … }
std::optional<LocationSize>
MachineInstr::getRestoreSize(const TargetInstrInfo *TII) const { … }
std::optional<LocationSize>
MachineInstr::getFoldedRestoreSize(const TargetInstrInfo *TII) const { … }
unsigned MachineInstr::getDebugInstrNum() { … }
unsigned MachineInstr::getDebugInstrNum(MachineFunction &MF) { … }
std::tuple<LLT, LLT> MachineInstr::getFirst2LLTs() const { … }
std::tuple<LLT, LLT, LLT> MachineInstr::getFirst3LLTs() const { … }
std::tuple<LLT, LLT, LLT, LLT> MachineInstr::getFirst4LLTs() const { … }
std::tuple<LLT, LLT, LLT, LLT, LLT> MachineInstr::getFirst5LLTs() const { … }
std::tuple<Register, LLT, Register, LLT>
MachineInstr::getFirst2RegLLTs() const { … }
std::tuple<Register, LLT, Register, LLT, Register, LLT>
MachineInstr::getFirst3RegLLTs() const { … }
std::tuple<Register, LLT, Register, LLT, Register, LLT, Register, LLT>
MachineInstr::getFirst4RegLLTs() const { … }
std::tuple<Register, LLT, Register, LLT, Register, LLT, Register, LLT, Register,
LLT>
MachineInstr::getFirst5RegLLTs() const { … }
void MachineInstr::insert(mop_iterator InsertBefore,
ArrayRef<MachineOperand> Ops) { … }
bool MachineInstr::mayFoldInlineAsmRegOp(unsigned OpId) const { … }