25#include "llvm/ADT/Statistic.h"
26#include "llvm/IR/Module.h"
29#define DEBUG_TYPE "polly-delicm"
36static cl::opt<bool> PollyPrintDeLICM(
"polly-print-delicm",
37 cl::desc(
"Polly - Print DeLICM/DePRE"),
41 DelicmMaxOps(
"polly-delicm-max-ops",
42 cl::desc(
"Maximum number of isl operations to invest for "
43 "lifetime analysis; 0=no limit"),
46cl::opt<bool> DelicmOverapproximateWrites(
47 "polly-delicm-overapproximate-writes",
49 "Do more PHI writes than necessary in order to avoid partial accesses"),
52cl::opt<cl::boolOrDefault> DelicmPartialWrites(
53 "polly-delicm-partial-writes",
54 cl::desc(
"Allow partial writes (default: true; false with "
55 "-polly-optimize-for-vectorization)"),
56 cl::init(cl::boolOrDefault::BOU_UNSET), cl::Hidden, cl::cat(
PollyCategory));
60static bool allowPartialPHIWrites() {
61 if (DelicmPartialWrites != cl::boolOrDefault::BOU_UNSET)
62 return DelicmPartialWrites == cl::boolOrDefault::BOU_TRUE;
67 DelicmComputeKnown(
"polly-delicm-compute-known",
68 cl::desc(
"Compute known content of array elements"),
71STATISTIC(DeLICMAnalyzed,
"Number of successfully analyzed SCoPs");
73 "Analyses aborted because max_operations was reached");
74STATISTIC(MappedValueScalars,
"Number of mapped Value scalars");
75STATISTIC(MappedPHIScalars,
"Number of mapped PHI scalars");
76STATISTIC(TargetsMapped,
"Number of stores used for at least one mapping");
77STATISTIC(DeLICMScopsModified,
"Number of SCoPs optimized");
79STATISTIC(NumValueWrites,
"Number of scalar value writes after DeLICM");
81 "Number of scalar value writes nested in affine loops after DeLICM");
82STATISTIC(NumPHIWrites,
"Number of scalar phi writes after DeLICM");
84 "Number of scalar phi writes nested in affine loops after DeLICM");
85STATISTIC(NumSingletonWrites,
"Number of singleton writes after DeLICM");
87 "Number of singleton writes nested in affine loops after DeLICM");
113 bool InclOverwrite) {
119 auto Result = computeReachingOverwrite(
120 std::move(Schedule), std::move(WritesMap), InclPrevWrite, InclOverwrite);
122 return Result.domain_factor_range();
135 isl::set Writes,
bool InclPrevWrite,
136 bool InclOverwrite) {
143 isl::space ResultSpace = ScatterSpace.map_from_domain_and_range(DomSpace);
144 return singleton(std::move(ReachOverwrite), ResultSpace);
199class Knowledge final {
252 void checkConsistency()
const {
268 auto Universe = Occupied.
unite(Unused);
283 : Occupied(std::move(Occupied)), Unused(std::move(Unused)),
284 Known(std::move(Known)), Written(std::move(Written)) {
289 bool isUsable()
const {
295 void print(llvm::raw_ostream &OS,
unsigned Indent = 0)
const {
298 OS.indent(Indent) <<
"Occupied: " << Occupied <<
"\n";
300 OS.indent(Indent) <<
"Occupied: <Everything else not in Unused>\n";
302 OS.indent(Indent) <<
"Unused: " << Unused <<
"\n";
304 OS.indent(Indent) <<
"Unused: <Everything else not in Occupied>\n";
305 OS.indent(Indent) <<
"Known: " << Known <<
"\n";
306 OS.indent(Indent) <<
"Written : " << Written <<
'\n';
308 OS.indent(Indent) <<
"Invalid knowledge\n";
313 void learnFrom(Knowledge That) {
318 "This function is only prepared to learn occupied elements from That");
319 assert(Occupied.
is_null() &&
"This function does not implement "
321 "this->Occupied.unite(That.Occupied);`");
323 Unused = Unused.
subtract(That.Occupied);
324 Known = Known.
unite(That.Known);
325 Written = Written.
unite(That.Written);
349 const Knowledge &Proposed,
350 llvm::raw_ostream *OS =
nullptr,
351 unsigned Indent = 0) {
357 auto ExistingUniverse = Existing.Occupied.
unite(Existing.Unused);
358 auto ProposedUniverse = Proposed.Occupied.
unite(Proposed.Unused);
359 assert(ExistingUniverse.is_equal(ProposedUniverse) &&
360 "Both inputs' Knowledges must be over the same universe");
389 auto ProposedValues = Proposed.Known.
unite(ProposedOccupiedAnyVal);
392 auto ExistingValues = Existing.Known.
unite(ExistingUnusedAnyVal);
394 auto MatchingVals = ExistingValues.
intersect(ProposedValues);
395 auto Matches = MatchingVals.
domain();
400 if (!Proposed.Occupied.
is_subset(Matches)) {
402 auto Conflicting = Proposed.Occupied.
subtract(Matches);
403 auto ExistingConflictingKnown =
405 auto ProposedConflictingKnown =
408 OS->indent(Indent) <<
"Proposed lifetime conflicting with Existing's\n";
409 OS->indent(Indent) <<
"Conflicting occupied: " << Conflicting <<
"\n";
410 if (!ExistingConflictingKnown.is_empty())
412 <<
"Existing Known: " << ExistingConflictingKnown <<
"\n";
413 if (!ProposedConflictingKnown.is_empty())
415 <<
"Proposed Known: " << ProposedConflictingKnown <<
"\n";
439 auto ProposedFixedDefs =
441 auto ProposedFixedKnown =
444 auto ExistingConflictingWrites =
446 auto ExistingConflictingWritesDomain = ExistingConflictingWrites.
domain();
448 auto CommonWrittenVal =
449 ProposedFixedKnown.
intersect(ExistingConflictingWrites);
450 auto CommonWrittenValDomain = CommonWrittenVal.domain();
452 if (!ExistingConflictingWritesDomain.is_subset(CommonWrittenValDomain)) {
454 auto ExistingConflictingWritten =
455 ExistingConflictingWrites.subtract_domain(CommonWrittenValDomain);
456 auto ProposedConflictingKnown = ProposedFixedKnown.subtract_domain(
457 ExistingConflictingWritten.domain());
460 <<
"Proposed a lifetime where there is an Existing write into it\n";
461 OS->indent(Indent) <<
"Existing conflicting writes: "
462 << ExistingConflictingWritten <<
"\n";
463 if (!ProposedConflictingKnown.is_empty())
465 <<
"Proposed conflicting known: " << ProposedConflictingKnown
472 auto ExistingAvailableDefs =
474 auto ExistingKnownDefs =
477 auto ProposedWrittenDomain = Proposed.Written.
domain();
478 auto KnownIdentical = ExistingKnownDefs.
intersect(Proposed.Written);
479 auto IdenticalOrUnused =
480 ExistingAvailableDefs.
unite(KnownIdentical.domain());
481 if (!ProposedWrittenDomain.is_subset(IdenticalOrUnused)) {
483 auto Conflicting = ProposedWrittenDomain.subtract(IdenticalOrUnused);
484 auto ExistingConflictingKnown =
485 ExistingKnownDefs.intersect_domain(Conflicting);
486 auto ProposedConflictingWritten =
489 OS->indent(Indent) <<
"Proposed writes into range used by Existing\n";
490 OS->indent(Indent) <<
"Proposed conflicting writes: "
491 << ProposedConflictingWritten <<
"\n";
492 if (!ExistingConflictingKnown.is_empty())
494 <<
"Existing conflicting known: " << ExistingConflictingKnown
502 auto ExistingWrittenDomain = Existing.Written.
domain();
508 ExistingKnownWritten.intersect(ProposedKnownWritten).domain();
510 if (!BothWritten.is_subset(CommonWritten)) {
512 auto Conflicting = BothWritten.subtract(CommonWritten);
513 auto ExistingConflictingWritten =
515 auto ProposedConflictingWritten =
518 OS->indent(Indent) <<
"Proposed writes at the same time as an already "
520 OS->indent(Indent) <<
"Conflicting writes: " << Conflicting <<
"\n";
521 if (!ExistingConflictingWritten.is_empty())
523 <<
"Exiting write: " << ExistingConflictingWritten <<
"\n";
524 if (!ProposedConflictingWritten.is_empty())
526 <<
"Proposed write: " << ProposedConflictingWritten <<
"\n";
539 Knowledge OriginalZone;
546 int NumberOfCompatibleTargets = 0;
550 int NumberOfTargetsMapped = 0;
553 int NumberOfMappedValueScalars = 0;
556 int NumberOfMappedPHIScalars = 0;
569 raw_ostream *OS =
nullptr;
571 return Knowledge::isConflicting(Zone, Proposed, OS, 4);
580 auto *MA =
S->getValueDef(SAI);
584 <<
" Reject because value is read-only within the scop\n");
592 auto Inst = MA->getAccessInstruction();
593 for (Instruction *UserInst : Inst->users()) {
595 if (!
S->contains(UserInst)) {
596 POLLY_DEBUG(dbgs() <<
" Reject because value is escaping\n");
605 auto *MA =
S->getPHIRead(SAI);
610 auto PHI = cast<PHINode>(MA->getAccessInstruction());
611 for (
auto Incoming :
PHI->blocks()) {
612 if (!
S->contains(Incoming)) {
614 <<
" Reject because at least one incoming block is "
615 "not in the scop region\n");
623 POLLY_DEBUG(dbgs() <<
" Reject ExitPHI or other non-value\n");
635 std::tuple<isl::union_map, isl::map>
640 auto Reads = makeEmptyUnionSet();
643 for (
auto *MA :
S->getValueUses(SAI))
644 Reads = Reads.unite(getDomainFor(MA));
647 auto ReadSchedule = getScatterFor(Reads);
649 auto *DefMA =
S->getValueDef(SAI);
653 auto Writes = getDomainFor(DefMA);
656 auto WriteScatter = getScatterFor(Writes);
659 auto ReachDef = getScalarReachingDefinition(DefMA->getStatement());
668 Writes.
get_space().map_from_domain_and_range(ScatterSpace));
671 auto Lifetime =
betweenScatter(WriteScatter, UseScatter,
false,
true);
674 auto DefUses = Uses.domain_factor_domain();
676 return std::make_pair(DefUses, Lifetime);
689 auto *DefMA =
S->getValueDef(SAI);
690 assert(DefMA->isValueKind());
691 assert(DefMA->isMustWrite());
692 auto *V = DefMA->getAccessValue();
693 auto *DefInst = DefMA->getAccessInstruction();
696 if (!DefMA->getLatestScopArrayInfo()->isValueKind())
700 auto DefSched = getScatterFor(DefMA);
704 auto DefTarget = TargetElt.
apply_domain(DefSched.reverse());
706 POLLY_DEBUG(dbgs() <<
" Def Mapping: " << DefTarget <<
'\n');
708 auto OrigDomain = getDomainFor(DefMA);
709 auto MappedDomain = DefTarget.domain();
710 if (!OrigDomain.is_subset(MappedDomain)) {
713 <<
" Reject because mapping does not encompass all instances\n");
723 std::tie(DefUses, Lifetime) = computeValueUses(SAI);
724 POLLY_DEBUG(dbgs() <<
" Lifetime: " << Lifetime <<
'\n');
734 if (DelicmComputeKnown)
735 ValInst = makeValInst(V, DefMA->getStatement(),
736 LI->getLoopFor(DefInst->getParent()));
741 auto EltKnownTranslator = DefTarget.range_product(Lifetime);
744 auto EltKnown = ValInst.
apply_domain(EltKnownTranslator);
748 auto WrittenTranslator = DefTarget.range_product(DefSched);
751 auto DefEltSched = ValInst.
apply_domain(WrittenTranslator);
761 mapValue(SAI, std::move(DefTarget), std::move(UseTarget),
762 std::move(Lifetime), std::move(Proposed));
767 void applyLifetime(Knowledge Proposed) {
768 Zone.learnFrom(std::move(Proposed));
787 Knowledge Proposed) {
789 for (
auto *MA :
S->getValueUses(SAI)) {
791 auto Domain = getDomainFor(MA);
801 auto *WA =
S->getValueDef(SAI);
802 WA->setNewAccessRelation(DefTarget);
803 applyLifetime(Proposed);
805 MappedValueScalars++;
806 NumberOfMappedValueScalars += 1;
810 bool IsCertain =
true) {
813 if (!DelicmComputeKnown)
825 auto Result = makeEmptyUnionMap();
828 for (
auto *MA :
S->getPHIIncomings(SAI)) {
831 auto *WriteStmt = MA->getStatement();
833 auto Incoming = MA->getIncoming();
834 assert(!Incoming.empty());
835 if (Incoming.size() == 1) {
836 ValInst = makeValInst(Incoming[0].second, WriteStmt,
837 LI->getLoopFor(Incoming[0].first));
847 Result = Result.unite(ValInst);
850 assert(Result.is_single_valued() &&
851 "Cannot have multiple incoming values for same incoming statement");
864 auto *PHIRead =
S->getPHIRead(SAI);
865 assert(PHIRead->isPHIKind());
866 assert(PHIRead->isRead());
869 if (!PHIRead->getLatestScopArrayInfo()->isPHIKind())
873 auto PHISched = getScatterFor(PHIRead);
876 auto PHITarget = PHISched.apply_range(TargetElt);
878 POLLY_DEBUG(dbgs() <<
" Mapping: " << PHITarget <<
'\n');
880 auto OrigDomain = getDomainFor(PHIRead);
881 auto MappedDomain = PHITarget.domain();
882 if (!OrigDomain.is_subset(MappedDomain)) {
885 <<
" Reject because mapping does not encompass all instances\n");
890 auto PerPHIWrites = computePerPHI(SAI);
891 if (PerPHIWrites.is_null()) {
893 dbgs() <<
" Reject because cannot determine incoming values\n");
898 auto WritesTarget = PerPHIWrites.apply_domain(PHITarget).reverse();
904 for (
auto *MA :
S->getPHIIncomings(SAI))
905 UniverseWritesDom = UniverseWritesDom.unite(getDomainFor(MA));
907 auto RelevantWritesTarget = WritesTarget;
908 if (DelicmOverapproximateWrites)
909 WritesTarget = expandMapping(WritesTarget, UniverseWritesDom);
911 auto ExpandedWritesDom = WritesTarget.domain();
912 if (!allowPartialPHIWrites() &&
913 !UniverseWritesDom.is_subset(ExpandedWritesDom)) {
915 dbgs() <<
" Reject because did not find PHI write mapping for "
917 if (DelicmOverapproximateWrites)
919 << RelevantWritesTarget <<
'\n');
920 POLLY_DEBUG(dbgs() <<
" Deduced Mapping: " << WritesTarget
923 << UniverseWritesDom.subtract(ExpandedWritesDom)
934 auto Lifetime =
betweenScatter(PerPHIWriteScatter, PHISched,
false,
true);
936 POLLY_DEBUG(dbgs() <<
" Lifetime: " << Lifetime <<
"\n");
942 auto WrittenValue = determinePHIWrittenValues(SAI);
945 auto WrittenTranslator = WritesTarget.range_product(Schedule);
948 auto Written = WrittenValue.apply_domain(WrittenTranslator);
952 auto LifetimeTranslator = WritesTarget.range_product(WriteLifetime);
958 auto EltLifetimeInst = WrittenKnownValue.apply_domain(LifetimeTranslator);
962 auto Occupied = LifetimeTranslator.range();
965 Knowledge Proposed(Occupied, {}, EltLifetimeInst, Written);
969 mapPHI(SAI, std::move(PHITarget), std::move(WritesTarget),
970 std::move(Lifetime), std::move(Proposed));
990 Knowledge Proposed) {
995 for (
auto *MA :
S->getPHIIncomings(SAI)) {
997 auto Domain = getDomainFor(MA);
1004 Domain.get_space().map_from_domain_and_range(ElementSpace);
1006 MA->setNewAccessRelation(NewAccRelMap);
1010 auto *PHIRead =
S->getPHIRead(SAI);
1011 PHIRead->setNewAccessRelation(ReadTarget);
1012 applyLifetime(Proposed);
1015 NumberOfMappedPHIScalars++;
1028 bool collapseScalarsToStore(
MemoryAccess *TargetStoreMA) {
1035 auto TargetDom = getDomainFor(TargetStmt);
1038 auto TargetAccRel = getAccessRelationFor(TargetStoreMA);
1047 Target = computeScalarReachingOverwrite(Schedule, TargetDom,
false,
true);
1053 "The only reason that these things have not been computed should "
1054 "be if the max-operations limit hit");
1056 dbgs() <<
"collapseScalarsToStore exceeded max_operations\n");
1057 DebugLoc Begin, End;
1059 OptimizationRemarkAnalysis R(
DEBUG_TYPE,
"OutOfQuota", Begin,
1061 R <<
"maximal number of operations exceeded during "
1062 "collapseScalarsToStore";
1063 S->getFunction().getContext().diagnose(R);
1073 auto EltTarget = Target.
apply_range(TargetAccRel);
1075 POLLY_DEBUG(dbgs() <<
" Target mapping is " << EltTarget <<
'\n');
1078 SmallVector<MemoryAccess *, 16> Worklist;
1081 SmallPtrSet<const ScopArrayInfo *, 16> Closed;
1084 auto ProcessAllIncoming = [&](
ScopStmt *Stmt) {
1085 for (
auto *MA : *Stmt) {
1086 if (!MA->isLatestScalarKind())
1091 Worklist.push_back(MA);
1096 if (
auto *WrittenValInputMA = TargetStmt->lookupInputAccessOf(WrittenVal))
1097 Worklist.push_back(WrittenValInputMA);
1099 ProcessAllIncoming(TargetStmt);
1101 auto AnyMapped =
false;
1102 auto &DL =
S->getRegion().getEntry()->getModule()->getDataLayout();
1106 while (!Worklist.empty()) {
1107 auto *MA = Worklist.pop_back_val();
1109 auto *SAI = MA->getScopArrayInfo();
1110 if (Closed.count(SAI))
1113 POLLY_DEBUG(dbgs() <<
"\n Trying to map " << MA <<
" (SAI: " << SAI
1117 if (!isMappable(SAI))
1120 auto MASize = DL.getTypeAllocSize(MA->getAccessValue()->getType());
1121 if (MASize > StoreSize) {
1123 dbgs() <<
" Reject because storage size is insufficient\n");
1129 if (!tryMapValue(SAI, EltTarget))
1132 auto *DefAcc =
S->getValueDef(SAI);
1133 ProcessAllIncoming(DefAcc->getStatement());
1141 if (!tryMapPHI(SAI, EltTarget))
1145 for (
auto *PHIWrite :
S->getPHIIncomings(SAI)) {
1146 auto *PHIWriteStmt = PHIWrite->getStatement();
1147 bool FoundAny =
false;
1148 for (
auto Incoming : PHIWrite->getIncoming()) {
1149 auto *IncomingInputMA =
1150 PHIWriteStmt->lookupInputAccessOf(Incoming.second);
1151 if (!IncomingInputMA)
1154 Worklist.push_back(IncomingInputMA);
1159 ProcessAllIncoming(PHIWrite->getStatement());
1169 NumberOfTargetsMapped++;
1180 false,
false,
true);
1182 auto Result = ArrayUnused.wrap();
1210 auto Map = getAccessRelationFor(MA);
1211 auto Set = Map.range();
1212 return Set.is_singleton();
1216 void printStatistics(llvm::raw_ostream &OS,
int Indent = 0)
const {
1217 OS.indent(Indent) <<
"Statistics {\n";
1218 OS.indent(Indent + 4) <<
"Compatible overwrites: "
1219 << NumberOfCompatibleTargets <<
"\n";
1220 OS.indent(Indent + 4) <<
"Overwrites mapped to: " << NumberOfTargetsMapped
1222 OS.indent(Indent + 4) <<
"Value scalars mapped: "
1223 << NumberOfMappedValueScalars <<
'\n';
1224 OS.indent(Indent + 4) <<
"PHI scalars mapped: "
1225 << NumberOfMappedPHIScalars <<
'\n';
1226 OS.indent(Indent) <<
"}\n";
1230 DeLICMImpl(
Scop *
S, LoopInfo *LI)
1232 MaxOpGuard(IslCtx.get(), DelicmMaxOps,
false) {}
1237 bool computeZone() {
1239 collectCompatibleElts();
1249 EltUnused = computeLifetime();
1250 EltKnown = computeKnown(
true,
false);
1251 EltWritten = computeWritten();
1257 "The only reason that these things have not been computed should "
1258 "be if the max-operations limit hit");
1260 POLLY_DEBUG(dbgs() <<
"DeLICM analysis exceeded max_operations\n");
1261 DebugLoc Begin, End;
1263 OptimizationRemarkAnalysis R(
DEBUG_TYPE,
"OutOfQuota", Begin,
1265 R <<
"maximal number of operations exceeded during zone analysis";
1266 S->getFunction().getContext().diagnose(R);
1270 Zone = OriginalZone = Knowledge({}, EltUnused, EltKnown, EltWritten);
1271 POLLY_DEBUG(dbgs() <<
"Computed Zone:\n"; OriginalZone.print(dbgs(), 4));
1273 assert(Zone.isUsable() && OriginalZone.isUsable());
1282 void greedyCollapse() {
1283 bool Modified =
false;
1284 bool MaxOpQuotaExceeded =
false;
1286 for (
auto &Stmt : *
S) {
1287 for (
auto *MA : Stmt) {
1295 <<
" pruned because it is a MAY_WRITE\n");
1296 OptimizationRemarkMissed R(
DEBUG_TYPE,
"TargetMayWrite",
1298 R <<
"Skipped possible mapping target because it is not an "
1299 "unconditional overwrite";
1300 S->getFunction().getContext().diagnose(R);
1304 if (Stmt.getNumIterators() == 0) {
1306 <<
" pruned because it is not in a loop\n");
1307 OptimizationRemarkMissed R(
DEBUG_TYPE,
"WriteNotInLoop",
1309 R <<
"skipped possible mapping target because it is not in a loop";
1310 S->getFunction().getContext().diagnose(R);
1314 if (isScalarAccess(MA)) {
1317 <<
" pruned because it writes only a single element\n");
1318 OptimizationRemarkMissed R(
DEBUG_TYPE,
"ScalarWrite",
1320 R <<
"skipped possible mapping target because the memory location "
1321 "written to does not depend on its outer loop";
1322 S->getFunction().getContext().diagnose(R);
1328 <<
" pruned because it is not a StoreInst\n");
1329 OptimizationRemarkMissed R(
DEBUG_TYPE,
"NotAStore",
1331 R <<
"skipped possible mapping target because non-store instructions "
1332 "are not supported";
1333 S->getFunction().getContext().diagnose(R);
1351 <<
" is incompatible because it writes multiple "
1352 "elements per instance\n");
1353 OptimizationRemarkMissed R(
DEBUG_TYPE,
"NonFunctionalAccRel",
1355 R <<
"skipped possible mapping target because it writes more than "
1357 S->getFunction().getContext().diagnose(R);
1362 if (!TouchedElts.
is_subset(CompatibleElts)) {
1366 <<
" is incompatible because it touches incompatible elements\n");
1367 OptimizationRemarkMissed R(
DEBUG_TYPE,
"IncompatibleElts",
1369 R <<
"skipped possible mapping target because a target location "
1370 "cannot be reliably analyzed";
1371 S->getFunction().getContext().diagnose(R);
1375 assert(isCompatibleAccess(MA));
1376 NumberOfCompatibleTargets++;
1377 POLLY_DEBUG(dbgs() <<
"Analyzing target access " << MA <<
"\n");
1378 if (collapseScalarsToStore(MA))
1381 MaxOpQuotaExceeded =
true;
1385 if (MaxOpQuotaExceeded)
1390 DeLICMScopsModified++;
1394 void print(llvm::raw_ostream &OS,
int Indent = 0) {
1395 if (!Zone.isUsable()) {
1396 OS.indent(Indent) <<
"Zone not computed\n";
1400 printStatistics(OS, Indent);
1401 if (!isModified()) {
1402 OS.indent(Indent) <<
"No modification has been made\n";
1405 printAccesses(OS, Indent);
1409 bool isModified()
const {
1410 return NumberOfTargetsMapped > 0 || NumberOfMappedValueScalars > 0 ||
1411 NumberOfMappedPHIScalars > 0;
1415static std::unique_ptr<DeLICMImpl> collapseToUnused(
Scop &
S, LoopInfo &LI) {
1416 std::unique_ptr<DeLICMImpl> Impl = std::make_unique<DeLICMImpl>(&
S, &LI);
1418 if (!Impl->computeZone()) {
1419 POLLY_DEBUG(dbgs() <<
"Abort because cannot reliably compute lifetimes\n");
1423 POLLY_DEBUG(dbgs() <<
"Collapsing scalars to unused array elements...\n");
1424 Impl->greedyCollapse();
1432static std::unique_ptr<DeLICMImpl> runDeLICMImpl(
Scop &
S, LoopInfo &LI) {
1433 std::unique_ptr<DeLICMImpl> Impl = collapseToUnused(
S, LI);
1452 llvm::raw_ostream *OS,
unsigned Indent) {
1453 Knowledge Existing(std::move(ExistingOccupied), std::move(ExistingUnused),
1454 std::move(ExistingKnown), std::move(ExistingWrites));
1455 Knowledge Proposed(std::move(ProposedOccupied), std::move(ProposedUnused),
1456 std::move(ProposedKnown), std::move(ProposedWrites));
1458 return Knowledge::isConflicting(Existing, Proposed, OS, Indent);
1462 LoopInfo &LI = *
S.getLI();
1463 std::unique_ptr<DeLICMImpl> Impl = runDeLICMImpl(
S, LI);
1465 if (PollyPrintDeLICM) {
1466 outs() <<
"Printing analysis 'Polly - DeLICM/DePRE' for region: '"
1467 <<
S.getName() <<
"' in function '" <<
S.getFunction().getName()
1470 assert(Impl->getScop() == &
S);
1472 outs() <<
"DeLICM result:\n";
1473 Impl->print(outs());
1477 return Impl->isModified();
llvm::cl::OptionCategory PollyCategory
STATISTIC(ScopFound, "Number of valid Scops")
isl::checked::set wrap() const
isl::checked::map apply_range(isl::checked::map map2) const
isl::checked::space get_space() const
isl::checked::map apply_domain(isl::checked::map map2) const
isl::checked::space range() const
isl::checked::union_set range() const
isl::checked::union_map reverse() const
isl::checked::union_map unite(isl::checked::union_map umap2) const
isl::checked::union_set domain() const
isl::checked::union_map apply_range(isl::checked::union_map umap2) const
isl::checked::space get_space() const
isl::checked::union_map apply_domain(isl::checked::union_map umap2) const
isl::checked::union_map intersect_domain(isl::checked::space space) const
isl::checked::union_map coalesce() const
isl::checked::union_map gist_domain(isl::checked::union_set uset) const
boolean is_single_valued() const
isl::checked::union_map intersect(isl::checked::union_map umap2) const
isl::checked::union_set subtract(isl::checked::union_set uset2) const
boolean is_disjoint(const isl::checked::union_set &uset2) const
boolean is_subset(const isl::checked::union_set &uset2) const
isl::checked::union_set unite(isl::checked::union_set uset2) const
isl::checked::union_set intersect(isl::checked::union_set uset2) const
static isl::map from_union_map(isl::union_map umap)
static isl::union_map from_domain(isl::union_set uset)
static isl::union_set empty(isl::ctx ctx)
Scoped limit of ISL operations.
bool hasQuotaExceeded() const
Return whether the current quota has exceeded.
IslQuotaScope enter(bool AllowReturnNull=true)
Enter a scope that can handle out-of-quota errors.
Scope guard for code that allows arbitrary isl function to return an error if the max-operations quot...
bool hasQuotaExceeded() const
Return whether the current quota has exceeded.
Represent memory accesses in statements.
isl::map getLatestAccessRelation() const
Return the newest access relation of this access.
bool isLatestArrayKind() const
Whether storage memory is either an custom .s2a/.phiops alloca (false) or an existing pointer into an...
bool isWrite() const
Is this a write memory access?
Instruction * getAccessInstruction() const
Return the access instruction of this memory access.
bool isMustWrite() const
Is this a must-write memory access?
ScopStmt * getStatement() const
Get the statement that contains this memory access.
bool isMayWrite() const
Is this a may-write memory access?
Value * getAccessValue() const
Return the access value of this memory access.
A class to store information about arrays in the SCoP.
bool isValueKind() const
Is this array info modeling an llvm::Value?
bool isPHIKind() const
Is this array info modeling special PHI node memory?
Base class for algorithms based on zones, like DeLICM.
isl::map makeValInst(llvm::Value *Val, ScopStmt *UserStmt, llvm::Loop *Scope, bool IsCertain=true)
Create a mapping from a statement instance to the instance of an llvm::Value that can be used in ther...
enum isl_error isl_ctx_last_error(isl_ctx *ctx)
isl::map betweenScatter(isl::map From, isl::map To, bool InclFrom, bool InclTo)
Construct a range of timepoints between two timepoints.
isl::union_map makeUnknownForDomain(isl::union_set Domain)
Create a domain-to-unknown value mapping.
isl::union_map computeReachingWrite(isl::union_map Schedule, isl::union_map Writes, bool Reverse, bool InclPrevDef, bool InclNextDef)
Compute the reaching definition statement or the next overwrite for each definition of an array eleme...
isl::union_map computeArrayUnused(isl::union_map Schedule, isl::union_map Writes, isl::union_map Reads, bool ReadEltInSameInst, bool InclLastRead, bool InclWrite)
Compute the timepoints where the contents of an array element are not used.
void getDebugLocations(const BBPair &P, DebugLoc &Begin, DebugLoc &End)
Set the begin and end source location for the region limited by P.
@ Value
MemoryKind::Value: Models an llvm::Value.
@ PHI
MemoryKind::PHI: Models PHI nodes within the SCoP.
bool isConflicting(isl::union_set ExistingOccupied, isl::union_set ExistingUnused, isl::union_map ExistingKnown, isl::union_map ExistingWrites, isl::union_set ProposedOccupied, isl::union_set ProposedUnused, isl::union_map ProposedKnown, isl::union_map ProposedWrites, llvm::raw_ostream *OS=nullptr, unsigned Indent=0)
Determine whether two lifetimes are conflicting.
void simplify(isl::set &Set)
Simplify a set inplace.
BBPair getBBPairForRegion(const Region *R)
Return the region delimiters (entry & exit block) of R.
bool PollyOptimizeForVectorization
Bypass some of Polly's profitability checks and add vectorize.enable metadata to vectorizable loops a...
isl::union_map applyDomainRange(isl::union_map UMap, isl::union_map Func)
Apply a map to the 'middle' of another relation.
isl::union_set convertZoneToTimepoints(isl::union_set Zone, bool InclStart, bool InclEnd)
Convert a zone (range between timepoints) to timepoints.
isl::map singleton(isl::union_map UMap, isl::space ExpectedSpace)
If by construction a union map is known to contain only a single map, return it.
isl::union_map filterKnownValInst(const isl::union_map &UMap)
Return only the mappings that map to known values.
isl::space getScatterSpace(const isl::union_map &Schedule)
Return the scatter space of a Schedule.
int NumValueWritesInLoops
int NumSingletonWritesInLoops
static TupleKindPtr Domain("Domain")
isl_size isl_union_map_n_map(__isl_keep isl_union_map *umap)