2002-08-09 20:08:06 +00:00
|
|
|
//===-- MachineInstrAnnot.cpp ---------------------------------------------===//
|
2002-05-19 15:30:21 +00:00
|
|
|
//
|
2002-08-09 20:08:06 +00:00
|
|
|
// This file defines Annotations used to pass information between code
|
|
|
|
// generation phases.
|
2002-05-19 15:30:21 +00:00
|
|
|
//
|
2002-08-09 20:08:06 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-19 15:30:21 +00:00
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineInstrAnnot.h"
|
2002-10-29 19:41:18 +00:00
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
|
|
|
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
|
|
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
2002-05-19 15:30:21 +00:00
|
|
|
#include "llvm/iOther.h"
|
2002-10-28 02:28:39 +00:00
|
|
|
#include "llvm/Type.h"
|
2002-05-19 15:30:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr,
|
|
|
|
TmpInstruction* _retAddrReg,
|
|
|
|
bool _isVarArgs, bool _noPrototype)
|
2002-10-29 19:41:18 +00:00
|
|
|
: callInstr(_callInstr),
|
2002-05-19 15:30:21 +00:00
|
|
|
funcPtr(isa<Function>(_callInstr->getCalledValue())
|
|
|
|
? NULL : _callInstr->getCalledValue()),
|
|
|
|
retAddrReg(_retAddrReg),
|
|
|
|
isVarArgs(_isVarArgs),
|
|
|
|
noPrototype(_noPrototype)
|
|
|
|
{
|
|
|
|
unsigned int numArgs = callInstr->getNumOperands();
|
|
|
|
argInfoVec.reserve(numArgs);
|
|
|
|
assert(callInstr->getOperand(0) == callInstr->getCalledValue()
|
|
|
|
&& "Operand 0 is ignored in the loop below!");
|
|
|
|
for (unsigned int i=1; i < numArgs; ++i)
|
|
|
|
argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i)));
|
2002-10-29 19:41:18 +00:00
|
|
|
|
|
|
|
// Enter this object in the MachineCodeForInstr object of the CallInst.
|
|
|
|
// This transfers ownership of this object.
|
|
|
|
MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
|
2002-05-19 15:30:21 +00:00
|
|
|
}
|
2002-09-28 17:03:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
const CallInst*
|
|
|
|
CallArgsDescriptor::getReturnValue() const
|
|
|
|
{
|
|
|
|
return (callInstr->getType() == Type::VoidTy? NULL : callInstr);
|
|
|
|
}
|
2002-10-29 19:41:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Mechanism to get the descriptor for a CALL MachineInstr.
|
|
|
|
// We get the LLVM CallInstr from the ret. addr. register argument
|
2002-10-31 15:34:48 +00:00
|
|
|
// of the CALL MachineInstr (which is explicit operand #3 for indirect
|
|
|
|
// calls or the last implicit operand for direct calls). We then get
|
|
|
|
// the CallArgsDescriptor from the MachineCodeForInstruction object for
|
|
|
|
// the CallInstr.
|
2002-10-29 19:41:18 +00:00
|
|
|
// This is roundabout but avoids adding a new map or annotation just
|
|
|
|
// to keep track of CallArgsDescriptors.
|
|
|
|
//
|
|
|
|
CallArgsDescriptor *CallArgsDescriptor::get(const MachineInstr* MI)
|
|
|
|
{
|
|
|
|
const TmpInstruction* retAddrReg =
|
2002-10-31 15:34:48 +00:00
|
|
|
cast<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
|
|
|
|
? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
|
|
|
|
: MI->getOperand(2).getVRegValue());
|
|
|
|
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(retAddrReg->getNumOperands() == 1 &&
|
|
|
|
isa<CallInst>(retAddrReg->getOperand(0)) &&
|
2002-10-31 15:34:48 +00:00
|
|
|
"Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
|
|
|
|
|
2002-10-29 19:41:18 +00:00
|
|
|
const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
|
|
|
|
|
|
|
|
CallArgsDescriptor* desc =
|
|
|
|
MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
|
|
|
|
assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
|
|
|
|
return desc;
|
|
|
|
}
|