[llvm-dev] Instruction arguments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Instruction arguments

Chris Lattner via llvm-dev
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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Instruction arguments

Chris Lattner via llvm-dev
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 <[hidden email]> 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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Instruction arguments

Chris Lattner via llvm-dev
In reply to this post by Chris Lattner via llvm-dev
On 01/19, Abid Malik via llvm-dev wrote:
> 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?

You don't want to access "1" directly if you want to compare it to
something other than a native C++ integer type such as
`int/unsigned/long/...`. These are SSA values on which pointer equality
works, especially since constants, e.g., i32 1, are unique.

Cheers,
  Johannes

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

signature.asc (235 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Instruction arguments

Chris Lattner via llvm-dev
Thanks, Ehud.

Thanks, Johannes.
I am trying to compare the call instruction (openMP ) compatibility wrt scheduling, iteration, and chunk size. I think accessing these constant values makes sense to form the set of call of instructions which are compatible. What do you think?

Can you elaborate?
"These are SSA values on which pointer equality
works, especially since constants, e.g., i32 1, are unique."

"i32 1" is constant. But how I can use this constant for equality check? It is not a sting or datatype that can be used for binary equality check.
Thanks,

On Sun, Jan 19, 2020 at 9:02 PM Doerfert, Johannes <[hidden email]> wrote:
On 01/19, Abid Malik via llvm-dev wrote:
> 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?

You don't want to access "1" directly if you want to compare it to
something other than a native C++ integer type such as
`int/unsigned/long/...`. These are SSA values on which pointer equality
works, especially since constants, e.g., i32 1, are unique.

Cheers,
  Johannes


--
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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Instruction arguments

Chris Lattner via llvm-dev
Constants are created via the `getXXX` routines. They are cached internally in the LLVMContext, so a particular constant won't be created twice in the same context ( -> unique). The common idiom for testing a constant is to compare the pointer itself with the one that you want. Look through the source code and you will see many examples.

To actually get the value inside the constant you will need to use the API I described before, which seems like what you are actually looking for.

If all you need is to compare with 1, then there is even a simpler API for this: Constant::isOneValue().


On Mon, Jan 20, 2020 at 11:23 AM Abid Malik <[hidden email]> wrote:
Thanks, Ehud.

Thanks, Johannes.
I am trying to compare the call instruction (openMP ) compatibility wrt scheduling, iteration, and chunk size. I think accessing these constant values makes sense to form the set of call of instructions which are compatible. What do you think?

Can you elaborate?
"These are SSA values on which pointer equality
works, especially since constants, e.g., i32 1, are unique."

"i32 1" is constant. But how I can use this constant for equality check? It is not a sting or datatype that can be used for binary equality check.
Thanks,

On Sun, Jan 19, 2020 at 9:02 PM Doerfert, Johannes <[hidden email]> wrote:
On 01/19, Abid Malik via llvm-dev wrote:
> 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?

You don't want to access "1" directly if you want to compare it to
something other than a native C++ integer type such as
`int/unsigned/long/...`. These are SSA values on which pointer equality
works, especially since constants, e.g., i32 1, are unique.

Cheers,
  Johannes


--
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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev