[llvm-commits] [llvm] r150624 - 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
Wed Feb 15 14:36:16 PST 2012


Author: void
Date: Wed Feb 15 16:36:15 2012
New Revision: 150624

URL: http://llvm.org/viewvc/llvm-project?rev=150624&view=rev
Log:
Modify the code that emits the module flags to use the new module flags accessor
method. This allows the target lowering code to not have to deal with MDNodes.

Also, avoid leaking memory like a sieve by not creating a global variable for
the image info section, but just emitting the code directly.

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=150624&r1=150623&r2=150624&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Wed Feb 15 16:36:15 2012
@@ -15,9 +15,9 @@
 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
 
-#include "llvm/ADT/StringRef.h"
 #include "llvm/MC/SectionKind.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace llvm {
   class MachineModuleInfo;
@@ -80,7 +80,8 @@
 
   /// emitModuleFlags - Emit the module flags that specify the garbage
   /// collection information.
-  virtual void emitModuleFlags(MCStreamer &Streamer, NamedMDNode *ModFlags,
+  virtual void emitModuleFlags(MCStreamer &Streamer,
+                               ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
                                Mangler *Mang, const TargetMachine &TM) const;
 
   virtual const MCSection *

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=150624&r1=150623&r2=150624&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Wed Feb 15 16:36:15 2012
@@ -15,9 +15,11 @@
 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
 
-#include "llvm/ADT/StringRef.h"
+#include "llvm/Module.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/SectionKind.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace llvm {
   class MachineModuleInfo;
@@ -56,8 +58,9 @@
                                     const MCSymbol *Sym) const;
 
   /// emitModuleFlags - Emit the module flags that the platform cares about.
-  virtual void emitModuleFlags(MCStreamer &, NamedMDNode *, Mangler *,
-                               const TargetMachine &) const {
+  virtual void emitModuleFlags(MCStreamer &,
+                               ArrayRef<Module::ModuleFlagEntry>,
+                               Mangler *, const TargetMachine &) const {
   }
 
   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=150624&r1=150623&r2=150624&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Feb 15 16:36:15 2012
@@ -858,8 +858,10 @@
   }
 
   // Emit module flags.
-  if (NamedMDNode *ModFlags = M.getModuleFlagsMetadata())
-    getObjFileLowering().emitModuleFlags(OutStreamer, ModFlags, Mang, TM);
+  SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
+  M.getModuleFlagsMetadata(ModuleFlags);
+  if (!ModuleFlags.empty())
+    getObjFileLowering().emitModuleFlags(OutStreamer, ModuleFlags, 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=150624&r1=150623&r2=150624&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Wed Feb 15 16:36:15 2012
@@ -374,57 +374,55 @@
 /// emitModuleFlags - Emit the module flags that specify the garbage collection
 /// information.
 void TargetLoweringObjectFileMachO::
-emitModuleFlags(MCStreamer &Streamer, NamedMDNode *ModFlags,
+emitModuleFlags(MCStreamer &Streamer,
+                ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
                 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;
+  StringRef SectionVal;
 
-  for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
-    MDNode *Flag = ModFlags->getOperand(i);
-    Value *Behavior = Flag->getOperand(0);
+  for (ArrayRef<Module::ModuleFlagEntry>::iterator
+         i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) {
+    const Module::ModuleFlagEntry &MFE = *i;
 
     // Ignore flags with 'Require' behavior.
-    if (cast<ConstantInt>(Behavior)->getZExtValue() == Module::Require)
+    if (MFE.Behavior == Module::Require)
       continue;
 
-    Value *Key = Flag->getOperand(1);
-    Value *Val = Flag->getOperand(2);
-
-    StringRef KeyStr = cast<MDString>(Key)->getString();
+    StringRef Key = MFE.Key->getString();
+    Value *Val = MFE.Val;
 
-    if (KeyStr == Version)
+    if (Key == "Objective-C Image Info Version")
       VersionVal = cast<ConstantInt>(Val)->getZExtValue();
-    else if (KeyStr == GC || KeyStr == GCOnly)
+    else if (Key == "Objective-C Garbage Collection" ||
+             Key == "Objective-C GC Only")
       GCFlags |= cast<ConstantInt>(Val)->getZExtValue();
-    else if (KeyStr == SectionSpec)
-      Section = cast<MDString>(Val)->getString();
+    else if (Key == "Objective-C Image Info Section")
+      SectionVal = 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);
+  // The section is mandatory. If we don't have it, then we don't have GC info.
+  if (SectionVal.empty()) return;
 
-  Streamer.SwitchSection(TheSection);
-  Streamer.EmitLabel(GVSym);
+  StringRef Segment, Section;
+  unsigned TAA = 0, StubSize = 0;
+  bool TAAParsed;
+  std::string ErrorCode =
+    MCSectionMachO::ParseSectionSpecifier(SectionVal, Segment, Section,
+                                          TAA, TAAParsed, StubSize);
+  if (!ErrorCode.empty()) {
+    // If invalid, report the error with report_fatal_error.
+    report_fatal_error("Invalid section specifier '" +
+                       Section + "': " + ErrorCode + ".");
+  }
 
+  // Get the section.
+  const MCSectionMachO *S =
+    getContext().getMachOSection(Segment, Section, TAA, StubSize,
+                                 SectionKind::getDataRel());
+  Streamer.SwitchSection(S);
+  Streamer.EmitLabel(getContext().
+                     GetOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
   Streamer.EmitIntValue(VersionVal, 4);
   Streamer.EmitIntValue(GCFlags, 4);
   Streamer.AddBlankLine();





More information about the llvm-commits mailing list