llvm.org GIT mirror llvm / 3dfe610
Revert r79563 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79691 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
2 changed file(s) with 0 addition(s) and 177 deletion(s). Raw diff Collapse all Expand all
+0
-16
lib/Target/PIC16/PIC16Passes/Makefile less more
None ##===- lib/Target/PIC16/Makefile ---------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 LEVEL = ../../../..
9 LIBRARYNAME = PIC16Passes
10 TARGET = PIC16
11
12 LOADABLE_MODULE = 1
13
14 include $(LEVEL)/Makefile.common
15
+0
-161
lib/Target/PIC16/PIC16Passes/PIC16CallGraph.cpp less more
None #include "llvm/Analysis/CallGraph.h"
1 #include "llvm/Pass.h"
2 #include "llvm/Module.h"
3 #include "llvm/Transforms/Utils/Cloning.h"
4 #include "llvm/Support/ErrorHandling.h"
5 #include "llvm/Support/raw_ostream.h"
6 #include
7 using namespace llvm;
8 using std::vector;
9 using std::string;
10
11 namespace {
12 class PIC16CallGraph : public ModulePass {
13 public:
14 static char ID; // Class identification
15 PIC16CallGraph() : ModulePass(&ID) {}
16
17 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
18 AU.setPreservesAll();
19 AU.addRequired();
20 }
21 virtual bool runOnModule(Module &M) {
22 // Initially record that no interrupt has been found
23 InterruptFound = false;
24
25 CallGraph &CG = getAnalysis();
26 for (CallGraph::iterator it = CG.begin() ; it != CG.end(); it++)
27 {
28 // External calling node doesn't have any function associated
29 // with it
30 if (!it->first)
31 continue;
32
33 if (it->first->getName().str() == "main") {
34 // See if the main itself is interrupt function then report an error.
35 if (it->first->getSection().find("interrupt") != string::npos)
36 reportError("Function 'main' can't be interrupt function");
37 else {
38 // Set the MainLine tag for function main also.
39 it->second->getFunction()->setSection("ML");
40 // mark the hierarchy
41 markFunctionHierarchy(it->second, "ML");
42 }
43 } else if (it->first->getSection().find("interrupt") != string::npos) {
44 if (InterruptFound)
45 reportError("More than one interrupt functions defined in the module");
46
47 InterruptFound = true;
48 markFunctionHierarchy(it->second, "IL");
49 }
50 }
51 return false;
52 }
53 private: // Functions
54 // Makr function hierarchy for the MainLine or InterruptLine.
55 void markFunctionHierarchy(CallGraphNode *CGN, string StringMark);
56
57 // Error reporting for PIC16Pass
58 void reportError(string ErrorString, vector &Values);
59 void reportError(string ErrorString);
60 private: // Data
61 // Records if the interrupt function has already been found.
62 // If more than one interrupt function is found then an error
63 // should be thrown.
64 bool InterruptFound;
65 };
66 char PIC16CallGraph::ID =0;
67 static RegisterPass
68 Y("pic16cg", "PIC16 CallGraph Construction");
69
70 } // End of anonymous namespace
71
72 void PIC16CallGraph::reportError(string ErrorString) {
73 errs() << "ERROR : " << ErrorString << "\n";
74 exit(1);
75 }
76
77 void PIC16CallGraph::
78 reportError (string ErrorString, vector &Values) {
79 unsigned ValCount = Values.size();
80 string TargetString;
81 for (unsigned i=0; i
82 TargetString = "%";
83 TargetString += ((char)i + '0');
84 ErrorString.replace(ErrorString.find(TargetString), TargetString.length(), Values[i]);
85 }
86 errs() << "ERROR : " << ErrorString << "\n";
87 exit(1);
88 //llvm_report_error(ErrorString);
89 }
90
91 void PIC16CallGraph::
92 markFunctionHierarchy(CallGraphNode *CGN, string StringMark) {
93 string AlternateMark;
94 string SharedMark = "SL";
95 if (StringMark == "ML")
96 AlternateMark = "IL";
97 else
98 AlternateMark = "ML";
99
100 // Mark all the called functions
101 for(CallGraphNode::iterator cgn_it = CGN->begin();
102 cgn_it != CGN->end(); ++cgn_it) {
103 Function *CalledF = cgn_it->second->getFunction();
104
105 // If calling an external function then CallGraphNode
106 // will not be associated with any function.
107 if (!CalledF)
108 continue;
109
110 // Issue diagnostic if interrupt function is being called.
111 if (CalledF->getSection().find("interrupt") != string::npos) {
112 vector Values;
113 Values.push_back(CalledF->getName().str());
114 reportError("Interrupt function (%0) can't be called", Values);
115 }
116
117 // If already shared mark then no need to check any further.
118 // Also a great potential for recursion.
119 if (CalledF->getSection().find(SharedMark) != string::npos) {
120 continue;
121 }
122
123 // Has already been mark
124 if (CalledF->getSection().find(StringMark) != string::npos) {
125 // Issue diagnostic
126 // Potential for recursion.
127 } else {
128 // Mark now
129 if (CalledF->getSection().find(AlternateMark) != string::npos) {
130 // Function is alternatively marked. It should be a shared one.
131
132 // Shared functions should be clone. Clone here.
133 Function *ClonedFunc = CloneFunction(CalledF);
134
135 // Add the newly created function to the module.
136 CalledF->getParent()->getFunctionList().push_back(ClonedFunc);
137
138 // The new function should be for interrupt line. Therefore should have the
139 // name suffixed with IL and section attribute marked with IL.
140 ClonedFunc->setName(CalledF->getName().str() + ".IL");
141 ClonedFunc->setSection("IL");
142
143 // Original function now should be for MainLine only.
144 CalledF->setSection("ML");
145
146 // Update the CallSite
147 CallSite CS = cgn_it->first;
148 CS.getInstruction()->getOperand(0)->setName(CalledF->getName().str() + ".shared");
149 } else {
150 // Function is not marked. It should be marked now.
151 CalledF->setSection(StringMark);
152 }
153 }
154
155 // Before going any further mark all the called function by current
156 // function.
157 markFunctionHierarchy(cgn_it->second ,StringMark);
158 } // end of loop of all called functions.
159
160 }