@@ -124,19 +124,17 @@ bool InlineLocalsResolution::runOnModule(Module& M)
124
124
125
125
LLVMContext& C = M.getContext ();
126
126
127
- for (Module::iterator I = M. begin (), E = M. end (); I != E; ++I )
127
+ for (Function& F : M )
128
128
{
129
- Function* pFunc = &(*I);
130
-
131
- if (pFunc->isDeclaration () || !isEntryFunc (pMdUtils, pFunc))
129
+ if (F.isDeclaration () || !isEntryFunc (pMdUtils, &F))
132
130
{
133
131
continue ;
134
132
}
135
133
136
134
unsigned int totalSize = 0 ;
137
135
138
136
// Get the offset at which local arguments start
139
- auto sizeIter = sizeMap.find (pFunc );
137
+ auto sizeIter = sizeMap.find (&F );
140
138
if (sizeIter != sizeMap.end ())
141
139
{
142
140
totalSize += sizeIter->second ;
@@ -146,7 +144,7 @@ bool InlineLocalsResolution::runOnModule(Module& M)
146
144
totalSize = (totalSize & 0xFFFF );
147
145
148
146
bool IsFirstSLMArgument = true ;
149
- for (Function::arg_iterator A = pFunc-> arg_begin (), AE = pFunc-> arg_end (); A != AE; ++A)
147
+ for (Function::arg_iterator A = F. arg_begin (), AE = F. arg_end (); A != AE; ++A)
150
148
{
151
149
Argument* arg = &(*A);
152
150
PointerType* ptrType = dyn_cast<PointerType>(arg->getType ());
@@ -176,15 +174,15 @@ bool InlineLocalsResolution::runOnModule(Module& M)
176
174
if (IsFirstSLMArgument) {
177
175
auto BufType = ArrayType::get (Type::getInt8Ty (M.getContext ()), 0 );
178
176
auto ExtSLM = new GlobalVariable (M, BufType, false , GlobalVariable::ExternalLinkage, nullptr ,
179
- pFunc-> getName () + " -ExtSLM" , nullptr , GlobalVariable::ThreadLocalMode::NotThreadLocal,
177
+ F. getName () + " -ExtSLM" , nullptr , GlobalVariable::ThreadLocalMode::NotThreadLocal,
180
178
ADDRESS_SPACE_LOCAL);
181
179
auto NewPtr = ConstantExpr::getBitCast (ExtSLM, arg->getType ());
182
180
arg->replaceAllUsesWith (NewPtr );
183
181
// Update MD.
184
182
LocalOffsetMD localOffset;
185
183
localOffset.m_Var = ExtSLM;
186
184
localOffset.m_Offset = Offset;
187
- modMD->FuncMD [pFunc ].localOffsets .push_back (localOffset);
185
+ modMD->FuncMD [&F ].localOffsets .push_back (localOffset);
188
186
189
187
IGC::appendToUsed (M, ExtSLM);
190
188
IsFirstSLMArgument = false ;
@@ -197,7 +195,7 @@ bool InlineLocalsResolution::runOnModule(Module& M)
197
195
// Bitcast to i8*, GEP, bitcast back to original type.
198
196
Value* sizeConstant = ConstantInt::get (Type::getInt32Ty (C), Offset);
199
197
SmallVector<Value*, 1 > idx (1 , sizeConstant);
200
- Instruction* pInsertBefore = &(*pFunc-> begin ()->getFirstInsertionPt ());
198
+ Instruction* pInsertBefore = &(*F. begin ()->getFirstInsertionPt ());
201
199
Type* pLocalCharPtrType = Type::getInt8Ty (C)->getPointerTo (ADDRESS_SPACE_LOCAL);
202
200
Instruction* pCharPtr = BitCastInst::CreatePointerCast (arg, pLocalCharPtrType, " localToChar" , pInsertBefore);
203
201
Value* pMovedCharPtr = GetElementPtrInst::Create (nullptr , pCharPtr, idx, " movedLocal" , pInsertBefore);
@@ -346,15 +344,15 @@ void InlineLocalsResolution::collectInfoOnSharedLocalMem(Module& M)
346
344
347
345
// scan inst to collect all call instructions
348
346
349
- for (Module::iterator F = M. begin (), FE = M. end (); F != FE; ++F )
347
+ for (Function& F : M )
350
348
{
351
- if (F-> isDeclaration ())
349
+ if (F. isDeclaration ())
352
350
{
353
351
continue ;
354
352
}
355
353
356
354
unsigned maxBytesOnFunc = 0 ;
357
- for (auto I = inst_begin (&(*F)) , IE = inst_end (&(*F) ); I != IE; ++I)
355
+ for (auto I = inst_begin (&F) , IE = inst_end (&F ); I != IE; ++I)
358
356
{
359
357
Instruction* inst = &(*I);
360
358
if (CallInst * CI = dyn_cast<CallInst>(inst))
@@ -389,7 +387,7 @@ void InlineLocalsResolution::collectInfoOnSharedLocalMem(Module& M)
389
387
}
390
388
if (maxBytesOnFunc != 0 )
391
389
{
392
- m_FuncToMemPoolSizeMap[&(*F) ] = maxBytesOnFunc;
390
+ m_FuncToMemPoolSizeMap[&F ] = maxBytesOnFunc;
393
391
}
394
392
}
395
393
@@ -467,7 +465,7 @@ void InlineLocalsResolution::collectInfoOnSharedLocalMem(Module& M)
467
465
}
468
466
469
467
// set debugging info, and insert mov inst.
470
- IF_DEBUG_INFO (for (auto I : m_FuncToVarsMap))
468
+ IF_DEBUG_INFO (for (const auto & I : m_FuncToVarsMap))
471
469
{
472
470
IF_DEBUG_INFO (Function * userFunc = I.first ;)
473
471
IF_DEBUG_INFO (for (auto G : I.second ))
@@ -492,18 +490,18 @@ void InlineLocalsResolution::computeOffsetList(Module& M, std::map<Function*, un
492
490
return ;
493
491
}
494
492
495
- // let's travese the CallGraph to calculate the local
493
+ // let's traverse the CallGraph to calculate the local
496
494
// variables of kernel from all user functions.
497
495
m_chkSet.clear ();
498
496
for (auto & N : CG)
499
497
{
500
498
Function* f = N.second ->getFunction ();
501
499
if (!f || f->isDeclaration () || m_chkSet.find (f) != m_chkSet.end ()) continue ;
502
- traveseCGN (*N.second );
500
+ traverseCGN (*N.second );
503
501
}
504
502
505
503
// set up the offsetMap;
506
- for (auto I : m_FuncToVarsMap)
504
+ for (const auto & I : m_FuncToVarsMap)
507
505
{
508
506
Function* F = I.first ;
509
507
@@ -538,16 +536,16 @@ void InlineLocalsResolution::computeOffsetList(Module& M, std::map<Function*, un
538
536
}
539
537
540
538
// Ok, we've collected the information, now write it into the MD.
541
- for (auto iter = sizeMap. begin (), end = sizeMap. end (); iter != end; ++iter )
539
+ for (auto & iter : sizeMap)
542
540
{
543
541
// ignore non-entry functions.
544
- if (!isEntryFunc (pMdUtils, iter-> first ))
542
+ if (!isEntryFunc (pMdUtils, iter. first ))
545
543
{
546
544
continue ;
547
545
}
548
546
549
547
// If this function doesn't have any locals, no need for MD.
550
- if (iter-> second == 0 )
548
+ if (iter. second == 0 )
551
549
{
552
550
continue ;
553
551
}
@@ -557,32 +555,35 @@ void InlineLocalsResolution::computeOffsetList(Module& M, std::map<Function*, un
557
555
// we are going to have inline parameters. So, we need to make sure the
558
556
// first local parameter is appropriately aligned, which, at worst,
559
557
// can be 256 bits.
560
- iter-> second = iSTD::Align (iter-> second , 32 );
558
+ iter. second = iSTD::Align (iter. second , 32 );
561
559
562
560
// Add the size information of this function
563
- modMD->FuncMD [iter-> first ].localSize = iter-> second ;
561
+ modMD->FuncMD [iter. first ].localSize = iter. second ;
564
562
565
563
// And now the offsets.
566
- for (auto offsetIter = offsetMap[iter-> first ]. begin (), offsetEnd = offsetMap[iter-> first ]. end (); offsetIter != offsetEnd; ++offsetIter )
564
+ for (const auto & offsetIter : offsetMap[iter. first ])
567
565
{
568
- unsigned Offset = offsetIter-> second ;
569
- if (!useAsPointerOnly (offsetIter-> first ))
566
+ unsigned Offset = offsetIter. second ;
567
+ if (!useAsPointerOnly (offsetIter. first ))
570
568
Offset |= VALID_LOCAL_HIGH_BITS;
571
569
572
570
LocalOffsetMD localOffset;
573
- localOffset.m_Var = offsetIter-> first ;
571
+ localOffset.m_Var = offsetIter. first ;
574
572
localOffset.m_Offset = Offset;
575
- modMD->FuncMD [iter-> first ].localOffsets .push_back (localOffset);
573
+ modMD->FuncMD [iter. first ].localOffsets .push_back (localOffset);
576
574
}
577
575
}
578
576
pMdUtils->save (M.getContext ());
579
577
}
580
578
581
- void InlineLocalsResolution::traveseCGN ( llvm::CallGraphNode& CGN)
579
+ void InlineLocalsResolution::traverseCGN ( const llvm::CallGraphNode& CGN)
582
580
{
583
581
Function* f = CGN.getFunction ();
584
582
585
- for (auto N : CGN)
583
+ // mark this function
584
+ m_chkSet.insert (f);
585
+
586
+ for (const auto & N : CGN)
586
587
{
587
588
Function* sub = N.second ->getFunction ();
588
589
if (!sub || sub->isDeclaration ()) continue ;
@@ -592,18 +593,15 @@ void InlineLocalsResolution::traveseCGN(llvm::CallGraphNode& CGN)
592
593
{
593
594
// this sub-routine is not visited before.
594
595
// visit it first
595
- traveseCGN (*N.second );
596
+ traverseCGN (*N.second );
596
597
}
597
598
598
599
// the sub-routine was visited before, collect information
599
600
600
601
// count each global on this sub-routine
601
602
GlobalVariableSet& GS_f = m_FuncToVarsMap[f];
602
- GlobalVariableSet& GS_sub = m_FuncToVarsMap[sub];
603
- for (auto I = GS_sub.begin (); I != GS_sub.end (); ++I)
604
- {
605
- GS_f.insert (*I);
606
- }
603
+ const GlobalVariableSet& GS_sub = m_FuncToVarsMap[sub];
604
+ GS_f.insert (GS_sub.begin (), GS_sub.end ());
607
605
608
606
// automatic storages
609
607
if (m_FuncToMemPoolSizeMap.find (sub) != m_FuncToMemPoolSizeMap.end ())
@@ -620,8 +618,4 @@ void InlineLocalsResolution::traveseCGN(llvm::CallGraphNode& CGN)
620
618
}
621
619
}
622
620
}
623
-
624
- // mark this function
625
-
626
- m_chkSet.insert (f);
627
621
}
0 commit comments