summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-16 21:36:31 +0000
committerChris Lattner <sabre@nondot.org>2004-08-16 21:36:31 +0000
commite97db86e1717c60e4f11e53f7b2550add7859f39 (patch)
tree14e1d36cd59b6b3fd43253c6858af96535ce98e5
parent5aff3551bdaa680582890c7e9a1e35a51247bf4a (diff)
downloadllvm-e97db86e1717c60e4f11e53f7b2550add7859f39.tar.gz
llvm-e97db86e1717c60e4f11e53f7b2550add7859f39.tar.bz2
llvm-e97db86e1717c60e4f11e53f7b2550add7859f39.tar.xz
Fold MachineInstrAnnot.cpp into this file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15828 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/MachineCodeForInstruction.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineCodeForInstruction.cpp b/lib/CodeGen/MachineCodeForInstruction.cpp
index c50c8b8c6a..c4b2ee5c9f 100644
--- a/lib/CodeGen/MachineCodeForInstruction.cpp
+++ b/lib/CodeGen/MachineCodeForInstruction.cpp
@@ -24,10 +24,13 @@
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/Type.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionInfo.h"
#include "../Target/SparcV9/MachineInstrAnnot.h"
+#include "../Target/SparcV9/SparcV9TmpInstr.h"
using namespace llvm;
MachineCodeForInstruction &MachineCodeForInstruction::get(const Instruction *I){
@@ -61,3 +64,56 @@ MachineCodeForInstruction::~MachineCodeForInstruction() {
// Free the CallArgsDescriptor if it exists.
delete callArgsDesc;
}
+
+
+CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr,
+ TmpInstruction* _retAddrReg,
+ bool _isVarArgs, bool _noPrototype)
+ : callInstr(_callInstr),
+ 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)));
+
+ // Enter this object in the MachineCodeForInstr object of the CallInst.
+ // This transfers ownership of this object.
+ MachineCodeForInstruction::get(callInstr).setCallArgsDescriptor(this);
+}
+
+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<TmpInstruction>(isa<Function>(MI->getOperand(0).getVRegValue())
+ ? MI->getImplicitRef(MI->getNumImplicitRefs()-1)
+ : MI->getOperand(2).getVRegValue());
+
+ assert(retAddrReg->getNumOperands() == 1 &&
+ isa<CallInst>(retAddrReg->getOperand(0)) &&
+ "Location of callInstr arg for CALL instr. changed? FIX THIS CODE!");
+
+ const CallInst* callInstr = cast<CallInst>(retAddrReg->getOperand(0));
+
+ CallArgsDescriptor* desc =
+ MachineCodeForInstruction::get(callInstr).getCallArgsDescriptor();
+ assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
+ return desc;
+}