aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineFunction.cpp31
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.