This sounds very similar to what PowerPC does, see: https://github.com/llvm/llvm-project/blob/master/llvm/lib/Target/PowerPC/PPCBranchSelector.cpp
However, PowerPC is doing this in the compiler backend, not in the assembler. One issue is that the process must be iterative, because branches can go both forward and backward, and replacing some branch instructions with the branch pairs can then cause other branches to go out of range.
-Hal
_______________________________________________ LLVM Developers mailing list llvm...@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-- Hal Finkel Lead, Compiler Technology and Programming Languages Leadership Computing Facility Argonne National Laboratory
--
With best regards, Anton Korobeynikov
Department of Statistical Modelling, Saint Petersburg State University
If done in the assembler, this is branch relaxation. You need to
implement the calls backs mayNeedRelaxation, and relaxInstruction
on your target MCAsmBackend. The iteration relaxation logic
already exists, see the generic MC code.
Philip
Hi Kai,
did you make any progress on this topic?
We have a similar case in our backend, where conditional branches
have only a limited range.
So for hand-written assembly, we would like to relax using the
scheme you describe: invert the branch condition and add an
unconditional jump.
As you've already discovered, the relaxInstruction callback
doesn't allow to insert additional instructions, but requires the
relaxed instruction to be returned.
We could work around that by relaxing to a pseudo instruction
whose size is the combined size of the conditional branch + jump
and expand it later to the actual instructions, but that seems
unnecessarily complex.
Did you come up with a better solution?
Konstantin
Thanks for highlighting that patch!
Using instruction bundles indeed sounds interesting, as it seems more flexible. We'll see how far we get with this.
Konstantin
We could make this work using bundles in our backend, but needed to pass the MCContext to relaxInstruction to be able to allocate new instructions without leaking memory.
Could someone have a look at the patch (https://reviews.llvm.org/D95375)?
Konstantin
-- --------------------------------------------------------------------------- Konstantin Schwarz Email: konstanti...@hightec-rt.com HighTec EDV-Systeme GmbH Phone: +49 681 92613 21 Europaallee 19 D-66113 Saarbrücken WWW: http://www.hightec-rt.com Managing Director: Vera Strothmann Register Court: Saarbrücken, HRB 10445, VAT ID: DE 138344222 This e-mail may contain confidential and/or privileged information. If you are not the intended recipient please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ---