[llvm-commits] [llvm] r79631 - in /llvm/trunk/lib/Target/PIC16: AsmPrinter/PIC16AsmPrinter.cpp AsmPrinter/PIC16AsmPrinter.h MCSectionPIC16.h PIC16.h PIC16PAN.h PIC16Passes/Makefile PIC16Passes/PIC16FrameOverlay.cpp PIC16Passes/PIC16FrameOverlay.h PIC16TargetObjectFile.cpp PIC16TargetObjectFile.h

Sanjiv Gupta sanjiv.gupta at microchip.com
Fri Aug 21 08:22:34 PDT 2009


Author: sgupta
Date: Fri Aug 21 10:22:33 2009
New Revision: 79631

URL: http://llvm.org/viewvc/llvm-project?rev=79631&view=rev
Log:
Add a pass to do call graph analyis to overlay the autos and frame sections of 
leaf functions. This pass will be extended to color other nodes of the call tree 
as well in future.

Added:
    llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp
    llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h
Modified:
    llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
    llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
    llvm/trunk/lib/Target/PIC16/MCSectionPIC16.h
    llvm/trunk/lib/Target/PIC16/PIC16.h
    llvm/trunk/lib/Target/PIC16/PIC16PAN.h
    llvm/trunk/lib/Target/PIC16/PIC16Passes/Makefile
    llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.cpp
    llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.h

Modified: llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp?rev=79631&r1=79630&r2=79631&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp Fri Aug 21 10:22:33 2009
@@ -73,7 +73,7 @@
   DbgInfo.BeginFunction(MF);
 
   // Emit the autos section of function.
-  EmitAutos(CurrentFnName);
+  EmitAutos(F);
 
   // Now emit the instructions of function in its code section.
   const MCSection *fCodeSection = 
@@ -362,9 +362,10 @@
   const TargetData *TD = TM.getTargetData();
   // Emit the data section name.
   O << "\n"; 
-  
+ 
+  std::string SectionName = getObjFileLowering().getNameForFunctFrame(F);
   const MCSection *fPDataSection =
-    getObjFileLowering().getSectionForFunctionFrame(CurrentFnName);
+    getObjFileLowering().getSectionForFunctionFrame(SectionName); 
   OutStreamer.SwitchSection(fPDataSection);
   
   // Emit function frame label
@@ -440,12 +441,12 @@
   }
 }
 
