This is an archive of the discontinued LLVM Phabricator instance.

[Polly] [BlockGen] Support partial writes in regions
ClosedPublic

Authored by grosser on Jun 1 2017, 3:33 AM.

Details

Summary

The RegionGenerator traditionally kept a BlockMap that mapped from original
basic blocks to newly generated basic blocks. With the introduction of partial
writes such a 1:1 mapping is not possible any more, as a single basic block
can be code generated into multiple basic blocks. Hence, depending on the use
case we need to either use the first basic block or the last basic block.

This is intended to address the last four cases of incorrect code generation
in our AOSP buildbot and hopefully should turn it green.

Diff Detail

Repository
rL LLVM

Event Timeline

grosser created this revision.Jun 1 2017, 3:33 AM
Meinersbur edited edge metadata.Jun 1 2017, 4:20 AM

We should think a bit more about when to use StartBlock and when to use EndBlock. Test cases to find the right choices could be helpful.

lib/CodeGen/BlockGenerators.cpp
1272 ↗(On Diff #100995)

Should this be EndBlockMap? Because it is the end of the previous BB that dominates BBCopy.

I changed it in the code and nothing changes. Is there a test case such that we could test this?

1354 ↗(On Diff #100995)

I'd expect only the end block ever by used (to repair dominance or PHI incoming blocks), but I also think it is safer to just apply it.

1439 ↗(On Diff #100995)

Call it RegionMapEnd?

Do we even need it? I removed it and tests still pass. Having only ValueMap per BB is easier to maintain (otherwise why shouldn't the *.partial blocks have one as well.). The call to copyInstScalar below will only update one of them: RegionMap, i.e. the EndBlock's value map will necessarily out of date. We could also keep the EndBlock's value map, because only in that one all values would be available.

1467–1469 ↗(On Diff #100995)

Should these be EndBlockMap? Since we look for the predecessor of an original block, which is the end of the copy. Test case?

test/Isl/CodeGen/partial_write_in_region.ll
13 ↗(On Diff #100995)

Can you remove the references do metadata (!3 etc) that we are not checking for? I observed metadata numbering sometimes being unstable.

grosser updated this revision to Diff 101348.Jun 4 2017, 1:00 AM
grosser marked 4 inline comments as done.

Address Michael's comments.

grosser edited the summary of this revision. (Show Details)Jun 4 2017, 1:00 AM
grosser edited the summary of this revision. (Show Details)

Hi Michael,

thank you for the comments. I believe this is now (close to) commit ready, but I would appreciate a final OK. Hope with this change, we can turn the buildbots green!

lib/CodeGen/BlockGenerators.cpp
1272 ↗(On Diff #100995)

I expanded the test case to cover this case. In fact, we had to lookup the dominator in EndBlockMap and had to return the lookup from StartBlockMap to make sure the correct definitions are provided.

1354 ↗(On Diff #100995)

OK, I leave it then.

1439 ↗(On Diff #100995)

No, we do not need it. I dropped it. The only place where we would have needed is was in add addOperandToPHI, which I now changed to lookup the necessary values in RegionMaps[BBCopyStart].

1467–1469 ↗(On Diff #100995)

It should. Due to https://bugs.llvm.org//show_bug.cgi?id=33265, I had some issues to create a working test case, but now added one with
test/Isl/CodeGen/partial_write_in_region_with_loop.ll.

Meinersbur added inline comments.Jun 6 2017, 8:00 AM
lib/CodeGen/BlockGenerators.cpp
1520 ↗(On Diff #101348)

If we try consistly have the BBMaps of the StartBlock store the correct value maps: This looks up the EndBlock, which will probably be always empty.

Meinersbur accepted this revision.Jun 6 2017, 8:01 AM

Otherwise, LGTM.

This revision is now accepted and ready to land.Jun 6 2017, 8:01 AM
This revision was automatically updated to reflect the committed changes.