llvm.org GIT mirror llvm / c25e1ea
Move actual section printing stuff to AsmPrinter from TAI reducing heap traffic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56573 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 11 years ago
11 changed file(s) with 33 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
112112 public:
113113 bool isNamed() const { return Flags & SectionFlags::Named; }
114114 unsigned getEntitySize() const { return (Flags >> 24) & 0xFF; }
115
115116 const std::string& getName() const { return Name; }
116117 unsigned getFlags() const { return Flags; }
117118 };
572573
573574 /// SectionForGlobal - This hooks returns proper section name for given
574575 /// global with all necessary flags and marks.
575 virtual std::string SectionForGlobal(const GlobalValue *GV) const;
576 virtual const Section* SectionForGlobal(const GlobalValue *GV) const;
576577
577578 // Helper methods for SectionForGlobal
578579 virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
114114 // FIXME: Make CurrentSection a Section* in the future
115115 CurrentSection = NewSection;
116116
117 if (!CurrentSection.empty())
118 O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
117 if (!CurrentSection.empty()) {
118 // If section is named we need to switch into it via special '.section'
119 // directive and also append funky flags. Otherwise - section name is just
120 // some magic assembler directive.
121 if (NS->isNamed())
122 O << TAI->getSwitchToSectionDirective()
123 << CurrentSection
124 << TAI->getSectionFlags(NS->getFlags());
125 else
126 O << CurrentSection;
127 O << TAI->getDataSectionStartSuffix() << '\n';
128 }
119129
120130 IsInTextSection = (NS->getFlags() & SectionFlags::Code);
121131 }
325335 // function body itself, otherwise the label differences won't make sense.
326336 // We should also do if the section name is NULL or function is declared in
327337 // discardable section.
328 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
338 SwitchToSection(TAI->SectionForGlobal(F));
329339 } else {
330340 SwitchToDataSection(JumpTableDataSection);
331341 }
845845 return;
846846 }
847847
848 std::string SectionName = TAI->SectionForGlobal(GVar);
849848 std::string name = Mang->getValueName(GVar);
850849 Constant *C = GVar->getInitializer();
851850 const Type *Type = C->getType();
857856 if (Subtarget->isTargetELF())
858857 O << "\t.type " << name << ",%object\n";
859858
860 SwitchToDataSection(SectionName.c_str());
859 SwitchToSection(TAI->SectionForGlobal(GVar));
861860
862861 if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) {
863862 // FIXME: This seems to be pretty darwin-specific
148148
149149 // Print out labels for the function.
150150 const Function *F = MF.getFunction();
151 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
151 SwitchToSection(TAI->SectionForGlobal(F));
152152
153153 EmitAlignment(4, F);
154154 switch (F->getLinkage()) {
213213 if (EmitSpecialLLVMGlobal(GVar))
214214 return;
215215
216 std::string SectionName = TAI->SectionForGlobal(GVar);
217216 std::string name = Mang->getValueName(GVar);
218217 Constant *C = GVar->getInitializer();
219218 unsigned Size = TD->getABITypeSize(C->getType());
220219 unsigned Align = TD->getPreferredAlignmentLog(GVar);
221220
222221 // 0: Switch to section
223 SwitchToDataSection(SectionName.c_str());
222 SwitchToSection(TAI->SectionForGlobal(GVar));
224223
225224 // 1: Check visibility
226225 printVisibility(name, GVar->getVisibility());
417417 // Print out labels for the function.
418418 const Function *F = MF.getFunction();
419419
420 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
420 SwitchToSection(TAI->SectionForGlobal(F));
421421 EmitAlignment(3, F);
422422
423423 switch (F->getLinkage()) {
129129 EmitConstantPool(MF.getConstantPool());
130130
131131 const Function *F = MF.getFunction();
132 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
132 SwitchToSection(TAI->SectionForGlobal(F));
133133
134134 // Print out labels for the function.
135135 EmitAlignment(5);
263263 return;
264264
265265 O << "\n\n";
266 std::string SectionName = TAI->SectionForGlobal(GVar);
267266 std::string name = Mang->getValueName(GVar);
268267 Constant *C = GVar->getInitializer();
269268 unsigned Size = TD->getABITypeSize(C->getType());
271270
272271 printVisibility(name, GVar->getVisibility());
273272
274 SwitchToDataSection(SectionName.c_str());
273 SwitchToSection(TAI->SectionForGlobal(GVar));
275274
276275 if (C->isNullValue() && !GVar->hasSection()) {
277276 if (!GVar->isThreadLocal() &&
223223 {
224224 // Print out the label for the function.
225225 const Function *F = MF.getFunction();
226 SwitchToTextSection(TAI->SectionForGlobal(F).c_str());
226 SwitchToSection(TAI->SectionForGlobal(F));
227227
228228 // 2 bits aligned
229229 EmitAlignment(2, F);
478478 return;
479479
480480 O << "\n\n";
481 std::string SectionName = TAI->SectionForGlobal(GVar);
482481 std::string name = Mang->getValueName(GVar);
483482 Constant *C = GVar->getInitializer();
484483 const Type *CTy = C->getType();
500499
501500 printVisibility(name, GVar->getVisibility());
502501
503 SwitchToDataSection(SectionName.c_str());
502 SwitchToSection(TAI->SectionForGlobal(GVar));
504503
505504 if (C->isNullValue() && !GVar->hasSection()) {
506505 if (!GVar->isThreadLocal() &&
570570
571571 // Print out labels for the function.
572572 const Function *F = MF.getFunction();
573 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
573 SwitchToSection(TAI->SectionForGlobal(F));
574574
575575 switch (F->getLinkage()) {
576576 default: assert(0 && "Unknown linkage type!");
661661 return;
662662
663663 std::string name = Mang->getValueName(GVar);
664 std::string SectionName = TAI->SectionForGlobal(GVar);
665664
666665 printVisibility(name, GVar->getVisibility());
667666
670669 unsigned Size = TD->getABITypeSize(Type);
671670 unsigned Align = TD->getPreferredAlignmentLog(GVar);
672671
673 SwitchToDataSection(SectionName.c_str());
672 SwitchToSection(TAI->SectionForGlobal(GVar));
674673
675674 if (C->isNullValue() && /* FIXME: Verify correct */
676675 !GVar->hasSection() &&
758757
759758 // Print out labels for the function.
760759 const Function *F = MF.getFunction();
761 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
760 SwitchToSection(TAI->SectionForGlobal(F));
762761
763762 switch (F->getLinkage()) {
764763 default: assert(0 && "Unknown linkage type!");
887886 }
888887
889888 std::string name = Mang->getValueName(GVar);
890 std::string SectionName = TAI->SectionForGlobal(GVar);
891889
892890 printVisibility(name, GVar->getVisibility());
893891
896894 unsigned Size = TD->getABITypeSize(Type);
897895 unsigned Align = TD->getPreferredAlignmentLog(GVar);
898896
899 SwitchToDataSection(SectionName.c_str());
897 SwitchToSection(TAI->SectionForGlobal(GVar));
900898
901899 if (C->isNullValue() && /* FIXME: Verify correct */
902900 !GVar->hasSection() &&
9898
9999 // Print out the label for the function.
100100 const Function *F = MF.getFunction();
101 SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
101 SwitchToSection(TAI->SectionForGlobal(F));
102102 EmitAlignment(4, F);
103103 O << "\t.globl\t" << CurrentFnName << '\n';
104104
241241 return;
242242
243243 O << "\n\n";
244 std::string SectionName = TAI->SectionForGlobal(GVar);
245244 std::string name = Mang->getValueName(GVar);
246245 Constant *C = GVar->getInitializer();
247246 unsigned Size = TD->getABITypeSize(C->getType());
249248
250249 printVisibility(name, GVar->getVisibility());
251250
252 SwitchToDataSection(SectionName.c_str());
251 SwitchToSection(TAI->SectionForGlobal(GVar));
253252
254253 if (C->isNullValue() && !GVar->hasSection()) {
255254 if (!GVar->isThreadLocal() &&
271271 return Flags;
272272 }
273273
274 std::string
274 const Section*
275275 TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
276276 const Section* S;
277277 // Select section name
285285 S = SelectSectionForGlobal(GV);
286286 }
287287
288 if (!S->isNamed())
289 return S->Name;
290
291 // If section is named we need to switch into it via special '.section'
292 // directive and also append funky flags. Otherwise - section name is just
293 // some magic assembler directive.
294 return getSwitchToSectionDirective() + S->Name + getSectionFlags(S->Flags);
288 return S;
295289 }
296290
297291 // Lame default implementation. Calculate the section name for global.
147147
148148 void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
149149 const Function *F = MF.getFunction();
150 std::string SectionName = TAI->SectionForGlobal(F);
151150
152151 decorateName(CurrentFnName, F);
153152
154 SwitchToTextSection(SectionName.c_str());
153 SwitchToSection(TAI->SectionForGlobal(F));
155154
156155 unsigned FnAlign = OptimizeForSize ? 1 : 4;
157156 if (!F->isDeclaration() && F->hasNote(FnAttr::OptimizeForSize))
765764 return;
766765 }
767766
768 std::string SectionName = TAI->SectionForGlobal(GVar);
769767 std::string name = Mang->getValueName(GVar);
770768 Constant *C = GVar->getInitializer();
771769 const Type *Type = C->getType();
777775 if (Subtarget->isTargetELF())
778776 O << "\t.type\t" << name << ",@object\n";
779777
780 SwitchToDataSection(SectionName.c_str());
778 SwitchToSection(TAI->SectionForGlobal(GVar));
781779
782780 if (C->isNullValue() && !GVar->hasSection()) {
783781 // FIXME: This seems to be pretty darwin-specific