diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /llvm/lib/CodeGen/MachineInstr.cpp | |
parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) |
Notes
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 159 |
1 files changed, 79 insertions, 80 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index fec20b2b1a05..08d786f8f12c 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -187,8 +187,8 @@ static void moveOperands(MachineOperand *Dst, MachineOperand *Src, unsigned NumOps, MachineRegisterInfo *MRI) { if (MRI) return MRI->moveOperands(Dst, Src, NumOps); - // MachineOperand is a trivially copyable type so we can just use memmove. + assert(Dst && Src && "Unknown operands"); std::memmove(Dst, Src, NumOps * sizeof(MachineOperand)); } @@ -316,27 +316,48 @@ void MachineInstr::RemoveOperand(unsigned OpNo) { --NumOperands; } -void MachineInstr::dropMemRefs(MachineFunction &MF) { - if (memoperands_empty()) - return; +void MachineInstr::setExtraInfo(MachineFunction &MF, + ArrayRef<MachineMemOperand *> MMOs, + MCSymbol *PreInstrSymbol, + MCSymbol *PostInstrSymbol, + MDNode *HeapAllocMarker) { + bool HasPreInstrSymbol = PreInstrSymbol != nullptr; + bool HasPostInstrSymbol = PostInstrSymbol != nullptr; + bool HasHeapAllocMarker = HeapAllocMarker != nullptr; + int NumPointers = + MMOs.size() + HasPreInstrSymbol + HasPostInstrSymbol + HasHeapAllocMarker; - // See if we can just drop all of our extra info. - if (!getPreInstrSymbol() && !getPostInstrSymbol()) { + // Drop all extra info if there is none. + if (NumPointers <= 0) { Info.clear(); return; } - if (!getPostInstrSymbol()) { - Info.set<EIIK_PreInstrSymbol>(getPreInstrSymbol()); + + // If more than one pointer, then store out of line. Store heap alloc markers + // out of line because PointerSumType cannot hold more than 4 tag types with + // 32-bit pointers. + // FIXME: Maybe we should make the symbols in the extra info mutable? + else if (NumPointers > 1 || HasHeapAllocMarker) { + Info.set<EIIK_OutOfLine>(MF.createMIExtraInfo( + MMOs, PreInstrSymbol, PostInstrSymbol, HeapAllocMarker)); return; } - if (!getPreInstrSymbol()) { - Info.set<EIIK_PostInstrSymbol>(getPostInstrSymbol()); + + // Otherwise store the single pointer inline. + if (HasPreInstrSymbol) + Info.set<EIIK_PreInstrSymbol>(PreInstrSymbol); + else if (HasPostInstrSymbol) + Info.set<EIIK_PostInstrSymbol>(PostInstrSymbol); + else + Info.set<EIIK_MMO>(MMOs[0]); +} + +void MachineInstr::dropMemRefs(MachineFunction &MF) { + if (memoperands_empty()) return; - } - // Otherwise allocate a fresh extra info with just these symbols. - Info.set<EIIK_OutOfLine>( - MF.createMIExtraInfo({}, getPreInstrSymbol(), getPostInstrSymbol())); + setExtraInfo(MF, {}, getPreInstrSymbol(), getPostInstrSymbol(), + getHeapAllocMarker()); } void MachineInstr::setMemRefs(MachineFunction &MF, @@ -346,15 +367,8 @@ void MachineInstr::setMemRefs(MachineFunction &MF, return; } - // Try to store a single MMO inline. - if (MMOs.size() == 1 && !getPreInstrSymbol() && !getPostInstrSymbol()) { - Info.set<EIIK_MMO>(MMOs[0]); - return; - } - - // Otherwise create an extra info struct with all of our info. - Info.set<EIIK_OutOfLine>( - MF.createMIExtraInfo(MMOs, getPreInstrSymbol(), getPostInstrSymbol())); + setExtraInfo(MF, MMOs, getPreInstrSymbol(), getPostInstrSymbol(), + getHeapAllocMarker()); } void MachineInstr::addMemOperand(MachineFunction &MF, @@ -376,7 +390,8 @@ void MachineInstr::cloneMemRefs(MachineFunction &MF, const MachineInstr &MI) { // instruction. We can do this whenever the pre- and post-instruction symbols // are the same (including null). if (getPreInstrSymbol() == MI.getPreInstrSymbol() && - getPostInstrSymbol() == MI.getPostInstrSymbol()) { + getPostInstrSymbol() == MI.getPostInstrSymbol() && + getHeapAllocMarker() == MI.getHeapAllocMarker()) { Info = MI.Info; return; } @@ -450,67 +465,42 @@ void MachineInstr::cloneMergedMemRefs(MachineFunction &MF, } void MachineInstr::setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol) { - MCSymbol *OldSymbol = getPreInstrSymbol(); - if (OldSymbol == Symbol) + // Do nothing if old and new symbols are the same. + if (Symbol == getPreInstrSymbol()) return; - if (OldSymbol && !Symbol) { - // We're removing a symbol rather than adding one. Try to clean up any - // extra info carried around. - if (Info.is<EIIK_PreInstrSymbol>()) { - Info.clear(); - return; - } - if (memoperands_empty()) { - assert(getPostInstrSymbol() && - "Should never have only a single symbol allocated out-of-line!"); - Info.set<EIIK_PostInstrSymbol>(getPostInstrSymbol()); - return; - } - - // Otherwise fallback on the generic update. - } else if (!Info || Info.is<EIIK_PreInstrSymbol>()) { - // If we don't have any other extra info, we can store this inline. - Info.set<EIIK_PreInstrSymbol>(Symbol); + // If there was only one symbol and we're removing it, just clear info. + if (!Symbol && Info.is<EIIK_PreInstrSymbol>()) { + Info.clear(); return; } - // Otherwise, allocate a full new set of extra info. - // FIXME: Maybe we should make the symbols in the extra info mutable? - Info.set<EIIK_OutOfLine>( - MF.createMIExtraInfo(memoperands(), Symbol, getPostInstrSymbol())); + setExtraInfo(MF, memoperands(), Symbol, getPostInstrSymbol(), + getHeapAllocMarker()); } void MachineInstr::setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol) { - MCSymbol *OldSymbol = getPostInstrSymbol(); - if (OldSymbol == Symbol) + // Do nothing if old and new symbols are the same. + if (Symbol == getPostInstrSymbol()) return; - if (OldSymbol && !Symbol) { - // We're removing a symbol rather than adding one. Try to clean up any - // extra info carried around. - if (Info.is<EIIK_PostInstrSymbol>()) { - Info.clear(); - return; - } - if (memoperands_empty()) { - assert(getPreInstrSymbol() && - "Should never have only a single symbol allocated out-of-line!"); - Info.set<EIIK_PreInstrSymbol>(getPreInstrSymbol()); - return; - } - - // Otherwise fallback on the generic update. - } else if (!Info || Info.is<EIIK_PostInstrSymbol>()) { - // If we don't have any other extra info, we can store this inline. - Info.set<EIIK_PostInstrSymbol>(Symbol); + // If there was only one symbol and we're removing it, just clear info. + if (!Symbol && Info.is<EIIK_PostInstrSymbol>()) { + Info.clear(); return; } - // Otherwise, allocate a full new set of extra info. - // FIXME: Maybe we should make the symbols in the extra info mutable? - Info.set<EIIK_OutOfLine>( - MF.createMIExtraInfo(memoperands(), getPreInstrSymbol(), Symbol)); + setExtraInfo(MF, memoperands(), getPreInstrSymbol(), Symbol, + getHeapAllocMarker()); +} + +void MachineInstr::setHeapAllocMarker(MachineFunction &MF, MDNode *Marker) { + // Do nothing if old and new symbols are the same. + if (Marker == getHeapAllocMarker()) + return; + + setExtraInfo(MF, memoperands(), getPreInstrSymbol(), getPostInstrSymbol(), + Marker); } void MachineInstr::cloneInstrSymbols(MachineFunction &MF, @@ -524,6 +514,7 @@ void MachineInstr::cloneInstrSymbols(MachineFunction &MF, setPreInstrSymbol(MF, MI.getPreInstrSymbol()); setPostInstrSymbol(MF, MI.getPostInstrSymbol()); + setHeapAllocMarker(MF, MI.getHeapAllocMarker()); } uint16_t MachineInstr::mergeFlagsWith(const MachineInstr &Other) const { @@ -1515,7 +1506,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, LLT TypeToPrint = MRI ? getTypeToPrint(StartOp, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(StartOp); - MO.print(OS, MST, TypeToPrint, /*PrintDef=*/false, IsStandalone, + MO.print(OS, MST, TypeToPrint, StartOp, /*PrintDef=*/false, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); ++StartOp; } @@ -1547,8 +1538,8 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, OS << "nsw "; if (getFlag(MachineInstr::IsExact)) OS << "exact "; - if (getFlag(MachineInstr::FPExcept)) - OS << "fpexcept "; + if (getFlag(MachineInstr::NoFPExcept)) + OS << "nofpexcept "; // Print the opcode name. if (TII) @@ -1570,7 +1561,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, const unsigned OpIdx = InlineAsm::MIOp_AsmString; LLT TypeToPrint = MRI ? getTypeToPrint(OpIdx, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(OpIdx); - getOperand(OpIdx).print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, + getOperand(OpIdx).print(OS, MST, TypeToPrint, OpIdx, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); @@ -1609,7 +1600,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, else { LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(i); - MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } else if (isDebugLabel() && MO.isMetadata()) { @@ -1620,7 +1611,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, else { LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(i); - MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } else if (i == AsmDescOp && MO.isImm()) { @@ -1687,7 +1678,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, if (MO.isImm() && isOperandSubregIdx(i)) MachineOperand::printSubRegIdx(OS, MO.getImm(), TRI); else - MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } @@ -1710,6 +1701,14 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, OS << " post-instr-symbol "; MachineOperand::printSymbol(OS, *PostInstrSymbol); } + if (MDNode *HeapAllocMarker = getHeapAllocMarker()) { + if (!FirstOp) { + FirstOp = false; + OS << ','; + } + OS << " heap-alloc-marker "; + HeapAllocMarker->printAsOperand(OS, MST); + } if (!SkipDebugLoc) { if (const DebugLoc &DL = getDebugLoc()) { @@ -1978,7 +1977,7 @@ void MachineInstr::setPhysRegsDeadExcept(ArrayRef<Register> UsedRegs, unsigned MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) { // Build up a buffer of hash code components. - SmallVector<size_t, 8> HashComponents; + SmallVector<size_t, 16> HashComponents; HashComponents.reserve(MI->getNumOperands() + 1); HashComponents.push_back(MI->getOpcode()); for (const MachineOperand &MO : MI->operands()) { |