X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FMachineInstrAnnot.cpp;h=99f6c76a28bb9524d3399527b8898c1c4e5bb4ae;hb=6a90f8202b0a0043de21130b1ba9d8006ba866ba;hp=ef064450ed060925986c5c20224db433e5fcb55a;hpb=f425884e275c66f975a68e56f24b33a2d1c6e5c6;p=oota-llvm.git diff --git a/lib/CodeGen/MachineInstrAnnot.cpp b/lib/CodeGen/MachineInstrAnnot.cpp index ef064450ed0..99f6c76a28b 100644 --- a/lib/CodeGen/MachineInstrAnnot.cpp +++ b/lib/CodeGen/MachineInstrAnnot.cpp @@ -1,22 +1,28 @@ //===-- MachineInstrAnnot.cpp ---------------------------------------------===// // +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// // This file defines Annotations used to pass information between code // generation phases. // //===----------------------------------------------------------------------===// -#include "llvm/CodeGen/MachineInstrAnnot.h" -#include "llvm/Annotation.h" -#include "llvm/iOther.h" - -AnnotationID CallArgsDescriptor::AID(AnnotationManager:: - getID("CodeGen::CallArgsDescriptor")); +#include "../Target/SparcV9/MachineInstrAnnot.h" +#include "llvm/CodeGen/InstrSelection.h" +#include "llvm/CodeGen/MachineCodeForInstruction.h" +#include "llvm/Instructions.h" +#include "llvm/Type.h" +using namespace llvm; -CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr, +CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr, TmpInstruction* _retAddrReg, bool _isVarArgs, bool _noPrototype) - : Annotation(AID), - callInstr(_callInstr), + : callInstr(_callInstr), funcPtr(isa(_callInstr->getCalledValue()) ? NULL : _callInstr->getCalledValue()), retAddrReg(_retAddrReg), @@ -29,11 +35,44 @@ CallArgsDescriptor::CallArgsDescriptor(const CallInst* _callInstr, && "Operand 0 is ignored in the loop below!"); for (unsigned int i=1; i < numArgs; ++i) argInfoVec.push_back(CallArgInfo(callInstr->getOperand(i))); + + // Enter this object in the MachineCodeForInstr object of the CallInst. + // This transfers ownership of this object. + MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this); } -const CallInst* +CallInst* CallArgsDescriptor::getReturnValue() const { return (callInstr->getType() == Type::VoidTy? NULL : callInstr); } + + +// Mechanism to get the descriptor for a CALL MachineInstr. +// We get the LLVM CallInstr from the ret. addr. register argument +// 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. +// 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 = + cast(isa(MI->getOperand(0).getVRegValue()) + ? MI->getImplicitRef(MI->getNumImplicitRefs()-1) + : MI->getOperand(2).getVRegValue()); + + assert(retAddrReg->getNumOperands() == 1 && + isa(retAddrReg->getOperand(0)) && + "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!"); + + const CallInst* callInstr = cast(retAddrReg->getOperand(0)); + + CallArgsDescriptor* desc = + MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor(); + assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?"); + return desc; +}