1+
12/* ===================== begin_copyright_notice ==================================
23
34Copyright (c) 2017 Intel Corporation
@@ -373,19 +374,20 @@ void CheckInstrTypes::visitGetElementPtrInst(llvm::GetElementPtrInst& I)
373374#undef PASS_CFG_ONLY
374375#undef PASS_ANALYSIS
375376
376- #define PASS_FLAG " InstrStatitic "
377+ #define PASS_FLAG " InstrStatistic "
377378#define PASS_DESCRIPTION " Check individual type of instructions"
378379#define PASS_CFG_ONLY false
379380#define PASS_ANALYSIS false
380- IGC_INITIALIZE_PASS_BEGIN (InstrStatitic , PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
381- IGC_INITIALIZE_PASS_END(InstrStatitic , PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
381+ IGC_INITIALIZE_PASS_BEGIN (InstrStatistic , PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
382+ IGC_INITIALIZE_PASS_END(InstrStatistic , PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
382383
383- char InstrStatitic ::ID = 0;
384+ char InstrStatistic ::ID = 0;
384385
385- InstrStatitic::InstrStatitic (CodeGenContext* ctx, InstrStatTypes type, InstrStatStage stage, int threshold) :
386+ InstrStatistic::InstrStatistic (CodeGenContext* ctx, InstrStatTypes type, InstrStatStage stage, int threshold) :
386387 FunctionPass(ID), m_ctx(ctx), m_type(type), m_stage(stage), m_threshold(threshold)
387388{
388- initializeInstrStatiticPass (*PassRegistry::getPassRegistry ());
389+ initializeInstrStatisticPass (*PassRegistry::getPassRegistry ());
390+ initializeLoopInfoWrapperPassPass (*PassRegistry::getPassRegistry ());
389391
390392 if (stage == InstrStatStage::BEGIN)
391393 {
@@ -395,34 +397,74 @@ InstrStatitic::InstrStatitic(CodeGenContext* ctx, InstrStatTypes type, InstrStat
395397 }
396398}
397399
398- bool InstrStatitic ::runOnFunction (Function& F)
400+ bool InstrStatistic ::runOnFunction (Function& F)
399401{
400- // run the pass
401- visit (F);
402+ bool changed = false ;
403+
404+ if (m_type == LICM_STAT) {
405+ m_LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
406+ changed = parseLoops ();
407+ }
408+ else {
409+ // run the pass
410+ visit (F);
411+ }
402412
403413 // if this is a call for ending statistic, find out if the difference exceeds the threshold.
404414 if (m_stage == InstrStatStage::END)
405415 {
406416 if (m_ctx->instrStat [m_type][InstrStatStage::BEGIN] - m_ctx->instrStat [m_type][InstrStatStage::END] > m_threshold)
407417 {
408418 m_ctx->instrStat [m_type][InstrStatStage::EXCEED_THRESHOLD] = 1 ;
419+ }
420+
421+ if (m_type == SROA_PROMOTED)
422+ {
409423 m_ctx->m_retryManager .Disable ();
410424 }
411425 }
412- return false ;
426+
427+ return changed;
413428}
414429
415- void InstrStatitic ::visitInstruction (llvm::Instruction& I)
430+ void InstrStatistic ::visitInstruction (llvm::Instruction& I)
416431{
417432}
418433
419- void InstrStatitic ::visitLoadInst (LoadInst& I)
434+ void InstrStatistic ::visitLoadInst (LoadInst& I)
420435{
421- m_ctx->instrStat [m_type][m_stage]++;
436+ if (m_type == SROA_PROMOTED)
437+ m_ctx->instrStat [m_type][m_stage]++;
422438}
423439
424- void InstrStatitic ::visitStoreInst (StoreInst& I)
440+ void InstrStatistic ::visitStoreInst (StoreInst& I)
425441{
426- m_ctx->instrStat [m_type][m_stage]++;
442+ if (m_type == SROA_PROMOTED)
443+ m_ctx->instrStat [m_type][m_stage]++;
427444}
428445
446+ bool InstrStatistic::parseLoops ()
447+ {
448+ bool changed = false ;
449+
450+ for (auto & LI : *m_LI)
451+ {
452+ Loop* L1 = &(*LI);
453+ changed |= parseLoop (L1);
454+
455+ for (auto & L2 : L1->getSubLoops ())
456+ {
457+ changed |= parseLoop (L2);
458+ }
459+ }
460+
461+ return changed;
462+ }
463+
464+ bool InstrStatistic::parseLoop (Loop* loop)
465+ {
466+ auto * header = loop->getHeader ();
467+ m_ctx->instrStat [m_type][m_stage] += header->size ();
468+
469+ return false ;
470+ }
0 commit comments