Remove use of SlowOperationInformer.
[oota-llvm.git] / lib / Transforms / Hello / Hello.cpp
1 //===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements two versions of the LLVM "Hello World" pass described
11 // in docs/WritingAnLLVMPass.html
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "hello"
16 #include "llvm/Pass.h"
17 #include "llvm/Function.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/Support/Streams.h"
20 #include "llvm/ADT/Statistic.h"
21 using namespace llvm;
22
23 STATISTIC(HelloCounter, "Counts number of functions greeted");
24
25 namespace {
26   // Hello - The first implementation, without getAnalysisUsage.
27   struct Hello : public FunctionPass {
28     virtual bool runOnFunction(Function &F) {
29       HelloCounter++;
30       std::string fname = F.getName();
31       EscapeString(fname);
32       cerr << "Hello: " << fname << "\n";
33       return false;
34     }
35   };
36   RegisterPass<Hello> X("hello", "Hello World Pass");
37
38   // Hello2 - The second implementation with getAnalysisUsage implemented.
39   struct Hello2 : public FunctionPass {
40     virtual bool runOnFunction(Function &F) {
41       HelloCounter++;
42       std::string fname = F.getName();
43       EscapeString(fname);
44       cerr << "Hello: " << fname << "\n";
45       return false;
46     }
47
48     // We don't modify the program, so we preserve all analyses
49     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
50       AU.setPreservesAll();
51     };
52   };
53   RegisterPass<Hello2> Y("hello2",
54                         "Hello World Pass (with getAnalysisUsage implemented)");
55 }