llvm.org GIT mirror llvm / a08efbf
CodeGen: Push the ModuleSlotTracker through MachineOperands Push `ModuleSlotTracker` through `MachineOperand`s, dropping the time for `llc -print-machineinstrs` on the testcase in PR23865 from ~13 seconds to ~9 seconds. Now `SlotTracker::processFunctionMetadata()` accounts for only 8% of the runtime, which seems reasonable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240845 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
6 changed file(s) with 64 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
11041104 // Debugging support
11051105 //
11061106 void print(raw_ostream &OS, bool SkipOpers = false) const;
1107 void print(raw_ostream &OS, ModuleSlotTracker &MST,
1108 bool SkipOpers = false) const;
11071109 void dump() const;
11081110
11091111 //===--------------------------------------------------------------------===//
2626 class FoldingSetNodeID;
2727 class MDNode;
2828 class raw_ostream;
29 class ModuleSlotTracker;
2930
3031 /// MachinePointerInfo - This class contains a discriminated union of
3132 /// information about pointers in memory operands, relating them back to LLVM IR
199200 ///
200201 void Profile(FoldingSetNodeID &ID) const;
201202
203 /// Support for operator<<.
204 /// @{
205 void print(raw_ostream &OS) const;
206 void print(raw_ostream &OS, ModuleSlotTracker &MST) const;
207 /// @}
208
202209 friend bool operator==(const MachineMemOperand &LHS,
203210 const MachineMemOperand &RHS) {
204211 return LHS.getValue() == RHS.getValue() &&
218225 }
219226 };
220227
221 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
228 inline raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO) {
229 MRO.print(OS);
230 return OS;
231 }
222232
223233 } // End llvm namespace
224234
2626 class MachineInstr;
2727 class MachineRegisterInfo;
2828 class MDNode;
29 class ModuleSlotTracker;
2930 class TargetMachine;
3031 class TargetRegisterInfo;
3132 class hash_code;
217218 void clearParent() { ParentMI = nullptr; }
218219
219220 void print(raw_ostream &os, const TargetRegisterInfo *TRI = nullptr) const;
221 void print(raw_ostream &os, ModuleSlotTracker &MST,
222 const TargetRegisterInfo *TRI = nullptr) const;
220223
221224 //===--------------------------------------------------------------------===//
222225 // Accessors that tell you what kind of MachineOperand you're looking at.
2828 /// space), or constant pool.
2929 class PseudoSourceValue {
3030 private:
31 friend raw_ostream &llvm::operator<<(raw_ostream &OS,
32 const MachineMemOperand &MMO);
31 friend class MachineMemOperand; // For printCustom().
3332
3433 /// printCustom - Implement printing for PseudoSourceValue. This is called
3534 /// from Value::print or Value's operator<<.
304304 OS << '\t';
305305 if (I->isInsideBundle())
306306 OS << " * ";
307 I->print(OS);
307 I->print(OS, MST);
308308 }
309309
310310 // Print the successors of this block according to the CFG.
2727 #include "llvm/IR/LLVMContext.h"
2828 #include "llvm/IR/Metadata.h"
2929 #include "llvm/IR/Module.h"
30 #include "llvm/IR/ModuleSlotTracker.h"
3031 #include "llvm/IR/Type.h"
3132 #include "llvm/IR/Value.h"
3233 #include "llvm/MC/MCInstrDesc.h"
295296 llvm_unreachable("Invalid machine operand type");
296297 }
297298
298 /// print - Print the specified machine operand.
299 ///
300299 void MachineOperand::print(raw_ostream &OS,
300 const TargetRegisterInfo *TRI) const {
301 ModuleSlotTracker DummyMST(nullptr);
302 print(OS, DummyMST, TRI);
303 }
304
305 void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
301306 const TargetRegisterInfo *TRI) const {
302307 switch (getType()) {
303308 case MachineOperand::MO_Register:
386391 break;
387392 case MachineOperand::MO_GlobalAddress:
388393 OS << "
389 getGlobal()->printAsOperand(OS, /*PrintType=*/false);
394 getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
390395 if (getOffset()) OS << "+" << getOffset();
391396 OS << '>';
392397 break;
397402 break;
398403 case MachineOperand::MO_BlockAddress:
399404 OS << '<';
400 getBlockAddress()->printAsOperand(OS, /*PrintType=*/false);
405 getBlockAddress()->printAsOperand(OS, /*PrintType=*/false, MST);
401406 if (getOffset()) OS << "+" << getOffset();
402407 OS << '>';
403408 break;
504509 return MinAlign(getBaseAlignment(), getOffset());
505510 }
506511
507 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MMO) {
508 assert((MMO.isLoad() || MMO.isStore()) &&
512 void MachineMemOperand::print(raw_ostream &OS) const {
513 ModuleSlotTracker DummyMST(nullptr);
514 print(OS, DummyMST);
515 }
516 void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST) const {
517 assert((isLoad() || isStore()) &&
509518 "SV has to be a load, store or both.");
510519
511 if (MMO.isVolatile())
520 if (isVolatile())
512521 OS << "Volatile ";
513522
514 if (MMO.isLoad())
523 if (isLoad())
515524 OS << "LD";
516 if (MMO.isStore())
525 if (isStore())
517526 OS << "ST";
518 OS << MMO.getSize();
527 OS << getSize();
519528
520529 // Print the address information.
521530 OS << "[";
522 if (const Value *V = MMO.getValue())
523 V->printAsOperand(OS, /*PrintType=*/false);
524 else if (const PseudoSourceValue *PSV = MMO.getPseudoValue())
531 if (const Value *V = getValue())
532 V->printAsOperand(OS, /*PrintType=*/false, MST);
533 else if (const PseudoSourceValue *PSV = getPseudoValue())
525534 PSV->printCustom(OS);
526535 else
527536 OS << "";
528537
529 unsigned AS = MMO.getAddrSpace();
538 unsigned AS = getAddrSpace();
530539 if (AS != 0)
531540 OS << "(addrspace=" << AS << ')';
532541
533542 // If the alignment of the memory reference itself differs from the alignment
534543 // of the base pointer, print the base alignment explicitly, next to the base
535544 // pointer.
536 if (MMO.getBaseAlignment() != MMO.getAlignment())
537 OS << "(align=" << MMO.getBaseAlignment() << ")";
538
539 if (MMO.getOffset() != 0)
540 OS << "+" << MMO.getOffset();
545 if (getBaseAlignment() != getAlignment())
546 OS << "(align=" << getBaseAlignment() << ")";
547
548 if (getOffset() != 0)
549 OS << "+" << getOffset();
541550 OS << "]";
542551
543552 // Print the alignment of the reference.
544 if (MMO.getBaseAlignment() != MMO.getAlignment() ||
545 MMO.getBaseAlignment() != MMO.getSize())
546 OS << "(align=" << MMO.getAlignment() << ")";
553 if (getBaseAlignment() != getAlignment() || getBaseAlignment() != getSize())
554 OS << "(align=" << getAlignment() << ")";
547555
548556 // Print TBAA info.
549 if (const MDNode *TBAAInfo = MMO.getAAInfo().TBAA) {
557 if (const MDNode *TBAAInfo = getAAInfo().TBAA) {
550558 OS << "(tbaa=";
551559 if (TBAAInfo->getNumOperands() > 0)
552560 TBAAInfo->getOperand(0)->printAsOperand(OS);
556564 }
557565
558566 // Print AA scope info.
559 if (const MDNode *ScopeInfo = MMO.getAAInfo().Scope) {
567 if (const MDNode *ScopeInfo = getAAInfo().Scope) {
560568 OS << "(alias.scope=";
561569 if (ScopeInfo->getNumOperands() > 0)
562570 for (unsigned i = 0, ie = ScopeInfo->getNumOperands(); i != ie; ++i) {
570578 }
571579
572580 // Print AA noalias scope info.
573 if (const MDNode *NoAliasInfo = MMO.getAAInfo().NoAlias) {
581 if (const MDNode *NoAliasInfo = getAAInfo().NoAlias) {
574582 OS << "(noalias=";
575583 if (NoAliasInfo->getNumOperands() > 0)
576584 for (unsigned i = 0, ie = NoAliasInfo->getNumOperands(); i != ie; ++i) {
584592 }
585593
586594 // Print nontemporal info.
587 if (MMO.isNonTemporal())
595 if (isNonTemporal())
588596 OS << "(nontemporal)";
589597
590 if (MMO.isInvariant())
598 if (isInvariant())
591599 OS << "(invariant)";
592
593 return OS;
594600 }
595601
596602 //===----------------------------------------------------------------------===//
15251531 }
15261532
15271533 void MachineInstr::print(raw_ostream &OS, bool SkipOpers) const {
1534 ModuleSlotTracker DummyMST(nullptr);
1535 print(OS, DummyMST, SkipOpers);
1536 }
1537
1538 void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
1539 bool SkipOpers) const {
15281540 // We can be a bit tidier if we know the MachineFunction.
15291541 const MachineFunction *MF = nullptr;
15301542 const TargetRegisterInfo *TRI = nullptr;
15491561 !getOperand(StartOp).isImplicit();
15501562 ++StartOp) {
15511563 if (StartOp != 0) OS << ", ";
1552 getOperand(StartOp).print(OS, TRI);
1564 getOperand(StartOp).print(OS, MST, TRI);
15531565 unsigned Reg = getOperand(StartOp).getReg();
15541566 if (TargetRegisterInfo::isVirtualRegister(Reg))
15551567 VirtRegs.push_back(Reg);
15761588 if (isInlineAsm() && e >= InlineAsm::MIOp_FirstOperand) {
15771589 // Print asm string.
15781590 OS << " ";
1579 getOperand(InlineAsm::MIOp_AsmString).print(OS, TRI);
1591 getOperand(InlineAsm::MIOp_AsmString).print(OS, MST, TRI);
15801592
15811593 // Print HasSideEffects, MayLoad, MayStore, IsAlignStack
15821594 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
16441656 if (DIV && !DIV->getName().empty())
16451657 OS << "!\"" << DIV->getName() << '\"';
16461658 else
1647 MO.print(OS, TRI);
1659 MO.print(OS, MST, TRI);
16481660 } else if (TRI && (isInsertSubreg() || isRegSequence()) && MO.isImm()) {
16491661 OS << TRI->getSubRegIndexName(MO.getImm());
16501662 } else if (i == AsmDescOp && MO.isImm()) {
16781690 // Compute the index of the next operand descriptor.
16791691 AsmDescOp += 1 + InlineAsm::getNumOperandRegisters(Flag);
16801692 } else
1681 MO.print(OS, TRI);
1693 MO.print(OS, MST, TRI);
16821694 }
16831695
16841696 // Briefly indicate whether any call clobbers were omitted.
17031715 OS << " mem:";
17041716 for (mmo_iterator i = memoperands_begin(), e = memoperands_end();
17051717 i != e; ++i) {
1706 OS << **i;
1718 (*i)->print(OS, MST);
17071719 if (std::next(i) != e)
17081720 OS << " ";
17091721 }