On Mon, 25 Apr 2005, Vladimir Prus wrote:> The GlobalsModRef::getModRefInfo has this logic: > > // If we are asking for mod/ref info of a direct call with a pointer to a > // global we are tracking, return information if we have it. > if (GlobalValue *GV = const_cast<GlobalValue*>(getUnderlyingObject(P))) > if (GV->hasInternalLinkage()) > > So, no information is produced for external variables, the function calls > Aliasanalysis::getModRefInfo, which sees that called function may write to > memory, and returns true for all global variables. > > Anything I can do about it? What I what is minimally accurate information > about all global variables a function may modify. "Modifies them all" is > clearly not even minimally accurate.Oh ok, now I remember. The deal here is that "globals-modref" is supposed to be a very simple mod/ref analysis that does no "pointer analysis" at all. In particular, it only tracks globals that it knows "never have their address taken". If a global has non-internal linkage, the compiler can't know that something outside of the program doesn't take its address and pass around its address. While in this case, globals modref could handle this case, you really want something more powerful like -ds-aa. -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
On Monday 25 April 2005 23:40, Chris Lattner wrote:> On Mon, 25 Apr 2005, Vladimir Prus wrote: > > The GlobalsModRef::getModRefInfo has this logic: > > > > // If we are asking for mod/ref info of a direct call with a pointer > > to a // global we are tracking, return information if we have it. > > if (GlobalValue *GV > > const_cast<GlobalValue*>(getUnderlyingObject(P))) if > > (GV->hasInternalLinkage()) > > > > So, no information is produced for external variables, the function calls > > Aliasanalysis::getModRefInfo, which sees that called function may write > > to memory, and returns true for all global variables. > > > > Anything I can do about it? What I what is minimally accurate information > > about all global variables a function may modify. "Modifies them all" is > > clearly not even minimally accurate. > > Oh ok, now I remember. The deal here is that "globals-modref" is supposed > to be a very simple mod/ref analysis that does no "pointer analysis" at > all. In particular, it only tracks globals that it knows "never have > their address taken". If a global has non-internal linkage, the compiler > can't know that something outside of the program doesn't take its address > and pass around its address.Even if something outside of the current module has the address of the global, it cannot modify that global, because the control never leaves the current module, no?> While in this case, globals modref could handle this case, you really want > something more powerful like -ds-aa.I'm missed -ds-aa in the list of passes and now tried it. Seems to work fine even when variables are declared external. Thanks! - Volodya
On Tue, 26 Apr 2005, Vladimir Prus wrote:>> to be a very simple mod/ref analysis that does no "pointer analysis" at >> all. In particular, it only tracks globals that it knows "never have >> their address taken". If a global has non-internal linkage, the compiler >> can't know that something outside of the program doesn't take its address >> and pass around its address. > > Even if something outside of the current module has the address of the global, > it cannot modify that global, because the control never leaves the current > module, no?In this case, yes, obviously. ;) The problem is that the pass does not track this possibility. It is meant to be a very simple and quick pass that handles one thing well (non-address taken globals). For example, in this function: extern int P; int test(int *Q) { *Q = 1; return P; } It can't decide whether 'test' could modify P. In practice, MANY trivial cases like this exist where globals mod/ref can't answer, so it does not even attempt to track external globals. If you're interested in this, a more powerful algorithm like DSA should be used, or you could build a context-sensitive mod/ref follow-on pass that uses a non-context-sensitive alias analysis algorithm (like andersens or steensgaards) as its base. -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
Seemingly Similar Threads
- [LLVMdev] "Best" alias analysis algorithm
- [LLVMdev] "Best" alias analysis algorithm
- [LLVMdev] "Best" alias analysis algorithm
- [LLVMdev] BasicAliasAnalysis: constant does not alias with noalias parameter
- [LLVMdev] problem with using DSA for a side-effect analysis