[llvm-commits] [llvm] r71661 - in /llvm/trunk/lib/Target/PIC16: PIC16AsmPrinter.cpp PIC16AsmPrinter.h PIC16TargetAsmInfo.cpp PIC16TargetAsmInfo.h
Sanjiv Gupta
sanjiv.gupta at microchip.com
Wed May 13 08:13:29 PDT 2009
Author: sgupta
Date: Wed May 13 10:13:17 2009
New Revision: 71661
URL: http://llvm.org/viewvc/llvm-project?rev=71661&view=rev
Log:
Run through the list of globals once and sectionize all types of globlas includeing declarations. Later emit them from their section lists.
Modified:
llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp
llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.h
llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h
Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=71661&r1=71660&r2=71661&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Wed May 13 10:13:17 2009
@@ -133,7 +133,7 @@
// If its a libcall name, record it to decls section.
if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
- Decls.push_back(Sname);
+ LibcallDecls.push_back(Sname);
}
O << Sname;
@@ -153,16 +153,16 @@
O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
}
-void PIC16AsmPrinter::printDecls(void) {
+void PIC16AsmPrinter::printLibcallDecls(void) {
// If no libcalls used, return.
- if (Decls.empty()) return;
+ if (LibcallDecls.empty()) return;
O << TAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
// Remove duplicate entries.
- Decls.sort();
- Decls.unique();
- for (std::list<const char*>::const_iterator I = Decls.begin();
- I != Decls.end(); I++) {
+ LibcallDecls.sort();
+ LibcallDecls.unique();
+ for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
+ I != LibcallDecls.end(); I++) {
O << TAI->getExternDirective() << *I << "\n";
O << TAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
O << TAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
@@ -188,17 +188,22 @@
I->setSection(TAI->SectionForGlobal(I)->getName());
}
- EmitExternsAndGlobals (M);
+ EmitFunctionDecls(M);
+ EmitUndefinedVars(M);
+ EmitDefinedVars(M);
EmitIData(M);
EmitUData(M);
- EmitAutos(M);
EmitRomData(M);
+ EmitAutos(M);
return Result;
}
-void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
+// Emit extern decls for functions imported from other modules, and emit
+// global declarations for function defined in this module and which are
+// available to other modules.
+void PIC16AsmPrinter::EmitFunctionDecls (Module &M) {
// Emit declarations for external functions.
- O << TAI->getCommentString() << "External defs and decls - BEGIN." <<"\n";
+ O << TAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
std::string Name = Mang->getValueName(I);
if (Name.compare("@abort") == 0)
@@ -219,33 +224,38 @@
O << directive << PAN::getArgsLabel(Name) << "\n";
}
- // Emit header file to include declaration of library functions
- // FIXME: find out libcall names.
- // O << "\t#include C16IntrinsicCalls.INC\n";
-
- // Emit declarations for external variable declarations and definitions.
- for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
- I != E; I++) {
- // Any variables reaching here with ".auto." in its name is a local scope
- // variable and should not be printed in global data section.
- std::string Name = Mang->getValueName(I);
- if (PAN::isLocalName(Name))
- continue;
+ O << TAI->getCommentString() << "Function Declarations - END." <<"\n";
+}
- if (!(I->isDeclaration() || I->hasExternalLinkage() ||
- I->hasCommonLinkage()))
- continue;
+// Emit variables imported from other Modules.
+void PIC16AsmPrinter::EmitUndefinedVars (Module &M)
+{
+ std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDecls->Items;
+ if (! Items.size()) return;
- const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
- TAI->getGlobalDirective();
- O << directive << Name << "\n";
+ O << "\n" << TAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
+ for (unsigned j = 0; j < Items.size(); j++) {
+ O << TAI->getExternDirective() << Mang->getValueName(Items[j]) << "\n";
+ }
+ O << TAI->getCommentString() << "Imported Variables - END" << "\n";
+}
+
+// Emit variables defined in this module and are available to other modules.
+void PIC16AsmPrinter::EmitDefinedVars (Module &M)
+{
+ std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDefs->Items;
+ if (! Items.size()) return;
+
+ O << "\n" << TAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
+ for (unsigned j = 0; j < Items.size(); j++) {
+ O << TAI->getGlobalDirective() << Mang->getValueName(Items[j]) << "\n";
}
- O << TAI->getCommentString() << "External defs and decls - END." <<"\n";
+ O << TAI->getCommentString() << "Exported Variables - END" << "\n";
}
+// Emit initialized data placed in ROM.
void PIC16AsmPrinter::EmitRomData (Module &M)
{
- const PIC16TargetAsmInfo *PTAI = static_cast<const PIC16TargetAsmInfo *>(TAI);
std::vector<const GlobalVariable*> Items = PTAI->ROSection->Items;
if (! Items.size()) return;
@@ -262,7 +272,7 @@
}
bool PIC16AsmPrinter::doFinalization(Module &M) {
- printDecls();
+ printLibcallDecls();
O << "\t" << "END\n";
bool Result = AsmPrinter::doFinalization(M);
return Result;
@@ -314,7 +324,6 @@
}
void PIC16AsmPrinter::EmitIData (Module &M) {
- const PIC16TargetAsmInfo *PTAI = static_cast<const PIC16TargetAsmInfo *>(TAI);
// Print all IDATA sections.
std::vector <PIC16Section *>IDATASections = PTAI->IDATASections;
@@ -333,7 +342,6 @@
}
void PIC16AsmPrinter::EmitUData (Module &M) {
- const PIC16TargetAsmInfo *PTAI = static_cast<const PIC16TargetAsmInfo *>(TAI);
const TargetData *TD = TM.getTargetData();
// Print all BSS sections.
@@ -358,7 +366,6 @@
{
// Section names for all globals are already set.
- const PIC16TargetAsmInfo *PTAI = static_cast<const PIC16TargetAsmInfo *>(TAI);
const TargetData *TD = TM.getTargetData();
// Now print all Autos sections.
Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.h?rev=71661&r1=71660&r2=71661&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.h Wed May 13 10:13:17 2009
@@ -17,6 +17,7 @@
#include "PIC16.h"
#include "PIC16TargetMachine.h"
+#include "PIC16TargetAsmInfo.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetAsmInfo.h"
@@ -31,6 +32,7 @@
bool V)
: AsmPrinter(O, TM, T, OL, V) {
PTLI = TM.getTargetLowering();
+ PTAI = static_cast<const PIC16TargetAsmInfo *> (T);
}
private :
virtual const char *getPassName() const {
@@ -42,13 +44,15 @@
void printCCOperand(const MachineInstr *MI, int opNum);
bool printInstruction(const MachineInstr *MI); // definition autogenerated.
bool printMachineInstruction(const MachineInstr *MI);
- void EmitExternsAndGlobals (Module &M);
+ void EmitFunctionDecls (Module &M);
+ void EmitUndefinedVars (Module &M);
+ void EmitDefinedVars (Module &M);
void EmitIData (Module &M);
void EmitUData (Module &M);
void EmitAutos (Module &M);
void EmitRomData (Module &M);
void emitFunctionData(MachineFunction &MF);
- void printDecls(void);
+ void printLibcallDecls(void);
protected:
bool doInitialization(Module &M);
@@ -56,7 +60,8 @@
private:
PIC16TargetLowering *PTLI;
- std::list<const char *> Decls; // List of extern decls.
+ const PIC16TargetAsmInfo *PTAI;
+ std::list<const char *> LibcallDecls; // List of extern decls.
};
} // end of namespace
Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp?rev=71661&r1=71660&r2=71661&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Wed May 13 10:13:17 2009
@@ -45,6 +45,8 @@
// in BeginModule, and gpasm cribbs for that .text symbol.
TextSection = getUnnamedSection("", SectionFlags::Code);
ROSection = new PIC16Section(getReadOnlySection());
+ ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls"));
+ ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs"));
}
const char *PIC16TargetAsmInfo::getRomDirective(unsigned size) const
@@ -196,9 +198,18 @@
// We select the section based on the initializer here, so it really
// has to be a GlobalVariable.
const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1);
- if (!GV1 || ! GV->hasInitializer())
+
+ if (!GV)
return TargetAsmInfo::SelectSectionForGlobal(GV1);
+ // Record Exteranl Var Decls.
+ if (GV->isDeclaration()) {
+ ExternalVarDecls->Items.push_back(GV);
+ return ExternalVarDecls->S_;
+ }
+
+ assert (GV->hasInitializer() && "A def without initializer?");
+
// First, if this is an automatic variable for a function, get the section
// name for it and return.
const std::string name = GV->getName();
@@ -206,6 +217,11 @@
return getSectionForAuto(GV);
}
+ // Record Exteranl Var Defs.
+ if (GV->hasExternalLinkage() || GV->hasCommonLinkage()) {
+ ExternalVarDefs->Items.push_back(GV);
+ }
+
// See if this is an uninitialized global.
const Constant *C = GV->getInitializer();
if (C->isNullValue())
@@ -240,4 +256,6 @@
}
delete ROSection;
+ delete ExternalVarDecls;
+ delete ExternalVarDefs;
}
Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h?rev=71661&r1=71660&r2=71661&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h Wed May 13 10:13:17 2009
@@ -45,6 +45,8 @@
mutable std::vector<PIC16Section *> IDATASections;
mutable std::vector<PIC16Section *> AutosSections;
mutable PIC16Section *ROSection;
+ mutable PIC16Section *ExternalVarDecls;
+ mutable PIC16Section *ExternalVarDefs;
virtual ~PIC16TargetAsmInfo();
private:
@@ -57,6 +59,8 @@
const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const;
const Section *getSectionForAuto(const GlobalVariable *GV) const;
virtual const Section *SelectSectionForGlobal(const GlobalValue *GV) const;
+
+
public:
void SetSectionForGVs(Module &M);
std::vector<PIC16Section *> getBSSSections() const {
More information about the llvm-commits
mailing list