Select section for constant pool entries
authorAnton Korobeynikov <asl@math.spbu.ru>
Thu, 7 Aug 2008 09:50:34 +0000 (09:50 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Thu, 7 Aug 2008 09:50:34 +0000 (09:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54448 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/ELFTargetAsmInfo.h
include/llvm/Target/TargetAsmInfo.h
lib/Target/ELFTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp

index 703d80069850796d2d0c521a1cce16246f10fcaa..fe339f8e591c7b1f22758df90cf17d0a75da52a1 100644 (file)
@@ -21,6 +21,7 @@
 namespace llvm {
   class GlobalValue;
   class GlobalVariable;
+  class Type;
 
   struct ELFTargetAsmInfo: public virtual TargetAsmInfo {
     explicit ELFTargetAsmInfo(const TargetMachine &TM);
@@ -28,7 +29,10 @@ namespace llvm {
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
     virtual std::string PrintSectionFlags(unsigned flags) const;
     const Section* MergeableConstSection(const GlobalVariable *GV) const;
+    inline const Section* MergeableConstSection(const Type *Ty) const;
     const Section* MergeableStringSection(const GlobalVariable *GV) const;
+    virtual const Section*
+    SelectSectionForMachineConst(const Type *Ty) const;
   protected:
     const TargetMachine* ETM;
   };
index 852e03a3791588d11fbd9af1553ea60d98e71169..e20a6c8995bcbd529804faf3186883a6fdce3c9e 100644 (file)
@@ -76,6 +76,7 @@ namespace llvm {
   class TargetMachine;
   class CallInst;
   class GlobalValue;
+  class Type;
 
   class Section {
     friend class TargetAsmInfo;
@@ -542,6 +543,8 @@ namespace llvm {
 
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
 
+    virtual const Section* SelectSectionForMachineConst(const Type *Ty) const;
+
     // Accessors.
     //
     const char *getTextSection() const {
index 6ce01a836b400f1760a0d76d17c0089f99ef903d..3b89c3f1e2dfa99f72c332879de47f9b6a265715 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/Target/ELFTargetAsmInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetData.h"
@@ -89,16 +90,28 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
     assert(0 && "Unsupported global");
 }
 
+const Section*
+ELFTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
+  // FIXME: Support data.rel stuff someday
+  return MergeableConstSection(Ty);
+}
+
 const Section*
 ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
-  const TargetData *TD = ETM->getTargetData();
   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
-  const Type *Type = C->getType();
+  const Type *Ty = C->getType();
+
+  return MergeableConstSection(Ty);
+}
+
+inline const Section*
+ELFTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
+  const TargetData *TD = ETM->getTargetData();
 
   // FIXME: string here is temporary, until stuff will fully land in.
   // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
   // currently directly used by asmprinter.
-  unsigned Size = TD->getABITypeSize(Type);
+  unsigned Size = TD->getABITypeSize(Ty);
   if (Size == 4 || Size == 8 || Size == 16) {
     std::string Name =  ".rodata.cst" + utostr(Size);
 
index ad804131b010393c8dcbaf1b79d4599280898d7c..eb74836aec328227076a8d4d922e6953d17e1edd 100644 (file)
@@ -321,6 +321,13 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
   return getDataSection_();
 }
 
+// Lame default implementation. Calculate the section name for machine const.
+const Section*
+TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
+  // FIXME: Support data.rel stuff someday
+  return getDataSection_();
+}
+
 std::string
 TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
                                       SectionKind::Kind Kind) const {