Thanks, I patch a version, it can give a heap variable info.
Now the curious is the patch version cannot give right answer for variable 
length array. for example,
int func(int m, int n)
{
int array[m][n];
...
}
here array is allocated by alloca, obviously a local variable.
But the original version can check it a local variable.

---Original---
From: "Richard Biener"<richard.guent...@gmail.com&gt;
Date: Wed, May 13, 2020 19:10 PM
To: "易会战"<huizha...@foxmail.com&gt;;
Cc: "gcc"<gcc@gcc.gnu.org&gt;;
Subject: Re: how to find variable related to a virtual ssa name


On Wed, May 13, 2020 at 11:38 AM 易会战 <huizha...@foxmail.com&gt; wrote:
&gt;
&gt; now I am working on gcc-9.3, can you give the specific code location to 
check not escaped heap? I try to add a flag.

set_uids_in_ptset

&gt; ---Original---
&gt; From: "Richard Biener"<richard.guent...@gmail.com&gt;
&gt; Date: Wed, May 13, 2020 17:28 PM
&gt; To: "易会战"<huizha...@foxmail.com&gt;;
&gt; Cc: "gcc"<gcc@gcc.gnu.org&gt;;
&gt; Subject: Re: how to find variable related to a virtual ssa name
&gt;
&gt; On Wed, May 13, 2020 at 11:08 AM 易会战 <huizha...@foxmail.com&gt; wrote:
&gt; &gt;
&gt; &gt; yes, it does not escape the function, but indeed allocate memory on 
heap. There is much specific method to judge the memory on heap although not 
escape the function?
&gt;
&gt; Not at the moment.&nbsp; The info is computed by tree-ssa-structalias.c in
&gt; compute_may_aliases,
&gt; the pass knows that a variable points to not escaped heap storage but this 
is
&gt; not stored anywhere ready for consumption.&nbsp; Adding a flag to
&gt; pt_solution would be easy though.
&gt;
&gt; Richard.
&gt;
&gt; &gt; ---Original---
&gt; &gt; From: "Richard Biener"<richard.guent...@gmail.com&gt;
&gt; &gt; Date: Wed, May 13, 2020 15:00 PM
&gt; &gt; To: "易会战"<huizha...@foxmail.com&gt;;
&gt; &gt; Cc: "gcc"<gcc@gcc.gnu.org&gt;;
&gt; &gt; Subject: Re: how to find variable related to a virtual ssa name
&gt; &gt;
&gt; &gt; On Wed, May 13, 2020 at 6:03 AM 易会战 <huizha...@foxmail.com&gt; wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; It seems the function ptr_deref_may_alias_global_p cannot give 
right result.
&gt; &gt; &gt; For example,
&gt; &gt; &gt; int func(int size, int i)
&gt; &gt; &gt; {
&gt; &gt; &gt; int * sum;
&gt; &gt; &gt; sum = malloc()
&gt; &gt; &gt; ....here some code access sum pointing to memory
&gt; &gt; &gt; return sum[i]
&gt; &gt; &gt; }
&gt; &gt; &gt; ptr_deref_may_alias_global_p tell me it is a local memory 
access. indeed sum is a local variable, but the pointer point to heap memory.
&gt; &gt; &gt; In fact there is a similiar function ref_may_alias_global_p, and 
it give similiar result.
&gt; &gt;
&gt; &gt; GCC can be clever and notice your malloc() result does not escape the 
function
&gt; &gt; which means stores to it are dead once you leave it.&nbsp; For this 
reason
&gt; &gt; it does not
&gt; &gt; mark the memory global.&nbsp; So make sure the allocated pointer 
escapes
&gt; &gt; and try again.
&gt; &gt;
&gt; &gt; &gt;
&gt; &gt; &gt;
&gt; &gt; &gt; ---Original---
&gt; &gt; &gt; From: "Richard Biener"<richard.guent...@gmail.com&gt;
&gt; &gt; &gt; Date: Tue, May 12, 2020 22:20 PM
&gt; &gt; &gt; To: "易会战"<huizha...@foxmail.com&gt;;
&gt; &gt; &gt; Cc: "gcc"<gcc@gcc.gnu.org&gt;;
&gt; &gt; &gt; Subject: Re: how to find variable related to a virtual ssa name
&gt; &gt; &gt;
&gt; &gt; &gt; On Tue, May 12, 2020 at 4:16 PM 易会战 <huizha...@foxmail.com&gt; 
wrote:
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; thanks a lot. I will check your advice.
&gt; &gt; &gt; &gt; Can you give some explaination about memory ssa, and how to 
use it. I check internal, cannot get it. Maybe you know some examples or some 
more materials.
&gt; &gt; &gt;
&gt; &gt; &gt; memory SSA in GCC is simply a SSA chain of all memory statements 
local
&gt; &gt; &gt; to a function
&gt; &gt; &gt; with a _single_ underlying variable (.MEM) and thus only one SSA 
name
&gt; &gt; &gt; live at the same
&gt; &gt; &gt; time.&nbsp; It can be used to quickly traverse stores via 
use-&gt;def chains
&gt; &gt; &gt; and loads inbetween
&gt; &gt; &gt; two stores via immediate uses.
&gt; &gt; &gt;
&gt; &gt; &gt; Richard.
&gt; &gt; &gt;
&gt; &gt; &gt; &gt; ---Original---
&gt; &gt; &gt; &gt; From: "Richard Biener"<richard.guent...@gmail.com&gt;
&gt; &gt; &gt; &gt; Date: Tue, May 12, 2020 22:02 PM
&gt; &gt; &gt; &gt; To: "易会战"<huizha...@foxmail.com&gt;;
&gt; &gt; &gt; &gt; Cc: "gcc"<gcc@gcc.gnu.org&gt;;
&gt; &gt; &gt; &gt; Subject: Re: how to find variable related to a virtual ssa 
name
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; On Tue, May 12, 2020 at 2:44 PM 易会战 via Gcc 
<gcc@gcc.gnu.org&gt; wrote:
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; hi, I am working on gcc ssa name. For each function, 
we can traverse all defined ssa name by macro FOR_EACH_SSA_NAME. If a ssa name 
is default definition for a symbol (check SSA_NAME_IS_DEFAULT_DEF) , I can get 
the symbol by SSA_NAME_VAR. But for a virtual DEFAULT DEF, I cannot get it, 
SSA_NAME_VAR return a identifier named .MEM. I cannot find which variable 
related to the default definition. Why and how I should find the related 
variable?
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; By the way , I give my current work,&amp;nbsp; I wish 
find a MEM_REF refer to global/heap memory or local stack. I try my best to get 
a correct memory type. Since MEM_REF have a base address, which is often a ssa 
name. Athough it is not virtual ssa name. But I find just check ssa name data 
flow is not enough to get the info.
&gt; &gt; &gt; &gt; &gt; For example, a malloc function allocate some heap 
memory and record the address in a global ptr. On gimple ssa IR, the malloc 
function return a address assigned to a ssa name , then ssa name assign the 
value to the global ptr. When i check ssa name defined by the global ptr, I 
donot know if the ptr point to global memory or local memory.
&gt; &gt; &gt; &gt; &gt; Please see the gimple code:
&gt; &gt; &gt; &gt; &gt; _2 = malloc()
&gt; &gt; &gt; &gt; &gt; ptr = _2
&gt; &gt; &gt; &gt; &gt; _3 = ptr
&gt; &gt; &gt; &gt; &gt; MEM_REF[BASE _3]
&gt; &gt; &gt; &gt; &gt; I wish get _3&amp;nbsp; is a address pointing to 
global memory. But just from _3=ptr, cannot judge it.&amp;nbsp;
&gt; &gt; &gt; &gt; &gt; I wish memory SSA can help solve the problem.
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; memory SSA will not solve this problem.&nbsp; You can 
instead query
&gt; &gt; &gt; &gt; points-to information
&gt; &gt; &gt; &gt; on _3 for example by calling ptr_deref_may_alias_global_p 
(_3) which internally
&gt; &gt; &gt; &gt; looks at SSA_NAME_PTR_INFO which contains the solution of 
the
&gt; &gt; &gt; &gt; points-to computation.
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; Richard.
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; Or gcc gives the info at other pass? wish get some 
advice. Thanks a lot.

Reply via email to