Emit the auto variables of a function into a different section than parameters.
authorSanjiv Gupta <sanjiv.gupta@microchip.com>
Mon, 20 Apr 2009 16:59:35 +0000 (16:59 +0000)
committerSanjiv Gupta <sanjiv.gupta@microchip.com>
Mon, 20 Apr 2009 16:59:35 +0000 (16:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69605 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PIC16/PIC16AsmPrinter.cpp
lib/Target/PIC16/PIC16AsmPrinter.h
tools/Makefile

index 84cf3121c15ca4753e5f79a8268fec244a543005..9db43d57d7274d60a5fd3ad719ea476398a47413 100644 (file)
@@ -67,7 +67,7 @@ bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
       else {
         // External Symbol is generated for temp data. Temp data in in
         // fdata.<functionname>.# section.
-        NewBank = "fdata." + CurrentFnName +".#";
+        NewBank = "fpdata." + CurrentFnName +".#";
       }
       // Operand after global address or external symbol should be  banksel.
       // Value 1 for this operand means we need to generate banksel else do not
@@ -117,8 +117,8 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   // Emit the frame address of the function at the beginning of code.
   O << CurrentFnName << ":\n";
-  O << "    retlw  low(" << CurrentFnName << ".frame)\n";
-  O << "    retlw  high(" << CurrentFnName << ".frame)\n"; 
+  O << "    retlw  low(" << FunctionLabelBegin<< CurrentFnName << ".frame)\n";
+  O << "    retlw  high(" << FunctionLabelBegin<< CurrentFnName << ".frame)\n"; 
 
 
   // Print out code for the function.
@@ -178,14 +178,22 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
       O << (int)MO.getImm();
       return;
 
-    case MachineOperand::MO_GlobalAddress:
-      O << Mang->getValueName(MO.getGlobal());
+    case MachineOperand::MO_GlobalAddress: {
+      std::string Name = Mang->getValueName(MO.getGlobal());
+      if (isLocalName(Name)) 
+        O << FunctionLabelBegin << Mang->getValueName(MO.getGlobal());
+      else
+         O << Mang->getValueName(MO.getGlobal());
       break;
-
-    case MachineOperand::MO_ExternalSymbol:
-      O << MO.getSymbolName();
+    }
+    case MachineOperand::MO_ExternalSymbol: {
+      std::string Name = MO.getSymbolName(); 
+      if (Name.find("__intrinsics.") != std::string::npos)
+        O  << MO.getSymbolName();
+      else
+        O << FunctionLabelBegin << MO.getSymbolName();
       break;
-
+    }
     case MachineOperand::MO_MachineBasicBlock:
       printBasicBlockLabel(MO.getMBB());
       return;
@@ -234,13 +242,13 @@ void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
 
     if (I->isDeclaration()) {
       O << "\textern " <<Name << "\n";
-      O << "\textern " << Name << ".retval\n";
-      O << "\textern " << Name << ".args\n";
+      O << "\textern "  << FunctionLabelBegin << Name << ".retval\n";
+      O << "\textern " << FunctionLabelBegin << Name << ".args\n";
     }
     else if (I->hasExternalLinkage()) {
       O << "\tglobal " << Name << "\n";
-      O << "\tglobal " << Name << ".retval\n";
-      O << "\tglobal " << Name << ".args\n";
+      O << "\tglobal " << FunctionLabelBegin << Name << ".retval\n";
+      O << "\tglobal " << FunctionLabelBegin<< Name << ".args\n";
     }
   }
 
@@ -371,15 +379,16 @@ void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
   unsigned FrameSize = 0;
   // Emit the data section name.
   O << "\n"; 
-  std::string SectionName = "fdata." + CurrentFnName + ".# " + "UDATA";
+  std::string SectionName = "fpdata." + CurrentFnName + ".# " + "UDATA_OVR";
 
-  const Section *fDataSection = TAI->getNamedSection(SectionName.c_str(),
-                                               SectionFlags::Writeable);
-  SwitchToSection(fDataSection);
+  const Section *fPDataSection = TAI->getNamedSection(SectionName.c_str(),
+                                                      SectionFlags::Writeable);
+  SwitchToSection(fPDataSection);
   
 
   // Emit function frame label
