blob: 08a6ade62480cbd2746b077fa38c5c600d7eb675 [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 Lattner13513b72007-02-27 05:13:54 +000021CCState::CCState(unsigned CC, const TargetMachine &tm,
22 SmallVector<CCValAssign, 16> &locs)
23 : CallingConv(CC), TM(tm), MRI(*TM.getRegisterInfo()), Locs(locs) {
Chris Lattner362e98a2007-02-27 04:43:02 +000024 // No stack is used.
25 StackOffset = 0;
26
27 UsedRegs.resize(MRI.getNumRegs());
28}
29
30
31/// MarkAllocated - Mark a register and all of its aliases as allocated.
32void CCState::MarkAllocated(unsigned Reg) {
33 UsedRegs[Reg/32] |= 1 << (Reg&31);
34
35 if (const unsigned *RegAliases = MRI.getAliasSet(Reg))
36 for (; (Reg = *RegAliases); ++RegAliases)
37 UsedRegs[Reg/32] |= 1 << (Reg&31);
38}
Chris Lattnerfb39f992007-02-28 06:56:37 +000039
Chris Lattner66baf262007-02-28 07:09:40 +000040/// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
41/// incorporating info about the formals into this state.
42void CCState::AnalyzeFormalArguments(SDNode *TheArgs, CCAssignFn Fn) {
43 unsigned NumArgs = TheArgs->getNumValues()-1;
44
45 for (unsigned i = 0; i != NumArgs; ++i) {
46 MVT::ValueType ArgVT = TheArgs->getValueType(i);
47 SDOperand FlagOp = TheArgs->getOperand(3+i);
48 unsigned ArgFlags = cast<ConstantSDNode>(FlagOp)->getValue();
49 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
50 cerr << "Formal argument #" << i << " has unhandled type "
51 << MVT::getValueTypeString(ArgVT) << "\n";
52 abort();
53 }
54 }
55}
56
57/// AnalyzeReturn - Analyze the returned values of an ISD::RET node,
58/// incorporating info about the result values into this state.
59void CCState::AnalyzeReturn(SDNode *TheRet, CCAssignFn Fn) {
60 // Determine which register each value should be copied into.
61 for (unsigned i = 0, e = TheRet->getNumOperands() / 2; i != e; ++i) {
62 MVT::ValueType VT = TheRet->getOperand(i*2+1).getValueType();
63 if (Fn(i, VT, VT, CCValAssign::Full,
64 cast<ConstantSDNode>(TheRet->getOperand(i*2+2))->getValue(), *this)){
65 cerr << "Return operand #" << i << " has unhandled type "
66 << MVT::getValueTypeString(VT) << "\n";
67 abort();
68 }
69 }
70}
71
72
Chris Lattnerfb39f992007-02-28 06:56:37 +000073/// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
74/// about the passed values into this state.
75void CCState::AnalyzeCallOperands(SDNode *TheCall, CCAssignFn Fn) {
76 unsigned NumOps = (TheCall->getNumOperands() - 5) / 2;
77 for (unsigned i = 0; i != NumOps; ++i) {
78 MVT::ValueType ArgVT = TheCall->getOperand(5+2*i).getValueType();
79 SDOperand FlagOp = TheCall->getOperand(5+2*i+1);
80 unsigned ArgFlags =cast<ConstantSDNode>(FlagOp)->getValue();
81 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
82 cerr << "Call operand #" << i << " has unhandled type "
83 << MVT::getValueTypeString(ArgVT) << "\n";
84 abort();
85 }
86 }
87}
88
Chris Lattner66baf262007-02-28 07:09:40 +000089/// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
90/// incorporating info about the passed values into this state.
91void CCState::AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn) {
92 for (unsigned i = 0, e = TheCall->getNumValues() - 1; i != e; ++i) {
93 MVT::ValueType VT = TheCall->getValueType(i);
94 if (Fn(i, VT, VT, CCValAssign::Full, 0, *this)) {
95 cerr << "Call result #" << i << " has unhandled type "
96 << MVT::getValueTypeString(VT) << "\n";
Chris Lattnerfb39f992007-02-28 06:56:37 +000097 abort();
98 }
99 }
100}
Chris Lattner66baf262007-02-28 07:09:40 +0000101