Page MenuHomePhabricator

[Thumb1][MachineOutliner] Add Machine Outliner support for Thumb1
Needs ReviewPublic

Authored by pestctrl on Apr 17 2021, 7:12 AM.



MachineOutliner support was previously added for Thumb2 and ARM modes.
Thumb1 support was left out, because there is no simple way to push
the LR onto the stack and then restore it back into the LR. Such an
idiom is required when:

  • A repeated sequence contains a call, which requires the LR to be saved and restored at the frame site.
  • MachineOutlinerDefault, where the LR needs to be saved and restored at the call site.

Besides the two situations described above, Thumb1 machine outlining
should be able to reuse all of the code introduced for machine
outlining in Thumb2, since all instructions generated fall in the
Thumb1 subset.

This patch enables Thumb1 support for the outliner, and introduces an
idiom for saving and restoring the LR. The LR can only be saved and
restored if there is an unused register in a repeated sequence. If
this is the case, then the machine outliner can generate this sequence
of instructions to save the LR:

PUSH R4     ;; Free up an auxilary register
PUSH LR     ;; LR must go on the top of the stack

......      ;; Original sequence of instructions

POP R4      ;; Pop LR off the stack into R4
            ;; (Cannot be directly popped into LR)
MOV LR, R4  ;; Move LR into the correct register
POP R4      ;; Pop the original value of R4 into R4

Diff Detail

Unit TestsFailed

640 msx64 debian > libomp.lock::omp_init_lock.c
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang -fopenmp -pthread -fno-experimental-isel -I /mnt/disks/ssd0/agent/llvm-project/openmp/runtime/test -I /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/runtime/src -L /mnt/disks/ssd0/agent/llvm-project/build/lib -I /mnt/disks/ssd0/agent/llvm-project/openmp/runtime/test/ompt /mnt/disks/ssd0/agent/llvm-project/openmp/runtime/test/lock/omp_init_lock.c -o /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/runtime/test/lock/Output/omp_init_lock.c.tmp -lm -latomic && /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/runtime/test/lock/Output/omp_init_lock.c.tmp

Event Timeline

pestctrl created this revision.Apr 17 2021, 7:12 AM
pestctrl requested review of this revision.Apr 17 2021, 7:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 17 2021, 7:12 AM
pestctrl edited the summary of this revision. (Show Details)Apr 17 2021, 7:14 AM
pestctrl edited the summary of this revision. (Show Details)Apr 17 2021, 7:22 AM
pestctrl updated this revision to Diff 338308.Apr 17 2021, 7:30 AM

Incorrect comment

yroux added a comment.Apr 23 2021, 8:15 AM

Hi and Thanks for working on this,

I've a couple of embedded comments, and can you add some tests to check SP-relative loads and stores handling ?


since there is not much logic in saveLROnsStack and restoreLRFromStack function what about removing them and creating the MIs here ?


why not adding FreeReg to MBB's LiveIns instead of spilling LR twice ?


I think that $r4 is not needed

pestctrl updated this revision to Diff 340380.Apr 25 2021, 1:23 PM

Fixed issues with clang-format

pestctrl updated this revision to Diff 340383.Apr 25 2021, 1:43 PM

Build MI's for save/restore LR in same function.

pestctrl marked an inline comment as done.Apr 25 2021, 1:44 PM
pestctrl added inline comments.

Huh, I had no idea you could do this. This might simplify my code a lot.