Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IR-based PGO #2474

Merged
merged 2 commits into from
Jan 18, 2018
Merged

Add IR-based PGO #2474

merged 2 commits into from
Jan 18, 2018

Conversation

JohanEngelen
Copy link
Member

First, some refactoring such that the code doesn't assume just one kind of PGO.

PGO_IRBasedUse,
};
extern PGOKind pgoMode;
inline bool isDoingPGOInstr() {
Copy link
Member

@dnadlinger dnadlinger Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this, but these names reads a bit odd – maybe isPGOInstrumenting, instrumentingForPGO, or something like that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then the other isUsingPGOProfile ?

@dnadlinger
Copy link
Member

You have probably thought about this, but maybe an alternative naming scheme would be "AST" instead of "frontend"?

@JohanEngelen
Copy link
Member Author

I used "frontend" because I think that's what is usually used in LLVM circles. In LLVM code, it's called "ClangPGO" (frontend based) and "LLVMPGO" (IR based).

@JohanEngelen
Copy link
Member Author

I'm renaming it to "AST Based", I like that better indeed.
Got IR-based to work aswell, very easy :)
(and it seems that using a sample-based PGO profile is also very easy now!)

@JohanEngelen JohanEngelen changed the title [WIP] Add IR-based PGO Add IR-based PGO Dec 28, 2017
@JohanEngelen
Copy link
Member Author

@jondegenhardt Done! :-) Important difference between AST- (old) and IR-based PGO in practical use is that the other commandline flags must be the same with IR PGO. This means that you have to specify -O3 when instrumenting with IR PGO as well. (you'll see "hash mismatch" warnings without it during -fprofile-use, meaning that the profile cannot be used and you won't get the optimizations you want)

@jondegenhardt
Copy link
Contributor

Very nice! I won't have a chance to try it until after new year, but I'll give it shot then.

@JohanEngelen
Copy link
Member Author

JohanEngelen commented Dec 28, 2017

Strange, anybody know why the file is not created? The CI systems error with:

773: $ "/Users/travis/build/ldc-developers/ldc/bin/ldc2" "-O3" "-fprofile-generate=/Users/travis/build/ldc-developers/ldc/tests/PGO/Output/irbased_indirect_calls.d.tmp.profraw" "-run" "/Users/travis/build/ldc-developers/ldc/tests/PGO/irbased_indirect_calls.d"

773: $ "/Users/travis/build/ldc-developers/ldc/bin/ldc-profdata" "merge" "/Users/travis/build/ldc-developers/ldc/tests/PGO/Output/irbased_indirect_calls.d.tmp.profraw" "-o" "/Users/travis/build/ldc-developers/ldc/tests/PGO/Output/irbased_indirect_calls.d.tmp.profdata"

773: # command stderr:

773: error: /Users/travis/build/ldc-developers/ldc/tests/PGO/Output/irbased_indirect_calls.d.tmp.profraw: No such file or directory

But the lit-test works fine on my machine.

Edit: nevermind, I found the problem.

@JohanEngelen
Copy link
Member Author

The failure on Windows is due to some bug in LLVM. I've a testcase and will submit it to their bugtracker.
So for now, I'll have to disable this on Windows...

@JohanEngelen
Copy link
Member Author

Shall I fully disable it on Windows, or only mark the test as XFail ? (only generating the profile for a Windows target is broken; profile usage still works)
I can also give a nice error message when a Windows target is chosen for profile generation? (right now, LLVM just outputs "Error:")

@JohanEngelen
Copy link
Member Author

(needless to say, I'd like to get this in quick, so other folks can start testing)

@kinke
Copy link
Member

kinke commented Dec 31, 2017

Thanks for doing this. Will it eventually supersede the AST-based one? [I would be looking forward to the resulting code cleanup.]

Wrt. Windows, XFAIL sounds good to me, as does a proper error message for the time being.

@JohanEngelen
Copy link
Member Author

Will it eventually supersede the AST-based one?

Maybe. The AST-based code makes a few PGO items easier and facilitates prototyping things (like the virtual call promotion I worked on). But probably most importantly, the AST-based instrumentation is the same as what's needed for code coverage. (https://clang.llvm.org/docs/SourceBasedCodeCoverage.html)
I don't have plans right now on taking the AST-based PGO further though, so I think people should move towards the IR-based PGO (Clang's AST-based PGO also stopped progressing, and all PGO effort is on IR-based PGO afaict).

[I would be looking forward to the resulting code cleanup.]

"cleanup" :'(

I'll add the error for Windows targets. I've already sent a question about the error to LLVM folks, I think it's just a bug somewhere (I can get it to (appear to) work with llvm's cmdline tools).

@kinke
Copy link
Member

kinke commented Dec 31, 2017

"cleanup" :'(

What I actually meant was code reduction, the less code to maintain, the better ;) - even more so if scattered around the code base like this one.

@@ -1033,6 +1032,8 @@ int cppmain(int argc, char **argv) {
global.lib_ext = "a";
}

opts::initializeInstrumentationOptionsFromCmdline();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to place the call here, after the triple has been initialized. The option sanity-checking needs to know the target triple, and I didn't want to separate the sanity checking from the initialization code.

@JohanEngelen
Copy link
Member Author

Any concerns before I pull this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants