diff --git a/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp b/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp index 09c55cb2618..eb8fab13626 100644 --- a/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp +++ b/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp @@ -1034,23 +1034,6 @@ void HexagonDAGToDAGISel::ppHoistZextI1(std::vector &&Nodes) { } } -void HexagonDAGToDAGISel::ppEmitAligna() { - auto &HST = static_cast(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()->setStackAlignBaseVReg(AR); -} - void HexagonDAGToDAGISel::PreprocessISelDAG() { // Repack all nodes before calling each preprocessing function, // because each of them can modify the set of nodes. @@ -1106,11 +1089,21 @@ void HexagonDAGToDAGISel::PreprocessISelDAG() { CurDAG->dump(); }); } +} - // 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(); +void HexagonDAGToDAGISel::EmitFunctionEntryCode() { + auto &HST = static_cast(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()->setStackAlignBaseVReg(AR); } // Match a frame index that can be used in an addressing mode. diff --git a/lib/Target/Hexagon/HexagonISelDAGToDAG.h b/lib/Target/Hexagon/HexagonISelDAGToDAG.h index c80d375aa7b..dd2c6f4fc95 100644 --- a/lib/Target/Hexagon/HexagonISelDAGToDAG.h +++ b/lib/Target/Hexagon/HexagonISelDAGToDAG.h @@ -51,6 +51,8 @@ public: return true; } void PreprocessISelDAG() override; + void EmitFunctionEntryCode() override; + void Select(SDNode *N) override; // Complex Pattern Selectors. @@ -137,7 +139,6 @@ private: void ppAddrReorderAddShl(std::vector &&Nodes); void ppAddrRewriteAndSrl(std::vector &&Nodes); void ppHoistZextI1(std::vector &&Nodes); - void ppEmitAligna(); SmallDenseMap RootWeights; SmallDenseMap RootHeights;