This is an archive of the discontinued LLVM Phabricator instance.

[Polly] [ScopInfo] Do not use ScopStmt in Domain derivation of ScopInfo. NFC
ClosedPublic

Authored by nandini12396 on Jun 6 2017, 7:13 AM.

Details

Summary

ScopStmts were being used in the computation of the Domain of the SCoPs in ScopInfo. Once statements are split, there will not be a 1-to-1 correspondence between Stmts and Basic blocks. Thus this patch avoids the use of getStmtFor() by creating a map of BB to InvalidDomain and using it to compute the domain of the statements.

Diff Detail

Event Timeline

nandini12396 created this revision.Jun 6 2017, 7:13 AM
nandini12396 added inline comments.Jun 6 2017, 7:18 AM
lib/Analysis/ScopInfo.cpp
2624

@Meinersbur : I would like to clarify again what it is to be done here. You said that the easiest approach would be to iterate over all statements that represent this BB and set their Invalid Domain. But I got confused why that is inefficient? Could you please repeat what you meant by using the DomainMap which maps BasicBlocks to their domains?

nandini12396 added inline comments.Jun 6 2017, 9:39 AM
lib/Analysis/ScopInfo.cpp
2624

Ok, I think I understood what you meant. Create a map of BB to Invalid Domain. So there is no need of using getStmtFor(BB) by directly setting in the map and using it to get it.

nandini12396 retitled this revision from [Polly] [WIP] Getting a SCoP statement for each instruction to [Polly] [WIP] Getting a SCoP statement for each instruction [NFC].Jun 6 2017, 9:47 AM
nandini12396 added subscribers: pollydev, llvm-commits.
Meinersbur added inline comments.Jun 6 2017, 10:56 AM
lib/Analysis/ScopInfo.cpp
2624

Yes, I meant creating a map and in a first step, compute the domain only for that map.

InvalidDomainMap[EntryBB] = ...

Then, in a second step, apply the InvalidDomain to all statement for their BasicBlock.

See Scop::DomainMap for a similar approach.

nandini12396 marked 3 inline comments as done.
nandini12396 retitled this revision from [Polly] [WIP] Getting a SCoP statement for each instruction [NFC] to [Polly] [WIP] Getting a SCoP statement for each instruction. NFC.
nandini12396 edited the summary of this revision. (Show Details)

@Meinersbur : Please have a look.

Meinersbur requested changes to this revision.Jun 9 2017, 10:30 AM

Please don't remove an overload of getStmtFor if it is still called somewhere. It doesn't compile otherwise. It must also pass check-polly so we can see there are no unintended behavioral changes.

lib/Analysis/ScopInfo.cpp
2626–2627

Please only iterate and setInvalidDomain only once at the end of the function, when InvalidDomainMap contains all latest entries.

You cannot call getBasicBlock() on region statements.

2727

Note that there are also region statements, which do not have a 1-to-1 correlation between statements and a BasicBlock.

You might either normalize to a region's entry block, or use the RegionNodetype (the RN variable) instead.

2743–2744

Update InvalidDomainMap instead.

This revision now requires changes to proceed.Jun 9 2017, 10:30 AM
nandini12396 edited edge metadata.

Hello Sir. I updated the diff to incorporate your comments. However, I don't know what I did wrong and there are 755 unexpected failures. Im still trying to understand that.

Sir, afaiu the problem seems to be that there maybe not be any ScopStmt, to which the first / last instruction of the BB belongs to; and hence the ScopStmt is null. So should I iterate over BB until I find the first/last instruction which corresponds to a ScopStmt ?

Meinersbur added inline comments.Jun 10 2017, 1:22 PM
include/polly/ScopInfo.h
2510–2513

Why did you move the location of this declaration?

lib/Analysis/ScopInfo.cpp
1327

As long as we did not remove getStmtFor(Instruction*), you can keep the assertion.

2655–2658

There is ScopStmt::getEntryBlock() which returns you the (Entry-)Block for the two cases.

2770

You must replace all occurrences of setInvalidDomain to update InvalidDomainMap instead.

