[cfe-commits] r54651 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/LangOptions.h lib/Basic/Targets.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/ModuleBuilder.cpp
Daniel Dunbar
daniel at zuster.org
Mon Aug 11 14:35:06 PDT 2008
Author: ddunbar
Date: Mon Aug 11 16:35:06 2008
New Revision: 54651
URL: http://llvm.org/viewvc/llvm-project?rev=54651&view=rev
Log:
Add LangOptions::NeXTRuntime.
- Wired to -fnext-runtime and -fgnu-runtime options.
- Defaults to GNU, no autoselection for NeXT.
Emit NeXT OBJC_IMAGE_INFO marker.
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Aug 11 16:35:06 2008
@@ -373,6 +373,14 @@
Exceptions("fexceptions",
llvm::cl::desc("Enable support for exception handling."));
+static llvm::cl::opt<bool>
+GNURuntime("fgnu-runtime",
+ llvm::cl::desc("Generate output compatible with the standard GNU Objective-C runtime."));
+
+static llvm::cl::opt<bool>
+NeXTRuntime("fnext-runtime",
+ llvm::cl::desc("Generate output compatible with the NeXT runtime."));
+
// FIXME: add:
// -ansi
// -trigraphs
@@ -439,6 +447,15 @@
Options.WritableStrings = WritableStrings;
Options.LaxVectorConversions = LaxVectorConversions;
Options.Exceptions = Exceptions;
+
+ if (NeXTRuntime) {
+ Options.NeXTRuntime = 1;
+ } else if (GNURuntime) {
+ Options.NeXTRuntime = 0;
+ } else {
+ // FIXME: Should autoselect based on platform.
+ Options.NeXTRuntime = 0;
+ }
}
static llvm::cl::opt<bool>
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Aug 11 16:35:06 2008
@@ -43,7 +43,9 @@
unsigned WritableStrings : 1; // Allow writable strings
unsigned LaxVectorConversions : 1;
unsigned Exceptions : 1; // Support exception handling.
-
+
+ unsigned NeXTRuntime : 1; // Use NeXT runtime.
+
private:
unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
// this enum as unsigned because MSVC insists on making enums
@@ -58,7 +60,7 @@
GC = ObjC1 = ObjC2 = 0;
C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0;
- LaxVectorConversions = Exceptions = 0;
+ LaxVectorConversions = Exceptions = NeXTRuntime = 0;
}
GCMode getGCMode() const { return (GCMode) GC; }
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Aug 11 16:35:06 2008
@@ -53,7 +53,7 @@
Define(Defs, "linux");
#endif
- if (1) {// -fobjc-gc controls this.
+ if (1) { // FIXME: -fobjc-gc controls this.
Define(Defs, "__weak", "");
Define(Defs, "__strong", "");
} else {
@@ -67,6 +67,9 @@
if (0) // darwin_pascal_strings
Define(Defs, "__PASCAL_STRINGS__");
+
+ if (0) // FIXME: -fnext-runtime controls this
+ Define(Defs, "__NEXT_RUNTIME__");
}
};
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Aug 11 16:35:06 2008
@@ -12,7 +12,11 @@
//===----------------------------------------------------------------------===//
#include "CGObjCRuntime.h"
+
+#include "CodeGenModule.h"
#include "clang/AST/Decl.h"
+#include "clang/Basic/LangOptions.h"
+
#include "llvm/Support/IRBuilder.h"
using namespace clang;
@@ -22,6 +26,18 @@
private:
CodeGen::CodeGenModule &CGM;
+ /// UsedGlobals - list of globals to pack into the llvm.used metadata
+ /// to prevent them from being clobbered.
+ std::vector<llvm::GlobalValue*> UsedGlobals;
+
+ /// EmitImageInfo - Emit the image info marker used to encode some module
+ /// level information.
+ void EmitImageInfo();
+
+ /// FinishModule - Write out global data structures at the end of
+ /// processing a translation unit.
+ void FinishModule();
+
public:
CGObjCMac(CodeGen::CodeGenModule &cgm);
virtual llvm::Constant *GenerateConstantString(const char *String,
@@ -94,6 +110,7 @@
} // end anonymous namespace
CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) {
+ EmitImageInfo();
}
// This has to perform the lookup every time, since posing and related
@@ -186,6 +203,9 @@
}
llvm::Function *CGObjCMac::ModuleInitFunction() {
+ // Abuse this interface function as a place to finalize.
+ FinishModule();
+
return NULL;
}
@@ -203,6 +223,74 @@
return 0;
}
+/* *** Private Interface *** */
+
+/// EmitImageInfo - Emit the image info marker used to encode some module
+/// level information.
+///
+/// See: <rdr://4810609&4810587&4810587>
+/// struct IMAGE_INFO {
+/// unsigned version;
+/// unsigned flags;
+/// };
+enum ImageInfoFlags {
+ eImageInfo_FixAndContinue = (1 << 0), // FIXME: Not sure what this implies
+ eImageInfo_GarbageCollected = (1 << 1),
+ eImageInfo_GCOnly = (1 << 2)
+};
+
+void CGObjCMac::EmitImageInfo() {
+ unsigned version = 0; // Version is unused?
+ unsigned flags = 0;
+
+ // FIXME: Fix and continue?
+ if (CGM.getLangOptions().getGCMode() != LangOptions::NonGC)
+ flags |= eImageInfo_GarbageCollected;
+ if (CGM.getLangOptions().getGCMode() == LangOptions::GCOnly)
+ flags |= eImageInfo_GCOnly;
+
+ fprintf(stderr, "flags: %d (%d)\n", flags, CGM.getLangOptions().getGCMode());
+
+ // Emitted as int[2];
+ llvm::Constant *values[2] = {
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, version),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, flags)
+ };
+ llvm::ArrayType *AT = llvm::ArrayType::get(llvm::Type::Int32Ty, 2);
+ llvm::GlobalValue *GV =
+ new llvm::GlobalVariable(AT, true,
+ llvm::GlobalValue::InternalLinkage,
+ llvm::ConstantArray::get(AT, values, 2),
+ "\01L_OBJC_IMAGE_INFO",
+ &CGM.getModule());
+
+ GV->setSection("__OBJC, __image_info,regular");
+
+ UsedGlobals.push_back(GV);
+}
+
+void CGObjCMac::FinishModule() {
+ std::vector<llvm::Constant*> Used;
+
+ llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+ for (std::vector<llvm::GlobalValue*>::iterator i = UsedGlobals.begin(),
+ e = UsedGlobals.end(); i != e; ++i) {
+ Used.push_back(llvm::ConstantExpr::getBitCast(*i, I8Ptr));
+ }
+
+ llvm::ArrayType *AT = llvm::ArrayType::get(I8Ptr, Used.size());
+ llvm::GlobalValue *GV =
+ new llvm::GlobalVariable(AT, false,
+ llvm::GlobalValue::AppendingLinkage,
+ llvm::ConstantArray::get(AT, Used),
+ "llvm.used",
+ &CGM.getModule());
+
+ GV->setSection("llvm.metadata");
+}
+
+/* *** */
+
CodeGen::CGObjCRuntime *CodeGen::CreateMacObjCRuntime(CodeGen::CodeGenModule &CGM){
return new CGObjCMac(CGM);
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Aug 11 16:35:06 2008
@@ -30,15 +30,13 @@
CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
llvm::Module &M, const llvm::TargetData &TD,
- Diagnostic &diags, bool GenerateDebugInfo,
- bool UseMacObjCRuntime)
+ Diagnostic &diags, bool GenerateDebugInfo)
: Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
Types(C, M, TD), Runtime(0), MemCpyFn(0), MemMoveFn(0), MemSetFn(0),
CFConstantStringClassRef(0) {
if (Features.ObjC1) {
- // TODO: Make this selectable at runtime
- if (UseMacObjCRuntime) {
+ if (Features.NeXTRuntime) {
Runtime = CreateMacObjCRuntime(*this);
} else {
Runtime = CreateGNUObjCRuntime(*this);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Aug 11 16:35:06 2008
@@ -105,7 +105,7 @@
public:
CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
const llvm::TargetData &TD, Diagnostic &Diags,
- bool GenerateDebugInfo, bool UseMacObjCRuntime);
+ bool GenerateDebugInfo);
~CodeGenModule();
Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=54651&r1=54650&r2=54651&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Mon Aug 11 16:35:06 2008
@@ -59,8 +59,7 @@
M->setDataLayout(Ctx->Target.getTargetDescription());
TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription()));
Builder.reset(new CodeGen::CodeGenModule(Context, Features, *M, *TD,
- Diags, GenerateDebugInfo,
- false));
+ Diags, GenerateDebugInfo));
}
virtual void HandleTopLevelDecl(Decl *D) {
More information about the cfe-commits
mailing list