-void PIC16AsmPrinter::EmitAutos(std::string FunctName) {
+void PIC16AsmPrinter::EmitAutos(const Function *F) {
   // Section names for all globals are already set.
   const TargetData *TD = TM.getTargetData();
 
   // Now print Autos section for this function.
-  std::string SectionName = PAN::getAutosSectionName(FunctName);
+  std::string SectionName = PAN::getAutosSectionName(CurrentFnName);
 
   // If this function is a cloned function then the name of auto section 
   // will not be present in the list of existing section. Hence this section
@@ -459,6 +460,15 @@
     if (AutosSections[i]->S_->getName() == SectionName) { 
       // Set the printing status to true
       AutosSections[i]->setPrintedStatus(true);
+      // Overlay auto sections with same function color.
+      std::string BaseSectionName = getObjFileLowering().
+                                    getNameForFunctFrame(F, true);
+      if (BaseSectionName != F->getName()) {
+        std::string NewSectionName = PAN::getAutosSectionName(BaseSectionName);
+        const_cast<MCSectionPIC16 *>(AutosSections[i]->S_)->setName(
+                                                            NewSectionName);
+      }
+
       OutStreamer.SwitchSection(AutosSections[i]->S_);
       const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items;
       for (unsigned j = 0; j < Items.size(); j++) {

Modified: llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h?rev=79631&r1=79630&r2=79631&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h (original)
+++ llvm/trunk/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h Fri Aug 21 10:22:33 2009
@@ -52,7 +52,7 @@
     void EmitDefinedVars (Module &M);
     void EmitIData (Module &M);
     void EmitUData (Module &M);
-    void EmitAutos (std::string FunctName);
+    void EmitAutos (const Function *F);
     void EmitRemainingAutos ();
     void EmitRomData (Module &M);
     void EmitFunctionFrame(MachineFunction &MF);

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

==============================================================================
--- llvm/trunk/lib/Target/PIC16/MCSectionPIC16.h (original)
+++ llvm/trunk/lib/Target/PIC16/MCSectionPIC16.h Fri Aug 21 10:22:33 2009
@@ -28,7 +28,8 @@
   public:
     
     const std::string &getName() const { return Name; }
-    
+
+    void setName(std::string name) { Name = name; }    
     static MCSectionPIC16 *Create(const StringRef &Name, 
                                   SectionKind K, MCContext &Ctx);
     

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

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16.h Fri Aug 21 10:22:33 2009
@@ -44,6 +44,7 @@
     UGE
   };
 }
+
   // External symbol names require memory to live till the program end.
   // So we have to allocate it and keep.
   inline static const char *createESName (const std::string &name) {

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

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16PAN.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16PAN.h Fri Aug 21 10:22:33 2009
@@ -22,8 +22,19 @@
 #include <cassert>
 #include <cstring>
 #include <string>
-
 namespace llvm {
+namespace PIC16Overlay {
+  // Implement Overlay through colors because we may want to enhance overlay
+  // architecture later. More colors can be added then. 
+  // Idea here is that functions with same color can be overlayed.
+  enum Overlay {
+    // A color name can only consist of upper case letters and underscore.
+    GREEN, // Stands for mainline functions that can be overlayed.
+    GREEN_IL, // Interrupt line version of GREEN.
+    RED // Stands for functions that can not be overlayed.
+  };
+}
+
   // A Central class to manage all ABI naming conventions.
   // PAN - [P]ic16 [A]BI [N]ames
   class PAN {
@@ -414,6 +425,27 @@
         }
       }
     }
+    inline static std::string getOverlayStr(unsigned Color) {
+      std::string Str = "Overlay=";
+      Str.append(getSectionNameForColor(Color));
+      return Str;
+    }
+
+    inline static std::string getSectionNameForColor(unsigned Color) {
+      switch (Color) {
+        case PIC16Overlay::GREEN:
+          return "GREEN";
+        case PIC16Overlay::GREEN_IL:
+          return "GREEN_IL";
+        default:
+          assert( 0 && "Color not supported");
+      }   
+    }
+
+    inline static std::string getAutosSectionForColor(std::string Color) {
+      return Color.append("_AUTOS");
+    }
+
   }; // class PAN.
 
 } // end namespace llvm;

