LLVM  8.0.1
ARMComputeBlockSize.cpp
Go to the documentation of this file.
1 //===--- ARMComputeBlockSize.cpp - Compute machine block sizes ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "ARM.h"
11 #include "ARMBaseInstrInfo.h"
12 #include "ARMBasicBlockInfo.h"
13 #include "ARMMachineFunctionInfo.h"
18 #include <vector>
19 
20 using namespace llvm;
21 
22 namespace llvm {
23 
24 // mayOptimizeThumb2Instruction - Returns true if optimizeThumb2Instructions
25 // below may shrink MI.
26 static bool
28  switch(MI->getOpcode()) {
29  // optimizeThumb2Instructions.
30  case ARM::t2LEApcrel:
31  case ARM::t2LDRpci:
32  // optimizeThumb2Branches.
33  case ARM::t2B:
34  case ARM::t2Bcc:
35  case ARM::tBcc:
36  // optimizeThumb2JumpTables.
37  case ARM::t2BR_JT:
38  case ARM::tBR_JTr:
39  return true;
40  }
41  return false;
42 }
43 
45  BasicBlockInfo &BBI) {
46  const ARMBaseInstrInfo *TII =
47  static_cast<const ARMBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
49  BBI.Size = 0;
50  BBI.Unalign = 0;
51  BBI.PostAlign = 0;
52 
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.
57  if (I.isInlineAsm())
58  BBI.Unalign = isThumb ? 1 : 2;
59  // Also consider instructions that may be shrunk later.
60  else if (isThumb && mayOptimizeThumb2Instruction(&I))
61  BBI.Unalign = 1;
62  }
63 
64  // tBR_JTr contains a .align 2 directive.
65  if (!MBB->empty() && MBB->back().getOpcode() == ARM::tBR_JTr) {
66  BBI.PostAlign = 2;
67  MBB->getParent()->ensureAlignment(2);
68  }
69 }
70 
71 std::vector<BasicBlockInfo> computeAllBlockSizes(MachineFunction *MF) {
72  std::vector<BasicBlockInfo> BBInfo;
73  BBInfo.resize(MF->getNumBlockIDs());
74 
75  for (MachineBasicBlock &MBB : *MF)
76  computeBlockSize(MF, &MBB, BBInfo[MBB.getNumber()]);
77 
78  return BBInfo;
79 }
80 
81 } // end namespace llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:24
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID&#39;s allocated.
void computeBlockSize(MachineFunction *MF, MachineBasicBlock *MBB, BasicBlockInfo &BBI)
static bool isThumb(const MCSubtargetInfo &STI)
BasicBlockInfo - Information about the offset and size of a single basic block.
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
static bool isThumbFunction(Function *F, Triple::ArchType ModuleArch)
virtual const TargetInstrInfo * getInstrInfo() const
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static bool mayOptimizeThumb2Instruction(const MachineInstr *MI)
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Returns the size of the specified MachineInstr.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned Size
Size - Size of the basic block in bytes.
Representation of each machine instruction.
Definition: MachineInstr.h:64
uint8_t Unalign
Unalign - When non-zero, the block contains instructions (inline asm) of unknown size.
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
#define I(x, y, z)
Definition: MD5.cpp:58
IRTranslator LLVM IR MI
uint8_t PostAlign
PostAlign - When non-zero, the block terminator contains a .align directive, so the end of the block ...
std::vector< BasicBlockInfo > computeAllBlockSizes(MachineFunction *MF)