[LLVMdev] Using Function Passes from Module Passes

Devang Patel dpatel at apple.com
Mon Dec 3 16:39:40 PST 2007


On Dec 3, 2007, at 2:59 PM, John Criswell wrote:

> Dear All,
>
> I'm having some problems using a function pass from a Module pass.  My
> code is as follows:
>
> DominatorTree & domTree;
> ...
> Function &F = *I; // I is an interator from using Module::begin()
> ...
> domTree = getAnalysis<DominatorTree>(F);
>
> When I compile this code, I get the following error:
>
>
> /home/vadve/criswell/src/llvm22/include/llvm/Pass.h: In member  
> function
> 'llvm::FunctionPass& llvm::FunctionPass::operator=(const
> llvm::FunctionPass&)':
> /home/vadve/criswell/src/llvm22/include/llvm/Pass.h:85: error: 'void
> llvm::Pass::operator=(const llvm::Pass&)' is private
> /home/vadve/criswell/src/llvm22/include/llvm/Pass.h:286: error: within
> this context
> /home/vadve/criswell/src/llvm22/include/llvm/Analysis/Dominators.h: In
> member function 'llvm::DominatorTree&
> llvm::DominatorTree::operator=(const llvm::DominatorTree&)':
> /home/vadve/criswell/src/llvm22/include/llvm/Analysis/Dominators.h: 
> 659:
> note: synthesized method 'llvm::FunctionPass&
> llvm::FunctionPass::operator=(const llvm::FunctionPass&)' first  
> required
> here
> /home/vadve/criswell/src/llvm22/projects/safecode/lib/ 
> ArrayBoundChecks/ArrayBoundCheck.cpp:
> In member function 'virtual bool
> llvm::ABC::ArrayBoundsCheck::runOnModule(llvm::Module&)':
> /home/vadve/criswell/src/llvm22/projects/safecode/lib/ 
> ArrayBoundChecks/ArrayBoundCheck.cpp:905:
> note: synthesized method 'llvm::DominatorTree&
> llvm::DominatorTree::operator=(const llvm::DominatorTree&)' first
> required here
>
> Does anyone know what I'm doing wrong?


No idea. To reproduce this, I tried following. But I did not get any  
compile time errors.
-
Devang


Index: DeadArgumentElimination.cpp
===================================================================
--- DeadArgumentElimination.cpp	(revision 44541)
+++ DeadArgumentElimination.cpp	(working copy)
@@ -31,6 +31,7 @@
  #include "llvm/Support/Debug.h"
  #include "llvm/ADT/Statistic.h"
  #include "llvm/Support/Compiler.h"
+#include "llvm/Analysis/Dominators.h"
  #include <set>
  using namespace llvm;

@@ -83,6 +84,10 @@

      virtual bool ShouldHackArguments() const { return false; }

+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<DominatorTree>();
+    }
+
    private:
      Liveness getArgumentLiveness(const Argument &A);
      bool isMaybeLiveArgumentNowLive(Argument *Arg);
@@ -280,6 +285,7 @@
  // well as arguments to functions which have their "address taken".
  //
  void DAE::SurveyFunction(Function &F) {
+  DominatorTree &DTDT = getAnalysis<DominatorTree>(F);
    bool FunctionIntrinsicallyLive = false;
    Liveness RetValLiveness = F.getReturnType() == Type::VoidTy ?  
Live : Dead;





More information about the llvm-dev mailing list