Ehsan Ali via llvm-dev
2017-Aug-15 01:39 UTC
[llvm-dev] Problem of getting two unused registers in eliminateFrameIndex()
Hello all, For my custom processor backend I am trying add some instruction using BuildMI() inside eliminateFrameIndex(). I tried RegScavenger like this: unsigned RegUnused0 = RS->FindUnusedReg(&LASER::GNPRegsRegClass); if (!RegUnused0) RegUnused0 = RS->scavengeRegister(&LASER::GNPRegsRegClass, II, SPAdj); assert(RegUnused0 && "Register scavenger failed"); RS->setRegUsed(RegUnused0); It works but there are two issues: 1) I need to registers and RegScavenger only returns one. 2) I cannot unset the used register and I get spill slot error message when I ran out of the available registers. So I gave up and tried createVirtualRegister(): MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo(); const TargetRegisterClass *RC = &LASER::GNPRegsRegClass; unsigned Reg = RegInfo.createVirtualRegister(RC); But then I get the following error: MachineCopyPropagation.cpp:267: void anonymous}::MachineCopyPropagation::CopyPropagateBlock(llvm::MachineBasicBlock&): Assertion `!TargetRegisterInfo::isVirtualRegister(Reg) && "MachineCopyPropagation should be run after register allocation!"' failed. How can I solve my problem of getting two free registers in eliminateFrameIndex() ? Thank you, Ehsan Ali.
Krzysztof Parzyszek via llvm-dev
2017-Aug-15 13:05 UTC
[llvm-dev] Problem of getting two unused registers in eliminateFrameIndex()
There isn't really much else that you can do here. If you anticipate that two extra registers will be needed at some particular point in the function, reserve two spill slots. Creating virtual registers in replaceFrameIndex should work, but make sure that your target implements "requiresRegisterScavenging", "requiresFrameIndexScavenging", "requiresFrameIndexReplacementScavenging" (all from TargetRegisterInfo) as appropriate. -Krzysztof On 8/14/2017 8:39 PM, Ehsan Ali via llvm-dev wrote:> Hello all, > > For my custom processor backend I am trying add some instruction using > BuildMI() inside eliminateFrameIndex(). > > I tried RegScavenger like this: > > unsigned RegUnused0 = RS->FindUnusedReg(&LASER::GNPRegsRegClass); > if (!RegUnused0) > RegUnused0 = RS->scavengeRegister(&LASER::GNPRegsRegClass, II, SPAdj); > assert(RegUnused0 && "Register scavenger failed"); > RS->setRegUsed(RegUnused0); > > It works but there are two issues: > > 1) I need to registers and RegScavenger only returns one. > 2) I cannot unset the used register and I get spill slot error message > when I ran out of the available registers. > > So I gave up and tried createVirtualRegister(): > > MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo(); > const TargetRegisterClass *RC = &LASER::GNPRegsRegClass; > unsigned Reg = RegInfo.createVirtualRegister(RC); > > But then I get the following error: > > MachineCopyPropagation.cpp:267: void > anonymous}::MachineCopyPropagation::CopyPropagateBlock(llvm::MachineBasicBlock&): > Assertion `!TargetRegisterInfo::isVirtualRegister(Reg) && > "MachineCopyPropagation should be run after register allocation!"' > failed. > > How can I solve my problem of getting two free registers in > eliminateFrameIndex() ? > > Thank you, > Ehsan Ali. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Ehsan Ali via llvm-dev
2017-Aug-15 14:36 UTC
[llvm-dev] Problem of getting two unused registers in eliminateFrameIndex()
Your hint was very helpful. I enabled "requiresFrameIndexScavenging" and the createVirtualRegister() worked as expected: bool LaserRegisterInfo:: requiresFrameIndexScavenging(const MachineFunction &MF) const { return true; } I don't understand the logic behind it but somehow they are related. Thank you Krzysztof. Ehsan Ali. On 8/15/17, Krzysztof Parzyszek via llvm-dev <llvm-dev at lists.llvm.org> wrote:> There isn't really much else that you can do here. If you anticipate > that two extra registers will be needed at some particular point in the > function, reserve two spill slots. > > Creating virtual registers in replaceFrameIndex should work, but make > sure that your target implements "requiresRegisterScavenging", > "requiresFrameIndexScavenging", > "requiresFrameIndexReplacementScavenging" (all from TargetRegisterInfo) > as appropriate. > > -Krzysztof > > On 8/14/2017 8:39 PM, Ehsan Ali via llvm-dev wrote: >> Hello all, >> >> For my custom processor backend I am trying add some instruction using >> BuildMI() inside eliminateFrameIndex(). >> >> I tried RegScavenger like this: >> >> unsigned RegUnused0 = RS->FindUnusedReg(&LASER::GNPRegsRegClass); >> if (!RegUnused0) >> RegUnused0 = RS->scavengeRegister(&LASER::GNPRegsRegClass, II, SPAdj); >> assert(RegUnused0 && "Register scavenger failed"); >> RS->setRegUsed(RegUnused0); >> >> It works but there are two issues: >> >> 1) I need to registers and RegScavenger only returns one. >> 2) I cannot unset the used register and I get spill slot error message >> when I ran out of the available registers. >> >> So I gave up and tried createVirtualRegister(): >> >> MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo(); >> const TargetRegisterClass *RC = &LASER::GNPRegsRegClass; >> unsigned Reg = RegInfo.createVirtualRegister(RC); >> >> But then I get the following error: >> >> MachineCopyPropagation.cpp:267: void >> anonymous}::MachineCopyPropagation::CopyPropagateBlock(llvm::MachineBasicBlock&): >> Assertion `!TargetRegisterInfo::isVirtualRegister(Reg) && >> "MachineCopyPropagation should be run after register allocation!"' >> failed. >> >> How can I solve my problem of getting two free registers in >> eliminateFrameIndex() ? >> >> Thank you, >> Ehsan Ali. >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, > hosted by The Linux Foundation > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >