1 //===-- MachineInstrAnnot.cpp ---------------------------------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines Annotations used to pass information between code
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineInstrAnnot.h"
16 #include "llvm/CodeGen/InstrSelection.h"
17 #include "llvm/CodeGen/MachineCodeForInstruction.h"
18 #include "llvm/iOther.h"
19 #include "llvm/Type.h"
23 CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr,
24 TmpInstruction* _retAddrReg,
25 bool _isVarArgs, bool _noPrototype)
26 : callInstr(_callInstr),
27 funcPtr(isa<Function>(_callInstr->getCalledValue())
28 ? NULL : _callInstr->getCalledValue()),
29 retAddrReg(_retAddrReg),
30 isVarArgs(_isVarArgs),
31 noPrototype(_noPrototype)
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)));
40 // Enter this object in the MachineCodeForInstr object of the CallInst.
41 // This transfers ownership of this object.
42 MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
47 CallArgsDescriptor::getReturnValue() const
49 return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
53 // Mechanism to get the descriptor for a CALL MachineInstr.
54 // We get the LLVM CallInstr from the ret. addr. register argument
55 // 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
59 // This is roundabout but avoids adding a new map or annotation just
60 // to keep track of CallArgsDescriptors.
62 CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI)
64 const TmpInstruction* retAddrReg =
65 cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
66 ? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
67 : MI->getOperand(2).getVRegValue());
69 assert(retAddrReg->getNumOperands() == 1 &&
70 isa<CallInst>(retAddrReg->getOperand(0)) &&
71 "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
73 const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
75 CallArgsDescriptor* desc =
76 MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
77 assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
81 } // End llvm namespace