Function temporaries can not overlap with retval or args.See the comment in source...
[oota-llvm.git] / lib / Target / PowerPC / PPCHazardRecognizers.cpp
index 43caf6c81865d7f21a77d661fea11ba5b75903c4..e7658fc9d4ae31c51f4d9558101a73711ce44aae 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "sched"
+#define DEBUG_TYPE "pre-RA-sched"
 #include "PPCHazardRecognizers.h"
 #include "PPC.h"
 #include "PPCInstrInfo.h"
+#include "llvm/CodeGen/ScheduleDAG.h"
 #include "llvm/Support/Debug.h"
-#include <iostream>
 using namespace llvm;
 
-
 //===----------------------------------------------------------------------===//
 // PowerPC 970 Hazard Recognizer
 //
@@ -52,7 +51,7 @@ PPCHazardRecognizer970::PPCHazardRecognizer970(const TargetInstrInfo &tii)
 }
 
 void PPCHazardRecognizer970::EndDispatchGroup() {
-  DEBUG(std::cerr << "=== Start of dispatch group\n");
+  DOUT << "=== Start of dispatch group\n";
   NumIssued = 0;
   
   // Structural hazard info.
@@ -66,16 +65,16 @@ PPCHazardRecognizer970::GetInstrType(unsigned Opcode,
                                      bool &isFirst, bool &isSingle,
                                      bool &isCracked,
                                      bool &isLoad, bool &isStore) {
-  if (Opcode < ISD::BUILTIN_OP_END) {
+  if ((int)Opcode >= 0) {
     isFirst = isSingle = isCracked = isLoad = isStore = false;
     return PPCII::PPC970_Pseudo;
   }
-  Opcode -= ISD::BUILTIN_OP_END;
+  Opcode = ~Opcode;
   
-  const TargetInstrDescriptor &TID = TII.get(Opcode);
+  const TargetInstrDesc &TID = TII.get(Opcode);
   
-  isLoad  = TID.Flags & M_LOAD_FLAG;
-  isStore = TID.Flags & M_STORE_FLAG;
+  isLoad  = TID.mayLoad();
+  isStore = TID.mayStore();
   
   unsigned TSFlags = TID.TSFlags;
   
@@ -88,7 +87,7 @@ PPCHazardRecognizer970::GetInstrType(unsigned Opcode,
 /// isLoadOfStoredAddress - If we have a load from the previously stored pointer
 /// as indicated by StorePtr1/StorePtr2/StoreSize, return true.
 bool PPCHazardRecognizer970::
-isLoadOfStoredAddress(unsigned LoadSize, SDOperand Ptr1, SDOperand Ptr2) const {
+isLoadOfStoredAddress(unsigned LoadSize, SDValue Ptr1, SDValue Ptr2) const {
   for (unsigned i = 0, e = NumStores; i != e; ++i) {
     // Handle exact and commuted addresses.
     if (Ptr1 == StorePtr1[i] && Ptr2 == StorePtr2[i])
@@ -103,8 +102,8 @@ isLoadOfStoredAddress(unsigned LoadSize, SDOperand Ptr1, SDOperand Ptr2) const {
         if (ConstantSDNode *LoadOffset = dyn_cast<ConstantSDNode>(Ptr1)) {
           // Okay the base pointers match, so we have [c1+r] vs [c2+r].  Check
           // to see if the load and store actually overlap.
-          int StoreOffs = StoreOffset->getValue();
-          int LoadOffs  = LoadOffset->getValue();
+          int StoreOffs = StoreOffset->getZExtValue();
+          int LoadOffs  = LoadOffset->getZExtValue();
           if (StoreOffs < LoadOffs) {
             if (int(StoreOffs+StoreSize[i]) > LoadOffs) return true;
           } else {
@@ -120,14 +119,15 @@ isLoadOfStoredAddress(unsigned LoadSize, SDOperand Ptr1, SDOperand Ptr2) const {
 /// terminate terminate the dispatch group.  We turn NoopHazard for any
 /// instructions that wouldn't terminate the dispatch group that would cause a
 /// pipeline flush.
-HazardRecognizer::HazardType PPCHazardRecognizer970::
-getHazardType(SDNode *Node) {
+ScheduleHazardRecognizer::HazardType PPCHazardRecognizer970::
+getHazardType(SUnit *SU) {
+  const SDNode *Node = SU->getNode()->getFlaggedMachineNode();
   bool isFirst, isSingle, isCracked, isLoad, isStore;
   PPCII::PPC970_Unit InstrType = 
     GetInstrType(Node->getOpcode(), isFirst, isSingle, isCracked,
                  isLoad, isStore);
   if (InstrType == PPCII::PPC970_Pseudo) return NoHazard;  
-  unsigned Opcode = Node->getOpcode()-ISD::BUILTIN_OP_END;
+  unsigned Opcode = Node->getMachineOpcode();
 
   // We can only issue a PPC970_First/PPC970_Single instruction (such as
   // crand/mtspr/etc) if this is the first cycle of the dispatch group.
@@ -159,7 +159,7 @@ getHazardType(SDNode *Node) {
   }
   
   // Do not allow MTCTR and BCTRL to be in the same dispatch group.
-  if (HasCTRSet && Opcode == PPC::BCTRL)
+  if (HasCTRSet && (Opcode == PPC::BCTRL_Macho || Opcode == PPC::BCTRL_ELF))
     return NoopHazard;
   
   // If this is a load following a store, make sure it's not to the same or
@@ -168,30 +168,29 @@ getHazardType(SDNode *Node) {
     unsigned LoadSize;
     switch (Opcode) {
     default: assert(0 && "Unknown load!");
-    case PPC::LBZ:
+    case PPC::LBZ:   case PPC::LBZU:
     case PPC::LBZX:
-    case PPC::LBZ8:
+    case PPC::LBZ8:  case PPC::LBZU8:
     case PPC::LBZX8:
     case PPC::LVEBX:
       LoadSize = 1;
       break;
-    case PPC::LHA:
+    case PPC::LHA:   case PPC::LHAU:
     case PPC::LHAX:
-    case PPC::LHZ:
+    case PPC::LHZ:   case PPC::LHZU:
     case PPC::LHZX:
     case PPC::LVEHX:
     case PPC::LHBRX:
-    case PPC::LHA8:
+    case PPC::LHA8:   case PPC::LHAU8:
     case PPC::LHAX8:
-    case PPC::LHZ8:
+    case PPC::LHZ8:   case PPC::LHZU8:
     case PPC::LHZX8:
       LoadSize = 2;
       break;
-    case PPC::LFS:
+    case PPC::LFS:    case PPC::LFSU:
     case PPC::LFSX:
-    case PPC::LWZ:
+    case PPC::LWZ:    case PPC::LWZU:
     case PPC::LWZX:
-    case PPC::LWZU:
     case PPC::LWA:
     case PPC::LWAX:
     case PPC::LVEWX:
@@ -200,13 +199,14 @@ getHazardType(SDNode *Node) {
     case PPC::LWZX8:
       LoadSize = 4;
       break;
-    case PPC::LFD:
+    case PPC::LFD:    case PPC::LFDU:
     case PPC::LFDX:
-    case PPC::LD:
+    case PPC::LD:     case PPC::LDU:
     case PPC::LDX:
       LoadSize = 8;
       break;
     case PPC::LVX:
+    case PPC::LVXL:
       LoadSize = 16;
       break;
     }
@@ -219,13 +219,14 @@ getHazardType(SDNode *Node) {
   return NoHazard;
 }
 
-void PPCHazardRecognizer970::EmitInstruction(SDNode *Node) {
+void PPCHazardRecognizer970::EmitInstruction(SUnit *SU) {
+  const SDNode *Node = SU->getNode()->getFlaggedMachineNode();
   bool isFirst, isSingle, isCracked, isLoad, isStore;
   PPCII::PPC970_Unit InstrType = 
     GetInstrType(Node->getOpcode(), isFirst, isSingle, isCracked,
                  isLoad, isStore);
   if (InstrType == PPCII::PPC970_Pseudo) return;  
-  unsigned Opcode = Node->getOpcode()-ISD::BUILTIN_OP_END;
+  unsigned Opcode = Node->getMachineOpcode();
 
   // Update structural hazard information.
   if (Opcode == PPC::MTCTR) HasCTRSet = true;
@@ -235,29 +236,26 @@ void PPCHazardRecognizer970::EmitInstruction(SDNode *Node) {
     unsigned ThisStoreSize;
     switch (Opcode) {
     default: assert(0 && "Unknown store instruction!");
-    case PPC::STB:
-    case PPC::STBX:
-    case PPC::STB8:
-    case PPC::STBX8:
+    case PPC::STB:    case PPC::STB8:
+    case PPC::STBU:   case PPC::STBU8:
+    case PPC::STBX:   case PPC::STBX8:
     case PPC::STVEBX:
       ThisStoreSize = 1;
       break;
-    case PPC::STH:
-    case PPC::STHX:
-    case PPC::STH8:
-    case PPC::STHX8:
+    case PPC::STH:    case PPC::STH8:
+    case PPC::STHU:   case PPC::STHU8:
+    case PPC::STHX:   case PPC::STHX8:
     case PPC::STVEHX:
     case PPC::STHBRX:
       ThisStoreSize = 2;
       break;
     case PPC::STFS:
+    case PPC::STFSU:
     case PPC::STFSX:
-    case PPC::STWU:
-    case PPC::STWX:
+    case PPC::STWX:   case PPC::STWX8:
     case PPC::STWUX:
-    case PPC::STW:
-    case PPC::STW8:
-    case PPC::STWX8:
+    case PPC::STW:    case PPC::STW8:
+    case PPC::STWU:   case PPC::STWU8:
     case PPC::STVEWX:
     case PPC::STFIWX:
     case PPC::STWBRX:
@@ -266,6 +264,7 @@ void PPCHazardRecognizer970::EmitInstruction(SDNode *Node) {
     case PPC::STD_32:
     case PPC::STDX_32:
     case PPC::STD:
+    case PPC::STDU:
     case PPC::STFD:
     case PPC::STFDX:
     case PPC::STDX:
@@ -273,6 +272,7 @@ void PPCHazardRecognizer970::EmitInstruction(SDNode *Node) {
       ThisStoreSize = 8;
       break;
     case PPC::STVX:
+    case PPC::STVXL:
       ThisStoreSize = 16;
       break;
     }
@@ -302,7 +302,3 @@ void PPCHazardRecognizer970::AdvanceCycle() {
   if (NumIssued == 5)
     EndDispatchGroup();
 }
-
-void PPCHazardRecognizer970::EmitNoop() {
-  AdvanceCycle();
-}