Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / ARM / ARMComputeBlockSize.cpp
blob828fc6568380c4c717a942a5a9782d8808edc16d
1 //===--- ARMComputeBlockSize.cpp - Compute machine block sizes ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "ARM.h"
10 #include "ARMBaseInstrInfo.h"
11 #include "ARMBasicBlockInfo.h"
12 #include "ARMMachineFunctionInfo.h"
13 #include "llvm/CodeGen/MachineBasicBlock.h"
14 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/MachineInstr.h"
16 #include "llvm/CodeGen/TargetSubtargetInfo.h"
17 #include <vector>
19 using namespace llvm;
21 namespace llvm {
23 // mayOptimizeThumb2Instruction - Returns true if optimizeThumb2Instructions
24 // below may shrink MI.
25 static bool
26 mayOptimizeThumb2Instruction(const MachineInstr *MI) {
27 switch(MI->getOpcode()) {
28 // optimizeThumb2Instructions.
29 case ARM::t2LEApcrel:
30 case ARM::t2LDRpci:
31 // optimizeThumb2Branches.
32 case ARM::t2B:
33 case ARM::t2Bcc:
34 case ARM::tBcc:
35 // optimizeThumb2JumpTables.
36 case ARM::t2BR_JT:
37 case ARM::tBR_JTr:
38 return true;
40 return false;
43 void computeBlockSize(MachineFunction *MF, MachineBasicBlock *MBB,
44 BasicBlockInfo &BBI) {
45 const ARMBaseInstrInfo *TII =
46 static_cast<const ARMBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
47 bool isThumb = MF->getInfo<ARMFunctionInfo>()->isThumbFunction();
48 BBI.Size = 0;
49 BBI.Unalign = 0;
50 BBI.PostAlign = 0;
52 for (MachineInstr &I : *MBB) {
53 BBI.Size += TII->getInstSizeInBytes(I);
54 // For inline asm, getInstSizeInBytes returns a conservative estimate.
55 // The actual size may be smaller, but still a multiple of the instr size.
56 if (I.isInlineAsm())
57 BBI.Unalign = isThumb ? 1 : 2;
58 // Also consider instructions that may be shrunk later.
59 else if (isThumb && mayOptimizeThumb2Instruction(&I))
60 BBI.Unalign = 1;
63 // tBR_JTr contains a .align 2 directive.
64 if (!MBB->empty() && MBB->back().getOpcode() == ARM::tBR_JTr) {
65 BBI.PostAlign = 2;
66 MBB->getParent()->ensureAlignment(2);
70 std::vector<BasicBlockInfo> computeAllBlockSizes(MachineFunction *MF) {
71 std::vector<BasicBlockInfo> BBInfo;
72 BBInfo.resize(MF->getNumBlockIDs());
74 for (MachineBasicBlock &MBB : *MF)
75 computeBlockSize(MF, &MBB, BBInfo[MBB.getNumber()]);
77 return BBInfo;
80 } // end namespace llvm