[llvm-commits] [llvm] r98363 - in /llvm/trunk: include/llvm/MC/MCContext.h include/llvm/Target/Mangler.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/ELFWriter.cpp lib/CodeGen/LLVMTargetMachine.cpp lib/Target/CBackend/CBackend.cpp lib/Target/Mangler.cpp tools/lto/LTOCodeGenerator.cpp tools/lto/LTOModule.cpp

Chris Lattner sabre at nondot.org
Fri Mar 12 10:44:54 PST 2010


Author: lattner
Date: Fri Mar 12 12:44:54 2010
New Revision: 98363

URL: http://llvm.org/viewvc/llvm-project?rev=98363&view=rev
Log:
make the mangler take an MCContext instead of an MAI.
No functionality change.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/include/llvm/Target/Mangler.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/Target/CBackend/CBackend.cpp
    llvm/trunk/lib/Target/Mangler.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/LTOModule.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Mar 12 12:44:54 2010
@@ -48,7 +48,7 @@
     /// objects.
     BumpPtrAllocator Allocator;
   public:
-    MCContext(const MCAsmInfo &MAI);
+    explicit MCContext(const MCAsmInfo &MAI);
     ~MCContext();
     
     const MCAsmInfo &getAsmInfo() const { return MAI; }

Modified: llvm/trunk/include/llvm/Target/Mangler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Mangler.h?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/Mangler.h (original)
+++ llvm/trunk/include/llvm/Target/Mangler.h Fri Mar 12 12:44:54 2010
@@ -23,7 +23,7 @@
 class Value;
 class GlobalValue;
 template <typename T> class SmallVectorImpl; 
-class MCAsmInfo;
+class MCContext;
 
 class Mangler {
 public:
@@ -34,7 +34,7 @@
   };
 
 private:
-  const MCAsmInfo &MAI;
+  const MCContext &Context;
 
   /// AnonGlobalIDs - We need to give global values the same name every time
   /// they are mangled.  This keeps track of the number we give to anonymous
@@ -47,9 +47,7 @@
   unsigned NextAnonGlobalID;
 
 public:
-  // Mangler ctor - if a prefix is specified, it will be prepended onto all
-  // symbols.
-  Mangler(const MCAsmInfo &mai) : MAI(mai), NextAnonGlobalID(1) {}
+  Mangler(const MCContext &context) : Context(context), NextAnonGlobalID(1) {}
 
   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
   /// and the specified global variable's name.  If the global variable doesn't

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Mar 12 12:44:54 2010
@@ -104,7 +104,7 @@
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .Initialize(OutContext, TM);
   
-  Mang = new Mangler(*MAI);
+  Mang = new Mangler(OutContext);
   
   // Allow the target to emit any magic that it wants at the start of the file.
   EmitStartOfAsmFile(M);

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Fri Mar 12 12:44:54 2010
@@ -109,7 +109,7 @@
   // Initialize TargetLoweringObjectFile.
   const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM);
   
-  Mang = new Mangler(*MAI);
+  Mang = new Mangler(OutContext);
 
   // ELF Header
   // ----------

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Fri Mar 12 12:44:54 2010
@@ -101,14 +101,12 @@
 
 // Set the default code model for the JIT for a generic target.
 // FIXME: Is small right here? or .is64Bit() ? Large : Small?
-void
-LLVMTargetMachine::setCodeModelForJIT() {
+void LLVMTargetMachine::setCodeModelForJIT() {
   setCodeModel(CodeModel::Small);
 }
 
 // Set the default code model for static compilation for a generic target.
-void
-LLVMTargetMachine::setCodeModelForStatic() {
+void LLVMTargetMachine::setCodeModelForStatic() {
   setCodeModel(CodeModel::Small);
 }
 

Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Fri Mar 12 12:44:54 2010
@@ -36,6 +36,7 @@
 #include "llvm/Target/Mangler.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetRegistry.h"
@@ -95,6 +96,7 @@
     LoopInfo *LI;
     const Module *TheModule;
     const MCAsmInfo* TAsm;
+    MCContext *TCtx;
     const TargetData* TD;
     std::map<const Type *, std::string> TypeNames;
     std::map<const ConstantFP *, unsigned> FPConstantMap;
@@ -1731,7 +1733,8 @@
     TAsm = Match->createAsmInfo(Triple);
 #endif    
   TAsm = new CBEMCAsmInfo();
-  Mang = new Mangler(*TAsm);
+  TCtx = new MCContext(*TAsm);
+  Mang = new Mangler(*TCtx);
 
   // Keep track of which functions are static ctors/dtors so they can have
   // an attribute added to their prototypes.

Modified: llvm/trunk/lib/Target/Mangler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mangler.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mangler.cpp (original)
+++ llvm/trunk/lib/Target/Mangler.cpp Fri Mar 12 12:44:54 2010
@@ -14,6 +14,7 @@
 #include "llvm/Target/Mangler.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
 using namespace llvm;
@@ -59,11 +60,10 @@
 /// appendMangledName - Add the specified string in mangled form if it uses
 /// any unusual characters.
 static void appendMangledName(SmallVectorImpl<char> &OutName, StringRef Str,
-                              const MCAsmInfo *MAI) {
+                              const MCAsmInfo &MAI) {
   // The first character is not allowed to be a number unless the target
   // explicitly allows it.
-  if ((MAI == 0 || !MAI->doesAllowNameToStartWithDigit()) &&
-      Str[0] >= '0' && Str[0] <= '9') {
+  if (!MAI.doesAllowNameToStartWithDigit() && Str[0] >= '0' && Str[0] <= '9') {
     MangleLetter(OutName, Str[0]);
     Str = Str.substr(1);
   }
@@ -100,6 +100,8 @@
   StringRef Name = GVName.toStringRef(TmpData);
   assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
   
+  const MCAsmInfo &MAI = Context.getAsmInfo();
+  
   // If the global name is not led with \1, add the appropriate prefixes.
   if (Name[0] == '\1') {
     Name = Name.substr(1);
@@ -134,7 +136,7 @@
   // On systems that do not allow quoted names, we need to mangle most
   // strange characters.
   if (!MAI.doesAllowQuotesInName())
-    return appendMangledName(OutName, Name, &MAI);
+    return appendMangledName(OutName, Name, MAI);
   
   // Okay, the system allows quoted strings.  We can quote most anything, the
   // only characters that need escaping are " and \n.

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Fri Mar 12 12:44:54 2010
@@ -27,24 +27,25 @@
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/StandardPasses.h"
-#include "llvm/Support/SystemUtils.h"
-#include "llvm/System/Host.h"
-#include "llvm/System/Program.h"
-#include "llvm/System/Signals.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/Target/Mangler.h"
 #include "llvm/Target/SubtargetFeature.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetSelect.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/StandardPasses.h"
+#include "llvm/Support/SystemUtils.h"
+#include "llvm/System/Host.h"
+#include "llvm/System/Program.h"
+#include "llvm/System/Signals.h"
 #include "llvm/Config/config.h"
 #include <cstdlib>
 #include <unistd.h>
@@ -252,7 +253,8 @@
             args.push_back(arch);
         }
         // add -static to assembler command line when code model requires
-        if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )
+        if ( (_assemblerPath != NULL) &&
+            (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )
             args.push_back("-static");
     }
     if ( needsCompilerOptions ) {
@@ -303,44 +305,44 @@
 
         // construct LTModule, hand over ownership of module and target
         const std::string FeatureStr =
-            SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple));
+           SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple));
         _target = march->createTargetMachine(Triple, FeatureStr);
     }
     return false;
 }
 
