ABIInfo.h revision 88c2fa96be989571b4afb6229f0ef5a3ef4450cb
19eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
29eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//
39eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//                     The LLVM Compiler Infrastructure
49eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//
59eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar// This file is distributed under the University of Illinois Open Source
69eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar// License. See LICENSE.TXT for details.
79eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//
89eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar//===----------------------------------------------------------------------===//
99eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
109eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar#ifndef CLANG_CODEGEN_ABIINFO_H
119eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar#define CLANG_CODEGEN_ABIINFO_H
129eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1388c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbarnamespace llvm {
1488c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar  class Type;
1588c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar}
1688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
179eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbarnamespace clang {
189eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  /* FIXME: All of this stuff should be part of the target interface
199eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar     somehow. It is currently here because it is not clear how to factor
209eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar     the targets to support this, since the Targets currently live in a
219eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar     layer below types n'stuff.
229eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  */
239eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
249eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  /// ABIArgInfo - Helper class to encapsulate information about how a
259eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  /// specific C type should be passed to or returned from a function.
269eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  class ABIArgInfo {
279eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  public:
289eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    enum Kind {
299eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      Default,
309eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      StructRet, /// Only valid for return values. The return value
319eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// should be passed through a pointer to a caller
329eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// allocated location passed as an implicit first
339eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// argument to the function.
349eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
359eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      Ignore,    /// Ignore the argument (treat as void). Useful for
369eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// void and empty structs.
379eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
389eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      Coerce,    /// Only valid for aggregate return types, the argument
399eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// should be accessed by coercion to a provided type.
409eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
419eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      ByVal,     /// Only valid for aggregate argument types. The
429eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// structure should be passed "byval" with the
439eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// specified alignment (0 indicates default
449eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// alignment).
459eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
469eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      Expand,    /// Only valid for aggregate argument types. The
479eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// structure should be expanded into consecutive
489eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// arguments for its constituent fields. Currently
499eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// expand is only allowed on structures whose fields
509eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// are all scalar types or are themselves expandable
519eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                 /// types.
529eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
539eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      KindFirst=Default, KindLast=Expand
549eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    };
559eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
569eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  private:
579eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    Kind TheKind;
589eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    const llvm::Type *TypeData;
599eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    unsigned UIntData;
609eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
619eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    ABIArgInfo(Kind K, const llvm::Type *TD=0,
629eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar               unsigned UI=0) : TheKind(K),
639eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                                TypeData(TD),
649eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                                UIntData(0) {}
659eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  public:
6688c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar    ABIArgInfo() : TheKind(Default), TypeData(0), UIntData(0) {}
6788c2fa96be989571b4afb6229f0ef5a3ef4450cbDaniel Dunbar
689eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getDefault() {
699eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(Default);
709eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
719eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getStructRet() {
729eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(StructRet);
739eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
749eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getIgnore() {
759eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(Ignore);
769eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
779eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getCoerce(const llvm::Type *T) {
789eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(Coerce, T);
799eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
809eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getByVal(unsigned Alignment) {
819eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(ByVal, 0, Alignment);
829eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
839eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    static ABIArgInfo getExpand() {
849eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return ABIArgInfo(Expand);
859eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
869eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
879eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    Kind getKind() const { return TheKind; }
889eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isDefault() const { return TheKind == Default; }
899eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isStructRet() const { return TheKind == StructRet; }
909eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isIgnore() const { return TheKind == Ignore; }
919eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isCoerce() const { return TheKind == Coerce; }
929eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isByVal() const { return TheKind == ByVal; }
939eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    bool isExpand() const { return TheKind == Expand; }
949eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
959eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    // Coerce accessors
969eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    const llvm::Type *getCoerceToType() const {
979eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      assert(TheKind == Coerce && "Invalid kind!");
989eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return TypeData;
999eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
1009eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1019eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    // ByVal accessors
1029eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    unsigned getByValAlignment() const {
1039eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      assert(TheKind == ByVal && "Invalid kind!");
1049eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar      return UIntData;
1059eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    }
1069eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  };
1079eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1089eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  /// ABIInfo - Target specific hooks for defining how a type should be
1099eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  /// passed or returned from functions.
1109eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  class ABIInfo {
1119eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  public:
1129eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    virtual ~ABIInfo();
1139eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1149eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    virtual ABIArgInfo classifyReturnType(QualType RetTy,
1159eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                                          ASTContext &Context) const = 0;
1169eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1179eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar    virtual ABIArgInfo classifyArgumentType(QualType Ty,
1189eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar                                            ASTContext &Context) const = 0;
1199eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar  };
1209eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar}  // end namespace clang
1219eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar
1229eb5c6d3242d85359b2d669564c5e2826efb1931Daniel Dunbar#endif
123