summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PIC16/PIC16Passes
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2009-08-21 15:22:33 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2009-08-21 15:22:33 +0000
commit9ae3bcb79eb1fcbea887acd533b310d6f34ca065 (patch)
treebb99bd15fab32fe980a7f0815d1ab104f72fee3c /llvm/lib/Target/PIC16/PIC16Passes
parent37fd02c5a1a21ff880fb87d28e9c974c8187f31c (diff)
downloadbcm5719-llvm-9ae3bcb79eb1fcbea887acd533b310d6f34ca065.tar.gz
bcm5719-llvm-9ae3bcb79eb1fcbea887acd533b310d6f34ca065.zip
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. llvm-svn: 79631
Diffstat (limited to 'llvm/lib/Target/PIC16/PIC16Passes')
-rw-r--r--llvm/lib/Target/PIC16/PIC16Passes/Makefile3
-rw-r--r--llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp69
-rw-r--r--llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h45
3 files changed, 117 insertions, 0 deletions
diff --git a/llvm/lib/Target/PIC16/PIC16Passes/Makefile b/llvm/lib/Target/PIC16/PIC16Passes/Makefile
index 919562106a1..61b43623a19 100644
--- a/llvm/lib/Target/PIC16/PIC16Passes/Makefile
+++ b/llvm/lib/Target/PIC16/PIC16Passes/Makefile
@@ -12,5 +12,8 @@ TARGET = PIC16
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
diff --git a/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp b/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp
new file mode 100644
index 00000000000..cfeb97d6e7e
--- /dev/null
+++ b/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.cpp
@@ -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");
+ }
+}
diff --git a/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h b/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h
new file mode 100644
index 00000000000..813ceba063b
--- /dev/null
+++ b/llvm/lib/Target/PIC16/PIC16Passes/PIC16FrameOverlay.h
@@ -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
OpenPOWER on IntegriCloud