summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PIC16/AsmPrinter
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2009-10-21 10:42:44 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2009-10-21 10:42:44 +0000
commit47ea7436181eedf2e7d07dc766874fb07965a5b1 (patch)
treed5bb67733b90dc240ab08208f4c44dec66e09ee8 /llvm/lib/Target/PIC16/AsmPrinter
parentd6e77d004aefd3ac3088db579c465d1d1e3bc08b (diff)
downloadbcm5719-llvm-47ea7436181eedf2e7d07dc766874fb07965a5b1.tar.gz
bcm5719-llvm-47ea7436181eedf2e7d07dc766874fb07965a5b1.zip
Add a pass to overlay pic16 data sections for function frame and automatic
variables. This pass can be invoked by llvm-ld or opt to traverse over the call graph to detect what function frames and their automatic variables can be overlaid. Currently this builds an archive , but needs to be changed to a loadable module. llvm-svn: 84753
Diffstat (limited to 'llvm/lib/Target/PIC16/AsmPrinter')
-rw-r--r--llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp50
-rw-r--r--llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h1
2 files changed, 48 insertions, 3 deletions
diff --git a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
index 3f719b99ff7..08b49c8e5f8 100644
--- a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
+++ b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
@@ -53,6 +53,45 @@ bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
return true;
}
+static int getFunctionColor(const Function *F) {
+ if (F->hasSection()) {
+ std::string Sectn = F->getSection();
+ std::string StrToFind = "Overlay=";
+ unsigned Pos = Sectn.find(StrToFind);
+
+ // Retreive the color number if the key is found.
+ if (Pos != std::string::npos) {
+ Pos += StrToFind.length();
+ std::string Color = "";
+ char c = Sectn.at(Pos);
+ // A Color can only consist of digits.
+ while (c >= '0' && c<= '9') {
+ Color.append(1,c);
+ Pos++;
+ if (Pos >= Sectn.length())
+ break;
+ c = Sectn.at(Pos);
+ }
+ return atoi(Color.c_str());
+ }
+ }
+
+ // Color was not set for function, so return -1.
+ return -1;
+}
+
+// Color the Auto section of the given function.
+void PIC16AsmPrinter::ColorAutoSection(const Function *F) {
+ std::string SectionName = PAN::getAutosSectionName(CurrentFnName);
+ PIC16Section* Section = PTOF->findPIC16Section(SectionName);
+ if (Section != NULL) {
+ int Color = getFunctionColor(F);
+ if (Color >= 0)
+ Section->setColor(Color);
+ }
+}
+
+
/// runOnMachineFunction - This emits the frame section, autos section and
/// assembly for each instruction. Also takes care of function begin debug
/// directive and file begin debug directive (if required) for the function.
@@ -68,6 +107,9 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
const Function *F = MF.getFunction();
CurrentFnName = Mang->getMangledName(F);
+ // Put the color information from function to its auto section.
+ ColorAutoSection(F);
+
// Emit the function frame (args and temps).
EmitFunctionFrame(MF);
@@ -255,7 +297,6 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
EmitDefinedVars(M);
EmitIData(M);
EmitUData(M);
- EmitAllAutos(M);
EmitRomData(M);
EmitUserSections(M);
return Result;
@@ -330,6 +371,7 @@ void PIC16AsmPrinter::EmitRomData(Module &M) {
}
bool PIC16AsmPrinter::doFinalization(Module &M) {
+ EmitAllAutos(M);
printLibcallDecls();
DbgInfo.EndModule(M);
O << "\n\t" << "END\n";
@@ -343,8 +385,10 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
// Emit the data section name.
O << "\n";
- const MCSection *fPDataSection =
- getObjFileLowering().SectionForFrame(CurrentFnName);
+ PIC16Section *fPDataSection = const_cast<PIC16Section *>(getObjFileLowering().
+ SectionForFrame(CurrentFnName));
+
+ fPDataSection->setColor(getFunctionColor(F));
OutStreamer.SwitchSection(fPDataSection);
// Emit function frame label
diff --git a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
index 580e2fdb7bc..b13d9ce3aac 100644
--- a/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
+++ b/llvm/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
@@ -63,6 +63,7 @@ namespace llvm {
void EmitSingleSection(const PIC16Section *S);
void EmitSectionList(Module &M,
const std::vector< PIC16Section *> &SList);
+ void ColorAutoSection(const Function *F);
protected:
bool doInitialization(Module &M);
bool doFinalization(Module &M);
OpenPOWER on IntegriCloud