Add a pass to do call graph analyis to overlay the autos and frame sections of
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetObjectFile.h
1 //===-- PIC16TargetObjectFile.h - PIC16 Object Info -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_TARGET_PIC16_TARGETOBJECTFILE_H
11 #define LLVM_TARGET_PIC16_TARGETOBJECTFILE_H
12
13 #include "llvm/Target/TargetLoweringObjectFile.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/Function.h"
16 #include <vector>
17 #include <string>
18
19 namespace llvm {
20   class GlobalVariable;
21   class Module;
22   class PIC16TargetMachine;
23   class MCSectionPIC16;
24   
25   enum { DataBankSize = 80 };
26
27   /// PIC16 Splits the global data into mulitple udata and idata sections.
28   /// Each udata and idata section needs to contain a list of globals that
29   /// they contain, in order to avoid scanning over all the global values 
30   /// again and printing only those that match the current section. 
31   /// Keeping values inside the sections make printing a section much easier.
32   ///
33   /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
34   ///
35   struct PIC16Section {
36     const MCSectionPIC16 *S_; // Connection to actual Section.
37     unsigned Size;  // Total size of the objects contained.
38     bool SectionPrinted;
39     std::vector<const GlobalVariable*> Items;
40     
41     PIC16Section(const MCSectionPIC16 *s) {
42       S_ = s;
43       Size = 0;
44       SectionPrinted = false;
45     }
46     bool isPrinted() const { return SectionPrinted; }
47     void setPrintedStatus(bool status) { SectionPrinted = status; } 
48   };
49   
50   class PIC16TargetObjectFile : public TargetLoweringObjectFile {
51     /// SectionsByName - Bindings of names to allocated sections.
52     mutable StringMap<MCSectionPIC16*> SectionsByName;
53
54     const TargetMachine *TM;
55     
56     const MCSectionPIC16 *getPIC16Section(const char *Name,
57                                           SectionKind K) const;
58   public:
59     mutable std::vector<PIC16Section*> BSSSections;
60     mutable std::vector<PIC16Section*> IDATASections;
61     mutable std::vector<PIC16Section*> AutosSections;
62     mutable std::vector<PIC16Section*> ROSections;
63     mutable PIC16Section *ExternalVarDecls;
64     mutable PIC16Section *ExternalVarDefs;
65
66     PIC16TargetObjectFile();
67     ~PIC16TargetObjectFile();
68     
69     void Initialize(MCContext &Ctx, const TargetMachine &TM);
70
71     
72     virtual const MCSection *
73     getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
74                              Mangler *Mang, const TargetMachine &TM) const;
75     
76     virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
77                                                     SectionKind Kind,
78                                                     Mangler *Mang,
79                                                     const TargetMachine&) const;
80
81     const MCSection *getSectionForFunction(const std::string &FnName, 
82                                            bool isInterrupt=false) const;
83     const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
84     
85     // If the current function is cloned then create the new autos section
86     // also. 
87     void createClonedSectionForAutos(const std::string &SecName);
88     std::string getNameForFunctFrame(const Function *F, 
89                                      bool IsAutosSection = false); 
90
91   private:
92     std::string getSectionNameForSym(const std::string &Sym) const;
93
94     const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
95     const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
96     const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
97     const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
98                                                std::string Addr = "") const;
99     const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
100                                                  std::string Addr = "") const;
101     const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
102     const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
103                                               std::string Addr = "") const;
104     const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
105                                             Mangler *Mang,
106                                             const std::string &Addr = "") const;
107   public:
108     void SetSectionForGVs(Module &M);
109     const std::vector<PIC16Section*> &getBSSSections() const {
110       return BSSSections;
111     }
112     const std::vector<PIC16Section*> &getIDATASections() const {
113       return IDATASections;
114     }
115     const std::vector<PIC16Section*> &getAutosSections() const {
116       return AutosSections;
117     }
118     const std::vector<PIC16Section*> &getROSections() const {
119       return ROSections;
120     }
121     
122   };
123 } // end namespace llvm
124
125 #endif