]> granicus.if.org Git - clang/blobdiff - lib/CodeGen/CGCall.h
Header guard canonicalization, clang part.
[clang] / lib / CodeGen / CGCall.h
index 55af4e5fbfa0ed3bb74fac3a911719d4d58bb254..b228733fb8ce56785e6430e58ac8878efac8f4e0 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef CLANG_CODEGEN_CGCALL_H
-#define CLANG_CODEGEN_CGCALL_H
+#ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H
+#define LLVM_CLANG_LIB_CODEGEN_CGCALL_H
 
 #include "CGValue.h"
+#include "EHScopeStack.h"
 #include "clang/AST/CanonicalType.h"
 #include "clang/AST/Type.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "ABIInfo.h"
 
 namespace llvm {
-  struct AttributeWithIndex;
+  class AttributeSet;
   class Function;
   class Type;
   class Value;
-
-  template<typename T, unsigned> class SmallVector;
 }
 
 namespace clang {
@@ -41,7 +40,7 @@ namespace clang {
   class VarDecl;
 
 namespace CodeGen {
-  typedef SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
+  typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
 
   struct CallArg {
     RValue RV;
@@ -57,15 +56,26 @@ namespace CodeGen {
   class CallArgList :
     public SmallVector<CallArg, 16> {
   public:
-    struct Writeback {
-      /// The original argument.
-      llvm::Value *Address;
+    CallArgList() : StackBase(nullptr), StackBaseMem(nullptr) {}
 
-      /// The pointee type of the original argument.
-      QualType AddressType;
+    struct Writeback {
+      /// The original argument.  Note that the argument l-value
+      /// is potentially null.
+      LValue Source;
 
       /// The temporary alloca.
       llvm::Value *Temporary;
+
+      /// A value to "use" after the writeback, or null.
+      llvm::Value *ToUse;
+    };
+
+    struct CallArgCleanup {
+      EHScopeStack::stable_iterator Cleanup;
+
+      /// The "is active" insertion point.  This instruction is temporary and
+      /// will be removed after insertion.
+      llvm::Instruction *IsActiveIP;
     };
 
     void add(RValue rvalue, QualType type, bool needscopy = false) {
@@ -78,72 +88,62 @@ namespace CodeGen {
                         other.Writebacks.begin(), other.Writebacks.end());
     }
 
-    void addWriteback(llvm::Value *address, QualType addressType,
-                      llvm::Value *temporary) {
+    void addWriteback(LValue srcLV, llvm::Value *temporary,
+                      llvm::Value *toUse) {
       Writeback writeback;
-      writeback.Address = address;
-      writeback.AddressType = addressType;
+      writeback.Source = srcLV;
       writeback.Temporary = temporary;
+      writeback.ToUse = toUse;
       Writebacks.push_back(writeback);
     }
 
     bool hasWritebacks() const { return !Writebacks.empty(); }
 
-    typedef SmallVectorImpl<Writeback>::const_iterator writeback_iterator;
-    writeback_iterator writeback_begin() const { return Writebacks.begin(); }
-    writeback_iterator writeback_end() const { return Writebacks.end(); }
+    typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator>
+      writeback_const_range;
 
-  private:
-    SmallVector<Writeback, 1> Writebacks;
-  };
-
-  /// 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);
+    writeback_const_range writebacks() const {
+      return writeback_const_range(Writebacks.begin(), Writebacks.end());
     }
 
-    /// 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);
+    void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
+                                   llvm::Instruction *IsActiveIP) {
+      CallArgCleanup ArgCleanup;
+      ArgCleanup.Cleanup = Cleanup;
+      ArgCleanup.IsActiveIP = IsActiveIP;
+      CleanupsToDeactivate.push_back(ArgCleanup);
     }
 
-    static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
-      return forPrototypePlus(prototype, 0);
+    ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
+      return CleanupsToDeactivate;
     }
 
-    static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
-      return forPrototype(prototype.getTypePtr());
-    }
+    void allocateArgumentMemory(CodeGenFunction &CGF);
+    llvm::Instruction *getStackBase() const { return StackBase; }
+    void freeArgumentMemory(CodeGenFunction &CGF) const;
 
-    static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
-                                         unsigned additional) {
-      return forPrototypePlus(prototype.getTypePtr(), additional);
-    }
+    /// \brief Returns if we're using an inalloca struct to pass arguments in
+    /// memory.
+    bool isUsingInAlloca() const { return StackBase; }
 
-    bool allowsOptionalArgs() const { return NumRequired != ~0U; }
-    unsigned getNumRequiredArgs() const {
-      assert(allowsOptionalArgs());
-      return NumRequired;
-    }
+  private:
+    SmallVector<Writeback, 1> Writebacks;
 
-    unsigned getOpaqueData() const { return NumRequired; }
-    static RequiredArgs getFromOpaqueData(unsigned value) {
-      if (value == ~0U) return All;
-      return RequiredArgs(value);
-    }
+    /// Deactivate these cleanups immediately before making the call.  This
+    /// is used to cleanup objects that are owned by the callee once the call
+    /// occurs.
+    SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
+
+    /// The stacksave call.  It dominates all of the argument evaluation.
+    llvm::CallInst *StackBase;
+
+    /// The alloca holding the stackbase.  We need it to maintain SSA form.
+    llvm::AllocaInst *StackBaseMem;
+
+    /// The iterator pointing to the stack restore cleanup.  We manually run and
+    /// deactivate this cleanup after the call in the unexceptional case because
+    /// it doesn't run in the normal order.
+    EHScopeStack::stable_iterator StackCleanup;
   };
 
   /// FunctionArgList - Type for representing both the decl and type
@@ -152,137 +152,6 @@ namespace CodeGen {
   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 {