AMDGPU/SI: Add s_waitcnt at the end of non-void functions
authorMarek Olsak <marek.olsak@amd.com>
Wed, 13 Jan 2016 17:23:09 +0000 (17:23 +0000)
committerMarek Olsak <marek.olsak@amd.com>
Wed, 13 Jan 2016 17:23:09 +0000 (17:23 +0000)
Summary:
v2: Make ReturnsVoid private, so that I can another 8 lines of code and
    look more productive.

Reviewers: tstellarAMD, arsenm

Subscribers: arsenm

Differential Revision: http://reviews.llvm.org/D16034

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257622 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/SIISelLowering.cpp
lib/Target/AMDGPU/SIInsertWaits.cpp
lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
lib/Target/AMDGPU/SIMachineFunctionInfo.h

index 0c678c4b73b9072f82683d1581c553f9d8d5bf16..4206e6fb869fbab8b1cdf67d2704be2cbbd43fb5 100644 (file)
@@ -893,6 +893,8 @@ SDValue SITargetLowering::LowerReturn(SDValue Chain,
     return AMDGPUTargetLowering::LowerReturn(Chain, CallConv, isVarArg, Outs,
                                              OutVals, DL, DAG);
 
     return AMDGPUTargetLowering::LowerReturn(Chain, CallConv, isVarArg, Outs,
                                              OutVals, DL, DAG);
 
+  Info->setIfReturnsVoid(Outs.size() == 0);
+
   SmallVector<ISD::OutputArg, 48> Splits;
   SmallVector<SDValue, 48> SplitVals;
 
   SmallVector<ISD::OutputArg, 48> Splits;
   SmallVector<SDValue, 48> SplitVals;
 
index 821aada526c744899a7b48ff9a43523ffcc3bf7c..d3b41797871ea05dbaf16c217aac4694ed46a376 100644 (file)
@@ -84,6 +84,9 @@ private:
 
   bool LastInstWritesM0;
 
 
   bool LastInstWritesM0;
 
+  /// \brief Whether the machine function returns void
+  bool ReturnsVoid;
+
   /// \brief Get increment/decrement amount for this instruction.
   Counters getHwCounts(MachineInstr &MI);
 
   /// \brief Get increment/decrement amount for this instruction.
   Counters getHwCounts(MachineInstr &MI);
 
@@ -322,7 +325,9 @@ bool SIInsertWaits::insertWait(MachineBasicBlock &MBB,
                                const Counters &Required) {
 
   // End of program? No need to wait on anything
                                const Counters &Required) {
 
   // End of program? No need to wait on anything
-  if (I != MBB.end() && I->getOpcode() == AMDGPU::S_ENDPGM)
+  // A function not returning void needs to wait, because other bytecode will
+  // be appended after it and we don't know what it will be.
+  if (I != MBB.end() && I->getOpcode() == AMDGPU::S_ENDPGM && ReturnsVoid)
     return false;
 
   // Figure out if the async instructions execute in order
     return false;
 
   // Figure out if the async instructions execute in order
@@ -465,6 +470,7 @@ bool SIInsertWaits::runOnMachineFunction(MachineFunction &MF) {
   LastIssued = ZeroCounts;
   LastOpcodeType = OTHER;
   LastInstWritesM0 = false;
   LastIssued = ZeroCounts;
   LastOpcodeType = OTHER;
   LastInstWritesM0 = false;
+  ReturnsVoid = MF.getInfo<SIMachineFunctionInfo>()->returnsVoid();
 
   memset(&UsedRegs, 0, sizeof(UsedRegs));
   memset(&DefinedRegs, 0, sizeof(DefinedRegs));
 
   memset(&UsedRegs, 0, sizeof(UsedRegs));
   memset(&DefinedRegs, 0, sizeof(DefinedRegs));
index 878fd768bba450eef83b44aa1be667bbd5d6a599..49677fc2b0a312ed4a9e8cf9e2d46197f2a0eed5 100644 (file)
@@ -47,6 +47,7 @@ SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
     WorkGroupInfoSystemSGPR(AMDGPU::NoRegister),
     PrivateSegmentWaveByteOffsetSystemSGPR(AMDGPU::NoRegister),
     PSInputAddr(0),
     WorkGroupInfoSystemSGPR(AMDGPU::NoRegister),
     PrivateSegmentWaveByteOffsetSystemSGPR(AMDGPU::NoRegister),
     PSInputAddr(0),
+    ReturnsVoid(true),
     LDSWaveSpillSize(0),
     PSInputEna(0),
     NumUserSGPRs(0),
     LDSWaveSpillSize(0),
     PSInputEna(0),
     NumUserSGPRs(0),
index 61d575385ffa4195dea212e71be84aac62b1e8ee..846ee5de057d2dee37a76e0e71c7e215a3eb4848 100644 (file)
@@ -59,6 +59,7 @@ class SIMachineFunctionInfo : public AMDGPUMachineFunction {
 
   // Graphics info.
   unsigned PSInputAddr;
 
   // Graphics info.
   unsigned PSInputAddr;
+  bool ReturnsVoid;
 
 public:
   // FIXME: Make private
 
 public:
   // FIXME: Make private
@@ -288,6 +289,14 @@ public:
     PSInputAddr |= 1 << Index;
   }
 
     PSInputAddr |= 1 << Index;
   }
 
+  bool returnsVoid() const {
+    return ReturnsVoid;
+  }
+
+  void setIfReturnsVoid(bool Value) {
+    ReturnsVoid = Value;
+  }
+
   unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
 };
 
   unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
 };