[LLVMdev] Error when trying to chain two llvm transform passes
Krzysztof Parzyszek
kparzysz at codeaurora.org
Tue Oct 30 16:15:06 PDT 2012
On 10/30/2012 5:35 PM, Ashwin kumar wrote:
>
>
> No. I am not sure how they work . I am trying to use the INITIALIZE_PASS
> macro. I get the following error
>
>
> *error: definition or redeclaration of 'initializeMyPassNamePass' not in
> a namespace enclosing 'llvm' *
> *
> *
>
>
> should i add the passname to a header file ? if so where?
The easiest way is to "cheat" and see how existing code does it. :)
Take, dead store elimination, for example:
In DeadStoreElimination.cpp, there is
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
AU.addRequired<DominatorTree>();
AU.addRequired<AliasAnalysis>();
AU.addRequired<MemoryDependenceAnalysis>();
AU.addPreserved<AliasAnalysis>();
AU.addPreserved<DominatorTree>();
AU.addPreserved<MemoryDependenceAnalysis>();
}
and
INITIALIZE_PASS_BEGIN(DSE, "dse", "Dead Store Elimination", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceAnalysis)
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
INITIALIZE_PASS_END(DSE, "dse", "Dead Store Elimination", false, false)
The macros will generate a function called "initializeDSEPass".
Now, in the same file, in the constructor, there is a call to it:
DSE() : FunctionPass(ID), AA(0), MD(0), DT(0) {
initializeDSEPass(*PassRegistry::getPassRegistry());
}
Now you can grep the sources to see if the "initializeDSEPass" is in any
header. In my source tree, it's in:
include/llvm/InitializePasses.h
lib/Transforms/Scalar/DeadStoreElimination.cpp
lib/Transforms/Scalar/Scalar.cpp
In InitializePasses.h there is a namespace "llvm" with all the
initialization functions listed in it. For a particular pass, the other
occurrences may differ slightly, but this is the core of what you need.
You don't really need to use RegisterPass. I only found two places that
use it and they both are in the code generation.
-Krzysztof
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
More information about the llvm-dev
mailing list