llvm.org GIT mirror llvm / 8266df7
CodeGen: Push the ModuleSlotTracker through Metadata For another 1% speedup on the testcase in PR23865, push the `ModuleSlotTracker` through to metadata-related printing in `MachineBasicBlock::print()`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240848 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
4 changed file(s) with 37 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2626 #include
2727
2828 namespace llvm {
29
2930 class LLVMContext;
3031 class Module;
32 class ModuleSlotTracker;
33
3134 template
3235 class SymbolTableListTraits;
3336
128131 ///
129132 /// If \c M is provided, metadata nodes will be numbered canonically;
130133 /// otherwise, pointer addresses are substituted.
134 /// @{
131135 void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const;
136 void printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST,
137 const Module *M = nullptr) const;
138 /// @}
132139 };
133140
134141 #define HANDLE_METADATA(CLASS) class CLASS;
4040
4141 /// Construct a slot tracker from a module.
4242 ///
43 /// If \a M is \c nullptr, uses a null slot tracker.
44 explicit ModuleSlotTracker(const Module *M);
43 /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
44 /// a slot tracker, and initializes all metadata slots. \c
45 /// ShouldInitializeAllMetadata defaults to true because this is expected to
46 /// be shared between multiple callers, and otherwise MDNode references will
47 /// not match up.
48 explicit ModuleSlotTracker(const Module *M,
49 bool ShouldInitializeAllMetadata = true);
4550
4651 /// Destructor to clean up storage.
4752 ~ModuleSlotTracker();
414414 break;
415415 case MachineOperand::MO_Metadata:
416416 OS << '<';
417 getMetadata()->printAsOperand(OS);
417 getMetadata()->printAsOperand(OS, MST);
418418 OS << '>';
419419 break;
420420 case MachineOperand::MO_MCSymbol:
557557 if (const MDNode *TBAAInfo = getAAInfo().TBAA) {
558558 OS << "(tbaa=";
559559 if (TBAAInfo->getNumOperands() > 0)
560 TBAAInfo->getOperand(0)->printAsOperand(OS);
560 TBAAInfo->getOperand(0)->printAsOperand(OS, MST);
561561 else
562562 OS << "";
563563 OS << ")";
568568 OS << "(alias.scope=";
569569 if (ScopeInfo->getNumOperands() > 0)
570570 for (unsigned i = 0, ie = ScopeInfo->getNumOperands(); i != ie; ++i) {
571 ScopeInfo->getOperand(i)->printAsOperand(OS);
571 ScopeInfo->getOperand(i)->printAsOperand(OS, MST);
572572 if (i != ie-1)
573573 OS << ",";
574574 }
582582 OS << "(noalias=";
583583 if (NoAliasInfo->getNumOperands() > 0)
584584 for (unsigned i = 0, ie = NoAliasInfo->getNumOperands(); i != ie; ++i) {
585 NoAliasInfo->getOperand(i)->printAsOperand(OS);
585 NoAliasInfo->getOperand(i)->printAsOperand(OS, MST);
586586 if (i != ie-1)
587587 OS << ",";
588588 }
669669 const Function *F)
670670 : M(M), F(F), Machine(&Machine) {}
671671
672 ModuleSlotTracker::ModuleSlotTracker(const Module *M)
673 : MachineStorage(
674 M ? new SlotTracker(M, /* ShouldInitializeAllMetadata */ true)
675 : nullptr),
672 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
673 bool ShouldInitializeAllMetadata)
674 : MachineStorage(M ? new SlotTracker(M, ShouldInitializeAllMetadata)
675 : nullptr),
676676 M(M), Machine(MachineStorage.get()) {}
677677
678678 ModuleSlotTracker::~ModuleSlotTracker() {}
32773277 }
32783278
32793279 static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD,
3280 const Module *M, bool OnlyAsOperand) {
3280 ModuleSlotTracker &MST, const Module *M,
3281 bool OnlyAsOperand) {
32813282 formatted_raw_ostream OS(ROS);
32823283
3283 auto *N = dyn_cast(&MD);
32843284 TypePrinting TypePrinter;
3285 SlotTracker Machine(M, /* ShouldInitializeAllMetadata */ N);
32863285 if (M)
32873286 TypePrinter.incorporateTypes(*M);
32883287
3289 WriteAsOperandInternal(OS, &MD, &TypePrinter, &Machine, M,
3288 WriteAsOperandInternal(OS, &MD, &TypePrinter, MST.getMachine(), M,
32903289 /* FromValue */ true);
3290
3291 auto *N = dyn_cast(&MD);
32913292 if (OnlyAsOperand || !N)
32923293 return;
32933294
32943295 OS << " = ";
3295 WriteMDNodeBodyInternal(OS, N, &TypePrinter, &Machine, M);
3296 WriteMDNodeBodyInternal(OS, N, &TypePrinter, MST.getMachine(), M);
32963297 }
32973298
32983299 void Metadata::printAsOperand(raw_ostream &OS, const Module *M) const {
3299 printMetadataImpl(OS, *this, M, /* OnlyAsOperand */ true);
3300 ModuleSlotTracker MST(M, isa(this));
3301 printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ true);
3302 }
3303
3304 void Metadata::printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST,
3305 const Module *M) const {
3306 printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ true);
33003307 }
33013308
33023309 void Metadata::print(raw_ostream &OS, const Module *M) const {
3303 printMetadataImpl(OS, *this, M, /* OnlyAsOperand */ false);
3310 ModuleSlotTracker MST(M, isa(this));
3311 printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ false);
33043312 }
33053313
33063314 // Value::dump - allow easy printing of Values from the debugger.