OSDN Git Service

[Hexagon] Replace EmitFunctionEntryCode with a DAG preprocessing code
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 24 Jan 2018 21:19:51 +0000 (21:19 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 24 Jan 2018 21:19:51 +0000 (21:19 +0000)
The code in EmitFunctionEntryCode needs to know the maximum stack
alignment, but it runs very early in the selection process (before
lowering). The final stack alignment may change during lowering, so
the code needs to be moved to where the alignment is known.

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

lib/Target/Hexagon/HexagonISelDAGToDAG.cpp
lib/Target/Hexagon/HexagonISelDAGToDAG.h

index eb8fab1..09c55cb 100644 (file)
@@ -1034,6 +1034,23 @@ void HexagonDAGToDAGISel::ppHoistZextI1(std::vector<SDNode*> &&Nodes) {
   }
 }
 
+void HexagonDAGToDAGISel::ppEmitAligna() {
+  auto &HST = static_cast<const HexagonSubtarget&>(MF->getSubtarget());
+  auto &HFI = *HST.getFrameLowering();
+  if (!HFI.needsAligna(*MF))
+    return;
+
+  MachineFrameInfo &MFI = MF->getFrameInfo();
+  MachineBasicBlock &EntryBB = MF->front();
+  unsigned AR = FuncInfo->CreateReg(MVT::i32);
+  unsigned MaxA = MFI.getMaxAlignment();
+  MachineBasicBlock::iterator End = EntryBB.end();
+  DebugLoc DL = EntryBB.findDebugLoc(End);
+  BuildMI(EntryBB, End, DL, HII->get(Hexagon::PS_aligna), AR)
+      .addImm(MaxA);
+  MF->getInfo<HexagonMachineFunctionInfo>()->setStackAlignBaseVReg(AR);
+}
+
 void HexagonDAGToDAGISel::PreprocessISelDAG() {
   // Repack all nodes before calling each preprocessing function,
   // because each of them can modify the set of nodes.
@@ -1089,21 +1106,11 @@ void HexagonDAGToDAGISel::PreprocessISelDAG() {
       CurDAG->dump();
     });
   }
-}
-
-void HexagonDAGToDAGISel::EmitFunctionEntryCode() {
-  auto &HST = static_cast<const HexagonSubtarget&>(MF->getSubtarget());
-  auto &HFI = *HST.getFrameLowering();
-  if (!HFI.needsAligna(*MF))
-    return;
 
-  MachineFrameInfo &MFI = MF->getFrameInfo();
-  MachineBasicBlock *EntryBB = &MF->front();
-  unsigned AR = FuncInfo->CreateReg(MVT::i32);
-  unsigned MaxA = MFI.getMaxAlignment();
-  BuildMI(EntryBB, DebugLoc(), HII->get(Hexagon::PS_aligna), AR)
-      .addImm(MaxA);
-  MF->getInfo<HexagonMachineFunctionInfo>()->setStackAlignBaseVReg(AR);
+  // Finally, emit the PS_aligna instruction, if necessary. Do it late,
+  // because the max required stack layout may change up until right before
+  // instruction selection.
+  ppEmitAligna();
 }
 
 // Match a frame index that can be used in an addressing mode.
index dd2c6f4..c80d375 100644 (file)
@@ -51,8 +51,6 @@ public:
     return true;
   }
   void PreprocessISelDAG() override;
-  void EmitFunctionEntryCode() override;
-
   void Select(SDNode *N) override;
 
   // Complex Pattern Selectors.
@@ -139,6 +137,7 @@ private:
   void ppAddrReorderAddShl(std::vector<SDNode*> &&Nodes);
   void ppAddrRewriteAndSrl(std::vector<SDNode*> &&Nodes);
   void ppHoistZextI1(std::vector<SDNode*> &&Nodes);
+  void ppEmitAligna();
 
   SmallDenseMap<SDNode *,int> RootWeights;
   SmallDenseMap<SDNode *,int> RootHeights;