diff options
author | Andrei Safronov <andrei.safronov@espressif.com> | 2024-11-08 01:50:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-08 01:50:42 +0300 |
commit | 3b1b1271fb552c996d9fdfa9a997f33013dd275f (patch) | |
tree | d07367bf5b101a47d8b55b5d0e5ad53c135629a2 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | fd799add2186356dc19e81106a1428a2edf7c20b (diff) | |
download | llvm-3b1b1271fb552c996d9fdfa9a997f33013dd275f.zip llvm-3b1b1271fb552c996d9fdfa9a997f33013dd275f.tar.gz llvm-3b1b1271fb552c996d9fdfa9a997f33013dd275f.tar.bz2 |
[Xtensa] Implement support for the BranchRelaxation. (#113450)
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index b56888a..7eb1c5e 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -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. + OffsetBB = alignTo(Offset, Alignment) + Alignment.value() - + FunctionAlignment.value(); + } + Offset = OffsetBB + BlockSize; + } + + return Offset; +} + /// This method iterates over the basic blocks and assigns their IsBeginSection /// and IsEndSection fields. This must be called after MBB layout is finalized /// and the SectionID's are assigned to MBBs. |