blob: 24c11527b03c53b3e2a6d5dd863ff4acce30159f [file] [log] [blame]
Sanjiv Guptab57ba372010-02-17 01:11:53 +00001//===-- 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
20using namespace llvm;
21using std::vector;
22using std::string;
23using std::map;
24
25namespace 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 Guptad4ec6342010-02-17 18:11:29 +000051
52 // Clone the body of a function.
53 Function *cloneFunction(Function *F);
Sanjiv Guptab57ba372010-02-17 01:11:53 +000054
Sanjiv Guptabd426bb2010-02-18 17:32:25 +000055 // Clone all shared functions.
56 void cloneSharedFunctions(CallGraphNode *isrCGN);
57
Sanjiv Gupta18c7a182010-02-18 18:00:35 +000058 // Remap all call sites to the shared function.
59 void remapAllSites(Function *Caller, Function *OrgF, Function *Clone);
60
Sanjiv Guptab57ba372010-02-17 01:11:53 +000061 // 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 Guptad4ec6342010-02-17 18:11:29 +000076
77 // Map of a already cloned functions.
78 map<Function *, Function *> ClonedFunctionMap;
79 typedef map<Function *, Function *>::iterator cloned_map_iterator;
Sanjiv Guptab57ba372010-02-17 01:11:53 +000080 };
81} // End of anonymous namespace
82
83#endif