Detemplatize the Statistic class. The only type it is instantiated with
[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 #include "llvm/Pass.h"
16 #include "llvm/Function.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/Support/SlowOperationInformer.h"
19 #include "llvm/Support/Streams.h"
20 #include "llvm/ADT/Statistic.h"
21 using namespace llvm;
22
23 namespace {
24   Statistic HelloCounter("hellocount",
25       "Counts number of functions greeted");
26   // Hello - The first implementation, without getAnalysisUsage.
27   struct Hello : public FunctionPass {
28     virtual bool runOnFunction(Function &F) {
29       SlowOperationInformer soi("EscapeString");
30       HelloCounter++;
31       std::string fname = F.getName();
32       EscapeString(fname);
33       llvm_cerr << "Hello: " << fname << "\n";
34       return false;
35     }
36   };
37   RegisterPass<Hello> X("hello", "Hello World Pass");
38
39   // Hello2 - The second implementation with getAnalysisUsage implemented.
40   struct Hello2 : public FunctionPass {
41     virtual bool runOnFunction(Function &F) {
42       SlowOperationInformer soi("EscapeString");
43       HelloCounter++;
44       std::string fname = F.getName();
45       EscapeString(fname);
46       llvm_cerr << "Hello: " << fname << "\n";
47       return false;
48     }
49
50     // We don't modify the program, so we preserve all analyses
51     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
52       AU.setPreservesAll();
53     };
54   };
55   RegisterPass<Hello2> Y("hello2",
56                         "Hello World Pass (with getAnalysisUsage implemented)");
57 }