[llvm-dev] Instruction arguments

Ehud Katz via llvm-dev llvm-dev at lists.llvm.org
Sun Jan 19 13:48:55 PST 2020


Assuming you want to extract the constant number from a Value, you may want
to try to cast it to a ConstantInt.
For example:

if (auto *CI = dyn_cast<ConstantInt>(arg)) {
  const APInt &Integer = CI->getValue();
  // Or if you know that it is a signed (or unsigned), and just want the
actual integer then use:
  int64_t  SExtInt = CI->getSExtValue(); // signed
  uint64_t ZExtInt = CI->getZExtValue(); // unsigned
  // Now you may use either one of the 3 options above...
}

Cheers,
Ehud.

On Sun, Jan 19, 2020 at 5:57 PM Abid Malik via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello,
>
>
> I am loop over the arguments of a call instruction :
> ---->
>
>                    for (Value *arg: c->args()){
> 					errs() << *arg << "\n";
> 					arg->print(llvm::errs(), false);
> 					errs()<<"\n";
> 				}
>
> ----->
>
> How can I convert the arg for binary comparison(== etc.)? If I am correct,
> it is not a string. If the argument is "i32 1", Is there a way to access
> the content value "1" directly?
>
> Thanks
>
> --
> Abid M. Malik
> ******************************************************
> "I have learned silence from the talkative, toleration from the
> intolerant, and kindness from the unkind"---Gibran
> "Success is not for the chosen few, but for the few who choose" --- John
> Maxwell
> "Being a good person does not depend on your religion or status in life,
> your race or skin color, political views or culture. IT DEPENDS ON HOW GOOD
> YOU TREAT OTHERS"--- Abid
> "The Universe is talking to us, and the language of the Universe is
> mathematics."----Abid
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200119/e2020621/attachment.html>


More information about the llvm-dev mailing list