1 //===-- llvm/Target/TargetLoweringObjectFile.h - 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 // This file implements classes used to handle lowerings specific to common 11 // object file formats. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 17 18 #include "llvm/ADT/StringRef.h" 19 #include "llvm/MC/MCObjectFileInfo.h" 20 #include "llvm/MC/SectionKind.h" 21 22 namespace llvm { 23 class MachineModuleInfo; 24 class Mangler; 25 class MCAsmInfo; 26 class MCContext; 27 class MCExpr; 28 class MCSection; 29 class MCSectionMachO; 30 class MCSymbol; 31 class MCStreamer; 32 class GlobalValue; 33 class TargetMachine; 34 35 class TargetLoweringObjectFile : public MCObjectFileInfo { 36 MCContext *Ctx; 37 38 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 39 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 40 41 public: 42 MCContext &getContext() const { return *Ctx; } 43 44 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0) {} 45 46 virtual ~TargetLoweringObjectFile(); 47 48 /// Initialize - this method must be called before any actual lowering is 49 /// done. This specifies the current context for codegen, and gives the 50 /// lowering implementations a chance to set up their default sections. 51 virtual void Initialize(MCContext &ctx, const TargetMachine &TM); 52 53 virtual void emitPersonalityValue(MCStreamer &Streamer, 54 const TargetMachine &TM, 55 const MCSymbol *Sym) const; 56 57 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 58 /// decide not to emit the UsedDirective for some symbols in llvm.used. 59 /// FIXME: REMOVE this (rdar://7071300) 60 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 61 Mangler *) const { 62 return GV != 0; 63 } 64 65 /// getSectionForConstant - Given a constant with the SectionKind, return a 66 /// section that it should be placed in. 67 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 68 69 /// getKindForGlobal - Classify the specified global variable into a set of 70 /// target independent categories embodied in SectionKind. 71 static SectionKind getKindForGlobal(const GlobalValue *GV, 72 const TargetMachine &TM); 73 74 /// SectionForGlobal - This method computes the appropriate section to emit 75 /// the specified global variable or function definition. This should not 76 /// be passed external (or available externally) globals. 77 const MCSection *SectionForGlobal(const GlobalValue *GV, 78 SectionKind Kind, Mangler *Mang, 79 const TargetMachine &TM) const; 80 81 /// SectionForGlobal - This method computes the appropriate section to emit 82 /// the specified global variable or function definition. This should not 83 /// be passed external (or available externally) globals. 84 const MCSection *SectionForGlobal(const GlobalValue *GV, 85 Mangler *Mang, 86 const TargetMachine &TM) const { 87 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM); 88 } 89 90 91 92 /// getExplicitSectionGlobal - Targets should implement this method to assign 93 /// a section to globals with an explicit section specfied. The 94 /// implementation of this method can assume that GV->hasSection() is true. 95 virtual const MCSection * 96 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 97 Mangler *Mang, const TargetMachine &TM) const = 0; 98 99 /// getSpecialCasedSectionGlobals - Allow the target to completely override 100 /// section assignment of a global. 101 virtual const MCSection * 102 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, 103 SectionKind Kind) const { 104 return 0; 105 } 106 107 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference 108 /// to the specified global variable from exception handling information. 109 /// 110 virtual const MCExpr * 111 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, 112 MachineModuleInfo *MMI, unsigned Encoding, 113 MCStreamer &Streamer) const; 114 115 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality. 116 virtual MCSymbol * 117 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, 118 MachineModuleInfo *MMI) const; 119 120 /// 121 const MCExpr * 122 getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding, 123 MCStreamer &Streamer) const; 124 125 protected: 126 virtual const MCSection * 127 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 128 Mangler *Mang, const TargetMachine &TM) const; 129 }; 130 131 } // end namespace llvm 132 133 #endif 134