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

Sanjiv Gupta sanjiv.gupta at microchip.com
Tue Feb 16 22:48:50 PST 2010


Author: sgupta
Date: Wed Feb 17 00:48:50 2010
New Revision: 96465

URL: http://llvm.org/viewvc/llvm-project?rev=96465&view=rev
Log:
Added a function to clone locals of a function.( which for pic16 are globals
with mangled names).

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

Modified: llvm/trunk/lib/Target/PIC16/PIC16ABINames.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16ABINames.h?rev=96465&r1=96464&r2=96465&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16ABINames.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16ABINames.h Wed Feb 17 00:48:50 2010
@@ -338,6 +338,22 @@
     inline static std::string getISRAddr(void) {
       return "0x4";
     }
+
+    // Returns the name of clone of a function.
+    static std::string getCloneFnName(const std::string &Func) {
+       return (Func + ".IL");
+    }
+
+    // Returns the name of clone of a variable.
+    static std::string getCloneVarName(const std::string &Fn, 
+                                       const std::string &Var) {
+      std::string cloneVarName = Var;
+      // These vars are named like fun.auto.var.
+      // Just replace the function name, with clone function name.
+      std::string cloneFnName = getCloneFnName(Fn);
+      cloneVarName.replace(cloneVarName.find(Fn), Fn.length(), cloneFnName);
+      return cloneVarName;
+    }
   }; // class PAN.
 } // end namespace llvm;
 

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=96465&r1=96464&r2=96465&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16Cloner.cpp Wed Feb 17 00:48:50 2010
@@ -124,7 +124,37 @@
 // Cloning the code of function itself.
 //
 void PIC16Cloner::CloneAutos(Function *F) {
-  // Not implemented yet.
+  // We'll need to update module's globals list as well. So keep a reference
+  // handy.
+  Module *M = F->getParent();
+  Module::GlobalListType &Globals = M->getGlobalList();
+
+  // Clear the leftovers in ValueMap by any previous cloning.
+  ValueMap.clear();
+
+  // Find the auto globls for this function and clone them, and put them
+  // in ValueMap.
+  std::string FnName = F->getName().str();
+  std::string VarName, ClonedVarName;
+  for (Module::global_iterator I = M->global_begin(), E = M->global_end();
+       I != E; ++I) {
+    VarName = I->getName().str();
+    if (PAN::isLocalToFunc(FnName, VarName)) {
+      // Auto variable for current function found. Clone it.
+      GlobalVariable *GV = I;
+
+      const Type *InitTy = GV->getInitializer()->getType();
+      GlobalVariable *ClonedGV = 
+        new GlobalVariable(InitTy, false, GV->getLinkage(), 
+                           GV->getInitializer());
+      ClonedGV->setName(PAN::getCloneVarName(FnName, VarName));
+      // Add these new globals to module's globals list.
+      Globals.push_back(ClonedGV);
+ 
+      // Update ValueMap.
+      ValueMap[GV] = ClonedGV;
+     }
+  }
 }
 
 





More information about the llvm-commits mailing list