X86CallingConv.h revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
1//=== X86CallingConv.h - X86 Custom Calling Convention Routines -*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the custom routines for the X86 Calling Convention that
11// aren't done by tablegen.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef X86CALLINGCONV_H
16#define X86CALLINGCONV_H
17
18#include "llvm/CodeGen/CallingConvLower.h"
19#include "llvm/IR/CallingConv.h"
20
21namespace llvm {
22
23inline bool CC_X86_AnyReg_Error(unsigned &, MVT &, MVT &,
24                                CCValAssign::LocInfo &, ISD::ArgFlagsTy &,
25                                CCState &) {
26  llvm_unreachable("The AnyReg calling convention is only supported by the " \
27                   "stackmap and patchpoint intrinsics.");
28  // gracefully fallback to X86 C calling convention on Release builds.
29  return false;
30}
31
32inline bool CC_X86_CDeclMethod_SRet(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
33                                    CCValAssign::LocInfo &LocInfo,
34                                    ISD::ArgFlagsTy &ArgFlags, CCState &State) {
35  // Swap the order of the first two parameters if the first parameter is sret.
36  if (ArgFlags.isSRet()) {
37    assert(ValNo == 0);
38    assert(ValVT == MVT::i32);
39    State.AllocateStack(8, 4);
40    State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, 4, LocVT, LocInfo));
41
42    // Indicate that we need to swap the order of the first and second
43    // parameters by "allocating" register zero.  There are no register
44    // parameters with cdecl methods, so we can use this to communicate to the
45    // next call.
46    State.AllocateReg(1);
47    return true;
48  } else if (ValNo == 1 && State.isAllocated(1)) {
49    assert(ValVT == MVT::i32 && "non-i32-sized this param unsupported");
50    // Stack was already allocated while processing sret.
51    State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, 0, LocVT, LocInfo));
52    return true;
53  }
54
55  // All other args use the C calling convention.
56  return false;
57}
58
59} // End llvm namespace
60
61#endif
62
63