r193717 - Add CodeGenABITypes.h for use in LLDB.

Mark Lacey mark.lacey at apple.com
Wed Oct 30 14:53:58 PDT 2013


Author: rudkx
Date: Wed Oct 30 16:53:58 2013
New Revision: 193717

URL: http://llvm.org/viewvc/llvm-project?rev=193717&view=rev
Log:
Add CodeGenABITypes.h for use in LLDB.

CodeGenABITypes is a wrapper built on top of CodeGenModule that exposes
some of the functionality of CodeGenTypes (held by CodeGenModule),
specifically methods that determine the LLVM types appropriate for
function argument and return values.

I addition to CodeGenABITypes.h, CGFunctionInfo.h is introduced, and the
definitions of ABIArgInfo, RequiredArgs, and CGFunctionInfo are moved
into this new header from the private headers ABIInfo.h and CGCall.h.

Exposing this functionality is one part of making it possible for LLDB
to determine the actual ABI locations of function arguments and return
values, making it possible for it to determine this for any supported
target without hard-coding ABI knowledge in the LLDB code.

Added:
    cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
    cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h
    cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp
Modified:
    cfe/trunk/lib/CodeGen/ABIInfo.h
    cfe/trunk/lib/CodeGen/CGAtomic.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGCall.h
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/lib/CodeGen/CMakeLists.txt
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/CodeGen/TargetInfo.cpp

Added: cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h?rev=193717&view=auto
==============================================================================
--- cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h (added)
+++ cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h Wed Oct 30 16:53:58 2013
@@ -0,0 +1,361 @@
+//==-- CGFunctionInfo.h - Representation of function argument/return types -==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines CGFunctionInfo and associated types used in representing the
+// LLVM source types and ABI-coerced types for function arguments and
+// return values.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CODEGEN_FUNCTION_INFO_H
+#define LLVM_CLANG_CODEGEN_FUNCTION_INFO_H
+
+#include "clang/AST/CanonicalType.h"
+#include "clang/AST/Type.h"
+#include "llvm/ADT/FoldingSet.h"
+
+#include <cassert>
+
+namespace llvm {
+  class Type;
+}
+
+namespace clang {
+namespace CodeGen {
+
+/// ABIArgInfo - Helper class to encapsulate information about how a
+/// specific C type should be passed to or returned from a function.
+class ABIArgInfo {
+public:
+  enum Kind {
+    /// Direct - Pass the argument directly using the normal converted LLVM
+    /// type, or by coercing to another specified type stored in
+    /// 'CoerceToType').  If an offset is specified (in UIntData), then the
+    /// argument passed is offset by some number of bytes in the memory
+    /// representation. A dummy argument is emitted before the real argument
+    /// if the specified type stored in "PaddingType" is not zero.
+    Direct,
+
+    /// Extend - Valid only for integer argument types. Same as 'direct'
+    /// but also emit a zero/sign extension attribute.
+    Extend,
+
+    /// Indirect - Pass the argument indirectly via a hidden pointer
+    /// with the specified alignment (0 indicates default alignment).
+    Indirect,
+
+    /// Ignore - Ignore the argument (treat as void). Useful for void and
+    /// empty structs.
+    Ignore,
+
+    /// Expand - Only valid for aggregate argument types. The structure should
+    /// be expanded into consecutive arguments for its constituent fields.
+    /// Currently expand is only allowed on structures whose fields
+    /// are all scalar types or are themselves expandable types.
+    Expand,
+
+    KindFirst=Direct, KindLast=Expand
+  };
+
+private:
+  Kind TheKind;
+  llvm::Type *TypeData;
+  llvm::Type *PaddingType;
+  unsigned UIntData;
+  bool BoolData0;
+  bool BoolData1;
+  bool InReg;
+  bool PaddingInReg;
+
+  ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
+             bool PIR, llvm::Type* P)
+    : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
+      BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
+
+public:
+  ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
+
+  static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
+                              llvm::Type *Padding = 0) {
+    return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
+  }
+  static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
+    return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
+  }
+  static ABIArgInfo getExtend(llvm::Type *T = 0) {
+    return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
+  }
+  static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
+    return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
+  }
+  static ABIArgInfo getIgnore() {
+    return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
+  }
+  static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
+                                , bool Realign = false
+                                , llvm::Type *Padding = 0) {
+    return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false,
+                      Padding);
+  }
+  static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
+                                , bool Realign = false) {
+    return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
+  }
+  static ABIArgInfo getExpand() {
+    return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
+  }
+  static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
+                                         llvm::Type *Padding) {
+   return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
+                     Padding);
+  }
+
+  Kind getKind() const { return TheKind; }
+  bool isDirect() const { return TheKind == Direct; }
+  bool isExtend() const { return TheKind == Extend; }
+  bool isIgnore() const { return TheKind == Ignore; }
+  bool isIndirect() const { return TheKind == Indirect; }
+  bool isExpand() const { return TheKind == Expand; }
+
+  bool canHaveCoerceToType() const {
+    return TheKind == Direct || TheKind == Extend;
+  }
+
+  // Direct/Extend accessors
+  unsigned getDirectOffset() const {
+    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
+    return UIntData;
+  }
+
+  llvm::Type *getPaddingType() const {
+    return PaddingType;
+  }
+
+  bool getPaddingInReg() const {
+    return PaddingInReg;
+  }
+
+  llvm::Type *getCoerceToType() const {
+    assert(canHaveCoerceToType() && "Invalid kind!");
+    return TypeData;
+  }
+
+  void setCoerceToType(llvm::Type *T) {
+    assert(canHaveCoerceToType() && "Invalid kind!");
+    TypeData = T;
+  }
+
+  bool getInReg() const {
+    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
+    return InReg;
+  }
+
+  // Indirect accessors
+  unsigned getIndirectAlign() const {
+    assert(TheKind == Indirect && "Invalid kind!");
+    return UIntData;
+  }
+
+  bool getIndirectByVal() const {
+    assert(TheKind == Indirect && "Invalid kind!");
+    return BoolData0;
+  }
+
+  bool getIndirectRealign() const {
+    assert(TheKind == Indirect && "Invalid kind!");
+    return BoolData1;
+  }
+
+  void dump() const;
+};
+
+/// A class for recording the number of arguments that a function
+/// signature requires.
+class RequiredArgs {
+  /// The number of required arguments, or ~0 if the signature does
+  /// not permit optional arguments.
+  unsigned NumRequired;
+public:
+  enum All_t { All };
+
+  RequiredArgs(All_t _) : NumRequired(~0U) {}
+  explicit RequiredArgs(unsigned n) : NumRequired(n) {
+    assert(n != ~0U);
+  }
+
+  /// Compute the arguments required by the given formal prototype,
+  /// given that there may be some additional, non-formal arguments
+  /// in play.
+  static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
+                                       unsigned additional) {
+    if (!prototype->isVariadic()) return All;
+    return RequiredArgs(prototype->getNumArgs() + additional);
+  }
+
+  static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
+    return forPrototypePlus(prototype, 0);
+  }
+
+  static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
+    return forPrototype(prototype.getTypePtr());
+  }
+
+  static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
+                                       unsigned additional) {
+    return forPrototypePlus(prototype.getTypePtr(), additional);
+  }
+
+  bool allowsOptionalArgs() const { return NumRequired != ~0U; }
+  unsigned getNumRequiredArgs() const {
+    assert(allowsOptionalArgs());
+    return NumRequired;
+  }
+
+  unsigned getOpaqueData() const { return NumRequired; }
+  static RequiredArgs getFromOpaqueData(unsigned value) {
+    if (value == ~0U) return All;
+    return RequiredArgs(value);
+  }
+};
+
+/// CGFunctionInfo - Class to encapsulate the information about a
+/// function definition.
+class CGFunctionInfo : public llvm::FoldingSetNode {
+  struct ArgInfo {
+    CanQualType type;
+    ABIArgInfo info;
+  };
+
+  /// The LLVM::CallingConv to use for this function (as specified by the
+  /// user).
+  unsigned CallingConvention : 8;
+
+  /// The LLVM::CallingConv to actually use for this function, which may
+  /// depend on the ABI.
+  unsigned EffectiveCallingConvention : 8;
+
+  /// The clang::CallingConv that this was originally created with.
+  unsigned ASTCallingConvention : 8;
+
+  /// Whether this function is noreturn.
+  unsigned NoReturn : 1;
+
+  /// Whether this function is returns-retained.
+  unsigned ReturnsRetained : 1;
+
+  /// How many arguments to pass inreg.
+  unsigned HasRegParm : 1;
+  unsigned RegParm : 4;
+
+  RequiredArgs Required;
+
+  unsigned NumArgs;
+  ArgInfo *getArgsBuffer() {
+    return reinterpret_cast<ArgInfo*>(this+1);
+  }
+  const ArgInfo *getArgsBuffer() const {
+    return reinterpret_cast<const ArgInfo*>(this + 1);
+  }
+
+  CGFunctionInfo() : Required(RequiredArgs::All) {}
+
+public:
+  static CGFunctionInfo *create(unsigned llvmCC,
+                                const FunctionType::ExtInfo &extInfo,
+                                CanQualType resultType,
+                                ArrayRef<CanQualType> argTypes,
+                                RequiredArgs required);
+
+  typedef const ArgInfo *const_arg_iterator;
+  typedef ArgInfo *arg_iterator;
+
+  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
+  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
+  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
+  arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
+
+  unsigned  arg_size() const { return NumArgs; }
+
+  bool isVariadic() const { return Required.allowsOptionalArgs(); }
+  RequiredArgs getRequiredArgs() const { return Required; }
+
+  bool isNoReturn() const { return NoReturn; }
+
+  /// In ARC, whether this function retains its return value.  This
+  /// is not always reliable for call sites.
+  bool isReturnsRetained() const { return ReturnsRetained; }
+
+  /// getASTCallingConvention() - Return the AST-specified calling
+  /// convention.
+  CallingConv getASTCallingConvention() const {
+    return CallingConv(ASTCallingConvention);
+  }
+
+  /// getCallingConvention - Return the user specified calling
+  /// convention, which has been translated into an LLVM CC.
+  unsigned getCallingConvention() const { return CallingConvention; }
+
+  /// getEffectiveCallingConvention - Return the actual calling convention to
+  /// use, which may depend on the ABI.
+  unsigned getEffectiveCallingConvention() const {
+    return EffectiveCallingConvention;
+  }
+  void setEffectiveCallingConvention(unsigned Value) {
+    EffectiveCallingConvention = Value;
+  }
+
+  bool getHasRegParm() const { return HasRegParm; }
+  unsigned getRegParm() const { return RegParm; }
+
+  FunctionType::ExtInfo getExtInfo() const {
+    return FunctionType::ExtInfo(isNoReturn(),
+                                 getHasRegParm(), getRegParm(),
+                                 getASTCallingConvention(),
+                                 isReturnsRetained());
+  }
+
+  CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
+
+  ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
+  const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
+
+  void Profile(llvm::FoldingSetNodeID &ID) {
+    ID.AddInteger(getASTCallingConvention());
+    ID.AddBoolean(NoReturn);
+    ID.AddBoolean(ReturnsRetained);
+    ID.AddBoolean(HasRegParm);
+    ID.AddInteger(RegParm);
+    ID.AddInteger(Required.getOpaqueData());
+    getReturnType().Profile(ID);
+    for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
+      it->type.Profile(ID);
+  }
+  static void Profile(llvm::FoldingSetNodeID &ID,
+                      const FunctionType::ExtInfo &info,
+                      RequiredArgs required,
+                      CanQualType resultType,
+                      ArrayRef<CanQualType> argTypes) {
+    ID.AddInteger(info.getCC());
+    ID.AddBoolean(info.getNoReturn());
+    ID.AddBoolean(info.getProducesResult());
+    ID.AddBoolean(info.getHasRegParm());
+    ID.AddInteger(info.getRegParm());
+    ID.AddInteger(required.getOpaqueData());
+    resultType.Profile(ID);
+    for (ArrayRef<CanQualType>::iterator
+           i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
+      i->Profile(ID);
+    }
+  }
+};
+
+}  // end namespace CodeGen
+}  // end namespace clang
+
+#endif

Added: cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h?rev=193717&view=auto
==============================================================================
--- cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h (added)
+++ cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h Wed Oct 30 16:53:58 2013
@@ -0,0 +1,80 @@
+//==---- CodeGenABITypes.h - Convert Clang types to LLVM types for ABI -----==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// CodeGenABITypes is a simple interface for getting LLVM types for
+// the parameters and the return value of a function given the Clang
+// types.
+//
+// The class is implemented as a public wrapper around the private
+// CodeGenTypes class in lib/CodeGen.
+//
+// It allows other clients, like LLDB, to determine the LLVM types that are
+// actually used in function calls, which makes it possible to then determine
+// the acutal ABI locations (e.g. registers, stack locations, etc.) that
+// these parameters are stored in.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CODEGEN_ABITYPES_H
+#define LLVM_CLANG_CODEGEN_ABITYPES_H
+
+#include "clang/AST/CanonicalType.h"
+#include "clang/AST/Type.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
+
+namespace llvm {
+  class DataLayout;
+  class Module;
+}
+
+namespace clang {
+class ASTContext;
+class CXXRecordDecl;
+class CodeGenOptions;
+class DiagnosticsEngine;
+class ObjCMethodDecl;
+
+namespace CodeGen {
+class CGFunctionInfo;
+class CodeGenModule;
+
+class CodeGenABITypes
+{
+public:
+  CodeGenABITypes(ASTContext &C, const CodeGenOptions &CodeGenOpts,
+                  llvm::Module &M, const llvm::DataLayout &TD,
+                  DiagnosticsEngine &Diags);
+
+  ~CodeGenABITypes();
+
+  /// These methods all forward to methods in the private implementation class
+  /// CodeGenTypes.
+
+  const CGFunctionInfo &arrangeObjCMessageSendSignature(
+                                                     const ObjCMethodDecl *MD,
+                                                     QualType receiverType);
+  const CGFunctionInfo &arrangeFreeFunctionType(
+                                               CanQual<FunctionProtoType> Ty);
+  const CGFunctionInfo &arrangeFreeFunctionType(
+                                             CanQual<FunctionNoProtoType> Ty);
+  const CGFunctionInfo &arrangeCXXMethodType(const CXXRecordDecl *RD,
+                                             const FunctionProtoType *FTP);
+  const CGFunctionInfo &arrangeLLVMFunctionInfo(CanQualType returnType,
+                                         llvm::ArrayRef<CanQualType> argTypes,
+                                         FunctionType::ExtInfo info,
+                                         RequiredArgs args);
+
+private:
+  CodeGen::CodeGenModule *CGM;
+};
+
+}  // end namespace CodeGen
+}  // end namespace clang
+
+#endif

Modified: cfe/trunk/lib/CodeGen/ABIInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ABIInfo.h (original)
+++ cfe/trunk/lib/CodeGen/ABIInfo.h Wed Oct 30 16:53:58 2013
@@ -36,151 +36,6 @@ namespace clang {
   // the targets to support this, since the Targets currently live in a
   // layer below types n'stuff.
 
-  /// ABIArgInfo - Helper class to encapsulate information about how a
-  /// specific C type should be passed to or returned from a function.
-  class ABIArgInfo {
-  public:
-    enum Kind {
-      /// Direct - Pass the argument directly using the normal converted LLVM
-      /// type, or by coercing to another specified type stored in
-      /// 'CoerceToType').  If an offset is specified (in UIntData), then the
-      /// argument passed is offset by some number of bytes in the memory
-      /// representation. A dummy argument is emitted before the real argument
-      /// if the specified type stored in "PaddingType" is not zero.
-      Direct,
-
-      /// Extend - Valid only for integer argument types. Same as 'direct'
-      /// but also emit a zero/sign extension attribute.
-      Extend,
-
-      /// Indirect - Pass the argument indirectly via a hidden pointer
-      /// with the specified alignment (0 indicates default alignment).
-      Indirect,
-
-      /// Ignore - Ignore the argument (treat as void). Useful for void and
-      /// empty structs.
-      Ignore,
-
-      /// Expand - Only valid for aggregate argument types. The structure should
-      /// be expanded into consecutive arguments for its constituent fields.
-      /// Currently expand is only allowed on structures whose fields
-      /// are all scalar types or are themselves expandable types.
-      Expand,
-
-      KindFirst=Direct, KindLast=Expand
-    };
-
-  private:
-    Kind TheKind;
-    llvm::Type *TypeData;
-    llvm::Type *PaddingType;
-    unsigned UIntData;
-    bool BoolData0;
-    bool BoolData1;
-    bool InReg;
-    bool PaddingInReg;
-
-    ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
-               bool PIR, llvm::Type* P)
-      : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
-        BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
-
-  public:
-    ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
-
-    static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
-                                llvm::Type *Padding = 0) {
-      return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
-    }
-    static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
-      return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
-    }
-    static ABIArgInfo getExtend(llvm::Type *T = 0) {
-      return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
-    }
-    static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
-      return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
-    }
-    static ABIArgInfo getIgnore() {
-      return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
-    }
-    static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
-                                  , bool Realign = false
-                                  , llvm::Type *Padding = 0) {
-      return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false, 
-                        Padding);
-    }
-    static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
-                                  , bool Realign = false) {
-      return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
-    }
-    static ABIArgInfo getExpand() {
-      return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
-    }
-    static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
-                                           llvm::Type *Padding) {
-     return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
-                       Padding);
-    }
-
-    Kind getKind() const { return TheKind; }
-    bool isDirect() const { return TheKind == Direct; }
-    bool isExtend() const { return TheKind == Extend; }
-    bool isIgnore() const { return TheKind == Ignore; }
-    bool isIndirect() const { return TheKind == Indirect; }
-    bool isExpand() const { return TheKind == Expand; }
-
-    bool canHaveCoerceToType() const {
-      return TheKind == Direct || TheKind == Extend;
-    }
-
-    // Direct/Extend accessors
-    unsigned getDirectOffset() const {
-      assert((isDirect() || isExtend()) && "Not a direct or extend kind");
-      return UIntData;
-    }
-
-    llvm::Type *getPaddingType() const {
-      return PaddingType;
-    }
-
-    bool getPaddingInReg() const {
-      return PaddingInReg;
-    }
-
-    llvm::Type *getCoerceToType() const {
-      assert(canHaveCoerceToType() && "Invalid kind!");
-      return TypeData;
-    }
-
-    void setCoerceToType(llvm::Type *T) {
-      assert(canHaveCoerceToType() && "Invalid kind!");
-      TypeData = T;
-    }
-
-    bool getInReg() const {
-      assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
-      return InReg;
-    }
-
-    // Indirect accessors
-    unsigned getIndirectAlign() const {
-      assert(TheKind == Indirect && "Invalid kind!");
-      return UIntData;
-    }
-
-    bool getIndirectByVal() const {
-      assert(TheKind == Indirect && "Invalid kind!");
-      return BoolData0;
-    }
-
-    bool getIndirectRealign() const {
-      assert(TheKind == Indirect && "Invalid kind!");
-      return BoolData1;
-    }
-
-    void dump() const;
-  };
 
   /// ABIInfo - Target specific hooks for defining how a type should be
   /// passed or returned from functions.

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Wed Oct 30 16:53:58 2013
@@ -15,6 +15,7 @@
 #include "CGCall.h"
 #include "CodeGenModule.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Intrinsics.h"

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Oct 30 16:53:58 2013
@@ -19,6 +19,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Intrinsics.h"
 

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Oct 30 16:53:58 2013
@@ -22,6 +22,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Attributes.h"

Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Wed Oct 30 16:53:58 2013
@@ -122,192 +122,12 @@ namespace CodeGen {
     SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
   };
 
