blob: 8d7d4724f5b82b3c8d209e79578858af3d535b82 [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"
10#include "llvm/CodeGen/InstrSelectionSupport.h"
11#include "llvm/CodeGen/MachineCodeForInstruction.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000012#include "llvm/iOther.h"
Chris Lattner0be79c62002-10-28 02:28:39 +000013#include "llvm/Type.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000014
Vikram S. Adve7e684a92002-05-19 15:30:21 +000015
16CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr,
17 TmpInstruction* _retAddrReg,
18 bool _isVarArgs, bool _noPrototype)
Vikram S. Advea2bae302002-10-29 19:41:18 +000019 : callInstr(_callInstr),
Vikram S. Adve7e684a92002-05-19 15:30:21 +000020 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. Advea2bae302002-10-29 19:41:18 +000032
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. Adve7e684a92002-05-19 15:30:21 +000036}
Vikram S. Advef4258842002-09-28 17:03:54 +000037
38
39const CallInst*
40CallArgsDescriptor::getReturnValue() const
41{
42 return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
43}
Vikram S. Advea2bae302002-10-29 19:41:18 +000044
45
46// Mechanism to get the descriptor for a CALL MachineInstr.
47// We get the LLVM CallInstr from the ret. addr. register argument
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000048// of the CALL MachineInstr (which is explicit operand #3 for indirect
49// calls or the last implicit operand for direct calls). We then get
50// the CallArgsDescriptor from the MachineCodeForInstruction object for
51// the CallInstr.
Vikram S. Advea2bae302002-10-29 19:41:18 +000052// This is roundabout but avoids adding a new map or annotation just
53// to keep track of CallArgsDescriptors.
54//
55CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI)
56{
57 const TmpInstruction* retAddrReg =
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000058 cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
59 ? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
60 : MI->getOperand(2).getVRegValue());
61
Vikram S. Advea2bae302002-10-29 19:41:18 +000062 assert(retAddrReg->getNumOperands() == 1 &&
63 isa<CallInst>(retAddrReg->getOperand(0)) &&
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000064 "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
65
Vikram S. Advea2bae302002-10-29 19:41:18 +000066 const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
67
68 CallArgsDescriptor* desc =
69 MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
70 assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
71 return desc;
72}