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

Andrei Safronov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 13:47:54 PST 2024


================
@@ -378,6 +378,37 @@ void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
   MBBNumberingEpoch++;
 }
 
+int64_t MachineFunction::estimateFunctionSizeInBytes() {
+  const TargetInstrInfo &TII = *getSubtarget().getInstrInfo();
+  const Align FunctionAlignment = getAlignment();
+  MachineFunction::iterator MBBI = begin(), E = end();
+  /// Offset - Distance from the beginning of the function to the end
+  /// of the basic block.
+  int64_t Offset = 0;
+
+  for (; MBBI != E; ++MBBI) {
+    const Align Alignment = MBBI->getAlignment();
+    int64_t BlockSize = 0;
+
+    for (auto &MI : *MBBI) {
+      BlockSize += TII.getInstSizeInBytes(MI);
+    }
+
+    int64_t OffsetBB;
+    if (Alignment <= FunctionAlignment) {
+      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.
----------------
andreisfr wrote:

I haven't seen an example for Xtensa at this time with block alignment large then function. Actually I implemented alignment handling like it is done in Branch Relaxation pass in postOffset function. I thought it may be useful for general case. 
https://github.com/llvm/llvm-project/blob/a518ed2d815c16010a6262edd0414a5f60a63a39/llvm/lib/CodeGen/BranchRelaxation.cpp#L68

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


More information about the llvm-commits mailing list