[llvm-dev] Help on finding Base GEP

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

[llvm-dev] Help on finding Base GEP

Bruce Hoult via llvm-dev
Hi, 

Below is the snippet of  LLVM IR code generated by Flang  

---snip--
  %3 = getelementptr i64, i64* %"a$sd", i64 11, !dbg !16
  %4 = bitcast i64* %3 to i32*, !dbg !16
  %5 = load i32, i32* %4, align 4, !dbg !16, !tbaa !22
---snip--

My requirement is for any such LoadInst (example: %5),  I want to check if its base GEP (i.e. %3) loads at particular offset (11) from its corresponding arrays descriptor structure (a$sd).

is there any API in LLVM to check this? or I need to write my own?

regards,
Venkat.



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

Re: [llvm-dev] Help on finding Base GEP

Bruce Hoult via llvm-dev
You can run SCEV which will see through bitcasts and GEPs, so it should give an expression of the form (base + offset) on the pointer of the load.

Cheers
siddharth

On Wed 30 May, 2018, 16:30 Venkataramanan Kumar via llvm-dev, <[hidden email]> wrote:
Hi, 

Below is the snippet of  LLVM IR code generated by Flang  

---snip--
  %3 = getelementptr i64, i64* %"a$sd", i64 11, !dbg !16
  %4 = bitcast i64* %3 to i32*, !dbg !16
  %5 = load i32, i32* %4, align 4, !dbg !16, !tbaa !22
---snip--

My requirement is for any such LoadInst (example: %5),  I want to check if its base GEP (i.e. %3) loads at particular offset (11) from its corresponding arrays descriptor structure (a$sd).

is there any API in LLVM to check this? or I need to write my own?

regards,
Venkat.


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Sending this from my phone, please excuse any typos!

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

Re: [llvm-dev] Help on finding Base GEP

Bruce Hoult via llvm-dev

On 05/30/2018 06:04 AM, Siddharth Bhat via llvm-dev wrote:
You can run SCEV which will see through bitcasts and GEPs, so it should give an expression of the form (base + offset) on the pointer of the load.

Specifically, you can use ScalarEvolution to subtract the expression for the base descriptor from the expression for the loaded pointer and see if the result is a SCEVConstant.

Also, you might find GetPointerBaseWithConstantOffset (in ValueTracking.h) useful.

 -Hal


Cheers
siddharth

On Wed 30 May, 2018, 16:30 Venkataramanan Kumar via llvm-dev, <[hidden email]> wrote:
Hi, 

Below is the snippet of  LLVM IR code generated by Flang  

---snip--
  %3 = getelementptr i64, i64* %"a$sd", i64 11, !dbg !16
  %4 = bitcast i64* %3 to i32*, !dbg !16
  %5 = load i32, i32* %4, align 4, !dbg !16, !tbaa !22
---snip--

My requirement is for any such LoadInst (example: %5),  I want to check if its base GEP (i.e. %3) loads at particular offset (11) from its corresponding arrays descriptor structure (a$sd).

is there any API in LLVM to check this? or I need to write my own?

regards,
Venkat.


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Sending this from my phone, please excuse any typos!


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

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

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

Re: [llvm-dev] Help on finding Base GEP

Bruce Hoult via llvm-dev
Hi,

On 30 May 2018 at 18:09, Hal Finkel <[hidden email]> wrote:

On 05/30/2018 06:04 AM, Siddharth Bhat via llvm-dev wrote:
You can run SCEV which will see through bitcasts and GEPs, so it should give an expression of the form (base + offset) on the pointer of the load.

Specifically, you can use ScalarEvolution to subtract the expression for the base descriptor from the expression for the loaded pointer and see if the result is a SCEVConstant.

Also, you might find GetPointerBaseWithConstantOffset (in ValueTracking.h) useful.

 -Hal


Thank you,  I will try using SCEV. 

regards,
Venkat.
 



Cheers
siddharth

On Wed 30 May, 2018, 16:30 Venkataramanan Kumar via llvm-dev, <[hidden email]> wrote:
Hi, 

Below is the snippet of  LLVM IR code generated by Flang  

---snip--
  %3 = getelementptr i64, i64* %"a$sd", i64 11, !dbg !16
  %4 = bitcast i64* %3 to i32*, !dbg !16
  %5 = load i32, i32* %4, align 4, !dbg !16, !tbaa !22
---snip--

My requirement is for any such LoadInst (example: %5),  I want to check if its base GEP (i.e. %3) loads at particular offset (11) from its corresponding arrays descriptor structure (a$sd).

is there any API in LLVM to check this? or I need to write my own?

regards,
Venkat.


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Sending this from my phone, please excuse any typos!


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

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory


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