Cheng-Chih Yang
2014-Aug-15 20:54 UTC
[LLVMdev] Default/initial values for function arguments?
Hi guys, I’m trying to figure out a way to assign initial values to function arguments. For a function in IR: define i32 @main (i32 %0, i32 %1) { %tmp = add i32 %0, %1 ... } I would like to make sure %0 has some initial value (e.g. i32 0) under some circumstances. Is there any easy way to do this? I understand that %0 comes from a live-in value which is defined from outside of the function. I could, at the ISelLowering stage when seeing an ADD, replace the “%0” with a i32 constant 0, but I don’t feel like this is the right approach. Should I try to look into SUBREG_TO_REG/INSERT_REG here? Or any other thoughts? Thanks, - Cheng-Chih
John Criswell
2014-Aug-15 21:59 UTC
[LLVMdev] Default/initial values for function arguments?
Dear Cheng-Chih, Can you clarify what you mean by ensuring that "%0 has a default value?" Are you trying to ensure that the function's arguments have a default value if the function is called with too few arguments? The only way that %0 is going to have an undefined value is if a) a function passes in an undefined value (like undef) or b) the function is called with few two arguments. Unless you're trying to address behavior that is undefined at the LLVM IR level, your question doesn't make much sense. Regards, John Criswell On 8/15/14, 4:54 PM, Cheng-Chih Yang wrote:> Hi guys, > > I’m trying to figure out a way to assign initial values to function arguments. For a function in IR: > > define i32 @main (i32 %0, i32 %1) > { > %tmp = add i32 %0, %1 > ... > } > > I would like to make sure %0 has some initial value (e.g. i32 0) under some circumstances. Is there any easy way to do this? I understand that %0 comes from a live-in value which is defined from outside of the function. I could, at the ISelLowering stage when seeing an ADD, replace the “%0” with a i32 constant 0, but I don’t feel like this is the right approach. > > Should I try to look into SUBREG_TO_REG/INSERT_REG here? Or any other thoughts? > > Thanks, > - Cheng-Chih > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Yang, Cheng-Chih
2014-Aug-15 22:14 UTC
[LLVMdev] Default/initial values for function arguments?
Hi John, I see. Then my question is probably better put as - if there's a good way in LowerFormalArgument() one can overwrite the input argument's default value? Now the backend I have does a CopyFromReg(), which reads from a virtual register mapping to the input argument. I'd like to overwrite its value, so that all further IR instructions using this register can see the updated value. Thanks, - Cheng-Chih -----Original Message----- From: John Criswell [mailto:jtcriswel at gmail.com] Sent: Friday, August 15, 2014 5:59 PM To: Yang, Cheng-Chih; llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Default/initial values for function arguments? Dear Cheng-Chih, Can you clarify what you mean by ensuring that "%0 has a default value?" Are you trying to ensure that the function's arguments have a default value if the function is called with too few arguments? The only way that %0 is going to have an undefined value is if a) a function passes in an undefined value (like undef) or b) the function is called with few two arguments. Unless you're trying to address behavior that is undefined at the LLVM IR level, your question doesn't make much sense. Regards, John Criswell On 8/15/14, 4:54 PM, Cheng-Chih Yang wrote:> Hi guys, > > I'm trying to figure out a way to assign initial values to function arguments. For a function in IR: > > define i32 @main (i32 %0, i32 %1) > { > %tmp = add i32 %0, %1 > ... > } > > I would like to make sure %0 has some initial value (e.g. i32 0) under some circumstances. Is there any easy way to do this? I understand that %0 comes from a live-in value which is defined from outside of the function. I could, at the ISelLowering stage when seeing an ADD, replace the "%0" with a i32 constant 0, but I don't feel like this is the right approach. > > Should I try to look into SUBREG_TO_REG/INSERT_REG here? Or any other thoughts? > > Thanks, > - Cheng-Chih > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev