Chris Lattner | 362e98a | 2007-02-27 04:43:02 +0000 | [diff] [blame] | 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" |
Chris Lattner | fb39f99 | 2007-02-28 06:56:37 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Chris Lattner | 362e98a | 2007-02-27 04:43:02 +0000 | [diff] [blame] | 17 | #include "llvm/Target/MRegisterInfo.h" |
Chris Lattner | 13513b7 | 2007-02-27 05:13:54 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 362e98a | 2007-02-27 04:43:02 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Chris Lattner | 13513b7 | 2007-02-27 05:13:54 +0000 | [diff] [blame] | 21 | CCState::CCState(unsigned CC, const TargetMachine &tm, |
| 22 | SmallVector<CCValAssign, 16> &locs) |
| 23 | : CallingConv(CC), TM(tm), MRI(*TM.getRegisterInfo()), Locs(locs) { |
Chris Lattner | 362e98a | 2007-02-27 04:43:02 +0000 | [diff] [blame] | 24 | // 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. |
| 32 | void 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 Lattner | fb39f99 | 2007-02-28 06:56:37 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 66baf26 | 2007-02-28 07:09:40 +0000 | [diff] [blame] | 40 | /// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node, |
| 41 | /// incorporating info about the formals into this state. |
| 42 | void 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. |
| 59 | void 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 Lattner | fb39f99 | 2007-02-28 06:56:37 +0000 | [diff] [blame] | 73 | /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info |
| 74 | /// about the passed values into this state. |
| 75 | void 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 Lattner | 66baf26 | 2007-02-28 07:09:40 +0000 | [diff] [blame] | 89 | /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node, |
| 90 | /// incorporating info about the passed values into this state. |
| 91 | void 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 Lattner | fb39f99 | 2007-02-28 06:56:37 +0000 | [diff] [blame] | 97 | abort(); |
| 98 | } |
| 99 | } |
| 100 | } |
Chris Lattner | 66baf26 | 2007-02-28 07:09:40 +0000 | [diff] [blame] | 101 | |