Tidy up ValueType names in comments.
[oota-llvm.git] / lib / CodeGen / SelectionDAG / CallingConvLower.cpp
1 //===-- 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"
16 #include "llvm/CodeGen/SelectionDAGNodes.h"
17 #include "llvm/Target/MRegisterInfo.h"
18 #include "llvm/Target/TargetMachine.h"
19 using namespace llvm;
20
21 CCState::CCState(unsigned CC, bool isVarArg, const TargetMachine &tm,
22                  SmallVector<CCValAssign, 16> &locs)
23   : CallingConv(CC), IsVarArg(isVarArg), TM(tm),
24     MRI(*TM.getRegisterInfo()), Locs(locs) {
25   // 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.
33 void 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 }
40
41 /// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
42 /// incorporating info about the formals into this state.
43 void 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.
60 void 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
74 /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
75 /// about the passed values into this state.
76 void 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
90 /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
91 /// incorporating info about the passed values into this state.
92 void 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";
98       abort();
99     }
100   }
101 }
102