CGCall.h revision 3b844ba7d5be205a9b4f5f0b0d1b7978977f4b8c
10dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
20dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//
30dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//                     The LLVM Compiler Infrastructure
40dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//
50dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar// This file is distributed under the University of Illinois Open Source
60dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar// License. See LICENSE.TXT for details.
70dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//
80dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//===----------------------------------------------------------------------===//
90dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//
100dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar// These classes wrap the information about a call or function
110dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar// definition used to handle ABI compliancy.
120dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//
130dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar//===----------------------------------------------------------------------===//
140dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
150dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#ifndef CLANG_CODEGEN_CGCALL_H
160dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#define CLANG_CODEGEN_CGCALL_H
170dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
1855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGValue.h"
1955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/CanonicalType.h"
2055fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/Type.h"
2131777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson#include "llvm/ADT/FoldingSet.h"
223b844ba7d5be205a9b4f5f0b0d1b7978977f4b8cChandler Carruth#include "llvm/IR/Value.h"
2346f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
2488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar// FIXME: Restructure so we don't have to expose so much stuff.
2588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar#include "ABIInfo.h"
2688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
270dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace llvm {
28761d7f78e2dac7ea5f35828c2271e60d91e106ceDevang Patel  struct AttributeWithIndex;
2988c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar  class Function;
3088c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar  class Type;
310dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class Value;
320dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
330dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  template<typename T, unsigned> class SmallVector;
340dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}
350dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
360dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace clang {
370dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class ASTContext;
380dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class Decl;
390dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class FunctionDecl;
400dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class ObjCMethodDecl;
417c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  class VarDecl;
420dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
430dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace CodeGen {
44686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
450dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
46c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman  struct CallArg {
47c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman    RValue RV;
48c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman    QualType Ty;
4955d484802f3e27930317739efc5f5956b78aac25Eli Friedman    bool NeedsCopy;
5055d484802f3e27930317739efc5f5956b78aac25Eli Friedman    CallArg(RValue rv, QualType ty, bool needscopy)
5155d484802f3e27930317739efc5f5956b78aac25Eli Friedman    : RV(rv), Ty(ty), NeedsCopy(needscopy)
52c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman    { }
53c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman  };
54c6d07821c529bb95e4cf072e49b736c5142f1786Eli Friedman
550dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// CallArgList - Type for representing both the value and type of
560dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// arguments in a call.
57d26bc76c98006609002d9930f8840490e88ac5b5John McCall  class CallArgList :
58686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    public SmallVector<CallArg, 16> {
59413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall  public:
60f85e193739c953358c865005855253af4f68a497John McCall    struct Writeback {
61f85e193739c953358c865005855253af4f68a497John McCall      /// The original argument.
62f85e193739c953358c865005855253af4f68a497John McCall      llvm::Value *Address;
63f85e193739c953358c865005855253af4f68a497John McCall
64f85e193739c953358c865005855253af4f68a497John McCall      /// The pointee type of the original argument.
65f85e193739c953358c865005855253af4f68a497John McCall      QualType AddressType;
66f85e193739c953358c865005855253af4f68a497John McCall
67f85e193739c953358c865005855253af4f68a497John McCall      /// The temporary alloca.
68f85e193739c953358c865005855253af4f68a497John McCall      llvm::Value *Temporary;
69f85e193739c953358c865005855253af4f68a497John McCall    };
70f85e193739c953358c865005855253af4f68a497John McCall
7155d484802f3e27930317739efc5f5956b78aac25Eli Friedman    void add(RValue rvalue, QualType type, bool needscopy = false) {
7255d484802f3e27930317739efc5f5956b78aac25Eli Friedman      push_back(CallArg(rvalue, type, needscopy));
73413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall    }
74f85e193739c953358c865005855253af4f68a497John McCall
75f85e193739c953358c865005855253af4f68a497John McCall    void addFrom(const CallArgList &other) {
76f85e193739c953358c865005855253af4f68a497John McCall      insert(end(), other.begin(), other.end());
77f85e193739c953358c865005855253af4f68a497John McCall      Writebacks.insert(Writebacks.end(),
78f85e193739c953358c865005855253af4f68a497John McCall                        other.Writebacks.begin(), other.Writebacks.end());
79f85e193739c953358c865005855253af4f68a497John McCall    }
80f85e193739c953358c865005855253af4f68a497John McCall
81f85e193739c953358c865005855253af4f68a497John McCall    void addWriteback(llvm::Value *address, QualType addressType,
82f85e193739c953358c865005855253af4f68a497John McCall                      llvm::Value *temporary) {
83f85e193739c953358c865005855253af4f68a497John McCall      Writeback writeback;
84f85e193739c953358c865005855253af4f68a497John McCall      writeback.Address = address;
85f85e193739c953358c865005855253af4f68a497John McCall      writeback.AddressType = addressType;
86f85e193739c953358c865005855253af4f68a497John McCall      writeback.Temporary = temporary;
87f85e193739c953358c865005855253af4f68a497John McCall      Writebacks.push_back(writeback);
88f85e193739c953358c865005855253af4f68a497John McCall    }
89f85e193739c953358c865005855253af4f68a497John McCall
90f85e193739c953358c865005855253af4f68a497John McCall    bool hasWritebacks() const { return !Writebacks.empty(); }
91f85e193739c953358c865005855253af4f68a497John McCall
92686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    typedef SmallVectorImpl<Writeback>::const_iterator writeback_iterator;
93f85e193739c953358c865005855253af4f68a497John McCall    writeback_iterator writeback_begin() const { return Writebacks.begin(); }
94f85e193739c953358c865005855253af4f68a497John McCall    writeback_iterator writeback_end() const { return Writebacks.end(); }
95f85e193739c953358c865005855253af4f68a497John McCall
96f85e193739c953358c865005855253af4f68a497John McCall  private:
97686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<Writeback, 1> Writebacks;
98d26bc76c98006609002d9930f8840490e88ac5b5John McCall  };
990dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
100de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  /// A class for recording the number of arguments that a function
101de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  /// signature requires.
102de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  class RequiredArgs {
103de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// The number of required arguments, or ~0 if the signature does
104de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// not permit optional arguments.
105de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned NumRequired;
106de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  public:
107de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    enum All_t { All };
108de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
109de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    RequiredArgs(All_t _) : NumRequired(~0U) {}
110de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    explicit RequiredArgs(unsigned n) : NumRequired(n) {
111de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      assert(n != ~0U);
112de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
113de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
114de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// Compute the arguments required by the given formal prototype,
115de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// given that there may be some additional, non-formal arguments
116de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// in play.
117de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
118de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                         unsigned additional) {
119de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      if (!prototype->isVariadic()) return All;
120de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return RequiredArgs(prototype->getNumArgs() + additional);
121de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
122de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
123de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
124de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return forPrototypePlus(prototype, 0);
125de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
126de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
127de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
128de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return forPrototype(prototype.getTypePtr());
129de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
130de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
131de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
132de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                         unsigned additional) {
133de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return forPrototypePlus(prototype.getTypePtr(), additional);
134de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
135de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
136de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    bool allowsOptionalArgs() const { return NumRequired != ~0U; }
137e56bb36e8eea89bae7dfe6eb6ea0455af126bf4aJohn McCall    unsigned getNumRequiredArgs() const {
138de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      assert(allowsOptionalArgs());
139de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return NumRequired;
140de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
141de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
142de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned getOpaqueData() const { return NumRequired; }
143de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static RequiredArgs getFromOpaqueData(unsigned value) {
144de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      if (value == ~0U) return All;
145de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return RequiredArgs(value);
146de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
147de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  };
148de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
1497c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// FunctionArgList - Type for representing both the decl and type
1507c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// of parameters to a function. The decl must be either a
1517c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// ParmVarDecl or ImplicitParamDecl.
152686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  class FunctionArgList : public SmallVector<const VarDecl*, 16> {
153d26bc76c98006609002d9930f8840490e88ac5b5John McCall  };
1541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1550dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// CGFunctionInfo - Class to encapsulate the information about a
1560dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// function definition.
15740a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar  class CGFunctionInfo : public llvm::FoldingSetNode {
15888c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    struct ArgInfo {
159ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall      CanQualType type;
16088c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar      ABIArgInfo info;
16188c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    };
16288c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
163ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// The LLVM::CallingConv to use for this function (as specified by the
164ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// user).
165de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned CallingConvention : 8;
166bac7c250c9b098ee3d637c8ed77da62e860d9244Daniel Dunbar
167ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// The LLVM::CallingConv to actually use for this function, which may
168ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// depend on the ABI.
169de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned EffectiveCallingConvention : 8;
170de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
171de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// The clang::CallingConv that this was originally created with.
172de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned ASTCallingConvention : 8;
173ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar
17404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall    /// Whether this function is noreturn.
175de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned NoReturn : 1;
17604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
177f85e193739c953358c865005855253af4f68a497John McCall    /// Whether this function is returns-retained.
178de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned ReturnsRetained : 1;
179de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
180de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// How many arguments to pass inreg.
181de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned HasRegParm : 1;
182de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    unsigned RegParm : 4;
183de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
184de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    RequiredArgs Required;
185f85e193739c953358c865005855253af4f68a497John McCall
18688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    unsigned NumArgs;
187de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    ArgInfo *getArgsBuffer() {
188de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return reinterpret_cast<ArgInfo*>(this+1);
189de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
190de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    const ArgInfo *getArgsBuffer() const {
191de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return reinterpret_cast<const ArgInfo*>(this + 1);
192de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
1930dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
194de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    CGFunctionInfo() : Required(RequiredArgs::All) {}
195425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
1960dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  public:
197de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    static CGFunctionInfo *create(unsigned llvmCC,
198de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                  const FunctionType::ExtInfo &extInfo,
199de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                  CanQualType resultType,
200de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                  ArrayRef<CanQualType> argTypes,
201de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                  RequiredArgs required);
202de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
20388c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    typedef const ArgInfo *const_arg_iterator;
20488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    typedef ArgInfo *arg_iterator;
205a0a99e02f5b2de3817706071077298ef040634feDaniel Dunbar
206de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
207de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
208de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    arg_iterator arg_begin() { return getArgsBuffer() + 1; }
209de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
2100dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
2114b5f0a4bd6645e87e5feae4be4675ce87d97b4a5Daniel Dunbar    unsigned  arg_size() const { return NumArgs; }
2124b5f0a4bd6645e87e5feae4be4675ce87d97b4a5Daniel Dunbar
213de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    bool isVariadic() const { return Required.allowsOptionalArgs(); }
214de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    RequiredArgs getRequiredArgs() const { return Required; }
215de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
21604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall    bool isNoReturn() const { return NoReturn; }
21704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
218de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// In ARC, whether this function retains its return value.  This
219f85e193739c953358c865005855253af4f68a497John McCall    /// is not always reliable for call sites.
220f85e193739c953358c865005855253af4f68a497John McCall    bool isReturnsRetained() const { return ReturnsRetained; }
221f85e193739c953358c865005855253af4f68a497John McCall
222de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// getASTCallingConvention() - Return the AST-specified calling
223ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// convention.
224de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    CallingConv getASTCallingConvention() const {
225de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return CallingConv(ASTCallingConvention);
226de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
227de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
228de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// getCallingConvention - Return the user specified calling
229de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    /// convention, which has been translated into an LLVM CC.
230bac7c250c9b098ee3d637c8ed77da62e860d9244Daniel Dunbar    unsigned getCallingConvention() const { return CallingConvention; }
231bac7c250c9b098ee3d637c8ed77da62e860d9244Daniel Dunbar
232ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// getEffectiveCallingConvention - Return the actual calling convention to
233ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    /// use, which may depend on the ABI.
234ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    unsigned getEffectiveCallingConvention() const {
235ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar      return EffectiveCallingConvention;
236ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    }
237ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    void setEffectiveCallingConvention(unsigned Value) {
238ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar      EffectiveCallingConvention = Value;
239ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar    }
240ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar
241a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    bool getHasRegParm() const { return HasRegParm; }
242425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    unsigned getRegParm() const { return RegParm; }
243425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
244de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    FunctionType::ExtInfo getExtInfo() const {
245de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      return FunctionType::ExtInfo(isNoReturn(),
246de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                   getHasRegParm(), getRegParm(),
247de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                   getASTCallingConvention(),
248de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                   isReturnsRetained());
249de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    }
250de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
251de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
252bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar
253de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
254de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
25540a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar
25640a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    void Profile(llvm::FoldingSetNodeID &ID) {
257de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddInteger(getASTCallingConvention());
25804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall      ID.AddBoolean(NoReturn);
259f85e193739c953358c865005855253af4f68a497John McCall      ID.AddBoolean(ReturnsRetained);
260a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman      ID.AddBoolean(HasRegParm);
261425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola      ID.AddInteger(RegParm);
262de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddInteger(Required.getOpaqueData());
26335e67d4387bbe3e7e17ee6b17eaa42eebb0eb9f1Daniel Dunbar      getReturnType().Profile(ID);
26488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar      for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
26588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar        it->type.Profile(ID);
26640a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    }
2671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    static void Profile(llvm::FoldingSetNodeID &ID,
268de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                        const FunctionType::ExtInfo &info,
269de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                        RequiredArgs required,
270de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                        CanQualType resultType,
271de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                        ArrayRef<CanQualType> argTypes) {
272de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddInteger(info.getCC());
273de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddBoolean(info.getNoReturn());
274de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddBoolean(info.getProducesResult());
275de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddBoolean(info.getHasRegParm());
276de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddInteger(info.getRegParm());
277de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      ID.AddInteger(required.getOpaqueData());
278de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      resultType.Profile(ID);
279de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      for (ArrayRef<CanQualType>::iterator
280de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall             i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
281de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall        i->Profile(ID);
282ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall      }
28340a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    }
2840dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  };
28531777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson
286d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson  /// ReturnValueSlot - Contains the address where the return value of a
287d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson  /// function can be stored, and whether the address is volatile or not.
28831777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  class ReturnValueSlot {
28931777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
29031777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson
29131777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  public:
29231777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    ReturnValueSlot() {}
29331777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
29431777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson      : Value(Value, IsVolatile) {}
29531777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson
29631777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    bool isNull() const { return !getValue(); }
29731777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson
29831777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    bool isVolatile() const { return Value.getInt(); }
29931777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson    llvm::Value *getValue() const { return Value.getPointer(); }
30031777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  };
30131777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson
3020dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}  // end namespace CodeGen
3030dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}  // end namespace clang
3040dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
3050dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#endif
306