Chris Lattner | 180e568 | 2002-08-08 20:10:38 +0000 | [diff] [blame] | 1 | //===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===// |
| 2 | // |
| 3 | // This file implements two versions of the LLVM "Hello World" pass described |
| 4 | // in docs/WritingAnLLVMPass.html |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | #include "llvm/Pass.h" |
| 9 | #include "llvm/Function.h" |
| 10 | |
| 11 | namespace { |
| 12 | // Hello - The first implementation, without getAnalysisUsage. |
| 13 | struct Hello : public FunctionPass { |
| 14 | virtual bool runOnFunction(Function &F) { |
| 15 | std::cerr << "Hello: " << F.getName() << "\n"; |
| 16 | return false; |
| 17 | } |
| 18 | }; |
| 19 | RegisterOpt<Hello> X("hello", "Hello World Pass"); |
| 20 | |
| 21 | // Hello2 - The second implementation with getAnalysisUsage implemented. |
| 22 | struct Hello2 : public FunctionPass { |
| 23 | virtual bool runOnFunction(Function &F) { |
| 24 | std::cerr << "Hello: " << F.getName() << "\n"; |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | // We don't modify the program, so we preserve all analyses |
| 29 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 30 | AU.setPreservesAll(); |
| 31 | }; |
| 32 | }; |
| 33 | RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)"); |
| 34 | } |