blob: 7f93753ccdfbce51bf8f7fea8f66285d14fca63e [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- MachineInstrAnnot.cpp ---------------------------------------------===//
Vikram S. Adve7e684a92002-05-19 15:30:21 +00002//
Chris Lattner035dfbe2002-08-09 20:08:06 +00003// This file defines Annotations used to pass information between code
4// generation phases.
Vikram S. Adve7e684a92002-05-19 15:30:21 +00005//
Chris Lattner035dfbe2002-08-09 20:08:06 +00006//===----------------------------------------------------------------------===//
Vikram S. Adve7e684a92002-05-19 15:30:21 +00007
8#include "llvm/CodeGen/MachineInstrAnnot.h"
Vikram S. Advea2bae302002-10-29 19:41:18 +00009#include "llvm/CodeGen/InstrSelection.h"
Vikram S. Advea2bae302002-10-29 19:41:18 +000010#include "llvm/CodeGen/MachineCodeForInstruction.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000011#include "llvm/iOther.h"
Chris Lattner0be79c62002-10-28 02:28:39 +000012#include "llvm/Type.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000013
Vikram S. Adve7e684a92002-05-19 15:30:21 +000014
15CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr,
16 TmpInstruction* _retAddrReg,
17 bool _isVarArgs, bool _noPrototype)
Vikram S. Advea2bae302002-10-29 19:41:18 +000018 : callInstr(_callInstr),
Vikram S. Adve7e684a92002-05-19 15:30:21 +000019 funcPtr(isa<Function>(_callInstr->getCalledValue())
20 ? NULL : _callInstr->getCalledValue()),
21 retAddrReg(_retAddrReg),
22 isVarArgs(_isVarArgs),
23 noPrototype(_noPrototype)
24{
25 unsigned int numArgs = callInstr->getNumOperands();
26 argInfoVec.reserve(numArgs);
27 assert(callInstr->getOperand(0) == callInstr->getCalledValue()
28 && "Operand 0 is ignored in the loop below!");
29 for (unsigned int i=1; i < numArgs; ++i)
30 argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i)));
Vikram S. Advea2bae302002-10-29 19:41:18 +000031
32 // Enter this object in the MachineCodeForInstr object of the CallInst.
33 // This transfers ownership of this object.
34 MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
Vikram S. Adve7e684a92002-05-19 15:30:21 +000035}
Vikram S. Advef4258842002-09-28 17:03:54 +000036
37
38const CallInst*
39CallArgsDescriptor::getReturnValue() const
40{
41 return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
42}
Vikram S. Advea2bae302002-10-29 19:41:18 +000043
44
45// Mechanism to get the descriptor for a CALL MachineInstr.
46// We get the LLVM CallInstr from the ret. addr. register argument
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000047// of the CALL MachineInstr (which is explicit operand #3 for indirect
48// calls or the last implicit operand for direct calls). We then get
49// the CallArgsDescriptor from the MachineCodeForInstruction object for
50// the CallInstr.
Vikram S. Advea2bae302002-10-29 19:41:18 +000051// This is roundabout but avoids adding a new map or annotation just
52// to keep track of CallArgsDescriptors.
53//
54CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI)
55{
56 const TmpInstruction* retAddrReg =
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000057 cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
58 ? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
59 : MI->getOperand(2).getVRegValue());
60
Vikram S. Advea2bae302002-10-29 19:41:18 +000061 assert(retAddrReg->getNumOperands() == 1 &&
62 isa<CallInst>(retAddrReg->getOperand(0)) &&
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000063 "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
64
Vikram S. Advea2bae302002-10-29 19:41:18 +000065 const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
66
67 CallArgsDescriptor* desc =
68 MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
69 assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
70 return desc;
71}