[llvm-commits] CVS: llvm/lib/Target/ARM/ARMAsmPrinter.cpp ARMFrameInfo.h ARMISelDAGToDAG.cpp

Rafael Espindola rafael.espindola at gmail.com
Fri Aug 25 10:55:30 PDT 2006



Changes in directory llvm/lib/Target/ARM:

ARMAsmPrinter.cpp updated: 1.13 -> 1.14
ARMFrameInfo.h updated: 1.1 -> 1.2
ARMISelDAGToDAG.cpp updated: 1.36 -> 1.37
---
Log message:

use @ for comments
store LR in an arbitrary stack slot
add support for writing varargs functions


---
Diffs of the changes:  (+61 -14)

 ARMAsmPrinter.cpp   |    2 -
 ARMFrameInfo.h      |    8 ------
 ARMISelDAGToDAG.cpp |   65 ++++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 61 insertions(+), 14 deletions(-)


Index: llvm/lib/Target/ARM/ARMAsmPrinter.cpp
diff -u llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.13 llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.14
--- llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.13	Thu Aug 24 11:13:15 2006
+++ llvm/lib/Target/ARM/ARMAsmPrinter.cpp	Fri Aug 25 12:55:16 2006
@@ -43,7 +43,7 @@
       Data32bitsDirective = "\t.word\t";
       Data64bitsDirective = 0;
       ZeroDirective = "\t.skip\t";
-      CommentString = "#";
+      CommentString = "@";
       ConstantPoolSection = "\t.text\n";
       AlignmentIsInBytes = false;
     }


Index: llvm/lib/Target/ARM/ARMFrameInfo.h
diff -u llvm/lib/Target/ARM/ARMFrameInfo.h:1.1 llvm/lib/Target/ARM/ARMFrameInfo.h:1.2
--- llvm/lib/Target/ARM/ARMFrameInfo.h:1.1	Wed Aug 16 09:43:33 2006
+++ llvm/lib/Target/ARM/ARMFrameInfo.h	Fri Aug 25 12:55:16 2006
@@ -22,20 +22,12 @@
 namespace llvm {
 
 class ARMFrameInfo: public TargetFrameInfo {
-  std::pair<unsigned, int> LR[1];
 
 public:
   ARMFrameInfo()
     : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
-    LR[0].first = ARM::R14;
-    LR[0].second = -4;
   }
 
-  const std::pair<unsigned, int> *
-  getCalleeSaveSpillSlots(unsigned &NumEntries) const {
-    NumEntries = 1;
-    return &LR[0];
-  }
 };
 
 } // End llvm namespace


Index: llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
diff -u llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.36 llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.37
--- llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.36	Thu Aug 24 12:19:08 2006
+++ llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp	Fri Aug 25 12:55:16 2006
@@ -32,6 +32,7 @@
 
 namespace {
   class ARMTargetLowering : public TargetLowering {
+    int VarArgsFrameIndex;            // FrameIndex for start of varargs area.
   public:
     ARMTargetLowering(TargetMachine &TM);
     virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
@@ -55,6 +56,9 @@
   setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
   setOperationAction(ISD::BR_CC, MVT::i32, Custom);
 
+  setOperationAction(ISD::VASTART,       MVT::Other, Custom);
+  setOperationAction(ISD::VAEND,         MVT::Other, Expand);
+
   setSchedulingPreference(SchedulingForRegPressure);
   computeRegisterProperties();
 }
@@ -238,6 +242,7 @@
 }
 
 static SDOperand LowerFORMAL_ARGUMENT(SDOperand Op, SelectionDAG &DAG,
+				      unsigned *vRegs,
 				      unsigned ArgNo) {
   MachineFunction &MF = DAG.getMachineFunction();
   MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
@@ -253,6 +258,7 @@
   if(ArgNo < num_regs) {
     unsigned VReg = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
     MF.addLiveIn(REGS[ArgNo], VReg);
+    vRegs[ArgNo] = VReg;
     return DAG.getCopyFromReg(Root, VReg, MVT::i32);
   } else {
     // If the argument is actually used, emit a load from the right stack
@@ -291,18 +297,65 @@
 		     DAG.getSrcValue(NULL));
 }
 
