This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Require a name for a block addr target
ClosedPublic

Authored by void on Jul 26 2019, 2:52 PM.

Details

Summary

A block address may be used in inline assembly. In which case it
requires a name so that the asm parser has something to parse. Creating
a name for every block address is a large hammer, but is necessary
because at the point when a temp symbol is created we don't necessarily
know if it's used in inline asm. This ensures that it exists regardless.

Diff Detail

Repository
rL LLVM

Event Timeline

void created this revision.Jul 26 2019, 2:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2019, 2:52 PM
void added a comment.Aug 7 2019, 11:24 AM

Friendly ping. :-)

Creating a name for every block address is a large hammer, but is necessary because at the point when a temp symbol is created we don't necessarily know if it's used in inline asm.

Sure we do; in this case if llvm::any_of the Uses of the BasicBlocks isa<CallBrInst> then we need to name the label. Right?

void updated this revision to Diff 214033.Aug 7 2019, 4:37 PM

Ah! Good point. Use "any_of" instead of creating a symbol for all block addresses.

void added a comment.Aug 7 2019, 4:38 PM

Ugh! The last update combined D65304 with this...:-/

void edited the summary of this revision. (Show Details)Aug 7 2019, 4:39 PM
void updated this revision to Diff 214036.Aug 7 2019, 5:08 PM

Remove accidentally added files.

void updated this revision to Diff 214045.Aug 7 2019, 5:54 PM

It's not enough to just check that a BB's address is used by a callbr, since
the value doesn't have to be directly used by it. E.g., it could be stored into
memory and then loaded.

void edited the summary of this revision. (Show Details)Aug 7 2019, 5:56 PM
test/CodeGen/X86/callbr-asm-obj-file.ll
1 ↗(On Diff #214045)

When I run this test case locally, I get:

$ llc < callbr-asm-obj-file.ll -filetype=obj -mtriple=x86_64-linux-gnu
<unknown>:0: error: Undefined temporary symbol

Am I holding it wrong?

nathanchance added inline comments.Aug 8 2019, 11:46 AM
test/CodeGen/X86/callbr-asm-obj-file.ll
1 ↗(On Diff #214045)

Do you have D65304 as well? With just this patch, I see that same error but with both patches, this test case works as expected.

test/CodeGen/X86/callbr-asm-obj-file.ll
1 ↗(On Diff #214045)

Ah, I missed the parent revision relationship between the two patches. Does phabricator UI show this relation anywhere?

nathanchance added inline comments.Aug 8 2019, 11:52 AM
test/CodeGen/X86/callbr-asm-obj-file.ll
1 ↗(On Diff #214045)

I see it right above my subscription to this revision.

void added a parent revision: D65304: [MC] Don't recreate a label if it's already used.
void added a comment.Aug 8 2019, 12:49 PM

In the "Revision Contents" box, there's a "Stack" tab. It looks like that's what shows the relationship.

I think the comment in LLVMTargetMachine::addAsmPrinter about // Don't waste memory on names of temp labels. should be amended in this patch to say ... unless it's address is taken or something to that effect.

void added a comment.Aug 9 2019, 1:07 PM

I think the comment in LLVMTargetMachine::addAsmPrinter about // Don't waste memory on names of temp labels. should be amended in this patch to say ... unless it's address is taken or something to that effect.

I'm not sure about that. It might be confusing to people, as we aren't technically wasting memory if the block address is taken. Also, the boolean being set here seems to have slightly different semantics from the change I made.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 9 2019, 1:17 PM
This revision was automatically updated to reflect the committed changes.