Skip to content

Commit 370a537

Browse files
tbujewskgfxbot
authored andcommitted
A set of small optimizations to reduce compilation time
Change-Id: I53292f03a19a928e49e3141082e53d34f070e6e8
1 parent 77e3412 commit 370a537

20 files changed

+323
-394
lines changed

visa/BinaryEncoding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ inline BinaryEncoding::Status BinaryEncoding::ProduceBinaryInstructions()
29532953
SetInstCounts((uint32_t)globalHalfInstNum);
29542954

29552955
EncodingHelper::dumpOptReport(globalInstNum, numCompactedInst, numCompacted3SrcInst, kernel);
2956-
for (auto x = offsetVector.begin(); x != offsetVector.end(); x++)
2956+
for (auto x = offsetVector.begin(), vEnd = offsetVector.end(); x != vEnd; x++)
29572957
{
29582958
// calculate offsets again since labels for forward jumps/calls
29592959
// are available now

visa/BinaryEncodingCNL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ void BinaryEncodingCNL::DoAll()
25782578
SetInstCounts((uint32_t)globalHalfInstNum);
25792579

25802580
EncodingHelper::dumpOptReport(globalInstNum, numCompactedInst, numCompacted3SrcInst, kernel);
2581-
for (auto x = offsetVector.begin(); x != offsetVector.end(); x++)
2581+
for (auto x = offsetVector.begin(), vEnd = offsetVector.end(); x != vEnd; x++)
25822582
{
25832583
if (!EncodeConditionalBranches(x->inst, x->offset))
25842584
{

visa/BuildCISAIRImpl.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,8 @@ void saveFCallState(G4_Kernel* kernel, savedFCallStates& savedFCallState)
443443
// the IR can be reused for another kernel rather than
444444
// recompiling.
445445
// kernel points to a stackcall function.
446-
for( BB_LIST_ITER bb_it = kernel->fg.BBs.begin();
447-
bb_it != kernel->fg.BBs.end();
448-
bb_it++ )
446+
for (auto curBB : kernel->fg.BBs)
449447
{
450-
G4_BB* curBB = (*bb_it);
451-
452448
if( curBB->size() > 0 && curBB->isEndWithFCall() )
453449
{
454450
// Save state for this fcall
@@ -542,8 +538,8 @@ void restoreFCallState(G4_Kernel* kernel, savedFCallStates& savedFCallState)
542538

543539
G4_Kernel* Get_Resolved_Compilation_Unit( common_isa_header header, std::list<G4_Kernel*> compilation_units, int idx )
544540
{
545-
for( std::list<G4_Kernel*>::iterator k = compilation_units.begin();
546-
k != compilation_units.end(); k++ )
541+
for( std::list<G4_Kernel*>::iterator k = compilation_units.begin(), c_end = compilation_units.end();
542+
k != c_end; k++ )
547543
{
548544
if( (*k)->fg.builder->getCUnitId() == (header.num_kernels + idx) && (*k)->fg.builder->getIsKernel() == false )
549545
{
@@ -696,7 +692,7 @@ void Stitch_Compiled_Units( common_isa_header header, std::list<G4_Kernel*>& com
696692
}
697693

698694
// Append declarations and color attributes from all callees to kernel
699-
for (auto it = callee_index.begin(); it != callee_index.end(); ++it )
695+
for (auto it = callee_index.begin(), ciEnd = callee_index.end(); it != ciEnd; ++it)
700696
{
701697
G4_Kernel* callee = Get_Resolved_Compilation_Unit( header, compilation_units, (*it) );
702698

@@ -839,17 +835,17 @@ int CISA_IR_Builder::Compile( const char* nameInput)
839835

840836
savedFCallStates savedFCallState;
841837

842-
for(std::list<VISAKernelImpl*>::iterator kernel_it = kernels.begin();
843-
kernel_it != kernels.end();
838+
for(std::list<VISAKernelImpl*>::iterator kernel_it = kernels.begin(), kend = kernels.end();
839+
kernel_it != kend;
844840
kernel_it++)
845841
{
846842
VISAKernelImpl* kernel = (*kernel_it);
847843

848844
saveFCallState(kernel->getKernel(), savedFCallState);
849845
}
850846

851-
for( std::list<VISAKernelImpl*>::iterator func_it = functions.begin();
852-
func_it != functions.end();
847+
for( std::list<VISAKernelImpl*>::iterator func_it = functions.begin(), fend = functions.end();
848+
func_it != fend;
853849
func_it++ )
854850
{
855851
VISAKernelImpl* function = (*func_it);
@@ -1041,8 +1037,8 @@ int CISA_IR_Builder::CreateVISAFileVar(VISA_FileVar *& decl, char *varName, unsi
10411037
if( IS_GEN_BOTH_PATH )
10421038
{
10431039
// Append file var to all kernel/function objects in CISA_IR_Builder
1044-
for( std::list<VISAKernelImpl*>::iterator it = m_kernels.begin();
1045-
it != m_kernels.end();
1040+
for( std::list<VISAKernelImpl*>::iterator it = m_kernels.begin(), kend = m_kernels.end();
1041+
it != kend;
10461042
it++ )
10471043
{
10481044
VISAKernelImpl* kernel = (*it);

visa/CFGStructurizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ G4_INST* CFGStructurizer::getJmpiInst(G4_BB *bb)
11591159

11601160
void CFGStructurizer::fini()
11611161
{
1162-
for (uint32_t i = 0; i< topANodes.size(); ++i)
1162+
for (uint32_t i = 0, size = topANodes.size(); i< size; ++i)
11631163
{
11641164
deletePST((ANodeHG*)topANodes[i]);
11651165
}
@@ -2169,7 +2169,7 @@ void CFGStructurizer::ANStack_reconstruct(ANodeHG *& node, ANodeBB *ndbb)
21692169

21702170
// Merging from ANStackIx to the top of ANStack is needed to make
21712171
// sure the order of children is correct.
2172-
for (uint32_t i = newNode->ANStackIx + 1; i < ANStack.size(); ++i)
2172+
for (uint32_t i = newNode->ANStackIx + 1, size = ANStack.size(); i < size; ++i)
21732173
{
21742174
ANodeHG *nd = (ANodeHG *)ANStack[i];
21752175
getNewRange(end, exit, nd->getEndBB(), nd->getExitBB());
@@ -3656,7 +3656,7 @@ void CFGStructurizer::run()
36563656
// Now, convert ANodes
36573657
if (topANodes.size() > 0)
36583658
{
3659-
for (uint32_t i = 0; i < topANodes.size(); ++i)
3659+
for (uint32_t i = 0, size = topANodes.size(); i < size; ++i)
36603660
{
36613661
(void)convertPST(topANodes[i], nullptr);
36623662
}

visa/Common_BinaryEncoding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ void BinaryEncodingBase::FixAlign16Inst(G4_INST* inst)
165165
G4_DstRegRegion* dst = inst->getDst();
166166
dst->setWriteMask(ChannelEnable_XYZW);
167167

168-
// convert sources to align16
169-
for (int k = 0; k < inst->getNumSrc(); k++)
168+
// convert sources to align16
169+
for (int k = 0, numSrc = inst->getNumSrc(); k < numSrc; k++)
170170
{
171171
ASSERT_USER(inst->getSrc(k)->isSrcRegRegion(), "Unexpected src to be converted to ALIGN16!");
172172
G4_SrcRegRegion* src = inst->getSrc(k)->asSrcRegRegion();
@@ -232,7 +232,7 @@ void BinaryEncodingBase::FixAlign16Inst(G4_INST* inst)
232232
// for double/half inst, we have to additionally fix the source as it doesn't support the .r swizzle
233233
if (isDoubleInst)
234234
{
235-
for (int i = 0; i < inst->getNumSrc(); ++i)
235+
for (int i = 0, numSrc = inst->getNumSrc(); i < numSrc; ++i)
236236
{
237237
MUST_BE_TRUE(inst->getSrc(i)->isSrcRegRegion(), "source must have a region");
238238
G4_SrcRegRegion* src = inst->getSrc(i)->asSrcRegRegion();
@@ -254,7 +254,7 @@ void BinaryEncodingBase::FixAlign16Inst(G4_INST* inst)
254254
void BinaryEncodingBase::FixMathInst(G4_INST* inst)
255255
{
256256
MUST_BE_TRUE(inst->isMath(), "Expect math instruction");
257-
for (int i = 0; i < inst->getNumSrc(); ++i)
257+
for (int i = 0, numSrc = inst->getNumSrc(); i < numSrc; ++i)
258258
{
259259
G4_Operand* src = inst->getSrc(i);
260260
if (src && src->isSrcRegRegion())

visa/DebugInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void KernelDebugInfo::computeMissingVISAIds()
547547
}
548548
}
549549

550-
for (unsigned int i = 0; i < seenVISAIds.size(); i++)
550+
for (unsigned int i = 0, size = seenVISAIds.size(); i < size; i++)
551551
{
552552
if (!seenVISAIds[i])
553553
{
@@ -627,7 +627,7 @@ void KernelDebugInfo::generateByteOffsetMapping(std::list<G4_BB*>& stackCallEntr
627627
unsigned int maxVISAIndex = 0;
628628
uint64_t maxGenIsaOffset = 0;
629629
// Now traverse CFG, create pair of CISA byte offset, gen binary offset and push to vector
630-
for (BB_LIST_ITER bb_it = kernel->fg.BBs.begin(); bb_it != kernel->fg.BBs.end(); bb_it++)
630+
for (BB_LIST_ITER bb_it = kernel->fg.BBs.begin(), bbEnd = kernel->fg.BBs.end(); bb_it != bbEnd; bb_it++)
631631
{
632632
G4_BB* bb = (*bb_it);
633633

@@ -658,8 +658,8 @@ void KernelDebugInfo::generateByteOffsetMapping(std::list<G4_BB*>& stackCallEntr
658658
break;
659659
}
660660

661-
for(INST_LIST_ITER inst_it = bb->begin();
662-
inst_it != bb->end();
661+
for (INST_LIST_ITER inst_it = bb->begin(), bbEnd = bb->end();
662+
inst_it != bbEnd;
663663
inst_it++)
664664
{
665665
G4_INST* inst = (*inst_it);
@@ -954,7 +954,7 @@ unsigned int populateMapDclName(VISAKernelImpl* kernel, std::map<G4_Declare*, st
954954
uint32_t KernelDebugInfo::getVarIndex(G4_Declare* dcl)
955955
{
956956
uint32_t retval = 0xffffffff;
957-
for (uint32_t i = 0; i < varsMap.size(); i++)
957+
for (uint32_t i = 0, size = varsMap.size(); i < size; i++)
958958
{
959959
if (dcl == varsMap[i]->dcl)
960960
{

0 commit comments

Comments
 (0)