namespace clang {
class Diagnostic;
class LangOptions;
+ class CompileOptions;
class CodeGenerator : public ASTConsumer {
public:
};
CodeGenerator *CreateLLVMCodeGen(Diagnostic &Diags,
- const LangOptions &Features,
- const std::string& ModuleName,
- bool GenerateDebugInfo);
+ const std::string &ModuleName,
+ const CompileOptions &CO);
}
#endif
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;
InlineFunctions = SimplifyLibCalls = UnrollLoops = 0;
VerifyModule = 1;
TimePasses = 0;
+ NoCommon = 0;
}
};
//
//===----------------------------------------------------------------------===//
-#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"
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) {
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() {
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);
#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 {
class ValueDecl;
class VarDecl;
class LangOptions;
+ class CompileOptions;
class Diagnostic;
class AnnotateAttr;
ASTContext &Context;
const LangOptions &Features;
+ const CompileOptions &CompileOpts;
llvm::Module &TheModule;
const llvm::TargetData &TheTargetData;
Diagnostic &Diags;
/// 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();
#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 {
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() {}
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) {
}
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);
}
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) {
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,
Opts.Features.insert(Opts.Features.end(),
TargetFeatures.begin(), TargetFeatures.end());
+ Opts.NoCommon = NoCommon | LangOpts.CPlusPlus;
+
// Handle -ftime-report.
Opts.TimePasses = TimeReport;
}