CGCall.h revision 263508
1317027Sdim//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
2317027Sdim//
3353358Sdim//                     The LLVM Compiler Infrastructure
4353358Sdim//
5353358Sdim// This file is distributed under the University of Illinois Open Source
6317027Sdim// License. See LICENSE.TXT for details.
7317027Sdim//
8317027Sdim//===----------------------------------------------------------------------===//
9317027Sdim//
10317027Sdim// These classes wrap the information about a call or function
11317027Sdim// definition used to handle ABI compliancy.
12317027Sdim//
13317027Sdim//===----------------------------------------------------------------------===//
14317027Sdim
15344779Sdim#ifndef CLANG_CODEGEN_CGCALL_H
16344779Sdim#define CLANG_CODEGEN_CGCALL_H
17317027Sdim
18317027Sdim#include "CGValue.h"
19317027Sdim#include "EHScopeStack.h"
20317027Sdim#include "clang/AST/CanonicalType.h"
21317027Sdim#include "clang/AST/Type.h"
22317027Sdim#include "llvm/ADT/FoldingSet.h"
23317027Sdim#include "llvm/IR/Value.h"
24317027Sdim
25317027Sdim// FIXME: Restructure so we don't have to expose so much stuff.
26317027Sdim#include "ABIInfo.h"
27317027Sdim
28317027Sdimnamespace llvm {
29317027Sdim  class AttributeSet;
30317027Sdim  class Function;
31317027Sdim  class Type;
32317027Sdim  class Value;
33317027Sdim}
34317027Sdim
35317027Sdimnamespace clang {
36  class ASTContext;
37  class Decl;
38  class FunctionDecl;
39  class ObjCMethodDecl;
40  class VarDecl;
41
42namespace CodeGen {
43  typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
44
45  struct CallArg {
46    RValue RV;
47    QualType Ty;
48    bool NeedsCopy;
49    CallArg(RValue rv, QualType ty, bool needscopy)
50    : RV(rv), Ty(ty), NeedsCopy(needscopy)
51    { }
52  };
53
54  /// CallArgList - Type for representing both the value and type of
55  /// arguments in a call.
56  class CallArgList :
57    public SmallVector<CallArg, 16> {
58  public:
59    struct Writeback {
60      /// The original argument.  Note that the argument l-value
61      /// is potentially null.
62      LValue Source;
63
64      /// The temporary alloca.
65      llvm::Value *Temporary;
66
67      /// A value to "use" after the writeback, or null.
68      llvm::Value *ToUse;
69    };
70
71    struct CallArgCleanup {
72      EHScopeStack::stable_iterator Cleanup;
73
74      /// The "is active" insertion point.  This instruction is temporary and
75      /// will be removed after insertion.
76      llvm::Instruction *IsActiveIP;
77    };
78
79    void add(RValue rvalue, QualType type, bool needscopy = false) {
80      push_back(CallArg(rvalue, type, needscopy));
81    }
82
83    void addFrom(const CallArgList &other) {
84      insert(end(), other.begin(), other.end());
85      Writebacks.insert(Writebacks.end(),
86                        other.Writebacks.begin(), other.Writebacks.end());
87    }
88
89    void addWriteback(LValue srcLV, llvm::Value *temporary,
90                      llvm::Value *toUse) {
91      Writeback writeback;
92      writeback.Source = srcLV;
93      writeback.Temporary = temporary;
94      writeback.ToUse = toUse;
95      Writebacks.push_back(writeback);
96    }
97
98    bool hasWritebacks() const { return !Writebacks.empty(); }
99
100    typedef SmallVectorImpl<Writeback>::const_iterator writeback_iterator;
101    writeback_iterator writeback_begin() const { return Writebacks.begin(); }
102    writeback_iterator writeback_end() const { return Writebacks.end(); }
103
104    void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
105                                   llvm::Instruction *IsActiveIP) {
106      CallArgCleanup ArgCleanup;
107      ArgCleanup.Cleanup = Cleanup;
108      ArgCleanup.IsActiveIP = IsActiveIP;
109      CleanupsToDeactivate.push_back(ArgCleanup);
110    }
111
112    ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
113      return CleanupsToDeactivate;
114    }
115
116  private:
117    SmallVector<Writeback, 1> Writebacks;
118
119    /// Deactivate these cleanups immediately before making the call.  This
120    /// is used to cleanup objects that are owned by the callee once the call
121    /// occurs.
122    SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
123  };
124
125  /// FunctionArgList - Type for representing both the decl and type
126  /// of parameters to a function. The decl must be either a
127  /// ParmVarDecl or ImplicitParamDecl.
128  class FunctionArgList : public SmallVector<const VarDecl*, 16> {
129  };
130
131  /// ReturnValueSlot - Contains the address where the return value of a
132  /// function can be stored, and whether the address is volatile or not.
133  class ReturnValueSlot {
134    llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
135
136  public:
137    ReturnValueSlot() {}
138    ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
139      : Value(Value, IsVolatile) {}
140
141    bool isNull() const { return !getValue(); }
142
143    bool isVolatile() const { return Value.getInt(); }
144    llvm::Value *getValue() const { return Value.getPointer(); }
145  };
146
147}  // end namespace CodeGen
148}  // end namespace clang
149
150#endif
151