1 //===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements two versions of the LLVM "Hello World" pass described
11 // in docs/WritingAnLLVMPass.html
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Pass.h"
16 #include "llvm/Function.h"
20 // Hello - The first implementation, without getAnalysisUsage.
21 struct Hello : public FunctionPass {
22 virtual bool runOnFunction(Function &F) {
23 std::cerr << "Hello: " << F.getName() << "\n";
27 RegisterOpt<Hello> X("hello", "Hello World Pass");
29 // Hello2 - The second implementation with getAnalysisUsage implemented.
30 struct Hello2 : public FunctionPass {
31 virtual bool runOnFunction(Function &F) {
32 std::cerr << "Hello: " << F.getName() << "\n";
36 // We don't modify the program, so we preserve all analyses
37 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41 RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");