[PATCH] D18541: [CodeGen] Consider register modified if it's used to pass landing pad parameters.

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 18:50:55 PDT 2016


On Mon, May 2, 2016 at 6:27 PM, Matthias Braun <matze at braunis.de> wrote:

> My first intuition would be that we just need to provide the proper
> clobber mask for all personality functions to get your desired behavior.
> However currently this would not help because these extra clobber masks are
> not passed to MachineRegisterInfo::addPhysRegsUsedFromRegMask() in the
> VirtRegRewriter and thus are not considered for prologue epilogue insertion.
>

This was no accident, I very carefully arranged to represent these masks as
something other than MachineOperands specifically so that PEI *wouldn't*
consider them clobbered. :)

On Win64, the unwinder arranges to restore all your registers to what they
were at the point of the throwing call site, either after you rejoin normal
control flow (via catchret in LLVM) or by unwinding out of the frame. They
*don't* restore the registers on entry into a funclet cleanuppad or
catchpad, which is why we have these register masks in in the first place.
Win64 has *many* CSRs including XMM registers, so if things were not
arranged this way, all functions using WinEH would have ridiculously large
prologues.

On Win32, we still have this hack in X86ISelLowering:
  // If this is an invoke in a 32-bit function using a funclet-based
  // personality, assume the function clobbers all registers. If an
exception
  // is thrown, the runtime will not restore CSRs.
  // FIXME: Model this more precisely so that we can register allocate
across
  // the normal edge and spill and fill across the exceptional edge.
  if (!Is64Bit && CLI.CS && CLI.CS->isInvoke()) {
    const Function *CallerFn = MF.getFunction();
    EHPersonality Pers =
        CallerFn->hasPersonalityFn()
            ? classifyEHPersonality(CallerFn->getPersonalityFn())
            : EHPersonality::Unknown;
    if (isFuncletEHPersonality(Pers))
      Mask = RegInfo->getNoPreservedMask();
  }
The old 32-bit unwinder is not kind enough to restore registers for us, so
we slapped a NoPreservedMask on the invoke, which makes PEI push all CSRs
(all three of them!). We could get rid of this hack if we added something
similar to what Marcin is proposing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160502/a88a130a/attachment.html>


More information about the llvm-commits mailing list