-  /// A class for recording the number of arguments that a function
-  /// signature requires.
-  class RequiredArgs {
-    /// The number of required arguments, or ~0 if the signature does
-    /// not permit optional arguments.
-    unsigned NumRequired;
-  public:
-    enum All_t { All };
-
-    RequiredArgs(All_t _) : NumRequired(~0U) {}
-    explicit RequiredArgs(unsigned n) : NumRequired(n) {
-      assert(n != ~0U);
-    }
-
-    /// Compute the arguments required by the given formal prototype,
-    /// given that there may be some additional, non-formal arguments
-    /// in play.
-    static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
-                                         unsigned additional) {
-      if (!prototype->isVariadic()) return All;
-      return RequiredArgs(prototype->getNumArgs() + additional);
-    }
-
-    static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
-      return forPrototypePlus(prototype, 0);
-    }
-
-    static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
-      return forPrototype(prototype.getTypePtr());
-    }
-
-    static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
-                                         unsigned additional) {
-      return forPrototypePlus(prototype.getTypePtr(), additional);
-    }
-
-    bool allowsOptionalArgs() const { return NumRequired != ~0U; }
-    unsigned getNumRequiredArgs() const {
-      assert(allowsOptionalArgs());
-      return NumRequired;
-    }
-
-    unsigned getOpaqueData() const { return NumRequired; }
-    static RequiredArgs getFromOpaqueData(unsigned value) {
-      if (value == ~0U) return All;
-      return RequiredArgs(value);
-    }
-  };
-
   /// FunctionArgList - Type for representing both the decl and type
   /// of parameters to a function. The decl must be either a
   /// ParmVarDecl or ImplicitParamDecl.
   class FunctionArgList : public SmallVector<const VarDecl*, 16> {
   };
 
