LLVM  4.0.0
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 "ARMBasicBlockInfo.h"
12 using namespace llvm;
13 
14 namespace llvm {
15 
16 // mayOptimizeThumb2Instruction - Returns true if optimizeThumb2Instructions
17 // below may shrink MI.
18 static bool
20  switch(MI->getOpcode()) {
21  // optimizeThumb2Instructions.
22  case ARM::t2LEApcrel:
23  case ARM::t2LDRpci:
24  // optimizeThumb2Branches.
25  case ARM::t2B:
26  case ARM::t2Bcc:
27  case ARM::tBcc:
28  // optimizeThumb2JumpTables.
29  case ARM::t2BR_JT:
30  return true;
31  }
32  return false;
33 }
34 
36  BasicBlockInfo &BBI) {
37  const ARMBaseInstrInfo *TII =
38  static_cast<const ARMBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
39  bool isThumb = MF->getInfo<ARMFunctionInfo>()->isThumbFunction();
40  BBI.Size = 0;
41  BBI.Unalign = 0;
42  BBI.PostAlign = 0;
43 
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.
48  if (I.isInlineAsm())
49  BBI.Unalign = isThumb ? 1 : 2;
50  // Also consider instructions that may be shrunk later.
51  else if (isThumb && mayOptimizeThumb2Instruction(&I))
52  BBI.Unalign = 1;
53  }
54 
55  // tBR_JTr contains a .align 2 directive.
56  if (!MBB->empty() && MBB->back().getOpcode() == ARM::tBR_JTr) {
57  BBI.PostAlign = 2;
58  MBB->getParent()->ensureAlignment(2);
59  }
60 }
61 
62 std::vector<BasicBlockInfo> computeAllBlockSizes(MachineFunction *MF) {
63  std::vector<BasicBlockInfo> BBInfo;
64  BBInfo.resize(MF->getNumBlockIDs());
65 
66  for (MachineBasicBlock &MBB : *MF)
67  computeBlockSize(MF, &MBB, BBInfo[MBB.getNumber()]);
68 
69  return BBInfo;
70 }
71 
72 } // end namespace
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
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.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const HexagonInstrInfo * TII
MachineBasicBlock * MBB
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:273
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
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:52
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:54
virtual const TargetInstrInfo * getInstrInfo() const
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)