/// Compute the resource usage in basic block MBB. const MachineTraceMetrics::FixedBlockInfo* MachineTraceMetrics::getResources(const MachineBasicBlock *MBB) { assert(MBB && "No basic block"); FixedBlockInfo *FBI = &BlockInfo[MBB->getNumber()]; if (FBI->hasResources()) return FBI; // Compute resource usage in the block. FBI->HasCalls = false; unsigned InstrCount = 0; // Add up per-processor resource cycles as well. unsigned PRKinds = SchedModel.getNumProcResourceKinds(); SmallVector<unsigned, 32> PRCycles(PRKinds); for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end(); I != E; ++I) { const MachineInstr *MI = I; if (MI->isTransient()) continue; ++InstrCount; if (MI->isCall()) FBI->HasCalls = true; // Count processor resources used. if (!SchedModel.hasInstrSchedModel()) continue; const MCSchedClassDesc *SC = SchedModel.resolveSchedClass(MI); if (!SC->isValid()) continue; for (TargetSchedModel::ProcResIter PI = SchedModel.getWriteProcResBegin(SC), PE = SchedModel.getWriteProcResEnd(SC); PI != PE; ++PI) { assert(PI->ProcResourceIdx < PRKinds && "Bad processor resource kind"); PRCycles[PI->ProcResourceIdx] += PI->Cycles; } } FBI->InstrCount = InstrCount; // Scale the resource cycles so they are comparable. unsigned PROffset = MBB->getNumber() * PRKinds; for (unsigned K = 0; K != PRKinds; ++K) ProcResourceCycles[PROffset + K] = PRCycles[K] * SchedModel.getResourceFactor(K); return FBI; }
/// Compute the resource usage in basic block MBB. const MachineTraceMetrics::FixedBlockInfo* MachineTraceMetrics::getResources(const MachineBasicBlock *MBB) { assert(MBB && "No basic block"); FixedBlockInfo *FBI = &BlockInfo[MBB->getNumber()]; if (FBI->hasResources()) return FBI; // Compute resource usage in the block. // FIXME: Compute per-functional unit counts. FBI->HasCalls = false; unsigned InstrCount = 0; for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end(); I != E; ++I) { const MachineInstr *MI = I; if (MI->isTransient()) continue; ++InstrCount; if (MI->isCall()) FBI->HasCalls = true; } FBI->InstrCount = InstrCount; return FBI; }