1 //===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
3 // This file implements two versions of the LLVM "Hello World" pass described
4 // in docs/WritingAnLLVMPass.html
6 //===----------------------------------------------------------------------===//
9 #include "llvm/Function.h"
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";
19 RegisterOpt<Hello> X("hello", "Hello World Pass");
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";
28 // We don't modify the program, so we preserve all analyses
29 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
33 RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");