blob: b4b41ac1761b211f3e6b149d3cfbfa3c24ae2e4d [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- MachineInstrAnnot.cpp ---------------------------------------------===//
Vikram S. Adve7e684a92002-05-19 15:30:21 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// 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 Lattner035dfbe2002-08-09 20:08:06 +000010// This file defines Annotations used to pass information between code
11// generation phases.
Vikram S. Adve7e684a92002-05-19 15:30:21 +000012//
Chris Lattner035dfbe2002-08-09 20:08:06 +000013//===----------------------------------------------------------------------===//
Vikram S. Adve7e684a92002-05-19 15:30:21 +000014
15#include "llvm/CodeGen/MachineInstrAnnot.h"
Vikram S. Advea2bae302002-10-29 19:41:18 +000016#include "llvm/CodeGen/InstrSelection.h"
Vikram S. Advea2bae302002-10-29 19:41:18 +000017#include "llvm/CodeGen/MachineCodeForInstruction.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000018#include "llvm/iOther.h"
Chris Lattner0be79c62002-10-28 02:28:39 +000019#include "llvm/Type.h"
Vikram S. Adve7e684a92002-05-19 15:30:21 +000020
Brian Gaeked0fde302003-11-11 22:41:34 +000021namespace llvm {
Vikram S. Adve7e684a92002-05-19 15:30:21 +000022
Vikram S. Adve4d2faf62003-07-10 19:46:15 +000023CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr,
Vikram S. Adve7e684a92002-05-19 15:30:21 +000024 TmpInstruction* _retAddrReg,
25 bool _isVarArgs, bool _noPrototype)
Vikram S. Advea2bae302002-10-29 19:41:18 +000026 : callInstr(_callInstr),
Vikram S. Adve7e684a92002-05-19 15:30:21 +000027 funcPtr(isa<Function>(_callInstr->getCalledValue())
28 ? NULL : _callInstr->getCalledValue()),
29 retAddrReg(_retAddrReg),
30 isVarArgs(_isVarArgs),
31 noPrototype(_noPrototype)
32{
33 unsigned int numArgs = callInstr->getNumOperands();
34 argInfoVec.reserve(numArgs);
35 assert(callInstr->getOperand(0) == callInstr->getCalledValue()
36 && "Operand 0 is ignored in the loop below!");
37 for (unsigned int i=1; i < numArgs; ++i)
38 argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i)));
Vikram S. Advea2bae302002-10-29 19:41:18 +000039
40 // Enter this object in the MachineCodeForInstr object of the CallInst.
41 // This transfers ownership of this object.
42 MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
Vikram S. Adve7e684a92002-05-19 15:30:21 +000043}
Vikram S. Advef4258842002-09-28 17:03:54 +000044
45
Vikram S. Adve4d2faf62003-07-10 19:46:15 +000046CallInst*
Vikram S. Advef4258842002-09-28 17:03:54 +000047CallArgsDescriptor::getReturnValue() const
48{
49 return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
50}
Vikram S. Advea2bae302002-10-29 19:41:18 +000051
52
53// Mechanism to get the descriptor for a CALL MachineInstr.
54// We get the LLVM CallInstr from the ret. addr. register argument
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000055// of the CALL MachineInstr (which is explicit operand #3 for indirect
56// calls or the last implicit operand for direct calls). We then get
57// the CallArgsDescriptor from the MachineCodeForInstruction object for
58// the CallInstr.
Vikram S. Advea2bae302002-10-29 19:41:18 +000059// This is roundabout but avoids adding a new map or annotation just
60// to keep track of CallArgsDescriptors.
61//
62CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI)
63{
64 const TmpInstruction* retAddrReg =
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000065 cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
66 ? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
67 : MI->getOperand(2).getVRegValue());
68
Vikram S. Advea2bae302002-10-29 19:41:18 +000069 assert(retAddrReg->getNumOperands() == 1 &&
70 isa<CallInst>(retAddrReg->getOperand(0)) &&
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000071 "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
72
Vikram S. Advea2bae302002-10-29 19:41:18 +000073 const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
74
75 CallArgsDescriptor* desc =
76 MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
77 assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
78 return desc;
79}
Brian Gaeked0fde302003-11-11 22:41:34 +000080
81} // End llvm namespace