-  O << CurrentFnName << ".frame:\n";
+  char ch;
+  O << FunctionLabelBegin << CurrentFnName << ".frame:\n";
 
   const Type *RetType = F->getReturnType();
   unsigned RetSize = 0; 
@@ -388,9 +397,10 @@ void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
   
   //Emit function return value space
   if(RetSize > 0)
-     O << CurrentFnName << ".retval    RES  " << RetSize << "\n";
+     O << FunctionLabelBegin << CurrentFnName << ".retval    RES  " << RetSize 
+       << "\n";
   else
-     O << CurrentFnName << ".retval:\n";
+     O << FunctionLabelBegin << CurrentFnName << ".retval:\n";
    
   // Emit variable to hold the space for function arguments 
   unsigned ArgSize = 0;
@@ -399,12 +409,22 @@ void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
     const Type *Ty = argi->getType();
     ArgSize += TD->getTypePaddedSize(Ty);
    }
-  O << CurrentFnName << ".args      RES  " << ArgSize << "\n";
+  O << FunctionLabelBegin << CurrentFnName << ".args      RES  " << ArgSize 
+    << "\n";
 
   // Emit temporary space
   int TempSize = PTLI->GetTmpSize();
   if (TempSize > 0 )
-    O << CurrentFnName << ".tmp       RES  " << TempSize <<"\n";
+    O << FunctionLabelBegin << CurrentFnName << ".tmp       RES  " << TempSize 
+      <<"\n";
+
+  // Emit the section name for local variables.
+  O << "\n";
+  std::string SecNameLocals = "fadata." + CurrentFnName + ".# " + "UDATA_OVR";
+
+  const Section *fADataSection = TAI->getNamedSection(SecNameLocals.c_str(),
+                                                      SectionFlags::Writeable);
+  SwitchToSection(fADataSection);
 
   // Emit the function variables. 
    
@@ -424,13 +444,13 @@ void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
     if (! isLocalToFunc(FuncName, VarName))
      continue;
 
-    I->setSection("fdata." + CurrentFnName + ".#");
+    I->setSection("fadata." + CurrentFnName + ".#");
     Constant *C = I->getInitializer();
     const Type *Ty = C->getType();
     unsigned Size = TD->getTypePaddedSize(Ty);
     FrameSize += Size; 
     // Emit memory reserve directive.
-    O << VarName << "  RES  " << Size << "\n";
+    O << FunctionLabelBegin << VarName << "  RES  " << Size << "\n";
   }
 
 }
index 05f6eff70de6eb97c8356af8633df62ee679859d..d9f81bd991d0e416e0fb3fa27198897ab39b4b7a 100644 (file)
@@ -28,6 +28,7 @@ namespace llvm {
                     const TargetAsmInfo *T, bool F, bool V)
       : AsmPrinter(O, TM, T, F, V) {
       CurBank = "";
+      FunctionLabelBegin = '@';
       IsRomData = false;
       PTLI = TM.getTargetLowering();
     }
@@ -55,6 +56,7 @@ namespace llvm {
     PIC16TargetLowering *PTLI;
     std::string CurBank;
     bool IsRomData;
+    char FunctionLabelBegin;
   };
 } // end of namespace
 
index 756d7d58c3c783d27135305f61f89d3b7ab3750f..12c0fa00f43bc03af301e15bd362062798b2e79c 100644 (file)
@@ -20,7 +20,7 @@ PARALLEL_DIRS := opt llvm-as llvm-dis \
                  llc llvm-ranlib llvm-ar llvm-nm \
                  llvm-ld llvm-prof llvm-link \
                  lli gccas gccld llvm-extract llvm-db \
-                 bugpoint llvm-bcanalyzer llvm-stub llvmc
+                 bugpoint llvm-bcanalyzer llvm-stub llvmc clang
 
 include $(LEVEL)/Makefile.config