-  /// CGFunctionInfo - Class to encapsulate the information about a
-  /// function definition.
-  class CGFunctionInfo : public llvm::FoldingSetNode {
-    struct ArgInfo {
-      CanQualType type;
-      ABIArgInfo info;
-    };
-
-    /// The LLVM::CallingConv to use for this function (as specified by the
-    /// user).
-    unsigned CallingConvention : 8;
-
-    /// The LLVM::CallingConv to actually use for this function, which may
-    /// depend on the ABI.
-    unsigned EffectiveCallingConvention : 8;
-
-    /// The clang::CallingConv that this was originally created with.
-    unsigned ASTCallingConvention : 8;
-
-    /// Whether this function is noreturn.
-    unsigned NoReturn : 1;
-
-    /// Whether this function is returns-retained.
-    unsigned ReturnsRetained : 1;
-
-    /// How many arguments to pass inreg.
-    unsigned HasRegParm : 1;
-    unsigned RegParm : 4;
-
-    RequiredArgs Required;
-
-    unsigned NumArgs;
-    ArgInfo *getArgsBuffer() {
-      return reinterpret_cast<ArgInfo*>(this+1);
-    }
-    const ArgInfo *getArgsBuffer() const {
-      return reinterpret_cast<const ArgInfo*>(this + 1);
-    }
-
-    CGFunctionInfo() : Required(RequiredArgs::All) {}
-
-  public:
-    static CGFunctionInfo *create(unsigned llvmCC,
-                                  const FunctionType::ExtInfo &extInfo,
-                                  CanQualType resultType,
-                                  ArrayRef<CanQualType> argTypes,
-                                  RequiredArgs required);
-
-    typedef const ArgInfo *const_arg_iterator;
-    typedef ArgInfo *arg_iterator;
-
-    const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
-    const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
-    arg_iterator arg_begin() { return getArgsBuffer() + 1; }
-    arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
-
-    unsigned  arg_size() const { return NumArgs; }
-
-    bool isVariadic() const { return Required.allowsOptionalArgs(); }
-    RequiredArgs getRequiredArgs() const { return Required; }
-
-    bool isNoReturn() const { return NoReturn; }
-
-    /// In ARC, whether this function retains its return value.  This
-    /// is not always reliable for call sites.
-    bool isReturnsRetained() const { return ReturnsRetained; }
-
-    /// getASTCallingConvention() - Return the AST-specified calling
-    /// convention.
-    CallingConv getASTCallingConvention() const {
-      return CallingConv(ASTCallingConvention);
-    }
-
-    /// getCallingConvention - Return the user specified calling
-    /// convention, which has been translated into an LLVM CC.
-    unsigned getCallingConvention() const { return CallingConvention; }
-
-    /// getEffectiveCallingConvention - Return the actual calling convention to
-    /// use, which may depend on the ABI.
-    unsigned getEffectiveCallingConvention() const {
-      return EffectiveCallingConvention;
-    }
-    void setEffectiveCallingConvention(unsigned Value) {
-      EffectiveCallingConvention = Value;
-    }
-
-    bool getHasRegParm() const { return HasRegParm; }
-    unsigned getRegParm() const { return RegParm; }
-
-    FunctionType::ExtInfo getExtInfo() const {
-      return FunctionType::ExtInfo(isNoReturn(),
-                                   getHasRegParm(), getRegParm(),
-                                   getASTCallingConvention(),
-                                   isReturnsRetained());
-    }
-
-    CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
-
-    ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
-    const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
-
-    void Profile(llvm::FoldingSetNodeID &ID) {
-      ID.AddInteger(getASTCallingConvention());
-      ID.AddBoolean(NoReturn);
-      ID.AddBoolean(ReturnsRetained);
-      ID.AddBoolean(HasRegParm);
-      ID.AddInteger(RegParm);
-      ID.AddInteger(Required.getOpaqueData());
-      getReturnType().Profile(ID);
-      for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
-        it->type.Profile(ID);
-    }
-    static void Profile(llvm::FoldingSetNodeID &ID,
-                        const FunctionType::ExtInfo &info,
-                        RequiredArgs required,
-                        CanQualType resultType,
-                        ArrayRef<CanQualType> argTypes) {
-      ID.AddInteger(info.getCC());
-      ID.AddBoolean(info.getNoReturn());
-      ID.AddBoolean(info.getProducesResult());
-      ID.AddBoolean(info.getHasRegParm());
-      ID.AddInteger(info.getRegParm());
-      ID.AddInteger(required.getOpaqueData());
-      resultType.Profile(ID);
-      for (ArrayRef<CanQualType>::iterator
-             i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
-        i->Profile(ID);
-      }
-    }
-  };
-  
   /// ReturnValueSlot - Contains the address where the return value of a 
   /// function can be stored, and whether the address is volatile or not.
   class ReturnValueSlot {

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Oct 30 16:53:58 2013
@@ -22,6 +22,7 @@
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 
 using namespace clang;

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Oct 30 16:53:58 2013
@@ -21,6 +21,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/GlobalVariable.h"

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Oct 30 16:53:58 2013
@@ -16,6 +16,7 @@
 #include "CGCXXABI.h"
 #include "CGDebugInfo.h"
 #include "CGObjCRuntime.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/Support/CallSite.h"

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Oct 30 16:53:58 2013
@@ -20,6 +20,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/IR/DataLayout.h"

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Oct 30 16:53:58 2013
@@ -23,6 +23,7 @@
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SetVector.h"

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp Wed Oct 30 16:53:58 2013
@@ -20,6 +20,7 @@
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/Support/CallSite.h"
 
 using namespace clang;

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Wed Oct 30 16:53:58 2013
@@ -16,6 +16,7 @@
 #include "CodeGenModule.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecordLayout.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SetVector.h"

Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Wed Oct 30 16:53:58 2013
@@ -41,6 +41,7 @@ add_clang_library(clangCodeGen
   CGStmt.cpp
   CGVTables.cpp
   CGVTT.cpp
+  CodeGenABITypes.cpp
   CodeGenAction.cpp
   CodeGenFunction.cpp
   CodeGenModule.cpp

Added: cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp?rev=193717&view=auto
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp (added)
+++ cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp Wed Oct 30 16:53:58 2013
@@ -0,0 +1,69 @@
+//==--- CodeGenABITypes.cpp - Convert Clang types to LLVM types for ABI ----==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// CodeGenABITypes is a simple interface for getting LLVM types for
+// the parameters and the return value of a function given the Clang
+// types.
+//
+// The class is implemented as a public wrapper around the private
+// CodeGenTypes class in lib/CodeGen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CodeGen/CodeGenABITypes.h"
+
+#include "clang/CodeGen/CGFunctionInfo.h"
+#include "CodeGenModule.h"
+
+using namespace clang;
+using namespace CodeGen;
+
+CodeGenABITypes::CodeGenABITypes(ASTContext &C,
+                                 const CodeGenOptions &CodeGenOpts,
+                                 llvm::Module &M,
+                                 const llvm::DataLayout &TD,
+                                 DiagnosticsEngine &Diags)
+  : CGM(new CodeGen::CodeGenModule(C, CodeGenOpts, M, TD, Diags)) {
+}
+
+CodeGenABITypes::~CodeGenABITypes()
+{
+  delete CGM;
+}
+
+const CGFunctionInfo &
+CodeGenABITypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
+                                                 QualType receiverType) {
+  return CGM->getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
+}
+
+const CGFunctionInfo &
+CodeGenABITypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty) {
+  return CGM->getTypes().arrangeFreeFunctionType(Ty);
+}
+
+const CGFunctionInfo &
+CodeGenABITypes::arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty) {
+  return CGM->getTypes().arrangeFreeFunctionType(Ty);
+}
+
+const CGFunctionInfo &
+CodeGenABITypes::arrangeCXXMethodType(const CXXRecordDecl *RD,
+                                      const FunctionProtoType *FTP) {
+  return CGM->getTypes().arrangeCXXMethodType(RD, FTP);
+}
+
+const CGFunctionInfo &
+CodeGenABITypes::arrangeLLVMFunctionInfo(CanQualType returnType,
+                                         llvm::ArrayRef<CanQualType> argTypes,
+                                         FunctionType::ExtInfo info,
+                                         RequiredArgs args) {
+  return CGM->getTypes().arrangeLLVMFunctionInfo(returnType, argTypes,
+                                                info, args);
+}

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Oct 30 16:53:58 2013
@@ -23,6 +23,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/Basic/OpenCL.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Intrinsics.h"

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Oct 30 16:53:58 2013
@@ -22,6 +22,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Module.h"

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=193717&r1=193716&r2=193717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Oct 30 16:53:58 2013
@@ -17,6 +17,7 @@
 #include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "clang/AST/RecordLayout.h"
+#include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/IR/DataLayout.h"





More information about the cfe-commits mailing list