public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Do all global structure variables escape in IPA-PTA?
@ 2020-08-25 13:09 Erick Ochoa
  2020-08-25 15:10 ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Erick Ochoa @ 2020-08-25 13:09 UTC (permalink / raw)
  To: GCC Development; +Cc: Philipp Tomsich, Christoph Müllner

Hi,

I'm trying to understand how the escape analysis in IPA-PTA works. I was 
testing a hypothesis where if a structure contains an array of 
characters and this array of characters is passed to fopen, the 
structure and all subfields will escape.

To do this, I made a program that has a global structure variable foo2 
that is has a field passed as an argument to fopen. I also made another 
variable foo whose array is initialized by the result of rand.

However, after compiling this program with -flto -flto-partition=none 
-fipa -fdump-ipa-pta -fdump-tree-all-all -Ofast (gcc --version 10.2.0)

E.g.

#include <stdio.h>
#include <math.h>
#include <string.h>

struct foo_t {
   char buffer1[100];
   char buffer2[100];
};

struct foo_t foo;
struct foo_t foo2;

int
main(int argc, char** argv)
{

   fopen(foo2.buffer1, "r");
   for (int i = 0; i < 100; i++)
   {
     foo.buffer1[i] = rand();
   }
   int i = rand();
   int retval = foo.buffer1[i % 100];
   return retval;
}

I see the PTA dump state the following:

ESCAPED = { STRING ESCAPED NONLOCAL foo2 }
foo = { ESCAPED NONLOCAL }
foo2 = { ESCAPED NONLOCAL }

which I understand as
* something externally visible might point to foo2
* foo2 might point to something externally visible
* foo might point to something externally visible

I have seen that global variables are stored in the .gnu.lto_.decls LTO 
file section. In the passes I have worked on I have ignored global 
variables. But can foo and foo2 be marked as escaping because the 
declarations are not streamed in yet? Or is there another reason I am 
not seeing? I am aware of aware of the several TODOs at the beginning of 
gcc/tree-ssa-structalias.c but I am unsure if they contribute to these 
variables being marked as escaping. (Maybe TODO 1 and TODO 2?)

Just FYI, I've been reading:
* Structure Aliasing in GCC
* Gimple Alias Improvements for GCC 4.5
* Memory SSA - A Unified Approach for Sparsely Representing Memory 
Operations

Thanks, I appreciate all help!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-08-26 11:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 13:09 Do all global structure variables escape in IPA-PTA? Erick Ochoa
2020-08-25 15:10 ` Richard Biener
2020-08-25 15:19   ` Erick Ochoa
2020-08-25 16:36     ` Erick Ochoa
2020-08-25 20:03       ` Richard Biener
2020-08-26  8:36         ` Erick Ochoa
2020-08-26  9:46           ` Erick Ochoa
2020-08-26 11:14             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).