blob: defbe3416e712855e476b0b0eb514635d4d4df25 [file] [log] [blame]
Chris Lattner362e98a2007-02-27 04:43:02 +00001//===-- llvm/CallingConvLower.cpp - Calling Conventions -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the CCState class, used for lowering and implementing
11// calling conventions.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/CodeGen/CallingConvLower.h"
Chris Lattnerfb39f992007-02-28 06:56:37 +000016#include "llvm/CodeGen/SelectionDAGNodes.h"
Chris Lattner362e98a2007-02-27 04:43:02 +000017#include "llvm/Target/MRegisterInfo.h"
Chris Lattner13513b72007-02-27 05:13:54 +000018#include "llvm/Target/TargetMachine.h"
Chris Lattner362e98a2007-02-27 04:43:02 +000019using namespace llvm;
20
Chris Lattneraeeccfc2007-06-19 00:11:09 +000021CCState::CCState(unsigned CC, bool isVarArg, const TargetMachine &tm,
Chris Lattner13513b72007-02-27 05:13:54 +000022 SmallVector<CCValAssign, 16> &locs)
Chris Lattneraeeccfc2007-06-19 00:11:09 +000023 : CallingConv(CC), IsVarArg(isVarArg), TM(tm),
24 MRI(*TM.getRegisterInfo()), Locs(locs) {
Chris Lattner362e98a2007-02-27 04:43:02 +000025 // No stack is used.
26 StackOffset = 0;
27
28 UsedRegs.resize(MRI.getNumRegs());
29}
30
31
32/// MarkAllocated - Mark a register and all of its aliases as allocated.
33void CCState::MarkAllocated(unsigned Reg) {
34 UsedRegs[Reg/32] |= 1 << (Reg&31);
35
36 if (const unsigned *RegAliases = MRI.getAliasSet(Reg))
37 for (; (Reg = *RegAliases); ++RegAliases)
38 UsedRegs[Reg/32] |= 1 << (Reg&31);
39}
Chris Lattnerfb39f992007-02-28 06:56:37 +000040
Chris Lattner66baf262007-02-28 07:09:40 +000041/// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
42/// incorporating info about the formals into this state.
43void CCState::AnalyzeFormalArguments(SDNode *TheArgs, CCAssignFn Fn) {
44 unsigned NumArgs = TheArgs->getNumValues()-1;
45
46 for (unsigned i = 0; i != NumArgs; ++i) {
47 MVT::ValueType ArgVT = TheArgs->getValueType(i);
48 SDOperand FlagOp = TheArgs->getOperand(3+i);
49 unsigned ArgFlags = cast<ConstantSDNode>(FlagOp)->getValue();
50 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
51 cerr << "Formal argument #" << i << " has unhandled type "
52 << MVT::getValueTypeString(ArgVT) << "\n";
53 abort();
54 }
55 }
56}
57
58/// AnalyzeReturn - Analyze the returned values of an ISD::RET node,
59/// incorporating info about the result values into this state.
60void CCState::AnalyzeReturn(SDNode *TheRet, CCAssignFn Fn) {
61 // Determine which register each value should be copied into.
62 for (unsigned i = 0, e = TheRet->getNumOperands() / 2; i != e; ++i) {
63 MVT::ValueType VT = TheRet->getOperand(i*2+1).getValueType();
64 if (Fn(i, VT, VT, CCValAssign::Full,
65 cast<ConstantSDNode>(TheRet->getOperand(i*2+2))->getValue(), *this)){
66 cerr << "Return operand #" << i << " has unhandled type "
67 << MVT::getValueTypeString(VT) << "\n";
68 abort();
69 }
70 }
71}
72
73
Chris Lattnerfb39f992007-02-28 06:56:37 +000074/// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
75/// about the passed values into this state.
76void CCState::AnalyzeCallOperands(SDNode *TheCall, CCAssignFn Fn) {
77 unsigned NumOps = (TheCall->getNumOperands() - 5) / 2;
78 for (unsigned i = 0; i != NumOps; ++i) {
79 MVT::ValueType ArgVT = TheCall->getOperand(5+2*i).getValueType();
80 SDOperand FlagOp = TheCall->getOperand(5+2*i+1);
81 unsigned ArgFlags =cast<ConstantSDNode>(FlagOp)->getValue();
82 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
83 cerr << "Call operand #" << i << " has unhandled type "
84 << MVT::getValueTypeString(ArgVT) << "\n";
85 abort();
86 }
87 }
88}
89
Chris Lattner66baf262007-02-28 07:09:40 +000090/// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
91/// incorporating info about the passed values into this state.
92void CCState::AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn) {
93 for (unsigned i = 0, e = TheCall->getNumValues() - 1; i != e; ++i) {
94 MVT::ValueType VT = TheCall->getValueType(i);
95 if (Fn(i, VT, VT, CCValAssign::Full, 0, *this)) {
96 cerr << "Call result #" << i << " has unhandled type "
97 << MVT::getValueTypeString(VT) << "\n";
Chris Lattnerfb39f992007-02-28 06:56:37 +000098 abort();
99 }
100 }
101}
Chris Lattner66baf262007-02-28 07:09:40 +0000102