@@ -39,20 +39,6 @@ const AIEBaseInstrInfo *getTII(MachineBasicBlock::iterator MII) {
3939 return static_cast <const AIEBaseInstrInfo *>(Subtarget.getInstrInfo ());
4040}
4141
42- const AIE::MachineBundle getAIEMachineBundle (MachineBasicBlock::iterator MII) {
43- const AIEBaseInstrInfo *TII = getTII (MII);
44- AIE::MachineBundle Bundle (TII->getFormatInterface ());
45- // Iterate over the instructions in the bundle.
46- MachineBasicBlock::const_instr_iterator I = ++MII->getIterator ();
47- MachineBasicBlock::instr_iterator E = MII->getParent ()->instr_end ();
48- while (I != E && I->isInsideBundle ()) {
49- MachineInstr *MI = const_cast <MachineInstr *>(&(*I));
50- Bundle.add (MI);
51- I++;
52- }
53- return Bundle;
54- }
55-
5642const VLIWFormat *getElongatedFormat (AIE::MachineBundle &Bundle,
5743 unsigned Size) {
5844 if (Bundle.isNOPBundle ()) {
@@ -108,7 +94,8 @@ unsigned applyRegionAlignment(MachineBasicBlock::iterator MI,
10894 unsigned f = 0 ;
10995 while (MI != EndMI) {
11096 if (MI->isBundle ()) {
111- AIE::MachineBundle Bundle = getAIEMachineBundle (MI);
97+ const AIEBaseInstrInfo *TII = getTII (MI);
98+ AIE::MachineBundle Bundle = TII->getAIEMachineBundle (MI);
11299 const VLIWFormat *Format = Bundle.getFormatOrNull ();
113100 assert (Format);
114101 Size = Format->getSize ();
@@ -154,34 +141,16 @@ unsigned applyRegionAlignment(MachineBasicBlock::iterator MI,
154141 return PadBytes;
155142}
156143
157- unsigned
158- getRegionSize (llvm::iterator_range<MachineBasicBlock::iterator> Region) {
159- unsigned Size = 0 ;
160- LLVM_DEBUG (dbgs () << " ---Region Begin---\n " );
161- for (auto it = Region.begin (), end = Region.end (); it != end; ++it) {
162- if (it->isBundle ()) {
163- AIE::MachineBundle Bundle = getAIEMachineBundle (it);
164- const VLIWFormat *Format = Bundle.getFormatOrNull ();
165- assert (Format);
166- Size += Format->getSize ();
167- LLVM_DEBUG (dbgs () << Format->Name << " \n " );
168- }
169- }
170- LLVM_DEBUG (dbgs () << " ---Region End---\n " );
171- LLVM_DEBUG (dbgs () << " Region Size"
172- << " " << Size << " \n " );
173- return Size;
174- }
175-
176144} // namespace
177145
178146void AIEMachineAlignment::applyBundlesAlignment (
179147 const std::vector<llvm::iterator_range<MachineBasicBlock::iterator>>
180- &Regions) {
148+ &Regions,
149+ const AIEBaseInstrInfo *TII) {
181150 for (auto Region : Regions) {
182151 unsigned Size = 0 ;
183152 unsigned PadBytes = 0 ;
184- Size = getRegionSize (Region);
153+ Size = TII-> getRegionSize (Region);
185154 if ((Size % 16 ) == 0 )
186155 continue ;
187156 PadBytes = 16 - (Size % 16 );
@@ -226,7 +195,9 @@ bool AIEMachineAlignment::runOnMachineFunction(MachineFunction &MF) {
226195 for (auto &MBB : MF) {
227196 std::vector<llvm::iterator_range<MachineBasicBlock::iterator>> Regions =
228197 findRegions (MBB);
229- applyBundlesAlignment (Regions);
198+ auto *TII = static_cast <const AIEBaseInstrInfo *>(
199+ MBB.getParent ()->getSubtarget ().getInstrInfo ());
200+ applyBundlesAlignment (Regions, TII);
230201 // Clean up BB local Regions
231202 Regions.clear ();
232203 }
0 commit comments