14
14
// ===----------------------------------------------------------------------===//
15
15
16
16
#include " ARM.h"
17
+ #include " ARMBasicBlockInfo.h"
17
18
#include " ARMMachineFunctionInfo.h"
18
19
#include " MCTargetDesc/ARMAddressingModes.h"
19
20
#include " Thumb2InstrInfo.h"
@@ -57,19 +58,6 @@ static cl::opt<unsigned>
57
58
CPMaxIteration (" arm-constant-island-max-iteration" , cl::Hidden, cl::init(30 ),
58
59
cl::desc(" The max number of iteration for converge" ));
59
60
60
-
61
- // / UnknownPadding - Return the worst case padding that could result from
62
- // / unknown offset bits. This does not include alignment padding caused by
63
- // / known offset bits.
64
- // /
65
- // / @param LogAlign log2(alignment)
66
- // / @param KnownBits Number of known low offset bits.
67
- static inline unsigned UnknownPadding (unsigned LogAlign, unsigned KnownBits) {
68
- if (KnownBits < LogAlign)
69
- return (1u << LogAlign) - (1u << KnownBits);
70
- return 0 ;
71
- }
72
-
73
61
namespace {
74
62
// / ARMConstantIslands - Due to limited PC-relative displacements, ARM
75
63
// / requires constant pool entries to be scattered among the instructions
@@ -83,78 +71,6 @@ namespace {
83
71
// / CPE - A constant pool entry that has been placed somewhere, which
84
72
// / tracks a list of users.
85
73
class ARMConstantIslands : public MachineFunctionPass {
86
- // / BasicBlockInfo - Information about the offset and size of a single
87
- // / basic block.
88
- struct BasicBlockInfo {
89
- // / Offset - Distance from the beginning of the function to the beginning
90
- // / of this basic block.
91
- // /
92
- // / Offsets are computed assuming worst case padding before an aligned
93
- // / block. This means that subtracting basic block offsets always gives a
94
- // / conservative estimate of the real distance which may be smaller.
95
- // /
96
- // / Because worst case padding is used, the computed offset of an aligned
97
- // / block may not actually be aligned.
98
- unsigned Offset;
99
-
100
- // / Size - Size of the basic block in bytes. If the block contains
101
- // / inline assembly, this is a worst case estimate.
102
- // /
103
- // / The size does not include any alignment padding whether from the
104
- // / beginning of the block, or from an aligned jump table at the end.
105
- unsigned Size ;
106
-
107
- // / KnownBits - The number of low bits in Offset that are known to be
108
- // / exact. The remaining bits of Offset are an upper bound.
109
- uint8_t KnownBits;
110
-
111
- // / Unalign - When non-zero, the block contains instructions (inline asm)
112
- // / of unknown size. The real size may be smaller than Size bytes by a
113
- // / multiple of 1 << Unalign.
114
- uint8_t Unalign;
115
-
116
- // / PostAlign - When non-zero, the block terminator contains a .align
117
- // / directive, so the end of the block is aligned to 1 << PostAlign
118
- // / bytes.
119
- uint8_t PostAlign;
120
-
121
- BasicBlockInfo () : Offset(0 ), Size (0 ), KnownBits(0 ), Unalign(0 ),
122
- PostAlign (0 ) {}
123
-
124
- // / Compute the number of known offset bits internally to this block.
125
- // / This number should be used to predict worst case padding when
126
- // / splitting the block.
127
- unsigned internalKnownBits () const {
128
- unsigned Bits = Unalign ? Unalign : KnownBits;
129
- // If the block size isn't a multiple of the known bits, assume the
130
- // worst case padding.
131
- if (Size & ((1u << Bits) - 1 ))
132
- Bits = countTrailingZeros (Size );
133
- return Bits;
134
- }
135
-
136
- // / Compute the offset immediately following this block. If LogAlign is
137
- // / specified, return the offset the successor block will get if it has
138
- // / this alignment.
139
- unsigned postOffset (unsigned LogAlign = 0 ) const {
140
- unsigned PO = Offset + Size ;
141
- unsigned LA = std::max (unsigned (PostAlign), LogAlign);
142
- if (!LA)
143
- return PO;
144
- // Add alignment padding from the terminator.
145
- return PO + UnknownPadding (LA, internalKnownBits ());
146
- }
147
-
148
- // / Compute the number of known low bits of postOffset. If this block
149
- // / contains inline asm, the number of known bits drops to the
150
- // / instruction alignment. An aligned terminator may increase the number
151
- // / of know bits.
152
- // / If LogAlign is given, also consider the alignment of the next block.
153
- unsigned postKnownBits (unsigned LogAlign = 0 ) const {
154
- return std::max (std::max (unsigned (PostAlign), LogAlign),
155
- internalKnownBits ());
156
- }
157
- };
158
74
159
75
std::vector<BasicBlockInfo> BBInfo;
160
76
@@ -330,7 +246,6 @@ namespace {
330
246
MachineBasicBlock *adjustJTTargetBlockForward (MachineBasicBlock *BB,
331
247
MachineBasicBlock *JTBB);
332
248
333
- void computeBlockSize (MachineBasicBlock *MBB);
334
249
unsigned getOffsetOf (MachineInstr *MI) const ;
335
250
unsigned getUserOffset (CPUser&) const ;
336
251
void dumpBBs ();
@@ -734,15 +649,8 @@ void ARMConstantIslands::scanFunctionJumpTables() {
734
649
// / and finding all of the constant pool users.
735
650
void ARMConstantIslands::
736
651
initializeFunctionInfo (const std::vector<MachineInstr*> &CPEMIs) {
737
- BBInfo.clear ();
738
- BBInfo.resize (MF->getNumBlockIDs ());
739
652
740
- // First thing, compute the size of all basic blocks, and see if the function
741
- // has any inline assembly in it. If so, we have to be conservative about
742
- // alignment assumptions, as we don't know for sure the size of any
743
- // instructions in the inline assembly.
744
- for (MachineBasicBlock &MBB : *MF)
745
- computeBlockSize (&MBB);
653
+ BBInfo = computeAllBlockSizes (MF);
746
654
747
655
// The known bits of the entry block offset are determined by the function
748
656
// alignment.
@@ -901,32 +809,6 @@ initializeFunctionInfo(const std::vector<MachineInstr*> &CPEMIs) {
901
809
}
902
810
}
903
811
904
- // / computeBlockSize - Compute the size and some alignment information for MBB.
905
- // / This function updates BBInfo directly.
906
- void ARMConstantIslands::computeBlockSize (MachineBasicBlock *MBB) {
907
- BasicBlockInfo &BBI = BBInfo[MBB->getNumber ()];
908
- BBI.Size = 0 ;
909
- BBI.Unalign = 0 ;
910
- BBI.PostAlign = 0 ;
911
-
912
- for (MachineInstr &I : *MBB) {
913
- BBI.Size += TII->GetInstSizeInBytes (I);
914
- // For inline asm, GetInstSizeInBytes returns a conservative estimate.
915
- // The actual size may be smaller, but still a multiple of the instr size.
916
- if (I.isInlineAsm ())
917
- BBI.Unalign = isThumb ? 1 : 2 ;
918
- // Also consider instructions that may be shrunk later.
919
- else if (isThumb && mayOptimizeThumb2Instruction (&I))
920
- BBI.Unalign = 1 ;
921
- }
922
-
923
- // tBR_JTr contains a .align 2 directive.
924
- if (!MBB->empty () && MBB->back ().getOpcode () == ARM::tBR_JTr) {
925
- BBI.PostAlign = 2 ;
926
- MBB->getParent ()->ensureAlignment (2 );
927
- }
928
- }
929
-
930
812
// / getOffsetOf - Return the current offset of the specified machine instruction
931
813
// / from the start of the function. This offset changes as stuff is moved
932
814
// / around inside the function.
@@ -1034,11 +916,11 @@ MachineBasicBlock *ARMConstantIslands::splitBlockBeforeInstr(MachineInstr *MI) {
1034
916
// the new jump we added. (It should be possible to do this without
1035
917
// recounting everything, but it's very confusing, and this is rarely
1036
918
// executed.)
1037
- computeBlockSize (OrigBB);
919
+ computeBlockSize (MF, OrigBB, BBInfo[OrigBB-> getNumber ()] );
1038
920
1039
921
// Figure out how large the NewMBB is. As the second half of the original
1040
922
// block, it may contain a tablejump.
1041
- computeBlockSize (NewBB);
923
+ computeBlockSize (MF, NewBB, BBInfo[NewBB-> getNumber ()] );
1042
924
1043
925
// All BBOffsets following these blocks must be modified.
1044
926
adjustBBOffsetsAfter (OrigBB);
@@ -1400,7 +1282,7 @@ void ARMConstantIslands::createNewWater(unsigned CPUserIndex,
1400
1282
unsigned MaxDisp = getUnconditionalBrDisp (UncondBr);
1401
1283
ImmBranches.push_back (ImmBranch (&UserMBB->back (),
1402
1284
MaxDisp, false , UncondBr));
1403
- computeBlockSize (UserMBB);
1285
+ computeBlockSize (MF, UserMBB, BBInfo[UserMBB-> getNumber ()] );
1404
1286
adjustBBOffsetsAfter (UserMBB);
1405
1287
return ;
1406
1288
}
0 commit comments