Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 1 | //===-- MachineInstrAnnot.cpp ---------------------------------------------===// |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 10 | // This file defines Annotations used to pass information between code |
| 11 | // generation phases. |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 12 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 14 | |
| 15 | #include "llvm/CodeGen/MachineInstrAnnot.h" |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/InstrSelection.h" |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 18 | #include "llvm/iOther.h" |
Chris Lattner | 0be79c6 | 2002-10-28 02:28:39 +0000 | [diff] [blame] | 19 | #include "llvm/Type.h" |
Chris Lattner | 0742b59 | 2004-02-23 18:38:20 +0000 | [diff] [blame^] | 20 | using namespace llvm; |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 21 | |
Vikram S. Adve | 4d2faf6 | 2003-07-10 19:46:15 +0000 | [diff] [blame] | 22 | CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr, |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 23 | TmpInstruction* _retAddrReg, |
| 24 | bool _isVarArgs, bool _noPrototype) |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 25 | : callInstr(_callInstr), |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 26 | funcPtr(isa<Function>(_callInstr->getCalledValue()) |
| 27 | ? NULL : _callInstr->getCalledValue()), |
| 28 | retAddrReg(_retAddrReg), |
| 29 | isVarArgs(_isVarArgs), |
| 30 | noPrototype(_noPrototype) |
| 31 | { |
| 32 | unsigned int numArgs = callInstr->getNumOperands(); |
| 33 | argInfoVec.reserve(numArgs); |
| 34 | assert(callInstr->getOperand(0) == callInstr->getCalledValue() |
| 35 | && "Operand 0 is ignored in the loop below!"); |
| 36 | for (unsigned int i=1; i < numArgs; ++i) |
| 37 | argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i))); |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 38 | |
| 39 | // Enter this object in the MachineCodeForInstr object of the CallInst. |
| 40 | // This transfers ownership of this object. |
| 41 | MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this); |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 42 | } |
Vikram S. Adve | f425884 | 2002-09-28 17:03:54 +0000 | [diff] [blame] | 43 | |
| 44 | |
Vikram S. Adve | 4d2faf6 | 2003-07-10 19:46:15 +0000 | [diff] [blame] | 45 | CallInst* |
Vikram S. Adve | f425884 | 2002-09-28 17:03:54 +0000 | [diff] [blame] | 46 | CallArgsDescriptor::getReturnValue() const |
| 47 | { |
| 48 | return (callInstr->getType() == Type::VoidTy? NULL : callInstr); |
| 49 | } |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | // Mechanism to get the descriptor for a CALL MachineInstr. |
| 53 | // We get the LLVM CallInstr from the ret. addr. register argument |
Vikram S. Adve | 26fbcec | 2002-10-31 15:34:48 +0000 | [diff] [blame] | 54 | // of the CALL MachineInstr (which is explicit operand #3 for indirect |
| 55 | // calls or the last implicit operand for direct calls). We then get |
| 56 | // the CallArgsDescriptor from the MachineCodeForInstruction object for |
| 57 | // the CallInstr. |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 58 | // This is roundabout but avoids adding a new map or annotation just |
| 59 | // to keep track of CallArgsDescriptors. |
| 60 | // |
| 61 | CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI) |
| 62 | { |
| 63 | const TmpInstruction* retAddrReg = |
Vikram S. Adve | 26fbcec | 2002-10-31 15:34:48 +0000 | [diff] [blame] | 64 | cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue()) |
| 65 | ? MI->getImplicitRef(MI->getNumImplicitRefs()-1) |
| 66 | : MI->getOperand(2).getVRegValue()); |
| 67 | |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 68 | assert(retAddrReg->getNumOperands() == 1 && |
| 69 | isa<CallInst>(retAddrReg->getOperand(0)) && |
Vikram S. Adve | 26fbcec | 2002-10-31 15:34:48 +0000 | [diff] [blame] | 70 | "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!"); |
| 71 | |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 72 | const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0)); |
| 73 | |
| 74 | CallArgsDescriptor* desc = |
| 75 | MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor(); |
| 76 | assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?"); |
| 77 | return desc; |
| 78 | } |