summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2009-04-21 05:54:51 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2009-04-21 05:54:51 +0000
commit3e3ef7c4d91d0ee7aaec823e74b57e8805261f1e (patch)
tree4b4aafe622a1c0029d8fe9ea1da28621a9f6d587 /llvm/lib
parent2f5693f62d57aa1370f381c57b4b69858295875f (diff)
downloadbcm5719-llvm-3e3ef7c4d91d0ee7aaec823e74b57e8805261f1e.tar.gz
bcm5719-llvm-3e3ef7c4d91d0ee7aaec823e74b57e8805261f1e.zip
Handle direct aggregate type arguments.
llvm-svn: 69665
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/PIC16/PIC16ISelLowering.cpp80
-rw-r--r--llvm/lib/Target/PIC16/PIC16ISelLowering.h7
2 files changed, 36 insertions, 51 deletions
diff --git a/llvm/lib/Target/PIC16/PIC16ISelLowering.cpp b/llvm/lib/Target/PIC16/PIC16ISelLowering.cpp
index cc7ce5557fe..dec92ad84df 100644
--- a/llvm/lib/Target/PIC16/PIC16ISelLowering.cpp
+++ b/llvm/lib/Target/PIC16/PIC16ISelLowering.cpp
@@ -527,9 +527,6 @@ PIC16TargetLowering::LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG,
MachineFrameInfo *MFI = MF.getFrameInfo();
const std::string Name = Func->getName();
- char *tmpName = new char [strlen(Name.c_str()) + 8];
- sprintf(tmpName, "%s.frame", Name.c_str());
- ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
FrameIndexSDNode *FR = dyn_cast<FrameIndexSDNode>(Op);
// FrameIndices are not stack offsets. But they represent the request
@@ -538,9 +535,19 @@ PIC16TargetLowering::LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG,
// with, we need to traverse all the FrameIndices available earlier in
// the list and add their requested size.
unsigned FIndex = FR->getIndex();
- Offset = 0;
- for (unsigned i=0; i<FIndex ; ++i) {
- Offset += MFI->getObjectSize(i);
+ char *tmpName = new char [strlen(Name.c_str()) + 8];
+ if (FIndex < ReservedFrameCount) {
+ sprintf(tmpName, "%s.frame", Name.c_str());
+ ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
+ Offset = 0;
+ for (unsigned i=0; i<FIndex ; ++i) {
+ Offset += MFI->getObjectSize(i);
+ }
+ } else {
+ // FrameIndex has been made for some temporary storage
+ sprintf(tmpName, "%s.tmp", Name.c_str());
+ ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
+ Offset = GetTmpOffsetForFI(FIndex, MFI->getObjectSize(FIndex));
}
return;
@@ -891,12 +898,7 @@ LowerIndirectCallArguments(SDValue Op, SDValue Chain, SDValue InFlag,
for (unsigned i = 0, ArgOffset = RetVals; i < NumOps; i++) {
// Get the arguments
Arg = TheCall->getArg(i);
- // If argument is FrameIndex then map it with temporary
- if (Arg.getOpcode() == PIC16ISD::Lo || Arg.getOpcode() == PIC16ISD::Hi) {
- if (Arg.getOperand(0).getOpcode() == ISD::TargetFrameIndex) {
- Arg = LegalizeFrameArgument(Arg, dl, DAG);
- }
- }
+
Ops.clear();
Ops.push_back(Chain);
Ops.push_back(Arg);
@@ -915,36 +917,6 @@ LowerIndirectCallArguments(SDValue Op, SDValue Chain, SDValue InFlag,
}
SDValue PIC16TargetLowering::
-LegalizeFrameArgument(SDValue Arg, DebugLoc dl, SelectionDAG &DAG) {
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *Func = MF.getFunction();
- MachineFrameInfo *MFI = MF.getFrameInfo();
- const std::string Name = Func->getName();
-
- // Caller creates the stack storage to pass the aggregate type
- // as argument. So it should be relative to tmp variable.
- SDValue FI = Arg.getOperand(0);
- char *tmpName = new char [strlen(Name.c_str()) + 8];
- sprintf(tmpName, "%s.tmp", Name.c_str());
- SDValue ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
- FrameIndexSDNode *FR = dyn_cast<FrameIndexSDNode>(FI);
-
- unsigned FIndex = FR->getIndex();
- // Reserve space in tmp variable for the aggregate type
- int FrameOffset = GetTmpOffsetForFI(FIndex, MFI->getObjectSize(FIndex));
-
- if (Arg.getOpcode() == PIC16ISD::Lo) {
- // Lo part of frame index
- SDValue FrameConst = DAG.getConstant(FrameOffset, MVT::i8);
- return DAG.getNode(PIC16ISD::Lo, dl, MVT::i8, ES, FrameConst);
- } else {
- // Hi part of frame index
- SDValue FrameConst = DAG.getConstant(FrameOffset + 1, MVT::i8);
- return DAG.getNode(PIC16ISD::Hi, dl, MVT::i8, ES, FrameConst);
- }
-}
-
-SDValue PIC16TargetLowering::
LowerDirectCallArguments(SDValue Op, SDValue Chain, SDValue ArgLabel,
SDValue InFlag, SelectionDAG &DAG) {
CallSDNode *TheCall = dyn_cast<CallSDNode>(Op);
@@ -975,12 +947,6 @@ LowerDirectCallArguments(SDValue Op, SDValue Chain, SDValue ArgLabel,
for (unsigned i=ArgCount, Offset = 0; i<NumOps; i++) {
// Get the argument
Arg = TheCall->getArg(i);
- // If argument is FrameIndex then map it with temporary
- if (Arg.getOpcode() == PIC16ISD::Lo || Arg.getOpcode() == PIC16ISD::Hi) {
- if (Arg.getOperand(0).getOpcode() == ISD::TargetFrameIndex) {
- Arg = LegalizeFrameArgument(Arg, dl, DAG);
- }
- }
StoreOffset = (Offset + AddressOffset);
// Store the argument on frame
@@ -1455,6 +1421,17 @@ SDValue PIC16TargetLowering::LowerSUB(SDValue Op, SelectionDAG &DAG) {
return DAG.getNode(Op.getOpcode(), dl, Tys, NewVal, Op.getOperand(1));
}
+void PIC16TargetLowering::InitReservedFrameCount(const Function *F) {
+ unsigned NumArgs = F->arg_size();
+
+ bool isVoidFunc = (F->getReturnType()->getTypeID() == Type::VoidTyID);
+
+ if (isVoidFunc)
+ ReservedFrameCount = NumArgs;
+ else
+ ReservedFrameCount = NumArgs + 1;
+}
+
// LowerFORMAL_ARGUMENTS - Argument values are loaded from the
// <fname>.args + offset. All arguments are already broken to leaglized
// types, so the offset just runs from 0 to NumArgVals - 1.
@@ -1467,13 +1444,16 @@ SDValue PIC16TargetLowering::LowerFORMAL_ARGUMENTS(SDValue Op,
SDValue Chain = Op.getOperand(0); // Formal arguments' chain
- // Reset the map of FI and TmpOffset
- ResetTmpOffsetMap();
// Get the callee's name to create the <fname>.args label to pass args.
MachineFunction &MF = DAG.getMachineFunction();
const Function *F = MF.getFunction();
std::string FuncName = F->getName();
+ // Reset the map of FI and TmpOffset
+ ResetTmpOffsetMap();
+ // Initialize the ReserveFrameCount
+ InitReservedFrameCount(F);
+
// Create the <fname>.args external symbol.
char *tmpName = new char [strlen(FuncName.c_str()) + 6];
sprintf(tmpName, "%s.args", FuncName.c_str());
diff --git a/llvm/lib/Target/PIC16/PIC16ISelLowering.h b/llvm/lib/Target/PIC16/PIC16ISelLowering.h
index d94f02bb8d4..06793c7b2d5 100644
--- a/llvm/lib/Target/PIC16/PIC16ISelLowering.h
+++ b/llvm/lib/Target/PIC16/PIC16ISelLowering.h
@@ -139,6 +139,7 @@ namespace llvm {
// new offset and returns.
unsigned GetTmpOffsetForFI(unsigned FI, unsigned slot_size);
void ResetTmpOffsetMap() { FiTmpOffsetMap.clear(); SetTmpSize(0); }
+ void InitReservedFrameCount(const Function *F);
// Return the size of Tmp variable
unsigned GetTmpSize() { return TmpSize; }
@@ -168,7 +169,6 @@ namespace llvm {
void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES,
int &Offset);
- SDValue LegalizeFrameArgument(SDValue Arg, DebugLoc dl, SelectionDAG &DAG);
// CALL node should have all legal operands only. Legalize all non-legal
// operands of CALL node and then return the new call will all operands
@@ -216,6 +216,11 @@ namespace llvm {
// This maps maintain zero based indexes for these FIs.
std::map<unsigned, unsigned> FiTmpOffsetMap;
unsigned TmpSize;
+
+ // These are the frames for return value and argument passing
+ // These FrameIndices will be expanded to foo.frame external symbol
+ // and all others will be expanded to foo.tmp external symbol.
+ unsigned ReservedFrameCount;
};
} // namespace llvm
OpenPOWER on IntegriCloud