CGCall.h revision 88c2fa96be989571b4afb6229f0ef5a3ef4450cb
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
1840a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar#include <llvm/ADT/FoldingSet.h>
190dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "clang/AST/Type.h"
200dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
2146f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar#include "CGValue.h"
2246f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
2388c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar// FIXME: Restructure so we don't have to expose so much stuff.
2488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar#include "ABIInfo.h"
2588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
260dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace llvm {
27761d7f78e2dac7ea5f35828c2271e60d91e106ceDevang Patel  struct AttributeWithIndex;
2888c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar  class Function;
2988c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar  class Type;
300dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class Value;
310dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
320dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  template<typename T, unsigned> class SmallVector;
330dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}
340dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
350dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace clang {
360dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class ASTContext;
370dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class Decl;
380dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class FunctionDecl;
390dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  class ObjCMethodDecl;
407c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  class VarDecl;
410dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
420dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbarnamespace CodeGen {
43761d7f78e2dac7ea5f35828c2271e60d91e106ceDevang Patel  typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
440dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
450dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// CallArgList - Type for representing both the value and type of
460dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// arguments in a call.
4746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
480dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
497c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// FunctionArgList - Type for representing both the decl and type
507c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// of parameters to a function. The decl must be either a
517c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  /// ParmVarDecl or ImplicitParamDecl.
527c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
537c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                            16> FunctionArgList;
545323a4b0a1c248fa2ffdf886bb41a5d8fba71d2dDaniel Dunbar
550dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// CGFunctionInfo - Class to encapsulate the information about a
560dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  /// function definition.
5740a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar  class CGFunctionInfo : public llvm::FoldingSetNode {
5888c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    struct ArgInfo {
5988c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar      QualType type;
6088c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar      ABIArgInfo info;
6188c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    };
6288c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
6388c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    unsigned NumArgs;
6488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    ArgInfo *Args;
650dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
660dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  public:
6788c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    typedef const ArgInfo *const_arg_iterator;
6888c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    typedef ArgInfo *arg_iterator;
69a0a99e02f5b2de3817706071077298ef040634feDaniel Dunbar
70541b63b1a9db77e4a8670e9823711c2c12e58afbDaniel Dunbar    CGFunctionInfo(QualType ResTy,
71541b63b1a9db77e4a8670e9823711c2c12e58afbDaniel Dunbar                   const llvm::SmallVector<QualType, 16> &ArgTys);
7288c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    ~CGFunctionInfo() { delete[] Args; }
7388c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
7488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    const_arg_iterator arg_begin() const { return Args + 1; }
7588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
7688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    arg_iterator arg_begin() { return Args + 1; }
7788c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    arg_iterator arg_end() { return Args + 1 + NumArgs; }
780dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
7988c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    QualType getReturnType() const { return Args[0].type; }
80bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar
8188c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    ABIArgInfo &getReturnInfo() { return Args[0].info; }
8288c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
8340a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar
8440a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    void Profile(llvm::FoldingSetNodeID &ID) {
8588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar      for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
8688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar        it->type.Profile(ID);
8740a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    }
8840a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    template<class Iterator>
8940a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    static void Profile(llvm::FoldingSetNodeID &ID,
9040a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar                        QualType ResTy,
9140a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar                        Iterator begin,
9240a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar                        Iterator end) {
9340a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar      ResTy.Profile(ID);
9440a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar      for (; begin != end; ++begin)
9540a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar        begin->Profile(ID);
9640a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar    }
970dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar  };
980dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}  // end namespace CodeGen
990dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar}  // end namespace clang
1000dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar
1010dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#endif
102