This is an archive of the discontinued LLVM Phabricator instance.

Pass -backend-option to LLVM when there is no target machine
ClosedPublic

Authored by yaxunl on Feb 23 2016, 2:39 PM.

Details

Summary

Clang should pass -backend-option to LLVM even though there is no target machine, since LLVM passes are used when emitting LLVM IR.

Differential Revision: http://reviews.llvm.org/D17552

Diff Detail

Repository
rL LLVM

Event Timeline

yaxunl updated this revision to Diff 48851.Feb 23 2016, 2:39 PM
yaxunl retitled this revision from to Pass -backend-option to LLVM when there is no target machine.
yaxunl updated this object.
yaxunl added reviewers: Anastasia, rsmith.
yaxunl added a subscriber: tstellarAMD.
yaxunl added a subscriber: cfe-commits.

Hi Anastasia/Richard,

I found this issue when investigating some codegen issues in Clang -cc1 with -emit-llvm. I need to pass an llvm option -print-after-all to the LLVM pass manager which is used to run the optimization passes before emitting llvm. However it did not work. Then I found ParseCommandLineOptions was only called when target machine was set. I fixed this by always call ParseCommandLineOptions even though there is no target machine.

This bug causes difficulty for OpenCL since it is usually compiled without target machine.

Could you please review this? Thanks.

Do you have a test case for this?

yaxunl updated this revision to Diff 49781.Mar 3 2016, 3:08 PM
yaxunl updated this object.
yaxunl added a reviewer: tstellarAMD.
yaxunl removed a subscriber: tstellarAMD.

Add a test for -backend-option with and w/o target machine as suggested by Tom.

rsmith accepted this revision.Mar 18 2016, 9:40 AM
rsmith edited edge metadata.

LGTM

This revision is now accepted and ready to land.Mar 18 2016, 9:40 AM
Anastasia accepted this revision.Mar 22 2016, 11:33 AM
Anastasia edited edge metadata.

LGTM, apart from small remark on the test!

test/Frontend/backend-option.c
2 ↗(On Diff #49781)

I think conceptually it's not correct to pass spir target with C module, although it doesn't make any difference here for this test. I would still change it to some x86 one.

yaxunl marked an inline comment as done.Mar 22 2016, 11:46 AM
yaxunl added inline comments.
test/Frontend/backend-option.c
2 ↗(On Diff #49781)

if we change it to x86, it has a target machine, so the test no longer reproduce the original issue.

How about add -x cl for the second command to force the source to be treated as cl source code, then it can reproduce the original issue and at the same time is valid for spir target?

Anastasia added inline comments.Mar 22 2016, 12:19 PM
test/Frontend/backend-option.c
2 ↗(On Diff #49781)

Sure!

yaxunl updated this revision to Diff 51326.Mar 22 2016, 1:08 PM
yaxunl edited edge metadata.
yaxunl marked an inline comment as done.

Add -x cl to the test when compiling it for spir target.

Ping. Tom, are you OK with this fix?

yaxunl added a subscriber: tstellarAMD.
This revision was automatically updated to reflect the committed changes.