I am working on LLVM backend and was wondering if there is any way by which I can access the value stored SDValue so I can either assign it as a literal or move it to register in an user defined instruction. Something like: SDValue Value = Op->getOperand(2); intValue = Value.get_integer_value //get Value as an int and then if ( intValue > 31) Thanks, Ambuj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150216/9a72caa2/attachment.html>
I am working on LLVM backend and was wondering if there is any way by which I can access the value stored SDValue so I can either assign it as a literal or move it to register in an user defined instruction. Something like: SDValue Value = Op->getOperand(2); intValue = Value.get_integer_value //get Value as an int and then if ( intValue > 31) emit udi 0,0,0,intValue else { emit load v1,intValue udi v1,0,0,0 } On Mon, Feb 16, 2015 at 4:19 PM, Ambuj Agrawal <ambujbwt at gmail.com> wrote:> I am working on LLVM backend and was wondering if there is any way by > which I can access the value stored SDValue so I can either assign it as a > literal or move it to register in an user defined instruction. > > Something like: > SDValue Value = Op->getOperand(2); > > intValue = Value.get_integer_value //get Value as an int > > and then > > if ( intValue > 31) > > > > Thanks, > Ambuj >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150216/48ecfa6a/attachment.html>
Hi Ambuj, On 16 February 2015 at 08:19, Ambuj Agrawal <ambujbwt at gmail.com> wrote:> SDValue Value = Op->getOperand(2); > > intValue = Value.get_integer_value //get Value as an intIf you know for some reason that it actually is a constant, you can write "Op->getConstantOperandVal(2)". If not, you obviously have to check that before trying to get the value. The usual idiom is something like: uint64_t IntVal = -1; if (auto *CN = dyn_cast<ConstantSDNode>(Value)) IntVal = CN->getZExtValue(); // Or some other accessor. Cheers. Tim.