Hi everyone, I have almost completed the implementation of a linux/ppc backend in llvm. There were a few things to modify in lib/Target/PowerPC with a lot of "if (!isDarwin)". There are some places where I need help before saying the port is complete. I attached the diff file as a reference 1) In order to generate a creqv instruction before a vararg call, I created a new instruction in PPCInstrInfo.td: SETCR which uses the new XForm_1_ext format. It does not use the XForm_1 format because I wanted to give only one register as operand. I'm not sure if this is the correct way to do this, but it works. 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved registers. However, Linux and Darwin do not have the same set of non-callee saved registers. I don't know how to make the if(isDarwin) test in here 3) R31, which replaces R1 as stack pointer when there is a dynamic allocation in a method, must be seen as a callee-saved register and must not be saved and restored like it is actually for Darwin. I don't know how to specify that, when there is a dynamic allocation, R31 must be added to the set of registers that are saved before entering the method and restored at the end. If anyone's kind enough to help me out :) Cheers, Nicolas -------------- next part -------------- A non-text attachment was scrubbed... Name: diff-powerpc-linux.patch Type: text/x-patch Size: 37019 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070202/2ad6a35d/attachment.bin>
Nicolas, Would you point me to the Linux/PPC ABI documents you are using so I can better judge what your restrictions are? These changes also have an effect on debugging and exception handling. Cheers, -- Jim On 2-Feb-07, at 08:58 AM, Nicolas Geoffray wrote:> Hi everyone, > > I have almost completed the implementation of a linux/ppc backend > in llvm. There were a few things to modify in > lib/Target/PowerPC with a lot of "if (!isDarwin)". > > There are some places where I need help before saying the port is > complete. I attached the diff file as a reference > > 1) In order to generate a creqv instruction before a vararg call, I > created a new instruction in PPCInstrInfo.td: SETCR which > uses the new XForm_1_ext format. It does not use the XForm_1 format > because I wanted to give only one register as operand. > I'm not sure if this is the correct way to do this, but it works. > > 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved > registers. However, Linux and Darwin do not have the same set > of non-callee saved registers. I don't know how to make the if > (isDarwin) test in here > > 3) R31, which replaces R1 as stack pointer when there is a dynamic > allocation in a method, must be seen as a callee-saved register and > must not be saved and restored like it is actually for Darwin. I > don't know how to specify that, when there is a dynamic allocation, > R31 must be added to the set of registers that are saved before > entering the method and restored at the end. > > > If anyone's kind enough to help me out :) > > Cheers, > Nicolas-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070202/4c44c658/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070202/4c44c658/attachment.bin>
On Fri, 2 Feb 2007, Nicolas Geoffray wrote:> I have almost completed the implementation of a linux/ppc backend in llvm.Cool!> There were a few things to modify in > lib/Target/PowerPC with a lot of "if (!isDarwin)".Some meta comments: 1. Please don't change PPC -> llvmPPC. I assume that you did this because PPC is a #define in some system header. Please just add a '#undef PPC' where appropriate to make this unneeded. 2. The X86 backend has the unfortunate habit of saying "if !darwin" "if !cygwin" etc. Most of the changes you've made are actually ABI related changes, not OS-specific changes. As such, I'd prefer it if you added two methods to PPCSubtarget: isMachoABI() and isELF_ABI() (or whatever is the right name of the ABI that linux uses) and use those instead. 3. Please split up the patch into independent chunks for easier review. This will make it much more likely that your pieces will be applied in a timely fashion :). This will also let you get pieces in before the whole thing is "done".> 1) In order to generate a creqv instruction before a vararg call, I created a > new instruction in PPCInstrInfo.td: SETCR which > uses the new XForm_1_ext format. It does not use the XForm_1 format because I > wanted to give only one register as operand. > I'm not sure if this is the correct way to do this, but it works.Yep, that's the right way to go.> 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved registers. > However, Linux and Darwin do not have the same set > of non-callee saved registers. I don't know how to make the if(isDarwin) test > in hereTake a look at ARM/ARMRegisterInfo.td for an example of this.> 3) R31, which replaces R1 as stack pointer when there is a dynamic allocation > in a method, must be seen as a callee-saved register and must not be saved > and restored like it is actually for Darwin. I don't know how to specify > that, when there is a dynamic allocation, R31 must be added to the set of > registers that are saved before entering the method and restored at the end.Can you just mark it callee saved? If so, and if there is an instruction in the function that clobbers R31, it should automatically be saved and restored. Thanks a lot for doing this, linux/ppc support is a major new feature! -Chris -- http://nondot.org/sabre/ http://llvm.org/
Hi Chris, Chris Lattner wrote:> On Fri, 2 Feb 2007, Nicolas Geoffray wrote: > > > Some meta comments: > > 1. Please don't change PPC -> llvmPPC. I assume that you did this because > PPC is a #define in some system header. Please just add a '#undef PPC' > where appropriate to make this unneeded. >OK> 2. The X86 backend has the unfortunate habit of saying "if !darwin" "if > !cygwin" etc. Most of the changes you've made are actually ABI related > changes, not OS-specific changes. As such, I'd prefer it if you added > two methods to PPCSubtarget: isMachoABI() and isELF_ABI() (or whatever > is the right name of the ABI that linux uses) and use those instead. >Well all of the changes are ABI related. In fact, could you give me an example of what is os-specific and not abi-specific? I'm not sure.> 3. Please split up the patch into independent chunks for easier review. > This will make it much more likely that your pieces will be applied in > a timely fashion :). This will also let you get pieces in before the > whole thing is "done". >OK>> 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved registers. >> However, Linux and Darwin do not have the same set >> of non-callee saved registers. I don't know how to make the if(isDarwin) test >> in here >> > > Take a look at ARM/ARMRegisterInfo.td for an example of this. > >Great, thx for the hint>> 3) R31, which replaces R1 as stack pointer when there is a dynamic allocation >> in a method, must be seen as a callee-saved register and must not be saved >> and restored like it is actually for Darwin. I don't know how to specify >> that, when there is a dynamic allocation, R31 must be added to the set of >> registers that are saved before entering the method and restored at the end. >> > > Can you just mark it callee saved? If so, and if there is an instruction > in the function that clobbers R31, it should automatically be saved and > restored. > >It is marked callee saved. Because when it is not needed as frame pointer it is used like an ordinary register. But when it is used as frame pointer, the prologue and epilogue change its value, but the algorithm in llvm that finds clobbered register does not select it.> Thanks a lot for doing this, linux/ppc support is a major new feature! > >No problem, that way I'll be able to work with llvm on my own box :) Thx, Nicolas
Hi Jim, I didn't use any documents, but intensively looked at gcc's output. I think this document: http://refspecs.freestandards.org/elf/elfspec_ppc.pdf is the last specification of the ABI. Cheers, Nicolas Jim Laskey wrote:> Nicolas, > > Would you point me to the Linux/PPC ABI documents you are using so I > can better judge what your restrictions are? These changes also have > an effect on debugging and exception handling. > > Cheers, > > -- Jim > > > On 2-Feb-07, at 08:58 AM, Nicolas Geoffray wrote: > >> Hi everyone, >> >> >> I have almost completed the implementation of a linux/ppc backend in >> llvm. There were a few things to modify in >> >> lib/Target/PowerPC with a lot of "if (!isDarwin)". >> >> >> There are some places where I need help before saying the port is >> complete. I attached the diff file as a reference >> >> >> 1) In order to generate a creqv instruction before a vararg call, I >> created a new instruction in PPCInstrInfo.td: SETCR which >> >> uses the new XForm_1_ext format. It does not use the XForm_1 format >> because I wanted to give only one register as operand. >> >> I'm not sure if this is the correct way to do this, but it works. >> >> >> 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved >> registers. However, Linux and Darwin do not have the same set >> >> of non-callee saved registers. I don't know how to make the >> if(isDarwin) test in here >> >> >> 3) R31, which replaces R1 as stack pointer when there is a dynamic >> allocation in a method, must be seen as a callee-saved register and >> must not be saved and restored like it is actually for Darwin. I >> don't know how to specify that, when there is a dynamic allocation, >> R31 must be added to the set of registers that are saved before >> entering the method and restored at the end. >> >> >> >> If anyone's kind enough to help me out :) >> >> >> Cheers, >> >> Nicolas >> > > ------------------------------------------------------------------------ > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Hi Chris, Chris Lattner wrote:>> 2) Line 369 of PPCInstrInfo.td, we declare the non-callee saved registers. >> However, Linux and Darwin do not have the same set >> of non-callee saved registers. I don't know how to make the if(isDarwin) test >> in here >> > > Take a look at ARM/ARMRegisterInfo.td for an example of thisI tried to define Defs just like ARMRegisterInfo.td does with different subtargets, but i get the obvious message: Value 'Defs' of type 'list<Register>' is incompatible with initializer '[{ (the code is at the end of this mail) I'm not sure how to play with Defs and what to write in a .td file. I tried a top-level if with a Predicate: def IsMacho : Predicate<"Subtarget->isMachoABI()">; if (isMacho) let Defs = .... else Defs = ... But this fails too. Any other ideas on how to get this right? Thx, Nicolas let isCall = 1, noResults = 1, PPC970_Unit = 7, // All calls clobber the non-callee saved registers... Defs = [{ static const unsigned Defs_ELF[] = {R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12, F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10, V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19, LR,CTR, CR0,CR1,CR5,CR6,CR7} static const unsigned Defs_Macho[] = {R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12, F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13, V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19, LR,CTR, CR0,CR1,CR5,CR6,CR7} GPRClass::iterator GPRClass::allocation_order_begin(const MachineFunction &MF) const { const TargetMachine &TM = MF.getTarget(); const PPCSubtarget &Subtarget = TM.getSubtarget<PPCSubtarget>(); if (Subtarget.isMachoABI()){ return Defs_Macho; } else { return Defs_ELF; } } GPRClass::iterator GPRClass::allocation_order_end(const MachineFunction &MF) const { const TargetMachine &TM = MF.getTarget(); const MRegisterInfo *RI = TM.getRegisterInfo(); const PPCSubtarget &Subtarget = TM.getSubtarget<PPCSubtarget>(); GPRClass::iterator I; if (Subtarget.isMachoABI()) { I = Defs_Macho + (sizeof(Defs_Macho)/sizeof(unsigned)); } else { I = Defs_ELF + (sizeof(Defs_ELF)/sizeof(unsigned)); } return I; } }] in { // Convenient aliases for call instructions def BL : IForm<18, 0, 1, (ops calltarget:$func, variable_ops), "bl $func", BrB, []>; // See Pat patterns below. def BLA : IForm<18, 1, 1, (ops aaddr:$func, variable_ops), "bla $func", BrB, [(PPCcall (i32 imm:$func))]>; def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (ops variable_ops), "bctrl", BrB, [(PPCbctrl)]>; }