This is an archive of the discontinued LLVM Phabricator instance.

[llvm] add CallBrPrepare pass to pipelines
ClosedPublic

Authored by nickdesaulniers on Dec 15 2022, 5:09 PM.

Details

Summary

Capstone of
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8

Clang changes are still necessary to enable the use of outputs along
indirect edges of asm goto statements.

Link: https://github.com/llvm/llvm-project/issues/53562

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptDec 15 2022, 5:09 PM
nickdesaulniers requested review of this revision.Dec 15 2022, 5:09 PM
nickdesaulniers edited the summary of this revision. (Show Details)
  • remove TODOs from commit message
nickdesaulniers planned changes to this revision.Dec 21 2022, 2:10 PM

TODO: add llvm/docs/LangRef.rst change from D138078.

  • rebase, format
nickdesaulniers planned changes to this revision.Jan 18 2023, 10:37 AM

Now that Loongarch has been merged, I need to fix failures in the following tests:

LLVM :: CodeGen/LoongArch/O0-pipeline.ll
LLVM :: CodeGen/LoongArch/opt-pipeline.ll
  • rebase, fix loongarch tests
efriedma added inline comments.Jan 25 2023, 9:23 AM
llvm/docs/LangRef.rst
8537

Labels aren't a thing in LLVM IR; if you mean "blockaddress", please state that explicitly. Otherwise, I'm not sure what you're referring to.

llvm/lib/CodeGen/MachineVerifier.cpp
632

80 cols?

jyknight added inline comments.Jan 25 2023, 10:49 AM
llvm/docs/LangRef.rst
8537

"indirect labels" are one of the arguments to the "callbr" instruction (see above syntax description and below description in "Arguments")

efriedma added inline comments.Jan 25 2023, 10:55 AM
llvm/docs/LangRef.rst
8537

Okay, but then how do you pass a label as a "function args"?

nickdesaulniers marked an inline comment as done.Jan 26 2023, 10:41 AM
nickdesaulniers added inline comments.
llvm/docs/LangRef.rst
8537

Labels aren't a thing in LLVM IR

callbr void asm "", "r,!i"(i32 %x)
            to label %fallthrough [label %indirect]

I see the word label twice there.

I'm also using language consistent with the rest of this section of the langref.
https://llvm.org/docs/LangRef.html#callbr-instruction

Perhaps the langref could use a fresh coat of paint here? But can that be orthogonal to this patch?

efriedma added inline comments.Jan 26 2023, 11:13 AM
llvm/docs/LangRef.rst
8537

The part I'm confused about is that I'm not sure what you mean by passing a label as a function argument. (Yes, labels exist in LLVM IR in the sense you're talking about, but they don't have an address you can pass as an argument.)

jyknight added inline comments.Jan 27 2023, 3:46 PM
llvm/docs/LangRef.rst
8537

Oh, I see what you mean. Maybe something like the following?

Note that in order to support outputs along indirect edges, LLVM may need to split critical edges, which may require synthesizing a replacement block for the indirect labels. Therefore, each callbr instruction must only transfer control to the addresses provided via its own indirect labels, and not addresses from a different callbr instruction or blockaddress value for the same blocks.

llvm/docs/LangRef.rst
8537

That's not precisely the point I'm trying to make. I'm trying to state that:

asm goto ("# %0 %1"::"i"(&&foo)::foo);

that %0 and %1 are no longer guaranteed to compare equal if we have to split the critical edge to foo. %0 will be the final destination, while %1 will be the synthesized block. How's best to reword this point?

efriedma added inline comments.Jan 30 2023, 8:36 PM
llvm/docs/LangRef.rst
8537

Just say that blockaddress constants which refer to a block will not compare equal to indirect labels referring to the same block? I guess?

jyknight added inline comments.Jan 31 2023, 5:52 AM
llvm/docs/LangRef.rst
8537

Try 2:
Note that in order to support outputs along indirect edges, LLVM may need to split critical edges, which may require synthesizing a replacement block for the indirect labels. Therefore, the address of a label as seen by another callbr instruction, or for a blockaddress constant, may not be equal to the address provided for the same block to this instruction's indirect labels operand. The assembly code may only transfer control to addresses provided via this instruction's indirect labels.

nickdesaulniers marked 7 inline comments as done.
void accepted this revision.Jan 31 2023, 4:51 PM
This revision is now accepted and ready to land.Jan 31 2023, 4:51 PM
  • final rebase
This revision was automatically updated to reflect the committed changes.

commit cf86855c4453 ("[M68k] fix test regression introduced by D140180")