[cfe-commits] r67735 - in /cfe/trunk: include/clang/CodeGen/ModuleBuilder.h include/clang/Frontend/CompileOptions.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/ModuleBuilder.cpp tools/clang-cc/Backend.cpp tools/clang-cc/clang.cpp

Chris Lattner sabre at nondot.org
Wed Mar 25 22:00:52 PDT 2009


Author: lattner
Date: Thu Mar 26 00:00:52 2009
New Revision: 67735

URL: http://llvm.org/viewvc/llvm-project?rev=67735&view=rev
Log:
most of this is plumbing to get CompileOptions down into 
CodeGenModule.  Once there, add a new NoCommon option to
it and implement -fno-common.

Modified:
    cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
    cfe/trunk/include/clang/Frontend/CompileOptions.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
    cfe/trunk/tools/clang-cc/Backend.cpp
    cfe/trunk/tools/clang-cc/clang.cpp

Modified: cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/include/clang/CodeGen/ModuleBuilder.h (original)
+++ cfe/trunk/include/clang/CodeGen/ModuleBuilder.h Thu Mar 26 00:00:52 2009
@@ -24,6 +24,7 @@
 namespace clang {
   class Diagnostic;
   class LangOptions;
+  class CompileOptions;
   
   class CodeGenerator : public ASTConsumer {
   public:
@@ -32,9 +33,8 @@
   };
   
   CodeGenerator *CreateLLVMCodeGen(Diagnostic &Diags,
-                                   const LangOptions &Features,
-                                   const std::string& ModuleName,
-                                   bool GenerateDebugInfo);
+                                   const std::string &ModuleName,
+                                   const CompileOptions &CO);
 }
 
 #endif

Modified: cfe/trunk/include/clang/Frontend/CompileOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompileOptions.h?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompileOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CompileOptions.h Thu Mar 26 00:00:52 2009
@@ -35,6 +35,7 @@
   unsigned VerifyModule      : 1; /// Control whether the module
                                   /// should be run through the LLVM Verifier.
   unsigned TimePasses        : 1; /// Set when -ftime-report is enabled.
+  unsigned NoCommon          : 1; /// Set when -fno-common or C++ is enabled.
 
   /// CPU - An optional CPU to target.
   std::string CPU;
@@ -52,6 +53,7 @@
     InlineFunctions = SimplifyLibCalls = UnrollLoops = 0;
     VerifyModule = 1;
     TimePasses = 0;
+    NoCommon = 0;
   }  
 };
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 26 00:00:52 2009
@@ -11,12 +11,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CGDebugInfo.h"
 #include "CodeGenModule.h"
+#include "CGDebugInfo.h"
 #include "CodeGenFunction.h"
 #include "CGCall.h"
 #include "CGObjCRuntime.h"
 #include "Mangle.h"
+#include "clang/Frontend/CompileOptions.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclCXX.h"
@@ -31,10 +32,11 @@
 using namespace CodeGen;
 
 
-CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
+CodeGenModule::CodeGenModule(ASTContext &C, const CompileOptions &compileOpts,
                              llvm::Module &M, const llvm::TargetData &TD,
-                             Diagnostic &diags, bool GenerateDebugInfo)
-  : BlockModule(C, M, TD, Types, *this), Context(C), Features(LO), TheModule(M),
+                             Diagnostic &diags)
+  : BlockModule(C, M, TD, Types, *this), Context(C),
+    Features(C.getLangOptions()), CompileOpts(compileOpts), TheModule(M),
     TheTargetData(TD), Diags(diags), Types(C, M, TD), Runtime(0),
     MemCpyFn(0), MemMoveFn(0), MemSetFn(0), CFConstantStringClassRef(0) {
 
@@ -48,7 +50,7 @@
     Runtime = CreateMacObjCRuntime(*this);
 
   // If debug info generation is enabled, create the CGDebugInfo object.
-  DebugInfo = GenerateDebugInfo ? new CGDebugInfo(this) : 0;
+  DebugInfo = CompileOpts.DebugInfo ? new CGDebugInfo(this) : 0;
 }
 
 CodeGenModule::~CodeGenModule() {
@@ -767,7 +769,7 @@
     case VarDecl::Register:
       assert(0 && "Can't have auto or register globals");
     case VarDecl::None:
-      if (!D->getInit())
+      if (!D->getInit() && !CompileOpts.NoCommon)
         GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
       else
         GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Mar 26 00:00:52 2009
@@ -14,15 +14,13 @@
 #ifndef CLANG_CODEGEN_CODEGENMODULE_H
 #define CLANG_CODEGEN_CODEGENMODULE_H
 
-#include "CodeGenTypes.h"
 #include "clang/AST/Attr.h"
+#include "CGBlocks.h"
+#include "CGCall.h"
+#include "CodeGenTypes.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
-
-#include "CGBlocks.h"
-#include "CGCall.h"
-
 #include <list>
 
 namespace llvm {
@@ -52,6 +50,7 @@
   class ValueDecl;
   class VarDecl;
   class LangOptions;
+  class CompileOptions;
   class Diagnostic;
   class AnnotateAttr;
 
@@ -71,6 +70,7 @@
 
   ASTContext &Context;
   const LangOptions &Features;
+  const CompileOptions &CompileOpts;
   llvm::Module &TheModule;
   const llvm::TargetData &TheTargetData;
   Diagnostic &Diags;
@@ -138,9 +138,8 @@
   /// strings. This value has type int * but is actually an Obj-C class pointer.
   llvm::Constant *CFConstantStringClassRef;
 public:
-  CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
-                const llvm::TargetData &TD, Diagnostic &Diags,
-                bool GenerateDebugInfo);
+  CodeGenModule(ASTContext &C, const CompileOptions &CompileOpts,
+                llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
 
   ~CodeGenModule();
 

Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Thu Mar 26 00:00:52 2009
@@ -13,20 +13,17 @@
 
 #include "clang/CodeGen/ModuleBuilder.h"
 #include "CodeGenModule.h"
+#include "clang/Frontend/CompileOptions.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
-using namespace clang;
-
-//===----------------------------------------------------------------------===//
-// LLVM Emitter
-
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/Module.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/ADT/OwningPtr.h"
+using namespace clang;
 
 
 namespace {
@@ -34,17 +31,14 @@
     Diagnostic &Diags;
     llvm::OwningPtr<const llvm::TargetData> TD;
     ASTContext *Ctx;
-    const LangOptions &Features;
-    bool GenerateDebugInfo;
+    const CompileOptions CompileOpts;  // Intentionally copied in.
   protected:
     llvm::OwningPtr<llvm::Module> M;
     llvm::OwningPtr<CodeGen::CodeGenModule> Builder;
   public:
-    CodeGeneratorImpl(Diagnostic &diags, const LangOptions &LO,
-                      const std::string& ModuleName,
-                      bool DebugInfoFlag)
-    : Diags(diags), Features(LO), GenerateDebugInfo(DebugInfoFlag),
-      M(new llvm::Module(ModuleName)) {}
+    CodeGeneratorImpl(Diagnostic &diags, const std::string& ModuleName,
+                      const CompileOptions &CO)
+      : Diags(diags), CompileOpts(CO), M(new llvm::Module(ModuleName)) {}
     
     virtual ~CodeGeneratorImpl() {}
     
@@ -62,8 +56,8 @@
       M->setTargetTriple(Ctx->Target.getTargetTriple());
       M->setDataLayout(Ctx->Target.getTargetDescription());
       TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription()));
-      Builder.reset(new CodeGen::CodeGenModule(Context, Features, *M, *TD,
-                                               Diags, GenerateDebugInfo));
+      Builder.reset(new CodeGen::CodeGenModule(Context, CompileOpts,
+                                               *M, *TD, Diags));
     }
     
     virtual void HandleTopLevelDecl(Decl *D) {
@@ -93,8 +87,7 @@
 }
 
 CodeGenerator *clang::CreateLLVMCodeGen(Diagnostic &Diags, 
-                                        const LangOptions &Features,
                                         const std::string& ModuleName,
-                                        bool GenerateDebugInfo) {
-  return new CodeGeneratorImpl(Diags, Features, ModuleName, GenerateDebugInfo);
+                                        const CompileOptions &CO) {
+  return new CodeGeneratorImpl(Diags, ModuleName, CO);
 }

Modified: cfe/trunk/tools/clang-cc/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Backend.cpp?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Backend.cpp (original)
+++ cfe/trunk/tools/clang-cc/Backend.cpp Thu Mar 26 00:00:52 2009
@@ -85,7 +85,7 @@
       OutputFile(outfile), 
       LLVMIRGeneration("LLVM IR Generation Time"),
       CodeGenerationTime("Code Generation Time"),
-      Gen(CreateLLVMCodeGen(Diags, langopts, InputFile, compopts.DebugInfo)),
+      Gen(CreateLLVMCodeGen(Diags, InputFile, compopts)),
       TheModule(0), TheTargetData(0), AsmOutStream(0), ModuleProvider(0),
       CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {
       

Modified: cfe/trunk/tools/clang-cc/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang.cpp?rev=67735&r1=67734&r2=67735&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang.cpp Thu Mar 26 00:00:52 2009
@@ -1235,6 +1235,10 @@
 static llvm::cl::opt<bool>
 OptSize("Os", llvm::cl::desc("Optimize for size"));
 
+static llvm::cl::opt<bool>
+NoCommon("fno-common",
+         llvm::cl::desc("Compile common globals like normal definitions"));
+
 // It might be nice to add bounds to the CommandLine library directly.
 struct OptLevelParser : public llvm::cl::parser<unsigned> {
   bool parse(llvm::cl::Option &O, const char *ArgName,
@@ -1281,6 +1285,8 @@
   Opts.Features.insert(Opts.Features.end(),
                        TargetFeatures.begin(), TargetFeatures.end());
   
+  Opts.NoCommon = NoCommon | LangOpts.CPlusPlus;
+  
   // Handle -ftime-report.
   Opts.TimePasses = TimeReport;
 }





More information about the cfe-commits mailing list