Distinguishing Pointer type variable and Ordinary Variable

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

Distinguishing Pointer type variable and Ordinary Variable

Abhinash Jain
This post was updated on .
C Code :-
int main()
{
 int a=10,c;
 int *b;
 c=20;
  b=&c;
 *b=a;
 return 0;
}

IR of above code :-
define i32 @main() #0 {
entry:
1.  %retval = alloca i32, align 4
2.  %a = alloca i32, align 4
3.  %c = alloca i32, align 4
4.  %b = alloca i32*, align 8
5.  store i32 0, i32* %retval
6.  store i32 10, i32* %a, align 4
7.  store i32 20, i32* %c, align 4
8.  store i32* %c, i32** %b, align 8
9.  %0 = load i32* %a, align 4
10.  %1 = load i32** %b, align 8
11.  store i32 %0, i32* %1, align 4
12.  ret i32 0
}


Line 9,10,11 of IR represents  *b=a;

How Do I recognise that i32* %1  on line 11, and i32** %b on line 8   is a pointer type variable through llvm pass??
And i32* %c on line 7 is a ordinary variable??

How to solve this issue ???

-EDITED-
Reply | Threaded
Open this post in threaded view
|

Re: Distinguishing Pointer Variable and Ordinary Variable

Joey Gouly
Check it's type to see if it's a pointer or not?


On 1 September 2013 12:31, Abhinash Jain <[hidden email]> wrote:
C Code :-
int main()
{
 int a=10,c;
 int *b;
 c=20;
 *b=a;
 return 0;
}

IR of above code :-
define i32 @main() #0 {
entry:
1.  %retval = alloca i32, align 4
2.  %a = alloca i32, align 4
3.  %c = alloca i32, align 4
4.  %b = alloca i32*, align 8
5.  store i32 0, i32* %retval
6.  store i32 10, i32* %a, align 4
7.  store i32 20, i32* %c, align 4
8.  %0 = load i32* %a, align 4
9.  %1 = load i32** %b, align 8
10.  store i32 %0, i32* %1, align 4
11.  ret i32 0
}


Line 8,9,10 of IR represents  *b=a;

Now I want to recognise whether i32* %1  on line 10 is a pointer variable or
ordinary variable through llvm pass.
So how to solve this issue ???



--
View this message in context: http://llvm.1065342.n5.nabble.com/Distinguishing-Pointer-Variable-and-Ordinary-Variable-tp60881.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Distinguishing Pointer Variable and Ordinary Variable

Abhinash Jain
Sorry I have actually edited the post.

I did check its type by using isa<PointerType>(cast<AllocaInst>(instr->getOperand(1))->getAllocatedType())
but it is only detecting  i32** %b on line 8 of IR as a pointer type.

Whereas I also want to detect the  i32* %1  on line 11 of IR as a pointer type. So how can I do this??
Reply | Threaded
Open this post in threaded view
|

Re: Distinguishing Pointer Variable and Ordinary Variable

Tim Northover-2
Hi,

On 1 September 2013 15:47, Abhinash Jain <[hidden email]> wrote:
> Sorry I have actually edited the post.

This is primarily an e-mail list; the vast majority of us won't see
any edits (on some web mirror?).

> I did check its type by using
> isa<PointerType>(cast<AllocaInst>(instr->getOperand(1))->getAllocatedType())
> but it is only detecting  i32** %b on line 8 of IR as a pointer type.

Not all pointers will come (directly or indirectly) from an
AllocaInst. You might just want
isa<PointerType>(instr->getOperand(1)->getType()), though of course
that'll be true for any memory operand of a store instruction.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Distinguishing Pointer Variable and Ordinary Variable

Duncan Sands
> Not all pointers will come (directly or indirectly) from an
> AllocaInst. You might just want
> isa<PointerType>(instr->getOperand(1)->getType()), though of course
> that'll be true for any memory operand of a store instruction.

isa<PointerType>(instr->getOperand(0)->getType()) will check if a pointer
is being stored.

Ciao, Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev