Initial implementation of PIC16 Cloner pass.
[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/DenseMap.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     // Error reporting for PIC16Pass
53     void reportError(string ErrorString, vector<string> &Values);
54     void reportError(string ErrorString);
55
56   private:  //data
57     // Records if the interrupt function has already been found.
58     // If more than one interrupt function is found then an error
59     // should be thrown.
60     bool foundISR;
61
62     // This ValueMap maps the auto variables of the original functions with
63     // the corresponding cloned auto variable of the cloned function. 
64     // This value map is passed during the function cloning so that all the
65     // uses of auto variables be updated properly. 
66     DenseMap<const Value*, Value*> ValueMap;
67   };
68 }  // End of anonymous namespace
69
70 #endif