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

Andrei Safronov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 06:30:45 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();
----------------
andreisfr wrote:

I moved this function to XtensaUtils.cpp.

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


More information about the llvm-commits mailing list