blob: 9dd684c1cc06f087491bc4bd0bcfb8d42b88b26b [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
Chris Lattner08d49632004-02-29 19:12:51 +000015#include "../Target/SparcV9/MachineInstrAnnot.h"
Brian Gaekef7d4efb2004-08-04 07:34:44 +000016#include "../Target/SparcV9/SparcV9TmpInstr.h"
Vikram S. Advea2bae302002-10-29 19:41:18 +000017#include "llvm/CodeGen/MachineCodeForInstruction.h"
Misha Brukman47b14a42004-07-29 17:30:56 +000018#include "llvm/Instructions.h"
Chris Lattner0be79c62002-10-28 02:28:39 +000019#include "llvm/Type.h"
Chris Lattner0742b592004-02-23 18:38:20 +000020using namespace llvm;
Vikram S. Adve7e684a92002-05-19 15:30:21 +000021
Vikram S. Adve4d2faf62003-07-10 19:46:15 +000022CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr,
Vikram S. Adve7e684a92002-05-19 15:30:21 +000023 TmpInstruction* _retAddrReg,
24 bool _isVarArgs, bool _noPrototype)
Vikram S. Advea2bae302002-10-29 19:41:18 +000025 : callInstr(_callInstr),
Vikram S. Adve7e684a92002-05-19 15:30:21 +000026 funcPtr(isa<Function>(_callInstr->getCalledValue())
27 ? NULL : _callInstr->getCalledValue()),
28 retAddrReg(_retAddrReg),
29 isVarArgs(_isVarArgs),
Brian Gaekef7d4efb2004-08-04 07:34:44 +000030 noPrototype(_noPrototype) {
Vikram S. Adve7e684a92002-05-19 15:30:21 +000031 unsigned int numArgs = callInstr->getNumOperands();
32 argInfoVec.reserve(numArgs);
33 assert(callInstr->getOperand(0) == callInstr->getCalledValue()
34 && "Operand 0 is ignored in the loop below!");
35 for (unsigned int i=1; i < numArgs; ++i)
36 argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i)));
Vikram S. Advea2bae302002-10-29 19:41:18 +000037
38 // Enter this object in the MachineCodeForInstr object of the CallInst.
39 // This transfers ownership of this object.
40 MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
Vikram S. Adve7e684a92002-05-19 15:30:21 +000041}
Vikram S. Advef4258842002-09-28 17:03:54 +000042
Brian Gaekef7d4efb2004-08-04 07:34:44 +000043CallInst *CallArgsDescriptor::getReturnValue() const {
Vikram S. Advef4258842002-09-28 17:03:54 +000044 return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
45}
Vikram S. Advea2bae302002-10-29 19:41:18 +000046
Vikram S. Advea2bae302002-10-29 19:41:18 +000047// Mechanism to get the descriptor for a CALL MachineInstr.
48// We get the LLVM CallInstr from the ret. addr. register argument
Vikram S. Adve26fbcec2002-10-31 15:34:48 +000049// of the CALL MachineInstr (which is explicit operand #3 for indirect
50// calls or the last implicit operand for direct calls). We then get
51// the CallArgsDescriptor from the MachineCodeForInstruction object for
52// the CallInstr.
Vikram S. Advea2bae302002-10-29 19:41:18 +000053// This is roundabout but avoids adding a new map or annotation just
54// to keep track of CallArgsDescriptors.
55//
Brian Gaekef7d4efb2004-08-04 07:34:44 +000056CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI) {
Vikram S. Advea2bae302002-10-29 19:41:18 +000057 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}