[LLVMdev] pass utilizing MemoryDependenceAnalysis?

Devang Patel dpatel at apple.com
Mon Oct 17 09:38:05 PDT 2011


On Oct 14, 2011, at 8:07 PM, ret val wrote:

> This gives me: Assertion failed: (0 && "Unable to find on the fly
> pass"), function getOnTheFlyPass, file PassManager.cpp
> 
> #include "llvm/Module.h"
> #include "llvm/Analysis/MemoryDependenceAnalysis.h"
> #include "llvm/Support/raw_ostream.h"
> using namespace llvm;
> 
> struct Hello: public FunctionPass {	


Now your pass is no longer a ModulePass!

If Hello is a FunctionPass then you try MemoryDependenceAnalysis *MD = &getAnalysis<MemoryDependenceAnalysis>()
If Hello is a ModulePass then you try if (!F.isDeclaration()) MemoryDependenceAnalysis *MD = &getAnalysis<MemoryDependenceAnalysis>(F)

-
Devang

> public:
> 	static char ID;
> 
> 	Hello(): FunctionPass(ID) {
> 		;;
> 	}
> 	
> 	virtual void getAnalysisUsage(AnalysisUsage &AU) const {
> 		AU.addRequired<MemoryDependenceAnalysis>();
> 		errs() << "addRequired called\n";
> 	}
> 
> 	virtual bool runOnFunction(Function &F) {
> 		if(F.isDeclaration() == true)
> 			return false;
> 		
> 		MemoryDependenceAnalysis *MD = &getAnalysis<MemoryDependenceAnalysis>(F);
> 		for(Function::iterator i = F.begin(); i != F.end(); ++i) {
> 			for(BasicBlock::iterator j = i->begin(); j != i->end(); ++j) {
> 				i->dump();
> 			}
> 		}
> 
> 		return false;
> 	}
> };
> 
> char Hello::ID = 0;
> static RegisterPass<Hello> X("hello", "Hello World Pass");
> 
> On Fri, Oct 14, 2011 at 10:47 AM, John Criswell <criswell at illinois.edu> wrote:
>> In runOnFunction(), you should check to see if the function F is a
>> declaration before calling getAnalysis(F).  Calling
>> getAnalysis<FunctionPass>() on a function that is a declaration will trigger
>> an assertion if the function is just a declaration.
>> 
>> To see if a function is a declaration, call its isDeclaration() method (i.e.
>> if (F->isDeclaration()) ... )
>> 
>> -- John T.
>> 
>> 
>> On 10/13/11 8:09 PM, ret val wrote:
>>> 
>>> #include "llvm/Module.h"
>>> #include "llvm/Analysis/MemoryDependenceAnalysis.h"
>>> #include "llvm/Support/raw_ostream.h"
>>> using namespace llvm;
>>> 
>>> struct Hello: public ModulePass {
>>> public:
>>>        static char ID;
>>>        MemoryDependenceAnalysis *MD;
>>> 
>>>        Hello(): ModulePass(ID) {
>>>                ;;
>>>        }
>>> 
>>>        virtual void getAnalysisUsage(AnalysisUsage&AU) const {
>>>                AU.addRequired<MemoryDependenceAnalysis>();
>>>                errs()<<  "addRequired called\n";
>>>        }
>>> 
>>>        virtual bool runOnModule(Module&M) {
>>>                for(Module::iterator f = M.begin(); f != M.end(); ++f)
>>>                        runOnFunction(*f, M);
>>> 
>>>                return false;
>>>        }
>>> 
>>> private:
>>>        bool runOnFunction(Function&F, Module&M) {
>>>                MD =&getAnalysis<MemoryDependenceAnalysis>(F);
>>>                for(Function::iterator i = F.begin(); i != F.end(); ++i) {
>>>                        for(BasicBlock::iterator j = i->begin(); j !=
>>> i->end(); ++j) {
>>>                                ;;
>>>                        }
>>>                }
>>> 
>>>                return false;
>>>        }
>>> };
>>> 
>>> char Hello::ID = 0;
>>> static RegisterPass<Hello>  X("hello", "Hello World Pass");
>>> 
>>> 
>>> On Thu, Oct 13, 2011 at 7:14 PM, ret val<retval386 at gmail.com>  wrote:
>>>> 
>>>> My pass(that I want to use MemoryDependenceAnalysis) is a ModulePass.
>>>> When I changed my assignment to:
>>>>        MD =&getAnalysis<MemoryDependenceAnalysis>(F);
>>>> 
>>>> It fixed my initial problem but left me with:
>>>>        Assertion failed: (ResultPass&&  "Unable to find requested
>>>> analysis info"), function getAnalysisID
>>>> 
>>>> 
>>>> On Thu, Oct 13, 2011 at 1:43 PM, ret val<retval386 at gmail.com>  wrote:
>>>>> 
>>>>> I wrote a pass(that is to be loaded by opt) that I would like to use
>>>>> in conjunction with MemoryDependenceAnalysis. I have tried using by
>>>>> including its header and adding this to my pass:
>>>>>        virtual void getAnalysisUsage(AnalysisUsage&AU) const {
>>>>>         errs()<<  "addRequired called\n";
>>>>>         AU.addRequired<MemoryDependenceAnalysis>();
>>>>>        }
>>>>> 
>>>>> And in my runOnFunction() method I have:
>>>>>        MD =&getAnalysis<MemoryDependenceAnalysis>();
>>>>> 
>>>>> The results in:
>>>>>        addRequired called
>>>>>        Assertion failed: (ResultPass&&  "getAnalysis*() called on an
>>>>> analysis that was not " "'required' by pass!"), function getAnalysisID
>>>>> 
>>>>> I do not know why. I noticed the DeadStoreElimination pass also uses
>>>>> this, but it does not use RegisterPass (like mine and the docs show).
>>>>> Instead it has lines like:
>>>>>        INITIALIZE_PASS_DEPENDENCY(MemoryDependenceAnalysis)
>>>>> 
>>>>> This gives me:
>>>>>        error: C++ requires a type specifier for all declarations
>>>>> 
>>>>> What is the correct way todo this?
>>>>> 
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> 
>> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list