-void LTOCodeGenerator::applyScopeRestrictions()
-{
-    if ( !_scopeRestrictionsDone ) {
-        Module* mergedModule = _linker.getModule();
+void LTOCodeGenerator::applyScopeRestrictions() {
+  if (_scopeRestrictionsDone) return;
+  Module *mergedModule = _linker.getModule();
+
+  // Start off with a verification pass.
+  PassManager passes;
+  passes.add(createVerifierPass());
 
-        // Start off with a verification pass.
-        PassManager passes;
-        passes.add(createVerifierPass());
-
-        // mark which symbols can not be internalized 
-        if ( !_mustPreserveSymbols.empty() ) {
-            Mangler mangler(*_target->getMCAsmInfo());
-            std::vector<const char*> mustPreserveList;
-            for (Module::iterator f = mergedModule->begin(), 
-                                        e = mergedModule->end(); f != e; ++f) {
-                if ( !f->isDeclaration() 
-                  && _mustPreserveSymbols.count(mangler.getNameWithPrefix(f)) )
-                  mustPreserveList.push_back(::strdup(f->getNameStr().c_str()));
-            }
-            for (Module::global_iterator v = mergedModule->global_begin(), 
-                                 e = mergedModule->global_end(); v !=  e; ++v) {
-                if ( !v->isDeclaration()
-                  && _mustPreserveSymbols.count(mangler.getNameWithPrefix(v)) )
-                  mustPreserveList.push_back(::strdup(v->getNameStr().c_str()));
-            }
-            passes.add(createInternalizePass(mustPreserveList));
-        }
-        // apply scope restrictions
-        passes.run(*mergedModule);
-        
-        _scopeRestrictionsDone = true;
+  // mark which symbols can not be internalized 
+  if (!_mustPreserveSymbols.empty()) {
+    MCContext Context(*_target->getMCAsmInfo());
+    Mangler mangler(Context);
+    std::vector<const char*> mustPreserveList;
+    for (Module::iterator f = mergedModule->begin(),
+         e = mergedModule->end(); f != e; ++f) {
+      if (!f->isDeclaration() &&
+          _mustPreserveSymbols.count(mangler.getNameWithPrefix(f)))
+        mustPreserveList.push_back(::strdup(f->getNameStr().c_str()));
+    }
+    for (Module::global_iterator v = mergedModule->global_begin(), 
+         e = mergedModule->global_end(); v !=  e; ++v) {
+      if (v->isDeclaration() &&
+          _mustPreserveSymbols.count(mangler.getNameWithPrefix(v)))
+        mustPreserveList.push_back(::strdup(v->getNameStr().c_str()));
     }
+    passes.add(createInternalizePass(mustPreserveList));
+  }
+  
+  // apply scope restrictions
+  passes.run(*mergedModule);
+  
+  _scopeRestrictionsDone = true;
 }
 
 /// Optimize merged modules using various IPO passes

Modified: llvm/trunk/tools/lto/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=98363&r1=98362&r2=98363&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOModule.cpp (original)
+++ llvm/trunk/tools/lto/LTOModule.cpp Fri Mar 12 12:44:54 2010
@@ -1,4 +1,4 @@
-//===-LTOModule.cpp - LLVM Link Time Optimizer ----------------------------===//
+//===-- LTOModule.cpp - LLVM Link Time Optimizer --------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -29,6 +29,7 @@
 #include "llvm/Target/Mangler.h"
 #include "llvm/Target/SubtargetFeature.h"
 #include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetSelect.h"
@@ -437,7 +438,8 @@
         _symbolsParsed = true;
         
         // Use mangler to add GlobalPrefix to names to match linker names.
-        Mangler mangler(*_target->getMCAsmInfo());
+        MCContext Context(*_target->getMCAsmInfo());
+        Mangler mangler(Context);
 
         // add functions
         for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {





More information about the llvm-commits mailing list