[llvm-commits] [llvm] r96485 - in /llvm/trunk/lib/Target/PIC16/PIC16Passes: PIC16Cloner.cpp PIC16Cloner.h

Sanjiv Gupta sanjiv.gupta at microchip.com
Wed Feb 17 10:11:29 PST 2010


Author: sgupta
Date: Wed Feb 17 12:11:29 2010
New Revision: 96485

URL: http://llvm.org/viewvc/llvm-project?rev=96485&view=rev
Log:
Added routine to clone the body of a function and maintain a map of already
cloned functions.

Modified:
    llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp
    llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.h

Modified: llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp?rev=96485&r1=96484&r2=96485&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp Wed Feb 17 12:11:29 2010
@@ -212,3 +212,41 @@
   } // end of loop of all called functions.
 }
 
+// Clone the given function and return it.
+// Note: it uses the ValueMap member of the class, which is already populated
+// by cloneAutos by the time we reach here. 
+// FIXME: Should we just pass ValueMap's ref as a parameter here? rather
+// than keeping the ValueMap as a member.
+Function *
+PIC16Cloner::cloneFunction(Function *OrgF) {
+   Function *ClonedF;
+
+   // See if we already cloned it. Return that. 
+   cloned_map_iterator cm_it = ClonedFunctionMap.find(OrgF);
+   if(cm_it != ClonedFunctionMap.end()) {
+     ClonedF = cm_it->second;
+     return ClonedF;
+   }
+
+   // Clone does not exist. 
+   // First clone the autos, and populate ValueMap.
+   CloneAutos(OrgF);
+
+   // Now create the clone.
+   ClonedF = CloneFunction(OrgF, ValueMap);
+
+   // The new function should be for interrupt line. Therefore should have 
+   // the name suffixed with IL and section attribute marked with IL. 
+   ClonedF->setName(PAN::getCloneFnName(OrgF->getName()));
+   ClonedF->setSection("IL");
+
+   // Add the newly created function to the module.
+   OrgF->getParent()->getFunctionList().push_back(ClonedF);
+
+   // Update the ClonedFunctionMap to record this cloning activity.
+   ClonedFunctionMap[OrgF] = ClonedF;
+
+   return ClonedF;
+}
+
+

Modified: llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.h?rev=96485&r1=96484&r2=96485&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.h Wed Feb 17 12:11:29 2010
@@ -48,6 +48,9 @@
 
     // Clone auto variables of function specified.
     void CloneAutos(Function *F);
+   
+    // Clone the body of a function.
+    Function *cloneFunction(Function *F);
 
     // Error reporting for PIC16Pass
     void reportError(string ErrorString, vector<string> &Values);
@@ -64,6 +67,10 @@
     // This value map is passed during the function cloning so that all the
     // uses of auto variables be updated properly. 
     DenseMap<const Value*, Value*> ValueMap;
+
+    // Map of a already cloned functions. 
+    map<Function *, Function *> ClonedFunctionMap;
+    typedef map<Function *, Function *>::iterator cloned_map_iterator;
   };
 }  // End of anonymous namespace
 





More information about the llvm-commits mailing list