2782

Shouldn't this changed to update InvalidDomainMap?

3013

The StmtMap does not contain all instructions. It never includes the terminator which PredBB->back() return. That is getStmtFor cannot any statement for its input.

This applies similarly to getStmtFor(&BB->front() as well which can be a synthesizable value.

nandini12396 marked 5 inline comments as done.
nandini12396 marked 3 inline comments as done.Jun 15 2017, 5:25 AM

The most appearing cause of failure of the test cases is:

opt: /home/nandini/llvm/tools/polly/lib/Analysis/ScopInfo.cpp:3058: bool polly::Scop::propagateDomainConstraints(llvm::Region*, llvm::DominatorTree&, llvm::LoopInfo&): Assertion `Domain' failed.

But I do not seem to understand the reason for this assertion fail. Can you please give me some pointers?

nandini12396 marked an inline comment as done.
nandini12396 retitled this revision from [Polly] [WIP] Getting a SCoP statement for each instruction. NFC to [Polly] [ScopInfo] Do not use ScopStmt in Domain derivation of ScopInfo. NFC.
nandini12396 edited the summary of this revision. (Show Details)
nandini12396 added inline comments.Jun 21 2017, 7:27 AM
lib/Analysis/ScopInfo.cpp
1474

@Meinersbur : I think I am doing something wrong here. Can you please help.

nandini12396 edited the summary of this revision. (Show Details)Jun 21 2017, 11:50 AM
Meinersbur added inline comments.Jun 22 2017, 10:36 AM
lib/Analysis/ScopBuilder.cpp
956 ↗(On Diff #103408)

The ScopStmt's invalid domains have already set in buildDomains. That is, the elements of InvalidDomainMap have been consumed already and setting them has no effect.

lib/Analysis/ScopInfo.cpp
2131

getBasicBlock() returns nullptr if Stmt is a region statement.

2654–2655

When we have multiple statements per BasicBlock, this would consume the same InvalidDomainMap[Stmt.getEntryBlock()] twice, giving us an use-after-free sometime later.

How are you sure that all entries of InvalidDomainMap are an entry block of some statement? There could be an BB from the middle of a region statement. Such a block's invalid domain would not be consumed, therefore leaking.

2830

You are leaking isl objects here: InvalidDomainMap[ExitBB] may already contain a value.

This is probably not the only leak. You can find some leak by using valgrind --leak-check=full on a failing test case with -polly-on-isl-error-abort=0 added could be useful to find those.

nandini12396 marked 2 inline comments as done.

I think it will be better to change the isl functions to their corresponding c++ version in another patch, since the change is large.

Could you make use of getFirstNonBoxedLoopFor? Then it LGTM.

lib/Analysis/ScopInfo.cpp
2784

Please try to avoid unrelated and unnecessary changes.

2816–2817

Could you extract this into its own function?

We once had the following code in ScopHelper.cpp, you could revive them:

llvm::Loop *polly::getFirstNonBoxedLoopFor(llvm::Loop *L, llvm::LoopInfo &LI,
                                           const BoxedLoopsSetTy &BoxedLoops) {
  while (BoxedLoops.count(L))
    L = L->getParentLoop();
  return L;
}

llvm::Loop *polly::getFirstNonBoxedLoopFor(llvm::BasicBlock *BB,
                                           llvm::LoopInfo &LI,
                                           const BoxedLoopsSetTy &BoxedLoops) {
  Loop *L = LI.getLoopFor(BB);
  return getFirstNonBoxedLoopFor(L, LI, BoxedLoops);
}

Please don't forget to also the change the other place where getFirstNonBoxedLoopFor could be used.

nandini12396 marked an inline comment as done.

Addressed comments.

Meinersbur accepted this revision.Jun 29 2017, 5:43 AM

LGTM, going to commit...

(When submitting a diff, please ensure that formatting is correct by running "make check-polly")

This revision is now accepted and ready to land.Jun 29 2017, 5:43 AM
This revision was automatically updated to reflect the committed changes.