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 "ARMBaseInstrInfo.h"
12 #include "ARMBasicBlockInfo.h"
13 #include "ARMMachineFunctionInfo.h"
14 #include "llvm/CodeGen/MachineBasicBlock.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/MachineInstr.h"
17 #include "llvm/CodeGen/TargetSubtargetInfo.h"
24 // mayOptimizeThumb2Instruction - Returns true if optimizeThumb2Instructions
25 // below may shrink MI.
27 mayOptimizeThumb2Instruction(const MachineInstr *MI) {
28 switch(MI->getOpcode()) {
29 // optimizeThumb2Instructions.
32 // optimizeThumb2Branches.
36 // optimizeThumb2JumpTables.
44 void computeBlockSize(MachineFunction *MF, MachineBasicBlock *MBB,
45 BasicBlockInfo &BBI) {
46 const ARMBaseInstrInfo *TII =
47 static_cast<const ARMBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
48 bool isThumb = MF->getInfo<ARMFunctionInfo>()->isThumbFunction();
53 for (MachineInstr &I : *MBB) {
54 BBI.Size += TII->getInstSizeInBytes(I);
55 // For inline asm, getInstSizeInBytes returns a conservative estimate.
56 // The actual size may be smaller, but still a multiple of the instr size.
58 BBI.Unalign = isThumb ? 1 : 2;
59 // Also consider instructions that may be shrunk later.
60 else if (isThumb && mayOptimizeThumb2Instruction(&I))
64 // tBR_JTr contains a .align 2 directive.
65 if (!MBB->empty() && MBB->back().getOpcode() == ARM::tBR_JTr) {
67 MBB->getParent()->ensureAlignment(2);
71 std::vector<BasicBlockInfo> computeAllBlockSizes(MachineFunction *MF) {
72 std::vector<BasicBlockInfo> BBInfo;
73 BBInfo.resize(MF->getNumBlockIDs());
75 for (MachineBasicBlock &MBB : *MF)
76 computeBlockSize(MF, &MBB, BBInfo[MBB.getNumber()]);
81 } // end namespace llvm