[llvm-commits] [llvm] r150507 - in /llvm/trunk: include/llvm/CodeGen/TargetLoweringObjectFileImpl.h include/llvm/Target/TargetLoweringObjectFile.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Bill Wendling isanbard at gmail.com
Tue Feb 14 13:28:14 PST 2012


Author: void
Date: Tue Feb 14 15:28:13 2012
New Revision: 150507

URL: http://llvm.org/viewvc/llvm-project?rev=150507&view=rev
Log:
Add code to the target lowering object file module to handle module flags.

The MachO back-end needs to emit the garbage collection flags specified in the
module flags. This is a WIP, so the front-end hasn't been modified to emit these
flags just yet. Documentation and front-end switching to occur soon.

Modified:
    llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Modified: llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=150507&r1=150506&r2=150507&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Tue Feb 14 15:28:13 2012
@@ -78,6 +78,11 @@
 public:
   virtual ~TargetLoweringObjectFileMachO() {}
 
+  /// emitModuleFlags - Emit the module flags that specify the garbage
+  /// collection information.
+  virtual void emitModuleFlags(MCStreamer &Streamer, NamedMDNode *ModFlags,
+                               Mangler *Mang, const TargetMachine &TM) const;
+
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=150507&r1=150506&r2=150507&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Tue Feb 14 15:28:13 2012
@@ -29,6 +29,7 @@
   class MCSectionMachO;
   class MCSymbol;
   class MCStreamer;
+  class NamedMDNode;
   class GlobalValue;
   class TargetMachine;
   
@@ -53,7 +54,12 @@
   virtual void emitPersonalityValue(MCStreamer &Streamer,
                                     const TargetMachine &TM,
                                     const MCSymbol *Sym) const;
-  
+
+  /// emitModuleFlags - Emit the module flags that the platform cares about.
+  virtual void emitModuleFlags(MCStreamer &, NamedMDNode *, Mangler *,
+                               const TargetMachine &) const {
+  }
+
   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
   /// decide not to emit the UsedDirective for some symbols in llvm.used.
   /// FIXME: REMOVE this (rdar://7071300)
@@ -86,9 +92,7 @@
                                     const TargetMachine &TM) const {
     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
   }
-  
-  
-  
+
   /// getExplicitSectionGlobal - Targets should implement this method to assign
   /// a section to globals with an explicit section specfied.  The
   /// implementation of this method can assume that GV->hasSection() is true.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=150507&r1=150506&r2=150507&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Feb 14 15:28:13 2012
@@ -857,6 +857,10 @@
     EmitVisibility(Name, V, false);
   }
 
+  // Emit module flags.
+  if (NamedMDNode *ModFlags = M.getModuleFlagsMetadata())
+    getObjFileLowering().emitModuleFlags(OutStreamer, ModFlags, Mang, TM);
+
   // Finalize debug and EH information.
   if (DE) {
     {

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=150507&r1=150506&r2=150507&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Tue Feb 14 15:28:13 2012
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
+#include "llvm/Module.h"
 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
@@ -370,6 +371,65 @@
 //                                 MachO
 //===----------------------------------------------------------------------===//
 
+/// emitModuleFlags - Emit the module flags that specify the garbage collection
+/// information.
+void TargetLoweringObjectFileMachO::
+emitModuleFlags(MCStreamer &Streamer, NamedMDNode *ModFlags,
+                Mangler *Mang, const TargetMachine &TM) const {
+  StringRef Version("Objective-C Image Info Version");
+  StringRef SectionSpec("Objective-C Image Info Section");
+  StringRef GC("Objective-C Garbage Collection");
+  StringRef GCOnly("Objective-C GC Only");
+
+  unsigned VersionVal = 0;
+  unsigned GCFlags = 0;
+  StringRef Section;
+
+  for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
+    MDNode *Flag = ModFlags->getOperand(i);
+    Value *Behavior = Flag->getOperand(0);
+
+    // Ignore flags with 'Require' behavior.
+    if (cast<ConstantInt>(Behavior)->getZExtValue() == Module::Require)
+      continue;
+
+    Value *Key = Flag->getOperand(1);
+    Value *Val = Flag->getOperand(2);
+
+    StringRef KeyStr = cast<MDString>(Key)->getString();
+
+    if (KeyStr == Version)
+      VersionVal = cast<ConstantInt>(Val)->getZExtValue();
+    else if (KeyStr == GC || KeyStr == GCOnly)
+      GCFlags |= cast<ConstantInt>(Val)->getZExtValue();
+    else if (KeyStr == SectionSpec)
+      Section = cast<MDString>(Val)->getString();
+  }
+
+  // The section is mandatory. If we don't have it, then we don't have image
+  // info information.
+  if (Section.empty()) return;
+
+  uint32_t Values[2] = { VersionVal, GCFlags };
+  Module *M = ModFlags->getParent();
+  Constant *Init = ConstantDataArray::get(M->getContext(), Values);
+  GlobalVariable *GV = new GlobalVariable(*M, Init->getType(), false,
+                                          GlobalValue::InternalLinkage, Init,
+                                          "\01L_OBJC_IMAGE_INFO");
+  GV->setSection(Section);
+
+  MCSymbol *GVSym = Mang->getSymbol(GV);
+  SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
+  const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM);
+
+  Streamer.SwitchSection(TheSection);
+  Streamer.EmitLabel(GVSym);
+
+  Streamer.EmitIntValue(VersionVal, 4);
+  Streamer.EmitIntValue(GCFlags, 4);
+  Streamer.AddBlankLine();
+}
+
 const MCSection *TargetLoweringObjectFileMachO::
 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const {





More information about the llvm-commits mailing list