Revert r110396 to fix buildbots.
[oota-llvm.git] / lib / Target / PIC16 / PIC16Passes / PIC16Cloner.h
1 //===-- PIC16Cloner.h - PIC16 LLVM Cloner for shared functions --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains declaration of a cloner class clone all functions that 
11 // are shared between the main line code (ML) and interrupt line code (IL).
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef PIC16CLONER_H
16 #define PIC16CLONER_H
17
18 #include "llvm/ADT/ValueMap.h"
19
20 using namespace llvm;
21 using std::vector;
22 using std::string;
23 using std::map;
24
25 namespace llvm {
26   // forward classes.
27   class Value;
28   class Function;
29   class Module;
30   class ModulePass;
31   class CallGraph;
32   class CallGraphNode;
33   class AnalysisUsage;
34
35   class PIC16Cloner : public ModulePass { 
36   public:
37     static char ID; // Class identification 
38     PIC16Cloner() : ModulePass(&ID)  {}
39
40     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41       AU.addRequired<CallGraph>();
42     }
43     virtual bool runOnModule(Module &M);
44
45   private: // Functions
46     // Mark reachable functions for the MainLine or InterruptLine.
47     void markCallGraph(CallGraphNode *CGN, string StringMark);
48
49     // Clone auto variables of function specified.
50     void CloneAutos(Function *F);
51    
52     // Clone the body of a function.
53     Function *cloneFunction(Function *F);
54
55     // Clone all shared functions.
56     void cloneSharedFunctions(CallGraphNode *isrCGN);
57
58     // Remap all call sites to the shared function.
59     void remapAllSites(Function *Caller, Function *OrgF, Function *Clone);
60
61     // Error reporting for PIC16Pass
62     void reportError(string ErrorString, vector<string> &Values);
63     void reportError(string ErrorString);
64
65   private:  //data
66     // Records if the interrupt function has already been found.
67     // If more than one interrupt function is found then an error
68     // should be thrown.
69     bool foundISR;
70
71     // This ValueMap maps the auto variables of the original functions with
72     // the corresponding cloned auto variable of the cloned function. 
73     // This value map is passed during the function cloning so that all the
74     // uses of auto variables be updated properly. 
75     ValueMap<const Value*, Value*> VMap;
76
77     // Map of a already cloned functions. 
78     map<Function *, Function *> ClonedFunctionMap;
79     typedef map<Function *, Function *>::iterator cloned_map_iterator;
80   };
81 }  // End of anonymous namespace
82
83 #endif