-static SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
+static SDOperand LowerVASTART(SDOperand Op, SelectionDAG &DAG,
+                              unsigned VarArgsFrameIndex) {
+  // vastart just stores the address of the VarArgsFrameIndex slot into the
+  // memory location argument.
+  MVT::ValueType PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
+  SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
+  return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR, 
+                     Op.getOperand(1), Op.getOperand(2));
+}
+
+static SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG,
+				       int &VarArgsFrameIndex) {
   std::vector<SDOperand> ArgValues;
   SDOperand Root = Op.getOperand(0);
+  unsigned VRegs[4];
 
-  for (unsigned ArgNo = 0, e = Op.Val->getNumValues()-1; ArgNo != e; ++ArgNo) {
-    SDOperand ArgVal = LowerFORMAL_ARGUMENT(Op, DAG, ArgNo);
+  unsigned NumArgs = Op.Val->getNumValues()-1;
+  for (unsigned ArgNo = 0; ArgNo < NumArgs; ++ArgNo) {
+    SDOperand ArgVal = LowerFORMAL_ARGUMENT(Op, DAG, VRegs, ArgNo);
 
     ArgValues.push_back(ArgVal);
   }
 
   bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
-  assert(!isVarArg);
+  if (isVarArg) {
+    MachineFunction &MF = DAG.getMachineFunction();
+    SSARegMap *RegMap = MF.getSSARegMap();
+    MachineFrameInfo *MFI = MF.getFrameInfo();
+    VarArgsFrameIndex = MFI->CreateFixedObject(MVT::getSizeInBits(MVT::i32)/8,
+                                               -16 + NumArgs * 4);
+
+
+    static const unsigned REGS[] = {
+      ARM::R0, ARM::R1, ARM::R2, ARM::R3
+    };
+    // If this function is vararg, store r0-r3 to their spots on the stack
+    // so that they may be loaded by deferencing the result of va_next.
+    SmallVector<SDOperand, 4> MemOps;
+    for (unsigned ArgNo = 0; ArgNo < 4; ++ArgNo) {
+      int ArgOffset = - (4 - ArgNo) * 4;
+      int FI = MFI->CreateFixedObject(MVT::getSizeInBits(MVT::i32)/8,
+				      ArgOffset);
+      SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
+
+      unsigned VReg;
+      if (ArgNo < NumArgs)
+	VReg = VRegs[ArgNo];
+      else
+	VReg = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
+      if (ArgNo >= NumArgs)
+	MF.addLiveIn(REGS[ArgNo], VReg);
+
+      SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::i32);
+      SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
+                                    Val, FIN, DAG.getSrcValue(NULL));
+      MemOps.push_back(Store);
+    }
+    Root = DAG.getNode(ISD::TokenFactor, MVT::Other,&MemOps[0],MemOps.size());
+  }
 
   ArgValues.push_back(Root);
 
@@ -346,7 +399,7 @@
   case ISD::GlobalAddress:
     return LowerGlobalAddress(Op, DAG);
   case ISD::FORMAL_ARGUMENTS:
-    return LowerFORMAL_ARGUMENTS(Op, DAG);
+    return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex);
   case ISD::CALL:
     return LowerCALL(Op, DAG);
   case ISD::RET:
@@ -355,6 +408,8 @@
     return LowerSELECT_CC(Op, DAG);
   case ISD::BR_CC:
     return LowerBR_CC(Op, DAG);
+  case ISD::VASTART:
+    return LowerVASTART(Op, DAG, VarArgsFrameIndex);
   }
 }
 






More information about the llvm-commits mailing list