This is an archive of the discontinued LLVM Phabricator instance.

[polly] migrate -polly-show to the new pass manager
ClosedPublic

Authored by YangKeao on Apr 13 2022, 6:23 AM.

Diff Detail

Event Timeline

YangKeao created this revision.Apr 13 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald Transcript
YangKeao requested review of this revision.Apr 13 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2022, 6:23 AM
YangKeao updated this revision to Diff 422788.Apr 14 2022, 2:45 AM
Meinersbur added inline comments.Apr 14 2022, 12:37 PM
polly/lib/Support/RegisterPasses.cpp
333–340

The legacy pass manger is till present and people are still using it (which includes me). That is, the old functionality should not be removed, especially without giving any notification (such as report_fatal_error as with the NPM).

In other places, common code was extracted into a separate function such as runSimplifyUsingNPM or wrapper passes provided. Could you do the same?

YangKeao updated this revision to Diff 423612.Apr 19 2022, 6:58 AM

Restore the pass of legacy pass manager.

YangKeao marked an inline comment as done.Apr 19 2022, 6:59 AM

Fixed in the newest diff.

YangKeao updated this revision to Diff 423817.Apr 19 2022, 10:48 PM

Remove duplicated implementation

YangKeao added inline comments.Apr 20 2022, 9:09 AM
polly/include/polly/ScopGraphPrinter.h
52

I realized that this specialization doesn't take effect. I should use DOTGraphTraits<ScopDetection>.

Meinersbur added inline comments.Apr 25 2022, 10:19 AM
polly/include/polly/ScopGraphPrinter.h
52

Are you going to make this change?

YangKeao added inline comments.May 3 2022, 1:01 AM
polly/include/polly/ScopGraphPrinter.h
52

Yes. I'm doing it right now (after the Labor Day holiday 😄 )

YangKeao updated this revision to Diff 426666.May 3 2022, 5:35 AM

fix and add test for the specialization

YangKeao marked an inline comment as done.May 3 2022, 6:21 AM
YangKeao updated this revision to Diff 426910.May 3 2022, 9:12 PM

format codes

When compiling under Windows with cmake -DPOLLY_ENABLE_GPGPU_CODEGEN=ON, I get a linker error:

Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTOnlyPrinterPass(void)" (?createDOTOnlyPrinterPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinki
ng::PollyForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTOnlyViewerPass(void)" (?createDOTOnlyViewerPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking
::PollyForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTPrinterPass(void)" (?createDOTPrinterPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking::Poll
yForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTViewerPass(void)" (?createDOTViewerPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking::PollyF
orcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
C:\Users\meinersbur\build\llvm-project\debug_vs17\Debug\bin\opt.exe : fatal error LNK1120: 4 unresolved externals [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]

I could not yet find a config that also fails under Linux, but it looks like some library dependencies are wrong.

polly/lib/Analysis/ScopGraphPrinter.cpp
73–76

I get a compiler error here:

