1 //===-- llvm/CallingConvLower.cpp - Calling Conventions -------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the CCState class, used for lowering and implementing
11 // calling conventions.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/CallingConvLower.h"
16 #include "llvm/CodeGen/SelectionDAGNodes.h"
17 #include "llvm/Target/MRegisterInfo.h"
18 #include "llvm/Target/TargetMachine.h"
21 CCState::CCState(unsigned CC, const TargetMachine &tm,
22 SmallVector<CCValAssign, 16> &locs)
23 : CallingConv(CC), TM(tm), MRI(*TM.getRegisterInfo()), Locs(locs) {
27 UsedRegs.resize(MRI.getNumRegs());
31 /// MarkAllocated - Mark a register and all of its aliases as allocated.
32 void CCState::MarkAllocated(unsigned Reg) {
33 UsedRegs[Reg/32] |= 1 << (Reg&31);
35 if (const unsigned *RegAliases = MRI.getAliasSet(Reg))
36 for (; (Reg = *RegAliases); ++RegAliases)
37 UsedRegs[Reg/32] |= 1 << (Reg&31);
40 /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
41 /// about the passed values into this state.
42 void CCState::AnalyzeCallOperands(SDNode *TheCall, CCAssignFn Fn) {
43 unsigned NumOps = (TheCall->getNumOperands() - 5) / 2;
44 for (unsigned i = 0; i != NumOps; ++i) {
45 MVT::ValueType ArgVT = TheCall->getOperand(5+2*i).getValueType();
46 SDOperand FlagOp = TheCall->getOperand(5+2*i+1);
47 unsigned ArgFlags =cast<ConstantSDNode>(FlagOp)->getValue();
48 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
49 cerr << "Call operand #" << i << " has unhandled type "
50 << MVT::getValueTypeString(ArgVT) << "\n";
56 /// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
57 /// incorporating info about the formals into this state.
58 void CCState::AnalyzeFormalArguments(SDNode *TheArgs, CCAssignFn Fn) {
59 unsigned NumArgs = TheArgs->getNumValues()-1;
61 for (unsigned i = 0; i != NumArgs; ++i) {
62 MVT::ValueType ArgVT = TheArgs->getValueType(i);
63 SDOperand FlagOp = TheArgs->getOperand(3+i);
64 unsigned ArgFlags = cast<ConstantSDNode>(FlagOp)->getValue();
65 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
66 cerr << "Formal argument #" << i << " has unhandled type "
67 << MVT::getValueTypeString(ArgVT) << "\n";