[cfe-commits] r104630 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CGCXXABI.h CMakeLists.txt CodeGenModule.cpp CodeGenModule.h ItaniumCXXABI.cpp

Charles Davis cdavis at mines.edu
Tue May 25 12:52:27 PDT 2010


Author: cdavis
Date: Tue May 25 14:52:27 2010
New Revision: 104630

URL: http://llvm.org/viewvc/llvm-project?rev=104630&view=rev
Log:
IRgen: Add a stub class for generating ABI-specific C++ code.

This class only supports name mangling (which is apparently used during C/ObjC
codegen). For now only the Itanium C++ ABI is supported. Patches to add a
second C++ ABI are forthcoming.

Added:
    cfe/trunk/lib/CodeGen/CGCXXABI.h
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CMakeLists.txt
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=104630&r1=104629&r2=104630&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue May 25 14:52:27 2010
@@ -13,6 +13,7 @@
 
 // We might split this into multiple files if it gets too unwieldy
 
+#include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "Mangle.h"
@@ -333,3 +334,5 @@
 
   return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
 }
+
+CXXABI::~CXXABI() {}

Added: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=104630&view=auto
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (added)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Tue May 25 14:52:27 2010
@@ -0,0 +1,37 @@
+//===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides an abstract class for C++ code generation. Concrete subclasses
+// of this implement code generation for specific C++ ABIs.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_CODEGEN_CXXABI_H
+#define CLANG_CODEGEN_CXXABI_H
+
+namespace clang {
+namespace CodeGen {
+  class CodeGenModule;
+  class MangleContext;
+
+/// Implements C++ ABI-specific code generation functions.
+class CXXABI {
+public:
+  virtual ~CXXABI();
+
+  /// Gets the mangle context.
+  virtual MangleContext &getMangleContext() = 0;
+};
+
+/// Creates an instance of a C++ ABI class.
+CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
+}
+}
+
+#endif

Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=104630&r1=104629&r2=104630&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Tue May 25 14:52:27 2010
@@ -28,9 +28,10 @@
   CodeGenFunction.cpp
   CodeGenModule.cpp
   CodeGenTypes.cpp
+  ItaniumCXXABI.cpp
   Mangle.cpp
   ModuleBuilder.cpp
   TargetInfo.cpp
   )
 
-add_dependencies(clangCodeGen ClangStmtNodes)
\ No newline at end of file
+add_dependencies(clangCodeGen ClangStmtNodes)

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=104630&r1=104629&r2=104630&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue May 25 14:52:27 2010
@@ -48,7 +48,7 @@
     Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
     TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags),
     Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()),
-    MangleCtx(C, diags), VTables(*this), Runtime(0),
+    VTables(*this), Runtime(0), ABI(0),
     CFConstantStringClassRef(0),
     NSConstantStringClassRef(0),
     VMContext(M.getContext()) {
@@ -62,12 +62,17 @@
   else
     Runtime = CreateMacObjCRuntime(*this);
 
+  if (!Features.CPlusPlus)
+    ABI = 0;
+  else createCXXABI();
+
   // If debug info generation is enabled, create the CGDebugInfo object.
   DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(*this) : 0;
 }
 
 CodeGenModule::~CodeGenModule() {
   delete Runtime;
+  delete ABI;
   delete DebugInfo;
 }
 
@@ -80,6 +85,11 @@
     Runtime = CreateMacObjCRuntime(*this);
 }
 
+void CodeGenModule::createCXXABI() {
+  // For now, just create an Itanium ABI.
+  ABI = CreateItaniumCXXABI(*this);
+}
+
 void CodeGenModule::Release() {
   EmitDeferred();
   EmitCXXGlobalInitFunc();

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=104630&r1=104629&r2=104630&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue May 25 14:52:27 2010
@@ -22,6 +22,7 @@
 #include "CGCall.h"
 #include "CGCXX.h"
 #include "CGVTables.h"
+#include "CGCXXABI.h"
 #include "CodeGenTypes.h"
 #include "GlobalDecl.h"
 #include "Mangle.h"
@@ -90,13 +91,13 @@
   mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
   Diagnostic &Diags;
   CodeGenTypes Types;
-  MangleContext MangleCtx;
 
   /// VTables - Holds information about C++ vtables.
   CodeGenVTables VTables;
   friend class CodeGenVTables;
 
   CGObjCRuntime* Runtime;
+  CXXABI* ABI;
   CGDebugInfo* DebugInfo;
 
   // WeakRefReferences - A set of references that have only been seen via
@@ -153,6 +154,8 @@
 
   /// Lazily create the Objective-C runtime
   void createObjCRuntime();
+  /// Lazily create the C++ ABI
+  void createCXXABI();
 
   llvm::LLVMContext &VMContext;
 public:
@@ -175,6 +178,16 @@
   /// been configured.
   bool hasObjCRuntime() { return !!Runtime; }
 
+  /// getCXXABI() - Return a reference to the configured
+  /// C++ ABI.
+  CXXABI &getCXXABI() {
+    if (!ABI) createCXXABI();
+    return *ABI;
+  }
+
+  /// hasCXXABI() - Return true iff a C++ ABI has been configured.
+  bool hasCXXABI() { return !!ABI; }
+
   llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
     return StaticLocalDeclMap[VD];
   }
@@ -189,7 +202,10 @@
   const LangOptions &getLangOptions() const { return Features; }
   llvm::Module &getModule() const { return TheModule; }
   CodeGenTypes &getTypes() { return Types; }
-  MangleContext &getMangleContext() { return MangleCtx; }
+  MangleContext &getMangleContext() {
+    if (!ABI) createCXXABI();
+    return ABI->getMangleContext();
+  }
   CodeGenVTables &getVTables() { return VTables; }
   Diagnostic &getDiags() const { return Diags; }
   const llvm::TargetData &getTargetData() const { return TheTargetData; }

Added: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=104630&view=auto
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (added)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue May 25 14:52:27 2010
@@ -0,0 +1,39 @@
+//===------- ItaniumCXXABI.cpp - Emit LLVM Code from ASTs for a Module ----===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides C++ code generation targetting the Itanium C++ ABI.  The class
+// in this file generates structures that follow the Itanium C++ ABI, which is
+// documented at:
+//  http://www.codesourcery.com/public/cxx-abi/abi.html
+//  http://www.codesourcery.com/public/cxx-abi/abi-eh.html
+//===----------------------------------------------------------------------===//
+
+#include "CGCXXABI.h"
+#include "CodeGenModule.h"
+#include "Mangle.h"
+
+using namespace clang;
+
+namespace {
+class ItaniumCXXABI : public CodeGen::CXXABI {
+  CodeGen::MangleContext MangleCtx;
+public:
+  ItaniumCXXABI(CodeGen::CodeGenModule &CGM) :
+    MangleCtx(CGM.getContext(), CGM.getDiags()) { }
+
+  CodeGen::MangleContext &getMangleContext() {
+    return MangleCtx;
+  }
+};
+}
+
+CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
+  return new ItaniumCXXABI(CGM);
+}
+





More information about the cfe-commits mailing list