[llvm] [Xtensa] Implement support for the BranchRelaxation. (PR #113450)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 18:31:42 PDT 2024


================
@@ -258,13 +258,32 @@ void XtensaFrameLowering::determineCalleeSaves(MachineFunction &MF,
 
 static unsigned estimateFunctionSizeInBytes(const MachineFunction &MF,
                                             const XtensaInstrInfo &TII) {
-  unsigned FnSize = 0;
+  const Align FunctiontAlignment = MF.getAlignment();
+  /// Offset - Distance from the beginning of the function to the end
+  /// of the basic block.
+  unsigned Offset = 0;
+
   for (auto &MBB : MF) {
+    const Align Alignment = MBB.getAlignment();
+    unsigned BlockSize = 0;
+
     for (auto &MI : MBB) {
-      FnSize += TII.getInstSizeInBytes(MI);
+      BlockSize += TII.getInstSizeInBytes(MI);
     }
+
+    unsigned OffsetBB;
+    if (Alignment <= FunctiontAlignment) {
+      OffsetBB = alignTo(Offset, Alignment);
+    } else {
+      // The alignment of this MBB is larger than the function's alignment, so
+      // we can't tell whether or not it will insert nops. Assume that it will.
+      OffsetBB = alignTo(Offset, Alignment) + Alignment.value() -
+                 FunctiontAlignment.value();
----------------
arsenm wrote:

Is this handled somewhere else already? Should this whole size estimate function be moved to a common helper function? 

https://github.com/llvm/llvm-project/pull/113450


More information about the llvm-commits mailing list