/home/meinersbur/src/llvm-project/polly/lib/Analysis/ScopGraphPrinter.cpp:73:6: error: redeclaration of ‘static void llvm::DOTGraphTraits<polly::ScopDetection>::printRegionCluster(const polly::ScopDetection&, const llvm::Region*, llvm::raw_ostream&, unsigned int)’ may not have default arguments [-fpermissive]
   73 | void DOTGraphTraits<ScopDetection>::printRegionCluster(const ScopDetection &SD,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The compiler is correct here, default parameters belong to the declaration, not definition. The pre-merge check does not seem to have caught this, maybe using a different compiler version (I am using gcc 11.2)

YangKeao added a comment.EditedMay 4 2022, 12:17 AM

When compiling under Windows with cmake -DPOLLY_ENABLE_GPGPU_CODEGEN=ON, I get a linker error:

Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTOnlyPrinterPass(void)" (?createDOTOnlyPrinterPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinki
ng::PollyForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTOnlyViewerPass(void)" (?createDOTOnlyViewerPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking
::PollyForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTPrinterPass(void)" (?createDOTPrinterPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking::Poll
yForcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
Polly.lib(PPCGCodeGeneration.obj) : error LNK2019: unresolved external symbol "class llvm::Pass * __cdecl polly::createDOTViewerPass(void)" (?createDOTViewerPass@polly@@YAPEAVPass@llvm@@XZ) referenced in function "public: __cdecl `anonymous namespace'::PollyForcePassLinking::PollyF
orcePassLinking(void)" (??0PollyForcePassLinking@?A0x3c23cca7@@QEAA@XZ) [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]
C:\Users\meinersbur\build\llvm-project\debug_vs17\Debug\bin\opt.exe : fatal error LNK1120: 4 unresolved externals [C:\Users\meinersbur\build\llvm-project\debug_vs17\tools\opt\opt.vcxproj]

I could not yet find a config that also fails under Linux, but it looks like some library dependencies are wrong.

Is it a clean build? I guess there are some cache breaks the linking. The function createDOTOnlyViewerPass is removed and replaced by createDOTOnlyViewerWrapperPass in this commit. Check the PollyForcePassLinking, it only calls the createDOTOnlyViewerWrapperPass.

I'm not sure whether this problem shows potential "dependencies issues" (as it seems failed to invalidate the cache) in the build system.

YangKeao updated this revision to Diff 426927.May 4 2022, 12:18 AM

move the default parameters to the declaration

YangKeao marked an inline comment as done.May 4 2022, 12:21 AM

Nice catch. Fixed in the latest commit.

Meinersbur added inline comments.May 4 2022, 12:40 PM
llvm/include/llvm/Analysis/RegionPrinter.h
30 ↗(On Diff #426927)

Nothing unusual of a declaration in RegionPrinter.h to be implemented in RegionPrinter.cpp.

polly/include/polly/ScopGraphPrinter.h
34

Looking at other specializations, all GraphTraits of an analysis are a pointer of the the analysis (GraphTraits<ScopDetection>). Why the change? I fear that GraphTraits users may accidentally try to copy the object.

63

Consider using llvm::StringRef

65–66

Use doxygen comments for API documentation.

polly/lib/Analysis/ScopGraphPrinter.cpp
95–96

Consider DOTGraphTraits<ScopDetection*>

Meinersbur added a comment.EditedMay 4 2022, 12:59 PM

I'm not sure whether this problem shows potential "dependencies issues" (as it seems failed to invalidate the cache) in the build system.

This was correct. A clean build fixed the issue.

YangKeao updated this revision to Diff 427675.May 6 2022, 10:33 AM
YangKeao marked 2 inline comments as done.

Use GraphTraits<ScopDetection *>, remove redundant comments

YangKeao marked 2 inline comments as done.May 6 2022, 10:37 AM
YangKeao added inline comments.
polly/include/polly/ScopGraphPrinter.h
34

Why the change?

Because we could get the reference to ScopDetection from FAM.getResult, and it's quite straightforward to pass the reference to everywhere.

I fear that GraphTraits users may accidentally try to copy the object.

When will it happen? The arguments of the functions are all passing through reference.

But as I'm not familiar with GraphTraits and its other usage, I think it's fine not to touch it in this commit. I will use GraphTraits<ScopDetection *> instead.

Meinersbur accepted this revision.May 6 2022, 11:42 AM

LGTM. Thanks for your work! Do I have permission to commit for you?

This revision is now accepted and ready to land.May 6 2022, 11:42 AM

LGTM. Thanks for your work! Do I have permission to commit for you?

Yes. Please commit these two patches. Thank you 🍻

This revision was landed with ongoing or failed builds.May 9 2022, 12:06 PM
This revision was automatically updated to reflect the committed changes.
RKSimon added inline comments.
polly/include/polly/ScopGraphPrinter.h
29

@YangKeao Can you remove the 'using namespace' from the header and move them internally to each source file? This might be the cause of the namespace resolution build failures on:

https://github.com/compiler-explorer/compiler-workflows/runs/6452927622

Meinersbur added inline comments.May 16 2022, 1:15 PM
polly/include/polly/ScopGraphPrinter.h
29

I was just looking into it when I noticed you already changed it. Thanks you.

phosek added a subscriber: phosek.May 25 2022, 5:30 PM

Polly :: ScopDetect/dot-scops-npm.ll test has been flaking on our bots since this change landed with the following test error:

Script:
--
: 'RUN: at line 1';   /opt/s/w/ir/x/w/staging/llvm_build/bin/opt  -polly-process-unprofitable  -polly-remarks-minimal  -polly-use-llvm-names  -polly-import-jscop-dir=/opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect  -polly-codegen-verify  "-passes=polly-scop-printer" -disable-output < /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll
: 'RUN: at line 2';   /opt/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot
--
Exit Code: 2

Command Output (stderr):
--
Writing 'scops.func.dot'...
FileCheck error: 'scops.func.dot' is empty.
FileCheck command line:  /opt/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot

--

Would it be possible to take a look?

Polly :: ScopDetect/dot-scops-npm.ll test has been flaking on our bots since this change landed with the following test error:

Script:
--
: 'RUN: at line 1';   /opt/s/w/ir/x/w/staging/llvm_build/bin/opt  -polly-process-unprofitable  -polly-remarks-minimal  -polly-use-llvm-names  -polly-import-jscop-dir=/opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect  -polly-codegen-verify  "-passes=polly-scop-printer" -disable-output < /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll
: 'RUN: at line 2';   /opt/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot
--
Exit Code: 2

Command Output (stderr):
--
Writing 'scops.func.dot'...
FileCheck error: 'scops.func.dot' is empty.
FileCheck command line:  /opt/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /opt/s/w/ir/x/w/llvm-llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot

--

Would it be possible to take a look?

@phosek Where can I find more information about the test execution? I want to know the platform, architecture, compiler...

I tried to execute the same command (with the latest llvm and polly) several times, but none of them produce this error.

@Meinersbur Do you have any idea about why it could fail or how to debug this problem 🤔 ?

I could only observe a single failure with my own buildbot was assuming it was something else.

https://lab.llvm.org/buildbot/#/builders/10/builds/15406

******************** TEST 'Polly :: ScopDetect/dot-scops-npm.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/bin/opt  -polly-process-unprofitable  -polly-remarks-minimal  -polly-use-llvm-names  -polly-import-jscop-dir=/home/worker/src/llvm-project/polly/test/ScopDetect  -polly-codegen-verify  "-passes=polly-scop-printer" -disable-output < /home/worker/src/llvm-project/polly/test/ScopDetect/dot-scops-npm.ll
: 'RUN: at line 2';   /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/bin/FileCheck /home/worker/src/llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot
--
Exit Code: 2
Command Output (stderr):
--
Writing 'scops.func.dot'...
FileCheck error: 'scops.func.dot' is empty.
FileCheck command line:  /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/bin/FileCheck /home/worker/src/llvm-project/polly/test/ScopDetect/dot-scops-npm.ll -input-file=scops.func.dot
--
********************

The test is suspicious in that it does not use %t for its temporary file, it could potentially clash with another test using the same file concurrently. I suspect it is ScopDetect/dot-scops-npm.ll. Don't we have a means to specify which file to write?

Meinersbur added inline comments.May 26 2022, 1:01 PM
polly/test/ScopDetect/dot-scops-npm.ll
33–61

CHECK_NEXT is uneffective. It was fixed in rGad1d60c3befd606d6864b367f939238e50fb0f7e.

I hope I fixed the race condition issue in rGcc871cf6b50f6a76f2083d192e2254a16832224b. Another possibility would have been to put both tests into the same file.