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 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 3 | // This file defines Annotations used to pass information between code |
| 4 | // generation phases. |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 5 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 6 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 7 | |
| 8 | #include "llvm/CodeGen/MachineInstrAnnot.h" |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 9 | #include "llvm/CodeGen/InstrSelection.h" |
| 10 | #include "llvm/CodeGen/InstrSelectionSupport.h" |
| 11 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 12 | #include "llvm/iOther.h" |
Chris Lattner | 0be79c6 | 2002-10-28 02:28:39 +0000 | [diff] [blame] | 13 | #include "llvm/Type.h" |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 14 | |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 15 | |
| 16 | CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr, |
| 17 | TmpInstruction* _retAddrReg, |
| 18 | bool _isVarArgs, bool _noPrototype) |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 19 | : callInstr(_callInstr), |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 20 | funcPtr(isa<Function>(_callInstr->getCalledValue()) |
| 21 | ? NULL : _callInstr->getCalledValue()), |
| 22 | retAddrReg(_retAddrReg), |
| 23 | isVarArgs(_isVarArgs), |
| 24 | noPrototype(_noPrototype) |
| 25 | { |
| 26 | unsigned int numArgs = callInstr->getNumOperands(); |
| 27 | argInfoVec.reserve(numArgs); |
| 28 | assert(callInstr->getOperand(0) == callInstr->getCalledValue() |
| 29 | && "Operand 0 is ignored in the loop below!"); |
| 30 | for (unsigned int i=1; i < numArgs; ++i) |
| 31 | argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i))); |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 32 | |
| 33 | // Enter this object in the MachineCodeForInstr object of the CallInst. |
| 34 | // This transfers ownership of this object. |
| 35 | MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this); |
Vikram S. Adve | 7e684a9 | 2002-05-19 15:30:21 +0000 | [diff] [blame] | 36 | } |
Vikram S. Adve | f425884 | 2002-09-28 17:03:54 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | const CallInst* |
| 40 | CallArgsDescriptor::getReturnValue() const |
| 41 | { |
| 42 | return (callInstr->getType() == Type::VoidTy? NULL : callInstr); |
| 43 | } |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | // Mechanism to get the descriptor for a CALL MachineInstr. |
| 47 | // We get the LLVM CallInstr from the ret. addr. register argument |
| 48 | // of the CALL MachineInstr, then get the CallArgsDescriptor from the |
| 49 | // MachineCodeForInstruction object for the CallInstr. |
| 50 | // This is roundabout but avoids adding a new map or annotation just |
| 51 | // to keep track of CallArgsDescriptors. |
| 52 | // |
| 53 | CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI) |
| 54 | { |
| 55 | const TmpInstruction* retAddrReg = |
| 56 | cast<TmpInstruction>(MI->getImplicitRef(MI->getNumImplicitRefs()-1)); |
| 57 | assert(retAddrReg->getNumOperands() == 1 && |
| 58 | isa<CallInst>(retAddrReg->getOperand(0)) && |
| 59 | "Order of implicit args of CALL instr. changed. FIX THIS CODE!"); |
| 60 | const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0)); |
| 61 | |
| 62 | CallArgsDescriptor* desc = |
| 63 | MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor(); |
| 64 | assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?"); |
| 65 | return desc; |
| 66 | } |