1 //===--- ARMComputeBlockSize.cpp - Compute machine block sizes ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "ARMBasicBlockInfo.h"
16 // mayOptimizeThumb2Instruction - Returns true if optimizeThumb2Instructions
17 // below may shrink MI.
19 mayOptimizeThumb2Instruction(const MachineInstr *MI) {
20 switch(MI->getOpcode()) {
21 // optimizeThumb2Instructions.
24 // optimizeThumb2Branches.
28 // optimizeThumb2JumpTables.
35 void computeBlockSize(MachineFunction *MF, MachineBasicBlock *MBB,
36 BasicBlockInfo &BBI) {
37 const ARMBaseInstrInfo *TII =
38 static_cast<const ARMBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
39 bool isThumb = MF->getInfo<ARMFunctionInfo>()->isThumbFunction();
44 for (MachineInstr &I : *MBB) {
45 BBI.Size += TII->getInstSizeInBytes(I);
46 // For inline asm, getInstSizeInBytes returns a conservative estimate.
47 // The actual size may be smaller, but still a multiple of the instr size.
49 BBI.Unalign = isThumb ? 1 : 2;
50 // Also consider instructions that may be shrunk later.
51 else if (isThumb && mayOptimizeThumb2Instruction(&I))
55 // tBR_JTr contains a .align 2 directive.
56 if (!MBB->empty() && MBB->back().getOpcode() == ARM::tBR_JTr) {
58 MBB->getParent()->ensureAlignment(2);
62 std::vector<BasicBlockInfo> computeAllBlockSizes(MachineFunction *MF) {
63 std::vector<BasicBlockInfo> BBInfo;
64 BBInfo.resize(MF->getNumBlockIDs());
66 for (MachineBasicBlock &MBB : *MF)
67 computeBlockSize(MF, &MBB, BBInfo[MBB.getNumber()]);