@@ -1020,7 +1020,8 @@ AllocaInst *CacheUtility::createCacheForScope(LimitContext ctx, Type *T,
1020
1020
IRBuilder<> v (&sublimits[i - 1 ].second .back ().first .preheader ->back ());
1021
1021
1022
1022
Value *idx = computeIndexOfChunk (
1023
- /* inForwardPass*/ true , v, containedloops);
1023
+ /* inForwardPass*/ true , v, containedloops,
1024
+ /* available*/ ValueToValueMapTy ());
1024
1025
1025
1026
#if LLVM_VERSION_MAJOR > 7
1026
1027
storeInto = v.CreateLoad (
@@ -1046,17 +1047,14 @@ AllocaInst *CacheUtility::createCacheForScope(LimitContext ctx, Type *T,
1046
1047
1047
1048
Value *CacheUtility::computeIndexOfChunk (
1048
1049
bool inForwardPass, IRBuilder<> &v,
1049
- const std::vector<std::pair<LoopContext, llvm::Value *>> &containedloops) {
1050
+ const std::vector<std::pair<LoopContext, llvm::Value *>> &containedloops,
1051
+ const ValueToValueMapTy &available) {
1050
1052
// List of loop indices in chunk from innermost to outermost
1051
1053
SmallVector<Value *, 3 > indices;
1052
1054
// List of cumulative indices in chunk from innermost to outermost
1053
1055
// where limit[i] = prod(loop limit[0..i])
1054
1056
SmallVector<Value *, 3 > limits;
1055
1057
1056
- // list of contained loop induction variables available for limit
1057
- // computation
1058
- ValueToValueMapTy available;
1059
-
1060
1058
// Iterate from innermost loop to outermost loop within a chunk
1061
1059
for (size_t i = 0 ; i < containedloops.size (); ++i) {
1062
1060
const auto &pair = containedloops[i];
@@ -1066,18 +1064,18 @@ Value *CacheUtility::computeIndexOfChunk(
1066
1064
1067
1065
// In the SingleIteration, var may be null (since there's no legal phinode)
1068
1066
// In that case the current iteration is simply the constnat Zero
1069
- if (var == nullptr )
1067
+ if (idx. var == nullptr )
1070
1068
var = ConstantInt::get (Type::getInt64Ty (newFunc->getContext ()), 0 );
1071
- else if (!inForwardPass) {
1069
+ else if (available.count (var)) {
1070
+ var = available.find (var)->second ;
1071
+ } else if (!inForwardPass) {
1072
1072
#if LLVM_VERSION_MAJOR > 7
1073
1073
var = v.CreateLoad (idx.var ->getType (), idx.antivaralloc );
1074
1074
#else
1075
1075
var = v.CreateLoad (idx.antivaralloc );
1076
1076
#endif
1077
- available[idx.var ] = var;
1078
1077
} else {
1079
1078
var = idx.var ;
1080
- available[idx.var ] = var;
1081
1079
}
1082
1080
if (idx.offset ) {
1083
1081
var = v.CreateAdd (var, lookupM (idx.offset , v), " " , /* NUW*/ true ,
@@ -1391,7 +1389,9 @@ void CacheUtility::storeInstructionInCache(LimitContext ctx,
1391
1389
bool isi1 = val->getType ()->isIntegerTy () &&
1392
1390
cast<IntegerType>(val->getType ())->getBitWidth () == 1 ;
1393
1391
Value *loc = getCachePointer (/* inForwardPass*/ true , v, ctx, cache, isi1,
1394
- /* storeInInstructionsMap*/ true );
1392
+ /* storeInInstructionsMap*/ true ,
1393
+ /* available*/ llvm::ValueToValueMapTy (),
1394
+ /* extraSize*/ nullptr );
1395
1395
1396
1396
Value *tostore = val;
1397
1397
@@ -1495,14 +1495,13 @@ void CacheUtility::storeInstructionInCache(LimitContext ctx,
1495
1495
Value *CacheUtility::getCachePointer (bool inForwardPass, IRBuilder<> &BuilderM,
1496
1496
LimitContext ctx, Value *cache, bool isi1,
1497
1497
bool storeInInstructionsMap,
1498
+ const ValueToValueMapTy &available,
1498
1499
Value *extraSize) {
1499
1500
assert (ctx.Block );
1500
1501
assert (cache);
1501
1502
1502
1503
auto sublimits = getSubLimits (inForwardPass, &BuilderM, ctx, extraSize);
1503
1504
1504
- ValueToValueMapTy available;
1505
-
1506
1505
Value *next = cache;
1507
1506
assert (next->getType ()->isPointerTy ());
1508
1507
@@ -1558,7 +1557,8 @@ Value *CacheUtility::getCachePointer(bool inForwardPass, IRBuilder<> &BuilderM,
1558
1557
const auto &containedloops = sublimits[i].second ;
1559
1558
1560
1559
if (containedloops.size () > 0 ) {
1561
- Value *idx = computeIndexOfChunk (inForwardPass, BuilderM, containedloops);
1560
+ Value *idx = computeIndexOfChunk (inForwardPass, BuilderM, containedloops,
1561
+ available);
1562
1562
if (EfficientBoolCache && isi1 && i == 0 )
1563
1563
idx = BuilderM.CreateLShr (
1564
1564
idx, ConstantInt::get (Type::getInt64Ty (newFunc->getContext ()), 3 ));
@@ -1621,14 +1621,15 @@ llvm::Value *CacheUtility::loadFromCachePointer(llvm::IRBuilder<> &BuilderM,
1621
1621
1622
1622
// / Given an allocation specified by the LimitContext ctx and cache, lookup the
1623
1623
// / underlying cached value.
1624
- Value *CacheUtility::lookupValueFromCache ( bool inForwardPass,
1625
- IRBuilder<> &BuilderM,
1626
- LimitContext ctx, Value *cache,
1627
- bool isi1, Value *extraSize ,
1628
- Value *extraOffset) {
1624
+ Value *
1625
+ CacheUtility::lookupValueFromCache ( bool inForwardPass, IRBuilder<> &BuilderM,
1626
+ LimitContext ctx, Value *cache, bool isi1 ,
1627
+ const ValueToValueMapTy &available ,
1628
+ Value *extraSize, Value *extraOffset) {
1629
1629
// Get the underlying cache pointer
1630
- auto cptr = getCachePointer (inForwardPass, BuilderM, ctx, cache, isi1,
1631
- /* storeInInstructionsMap*/ false , extraSize);
1630
+ auto cptr =
1631
+ getCachePointer (inForwardPass, BuilderM, ctx, cache, isi1,
1632
+ /* storeInInstructionsMap*/ false , available, extraSize);
1632
1633
1633
1634
// Optionally apply the additional offset
1634
1635
if (extraOffset) {
0 commit comments