Modified: llvm/trunk/lib/Target/PIC16/PIC16Passes/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Passes/Makefile?rev=79631&r1=79630&r2=79631&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/Makefile (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/Makefile Fri Aug 21 10:22:33 2009
@@ -12,5 +12,8 @@
 
 LOADABLE_MODULE = 1
 
+# Hack: we need to include 'main' pic16 target directory to grab private headers
+CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
+
 include $(LEVEL)/Makefile.common
 

Added: llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp?rev=79631&view=auto

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp (added)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp Fri Aug 21 10:22:33 2009
@@ -0,0 +1,69 @@
+//===-- PIC16FrameOverlay.cpp - Implementation for PIC16 Frame Overlay===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the PIC16 Frame Overlay implementation.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "llvm/Analysis/CallGraph.h"
+#include "llvm/Pass.h"
+#include "llvm/Module.h"
+#include "llvm/Support/raw_ostream.h"
+#include "PIC16.h"
+#include "PIC16FrameOverlay.h"
+#include <vector>
+#include <iostream>
+using namespace llvm;
+using std::vector;
+using std::string;
+
+
+void PIC16FrameOverlay::getAnalysisUsage(AnalysisUsage &AU) const {
+  AU.setPreservesCFG();
+  AU.addRequired<CallGraph>();
+}
+
+bool PIC16FrameOverlay::runOnModule(Module &M) {
+  CallGraph &CG = getAnalysis<CallGraph>();
+  for (CallGraph::iterator it = CG.begin() ; it != CG.end(); it++)
+  {
+    // External calling node doesn't have any function associated 
+    // with it
+    if (!it->first)
+      continue;
+
+    if (it->second->size() == 0) {
+      if (PAN::isInterruptLineFunction(it->first))
+        ColorFunction(it->second, PIC16Overlay::GREEN_IL);
+      else 
+        ColorFunction(it->second, PIC16Overlay::GREEN);
+    }
+  }
+  return false;
+}
+
+void PIC16FrameOverlay::ColorFunction(CallGraphNode *CGN, unsigned Color) {
+  switch (Color) {
+    case PIC16Overlay::GREEN:
+    case PIC16Overlay::GREEN_IL: {
+      Function *LeafFunct = CGN->getFunction();
+      std::string Section = "";
+      if (LeafFunct->hasSection()) {
+        Section = LeafFunct->getSection();
+        Section.append(" ");
+      }
+      Section.append(PAN::getOverlayStr(Color));
+      LeafFunct->setSection(Section);
+      break;
+    }
+    default:
+      assert( 0 && "Color not supported");   
+  }
+}

Added: llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h?rev=79631&view=auto

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h (added)
+++ llvm/trunk/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h Fri Aug 21 10:22:33 2009
@@ -0,0 +1,45 @@
+//===-- PIC16FrameOverlay.h - Interface for PIC16 Frame Overlay -*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the PIC16 Frame Overlay infrastructure.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PIC16FRAMEOVERLAY_H
+#define PIC16FRAMEOVERLAY_H
+ 
+#include "llvm/Analysis/CallGraph.h"
+#include "llvm/Pass.h"
+#include "llvm/Module.h"
+#include "llvm/Support/raw_ostream.h"
+#include <vector>
+#include <iostream>
+using std::vector;
+using std::string;
+using namespace llvm;
+
+namespace  { 
+
+  class PIC16FrameOverlay : public ModulePass { 
+  public:
+    static char ID; // Class identification 
+    PIC16FrameOverlay() : ModulePass(&ID)  {}
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const; 
+    virtual bool runOnModule(Module &M); 
+  private: 
+    void ColorFunction(CallGraphNode *CGN, unsigned Color);
+  };
+  char PIC16FrameOverlay::ID = 0;
+  static RegisterPass<PIC16FrameOverlay>
+  Y("pic16overlay", "PIC16 Frame Overlay Analysis");
+
+}  // End of  namespace
+
+#endif

Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.cpp?rev=79631&r1=79630&r2=79631&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.cpp Fri Aug 21 10:22:33 2009
@@ -82,6 +82,35 @@
   return getPIC16Section(T.c_str(), SectionKind::getDataRel());
 }
 
+std::string PIC16TargetObjectFile::getNameForFunctFrame(const Function *F,
+                                                          bool IsAutosSection) {
+  std::string SectionName = F->getName();
+  if (F->hasSection()) {
+    std::string Sectn = F->getSection();
+    std::string StrToFind = "Overlay=";
+    unsigned Pos = Sectn.find(StrToFind);
+    if (Pos != std::string::npos) {
+      Pos += StrToFind.length();
+      std::string Color = "";
+      char c = Sectn.at(Pos);
+      // A Color can only consist on upper case letters or underscore.
+      while ((c >= 'A' && c<= 'Z') || c == '_') {
+        Color.append(1,c);
+        Pos++;
+        if (Pos >= Sectn.length())
+          break;
+        c = Sectn.at(Pos);
+      }
+      // Autos Section need to be given a different name from function frame. 
+      if (IsAutosSection)
+        SectionName = PAN::getAutosSectionForColor(Color);
+      else
+        SectionName = Color;
+    }
+  }
+  return SectionName;
+}
+
 const MCSection *
 PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
   assert(GV->hasInitializer() && "This global doesn't need space");

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

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetObjectFile.h Fri Aug 21 10:22:33 2009
@@ -12,6 +12,7 @@
 
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Function.h"
 #include <vector>
 #include <string>
 
@@ -84,6 +85,9 @@
     // If the current function is cloned then create the new autos section
     // also. 
     void createClonedSectionForAutos(const std::string &SecName);
+    std::string getNameForFunctFrame(const Function *F, 
+                                     bool IsAutosSection = false); 
+
   private:
     std::string getSectionNameForSym(const std::string &Sym) const;
 





More information about the llvm-commits mailing list