[LLVMdev] Functions: sret and readnone
Stephan
stephan.reiter at gmail.com
Fri Nov 6 04:19:20 PST 2009
Duncan, thanks for your answer!
> In order to perform this transform the optimizers would have to work out
> that sample does not modify any global state. This cannot be done without
> knowing the definition of sample, but you only provide a declaration.
Which is why I am trying to supply this additional information in a
custom alias analysis pass, but it doesn't seem to work. (The
AAEvalPass stats are precisely for this custom pass.)
Could you take a look at the code, please? Am I missing something
here?
class VISIBILITY_HIDDEN MySretAliasAnalysis : public FunctionPass,
public AliasAnalysis
{
std::map<std::string, bool> _srets;
public:
static char ID;
MySretAliasAnalysis() : FunctionPass(&ID)
{
_srets["sample$int$float2"] = true;
_srets["sample$int$float3"] = true;
}
void getAnalysisUsage(llvm::AnalysisUsage &usage) const
{
AliasAnalysis::getAnalysisUsage(usage);
usage.setPreservesAll();
}
bool runOnFunction(Function &F)
{
AliasAnalysis::InitializeAliasAnalysis(this);
return false;
}
ModRefBehavior getModRefBehavior(CallSite CS,
std::vector<PointerAccessInfo> *Info = 0)
{
if(_srets.find(CS.getCalledFunction()->getName()) != _srets.end())
return AliasAnalysis::AccessesArguments; // only accesses args, no
globals
return AliasAnalysis::getModRefBehavior(CS, Info);
}
ModRefBehavior getModRefBehavior(Function *F,
std::vector<PointerAccessInfo> *Info = 0)
{
if(_srets.find(F->getName()) != _srets.end())
return AliasAnalysis::AccessesArguments; // only accesses args, no
globals
return AliasAnalysis::getModRefBehavior(F, Info);
}
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size)
{
std::string functionName = CS.getCalledFunction()->getNameStr();
if(_srets.find(functionName) != _srets.end())
{
if(CS.hasArgument(P))
{
if(CS.getArgument(0) == P)
return AliasAnalysis::Mod; // modify value pointed to by sret
param
else
return AliasAnalysis::NoModRef; // there aren't any other pointer
args
}
}
return AliasAnalysis::getModRefInfo(CS, P, Size);
}
bool hasNoModRefInfoForCalls() const { return false; }
};
> If you provided a body too then the GlobalsModRef analysis might be able to
> work it out.
That's not an option because I want the sample function to be resolved
as an external function by the jitter.
Thanks for your time,
Stephan
More information about the llvm-dev
mailing list