@@ -86,10 +86,10 @@ struct OutlinableGroup {
86
86
87
87
// / The number of instructions that will be outlined by extracting \ref
88
88
// / Regions.
89
- unsigned Benefit = 0 ;
89
+ InstructionCost Benefit = 0 ;
90
90
// / The number of added instructions needed for the outlining of the \ref
91
91
// / Regions.
92
- unsigned Cost = 0 ;
92
+ InstructionCost Cost = 0 ;
93
93
94
94
// / The argument that needs to be marked with the swifterr attribute. If not
95
95
// / needed, there is no value.
@@ -243,8 +243,8 @@ constantMatches(Value *V, unsigned GVN,
243
243
return false ;
244
244
}
245
245
246
- unsigned OutlinableRegion::getBenefit (TargetTransformInfo &TTI) {
247
- InstructionCost Benefit ( 0 ) ;
246
+ InstructionCost OutlinableRegion::getBenefit (TargetTransformInfo &TTI) {
247
+ InstructionCost Benefit = 0 ;
248
248
249
249
// Estimate the benefit of outlining a specific sections of the program. We
250
250
// delegate mostly this task to the TargetTransformInfo so that if the target
@@ -274,7 +274,7 @@ unsigned OutlinableRegion::getBenefit(TargetTransformInfo &TTI) {
274
274
}
275
275
}
276
276
277
- return * Benefit. getValue () ;
277
+ return Benefit;
278
278
}
279
279
280
280
// / Find whether \p Region matches the global value numbering to Constant
@@ -1287,8 +1287,9 @@ void IROutliner::pruneIncompatibleRegions(
1287
1287
}
1288
1288
}
1289
1289
1290
- unsigned IROutliner::findBenefitFromAllRegions (OutlinableGroup &CurrentGroup) {
1291
- unsigned RegionBenefit = 0 ;
1290
+ InstructionCost
1291
+ IROutliner::findBenefitFromAllRegions (OutlinableGroup &CurrentGroup) {
1292
+ InstructionCost RegionBenefit = 0 ;
1292
1293
for (OutlinableRegion *Region : CurrentGroup.Regions ) {
1293
1294
TargetTransformInfo &TTI = getTTI (*Region->StartBB ->getParent ());
1294
1295
// We add the number of instructions in the region to the benefit as an
@@ -1301,8 +1302,9 @@ unsigned IROutliner::findBenefitFromAllRegions(OutlinableGroup &CurrentGroup) {
1301
1302
return RegionBenefit;
1302
1303
}
1303
1304
1304
- unsigned IROutliner::findCostOutputReloads (OutlinableGroup &CurrentGroup) {
1305
- unsigned OverallCost = 0 ;
1305
+ InstructionCost
1306
+ IROutliner::findCostOutputReloads (OutlinableGroup &CurrentGroup) {
1307
+ InstructionCost OverallCost = 0 ;
1306
1308
for (OutlinableRegion *Region : CurrentGroup.Regions ) {
1307
1309
TargetTransformInfo &TTI = getTTI (*Region->StartBB ->getParent ());
1308
1310
@@ -1311,7 +1313,7 @@ unsigned IROutliner::findCostOutputReloads(OutlinableGroup &CurrentGroup) {
1311
1313
Optional<Value *> OV = Region->Candidate ->fromGVN (OutputGVN);
1312
1314
assert (OV.hasValue () && " Could not find value for GVN?" );
1313
1315
Value *V = OV.getValue ();
1314
- unsigned LoadCost =
1316
+ InstructionCost LoadCost =
1315
1317
TTI.getMemoryOpCost (Instruction::Load, V->getType (), Align (1 ), 0 ,
1316
1318
TargetTransformInfo::TCK_CodeSize);
1317
1319
@@ -1333,10 +1335,10 @@ unsigned IROutliner::findCostOutputReloads(OutlinableGroup &CurrentGroup) {
1333
1335
// / \param [in] TTI - The TargetTransformInfo used to collect information for
1334
1336
// / new instruction costs.
1335
1337
// / \returns the additional cost to handle the outputs.
1336
- static unsigned findCostForOutputBlocks (Module &M,
1337
- OutlinableGroup &CurrentGroup,
1338
- TargetTransformInfo &TTI) {
1339
- unsigned OutputCost = 0 ;
1338
+ static InstructionCost findCostForOutputBlocks (Module &M,
1339
+ OutlinableGroup &CurrentGroup,
1340
+ TargetTransformInfo &TTI) {
1341
+ InstructionCost OutputCost = 0 ;
1340
1342
1341
1343
for (const ArrayRef<unsigned > &OutputUse :
1342
1344
CurrentGroup.OutputGVNCombinations ) {
@@ -1345,7 +1347,7 @@ static unsigned findCostForOutputBlocks(Module &M,
1345
1347
Optional<Value *> OV = Candidate.fromGVN (GVN);
1346
1348
assert (OV.hasValue () && " Could not find value for GVN?" );
1347
1349
Value *V = OV.getValue ();
1348
- unsigned StoreCost =
1350
+ InstructionCost StoreCost =
1349
1351
TTI.getMemoryOpCost (Instruction::Load, V->getType (), Align (1 ), 0 ,
1350
1352
TargetTransformInfo::TCK_CodeSize);
1351
1353
@@ -1358,7 +1360,7 @@ static unsigned findCostForOutputBlocks(Module &M,
1358
1360
OutputCost += StoreCost;
1359
1361
}
1360
1362
1361
- unsigned BranchCost =
1363
+ InstructionCost BranchCost =
1362
1364
TTI.getCFInstrCost (Instruction::Br, TargetTransformInfo::TCK_CodeSize);
1363
1365
LLVM_DEBUG (dbgs () << " Adding " << BranchCost << " to the current cost for"
1364
1366
<< " a branch instruction\n " );
@@ -1368,15 +1370,15 @@ static unsigned findCostForOutputBlocks(Module &M,
1368
1370
// If there is more than one output scheme, we must have a comparison and
1369
1371
// branch for each different item in the switch statement.
1370
1372
if (CurrentGroup.OutputGVNCombinations .size () > 1 ) {
1371
- unsigned ComparisonCost = TTI.getCmpSelInstrCost (
1373
+ InstructionCost ComparisonCost = TTI.getCmpSelInstrCost (
1372
1374
Instruction::ICmp, Type::getInt32Ty (M.getContext ()),
1373
1375
Type::getInt32Ty (M.getContext ()), CmpInst::BAD_ICMP_PREDICATE,
1374
1376
TargetTransformInfo::TCK_CodeSize);
1375
- unsigned BranchCost =
1377
+ InstructionCost BranchCost =
1376
1378
TTI.getCFInstrCost (Instruction::Br, TargetTransformInfo::TCK_CodeSize);
1377
1379
1378
1380
unsigned DifferentBlocks = CurrentGroup.OutputGVNCombinations .size ();
1379
- unsigned TotalCost = ComparisonCost * BranchCost * DifferentBlocks;
1381
+ InstructionCost TotalCost = ComparisonCost * BranchCost * DifferentBlocks;
1380
1382
1381
1383
LLVM_DEBUG (dbgs () << " Adding: " << TotalCost
1382
1384
<< " instructions for each switch case for each different"
@@ -1388,15 +1390,16 @@ static unsigned findCostForOutputBlocks(Module &M,
1388
1390
}
1389
1391
1390
1392
void IROutliner::findCostBenefit (Module &M, OutlinableGroup &CurrentGroup) {
1391
- unsigned RegionBenefit = findBenefitFromAllRegions (CurrentGroup);
1393
+ InstructionCost RegionBenefit = findBenefitFromAllRegions (CurrentGroup);
1392
1394
CurrentGroup.Benefit += RegionBenefit;
1393
1395
LLVM_DEBUG (dbgs () << " Current Benefit: " << CurrentGroup.Benefit << " \n " );
1394
1396
1395
- unsigned OutputReloadCost = findCostOutputReloads (CurrentGroup);
1397
+ InstructionCost OutputReloadCost = findCostOutputReloads (CurrentGroup);
1396
1398
CurrentGroup.Cost += OutputReloadCost;
1397
1399
LLVM_DEBUG (dbgs () << " Current Cost: " << CurrentGroup.Cost << " \n " );
1398
1400
1399
- unsigned AverageRegionBenefit = RegionBenefit / CurrentGroup.Regions .size ();
1401
+ InstructionCost AverageRegionBenefit =
1402
+ RegionBenefit / CurrentGroup.Regions .size ();
1400
1403
unsigned OverallArgumentNum = CurrentGroup.ArgumentTypes .size ();
1401
1404
unsigned NumRegions = CurrentGroup.Regions .size ();
1402
1405
TargetTransformInfo &TTI =
@@ -1609,8 +1612,7 @@ unsigned IROutliner::doOutline(Module &M) {
1609
1612
<< ore::NV (std::to_string (CurrentGroup.Regions .size ()))
1610
1613
<< " regions due to estimated increase of "
1611
1614
<< ore::NV (" InstructionIncrease" ,
1612
- std::to_string (static_cast <int >(CurrentGroup.Cost -
1613
- CurrentGroup.Benefit )))
1615
+ CurrentGroup.Cost - CurrentGroup.Benefit )
1614
1616
<< " instructions at locations " ;
1615
1617
interleave (
1616
1618
CurrentGroup.Regions .begin (), CurrentGroup.Regions .end (),
@@ -1658,8 +1660,7 @@ unsigned IROutliner::doOutline(Module &M) {
1658
1660
OptimizationRemark R (DEBUG_TYPE, " Outlined" , C->front ()->Inst );
1659
1661
R << " outlined " << ore::NV (std::to_string (CurrentGroup.Regions .size ()))
1660
1662
<< " regions with decrease of "
1661
- << ore::NV (" Benefit" , std::to_string (static_cast <int >(
1662
- CurrentGroup.Benefit - CurrentGroup.Cost )))
1663
+ << ore::NV (" Benefit" , CurrentGroup.Benefit - CurrentGroup.Cost )
1663
1664
<< " instructions at locations " ;
1664
1665
interleave (
1665
1666
CurrentGroup.Regions .begin (), CurrentGroup.Regions .end (),
0 commit comments