[llvm-commits] CVS: llvm/lib/Target/ARM/ARMAsmPrinter.cpp ARMISelDAGToDAG.cpp ARMInstrInfo.td

Rafael Espindola rafael.espindola at gmail.com
Sat Jul 15 18:03:27 PDT 2006



Changes in directory llvm/lib/Target/ARM:

ARMAsmPrinter.cpp updated: 1.5 -> 1.6
ARMISelDAGToDAG.cpp updated: 1.15 -> 1.16
ARMInstrInfo.td updated: 1.7 -> 1.8
---
Log message:

skeleton of a lowerCall implementation for ARM


---
Diffs of the changes:  (+79 -5)

 ARMAsmPrinter.cpp   |    8 +++--
 ARMISelDAGToDAG.cpp |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 ARMInstrInfo.td     |    6 ++++
 3 files changed, 79 insertions(+), 5 deletions(-)


Index: llvm/lib/Target/ARM/ARMAsmPrinter.cpp
diff -u llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.5 llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.6
--- llvm/lib/Target/ARM/ARMAsmPrinter.cpp:1.5	Tue Jul 11 06:36:48 2006
+++ llvm/lib/Target/ARM/ARMAsmPrinter.cpp	Sat Jul 15 20:02:57 2006
@@ -156,9 +156,11 @@
     assert(0 && "not implemented");
     abort();
     return;
-  case MachineOperand::MO_GlobalAddress:
-    assert(0 && "not implemented");
-    abort();
+  case MachineOperand::MO_GlobalAddress: {
+    GlobalValue *GV = MO.getGlobal();
+    std::string Name = Mang->getValueName(GV);
+    O << Name;
+  }
     break;
   case MachineOperand::MO_ExternalSymbol:
     assert(0 && "not implemented");


Index: llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
diff -u llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.15 llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.16
--- llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:1.15	Tue Jul 11 06:36:48 2006
+++ llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp	Sat Jul 15 20:02:57 2006
@@ -13,6 +13,7 @@
 
 #include "ARM.h"
 #include "ARMTargetMachine.h"
+#include "llvm/CallingConv.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/Intrinsics.h"
@@ -33,6 +34,7 @@
   public:
     ARMTargetLowering(TargetMachine &TM);
     virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
+    virtual const char *getTargetNodeName(unsigned Opcode) const;
   };
 
 }
@@ -42,9 +44,73 @@
   setOperationAction(ISD::RET, MVT::Other, Custom);
 }
 
+namespace llvm {
+  namespace ARMISD {
+    enum NodeType {
+      // Start the numbering where the builting ops and target ops leave off.
+      FIRST_NUMBER = ISD::BUILTIN_OP_END+ARM::INSTRUCTION_LIST_END,
+      /// CALL - A direct function call.
+      CALL
+    };
+  }
+}
+
+const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
+  switch (Opcode) {
+  default: return 0;
+  case ARMISD::CALL:          return "ARMISD::CALL";
+  }
+}
+
+// This transforms a ISD::CALL node into a
+// callseq_star <- ARMISD:CALL <- callseq_end
+// chain
 static SDOperand LowerCALL(SDOperand Op, SelectionDAG &DAG) {
-  assert(0 && "Not implemented");
-  abort();
+  SDOperand Chain    = Op.getOperand(0);
+  unsigned CallConv  = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
+  assert(CallConv == CallingConv::C && "unknown calling convention");
+  bool isVarArg      = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
+  assert(isVarArg == false && "VarArg not supported");
+  bool isTailCall    = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0;
+  assert(isTailCall == false && "tail call not supported");
+  SDOperand Callee   = Op.getOperand(4);
+  unsigned NumOps    = (Op.getNumOperands() - 5) / 2;
+  assert(NumOps == 0);
+
+  // Count how many bytes are to be pushed on the stack. Initially
+  // only the link register.
+  unsigned NumBytes = 4;
+
+  // Adjust the stack pointer for the new arguments...
+  // These operations are automatically eliminated by the prolog/epilog pass
+  Chain = DAG.getCALLSEQ_START(Chain,
+                               DAG.getConstant(NumBytes, MVT::i32));
+
+  std::vector<MVT::ValueType> NodeTys;
+  NodeTys.push_back(MVT::Other);   // Returns a chain
+  NodeTys.push_back(MVT::Flag);    // Returns a flag for retval copy to use.
+
+  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
+  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
+  // node so that legalize doesn't hack it.
+  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
+    Callee = DAG.getTargetGlobalAddress(G->getGlobal(), Callee.getValueType());
+
+  // If this is a direct call, pass the chain and the callee.
+  assert (Callee.Val);
+  std::vector<SDOperand> Ops;
+  Ops.push_back(Chain);
+  Ops.push_back(Callee);
+
+  unsigned CallOpc = ARMISD::CALL;
+  Chain = DAG.getNode(CallOpc, NodeTys, Ops);
+
+  assert(Op.Val->getValueType(0) == MVT::Other);
+
+  Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
+                      DAG.getConstant(NumBytes, MVT::i32));
+
+  return Chain;
 }
 
 static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {


Index: llvm/lib/Target/ARM/ARMInstrInfo.td
diff -u llvm/lib/Target/ARM/ARMInstrInfo.td:1.7 llvm/lib/Target/ARM/ARMInstrInfo.td:1.8
--- llvm/lib/Target/ARM/ARMInstrInfo.td:1.7	Tue Jul 11 06:36:48 2006
+++ llvm/lib/Target/ARM/ARMInstrInfo.td	Sat Jul 15 20:02:57 2006
@@ -41,6 +41,10 @@
 def callseq_start  : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeq, [SDNPHasChain]>;
 def callseq_end    : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeq, [SDNPHasChain]>;
 
+def SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
+def ARMcall        : SDNode<"ARMISD::CALL", SDT_ARMcall,
+                           [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
+
 def ADJCALLSTACKUP : InstARM<(ops i32imm:$amt),
                             "!ADJCALLSTACKUP $amt",
                             [(callseq_end imm:$amt)]>;
@@ -51,6 +55,8 @@
 
 def bxr: InstARM<(ops IntRegs:$dst), "bx $dst", [(brind IntRegs:$dst)]>;
 
+def bl: InstARM<(ops i32imm:$func, variable_ops), "bl $func", [(ARMcall tglobaladdr:$func)]>;
+
 def ldr   : InstARM<(ops IntRegs:$dst, memri:$addr),
                      "ldr $dst, [$addr]",
                      [(set IntRegs:$dst, (load iaddr:$addr))]>;






More information about the llvm-commits mailing list