Sanjiv Gupta | b57ba37 | 2010-02-17 01:11:53 +0000 | [diff] [blame] | 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); |
Sanjiv Gupta | d4ec634 | 2010-02-17 18:11:29 +0000 | [diff] [blame] | 51 | |
| 52 | // Clone the body of a function. |
| 53 | Function *cloneFunction(Function *F); |
Sanjiv Gupta | b57ba37 | 2010-02-17 01:11:53 +0000 | [diff] [blame] | 54 | |
Sanjiv Gupta | bd426bb | 2010-02-18 17:32:25 +0000 | [diff] [blame] | 55 | // Clone all shared functions. |
| 56 | void cloneSharedFunctions(CallGraphNode *isrCGN); |
| 57 | |
Sanjiv Gupta | 18c7a18 | 2010-02-18 18:00:35 +0000 | [diff] [blame] | 58 | // Remap all call sites to the shared function. |
| 59 | void remapAllSites(Function *Caller, Function *OrgF, Function *Clone); |
| 60 | |
Sanjiv Gupta | b57ba37 | 2010-02-17 01:11:53 +0000 | [diff] [blame] | 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 | DenseMap<const Value*, Value*> ValueMap; |
Sanjiv Gupta | d4ec634 | 2010-02-17 18:11:29 +0000 | [diff] [blame] | 76 | |
| 77 | // Map of a already cloned functions. |
| 78 | map<Function *, Function *> ClonedFunctionMap; |
| 79 | typedef map<Function *, Function *>::iterator cloned_map_iterator; |
Sanjiv Gupta | b57ba37 | 2010-02-17 01:11:53 +0000 | [diff] [blame] | 80 | }; |
| 81 | } // End of anonymous namespace |
| 82 | |
| 83 | #endif |