Mips16InstrInfo.cpp: Use <cctype> instead of <ctype.h>
[oota-llvm.git] / lib / Target / Mips / Mips16InstrInfo.cpp
1 //===-- Mips16InstrInfo.cpp - Mips16 Instruction Information --------------===//
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 // This file contains the Mips16 implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "Mips16InstrInfo.h"
14 #include "InstPrinter/MipsInstPrinter.h"
15 #include "MipsMachineFunction.h"
16 #include "MipsTargetMachine.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/CodeGen/MachineRegisterInfo.h"
21 #include "llvm/CodeGen/RegisterScavenging.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/TargetRegistry.h"
27 #include <cctype>
28
29 using namespace llvm;
30
31 static cl::opt<bool> NeverUseSaveRestore(
32   "mips16-never-use-save-restore",
33   cl::init(false),
34   cl::desc("For testing ability to adjust stack pointer "
35            "without save/restore instruction"),
36   cl::Hidden);
37
38
39 Mips16InstrInfo::Mips16InstrInfo(MipsTargetMachine &tm)
40   : MipsInstrInfo(tm, Mips::Bimm16),
41     RI(*tm.getSubtargetImpl()) {}
42
43 const MipsRegisterInfo &Mips16InstrInfo::getRegisterInfo() const {
44   return RI;
45 }
46
47 /// isLoadFromStackSlot - If the specified machine instruction is a direct
48 /// load from a stack slot, return the virtual or physical register number of
49 /// the destination along with the FrameIndex of the loaded stack slot.  If
50 /// not, return 0.  This predicate must return 0 if the instruction has
51 /// any side effects other than loading from the stack slot.
52 unsigned Mips16InstrInfo::
53 isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const
54 {
55   return 0;
56 }
57
58 /// isStoreToStackSlot - If the specified machine instruction is a direct
59 /// store to a stack slot, return the virtual or physical register number of
60 /// the source reg along with the FrameIndex of the loaded stack slot.  If
61 /// not, return 0.  This predicate must return 0 if the instruction has
62 /// any side effects other than storing to the stack slot.
63 unsigned Mips16InstrInfo::
64 isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const
65 {
66   return 0;
67 }
68
69 void Mips16InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
70                                   MachineBasicBlock::iterator I, DebugLoc DL,
71                                   unsigned DestReg, unsigned SrcReg,
72                                   bool KillSrc) const {
73   unsigned Opc = 0;
74
75   if (Mips::CPU16RegsRegClass.contains(DestReg) &&
76       Mips::GPR32RegClass.contains(SrcReg))
77     Opc = Mips::MoveR3216;
78   else if (Mips::GPR32RegClass.contains(DestReg) &&
79            Mips::CPU16RegsRegClass.contains(SrcReg))
80     Opc = Mips::Move32R16;
81   else if ((SrcReg == Mips::HI0) &&
82            (Mips::CPU16RegsRegClass.contains(DestReg)))
83     Opc = Mips::Mfhi16, SrcReg = 0;
84
85   else if ((SrcReg == Mips::LO0) &&
86            (Mips::CPU16RegsRegClass.contains(DestReg)))
87     Opc = Mips::Mflo16, SrcReg = 0;
88
89
90   assert(Opc && "Cannot copy registers");
91
92   MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc));
93
94   if (DestReg)
95     MIB.addReg(DestReg, RegState::Define);
96
97   if (SrcReg)
98     MIB.addReg(SrcReg, getKillRegState(KillSrc));
99 }
100
101 void Mips16InstrInfo::
102 storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
103                 unsigned SrcReg, bool isKill, int FI,
104                 const TargetRegisterClass *RC, const TargetRegisterInfo *TRI,
105                 int64_t Offset) const {
106   DebugLoc DL;
107   if (I != MBB.end()) DL = I->getDebugLoc();
108   MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOStore);
109   unsigned Opc = 0;
110   if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
111     Opc = Mips::SwRxSpImmX16;
112   assert(Opc && "Register class not handled!");
113   BuildMI(MBB, I, DL, get(Opc)).addReg(SrcReg, getKillRegState(isKill)).
114       addFrameIndex(FI).addImm(Offset)
115       .addMemOperand(MMO);
116 }
117
118 void Mips16InstrInfo::
119 loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
120                  unsigned DestReg, int FI, const TargetRegisterClass *RC,
121                  const TargetRegisterInfo *TRI, int64_t Offset) const {
122   DebugLoc DL;
123   if (I != MBB.end()) DL = I->getDebugLoc();
124   MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOLoad);
125   unsigned Opc = 0;
126
127   if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
128     Opc = Mips::LwRxSpImmX16;
129   assert(Opc && "Register class not handled!");
130   BuildMI(MBB, I, DL, get(Opc), DestReg).addFrameIndex(FI).addImm(Offset)
131     .addMemOperand(MMO);
132 }
133
134 bool Mips16InstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
135   MachineBasicBlock &MBB = *MI->getParent();
136   switch(MI->getDesc().getOpcode()) {
137   default:
138     return false;
139   case Mips::RetRA16:
140     ExpandRetRA16(MBB, MI, Mips::JrcRa16);
141     break;
142   }
143
144   MBB.erase(MI);
145   return true;
146 }
147
148 /// GetOppositeBranchOpc - Return the inverse of the specified
149 /// opcode, e.g. turning BEQ to BNE.
150 unsigned Mips16InstrInfo::getOppositeBranchOpc(unsigned Opc) const {
151   switch (Opc) {
152   default:  llvm_unreachable("Illegal opcode!");
153   case Mips::BeqzRxImmX16: return Mips::BnezRxImmX16;
154   case Mips::BnezRxImmX16: return Mips::BeqzRxImmX16;
155   case Mips::BteqzT8CmpX16: return Mips::BtnezT8CmpX16;
156   case Mips::BteqzT8SltX16: return Mips::BtnezT8SltX16;
157   case Mips::BteqzT8SltiX16: return Mips::BtnezT8SltiX16;
158   case Mips::BtnezX16: return Mips::BteqzX16;
159   case Mips::BtnezT8CmpiX16: return Mips::BteqzT8CmpiX16;
160   case Mips::BtnezT8SltuX16: return Mips::BteqzT8SltuX16;
161   case Mips::BtnezT8SltiuX16: return Mips::BteqzT8SltiuX16;
162   case Mips::BteqzX16: return Mips::BtnezX16;
163   case Mips::BteqzT8CmpiX16: return Mips::BtnezT8CmpiX16;
164   case Mips::BteqzT8SltuX16: return Mips::BtnezT8SltuX16;
165   case Mips::BteqzT8SltiuX16: return Mips::BtnezT8SltiuX16;
166   case Mips::BtnezT8CmpX16: return Mips::BteqzT8CmpX16;
167   case Mips::BtnezT8SltX16: return Mips::BteqzT8SltX16;
168   case Mips::BtnezT8SltiX16: return Mips::BteqzT8SltiX16;
169   }
170   assert(false && "Implement this function.");
171   return 0;
172 }
173
174 // Adjust SP by FrameSize bytes. Save RA, S0, S1
175 void Mips16InstrInfo::makeFrame(unsigned SP, int64_t FrameSize,
176                     MachineBasicBlock &MBB,
177                     MachineBasicBlock::iterator I) const {
178   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
179   if (!NeverUseSaveRestore) {
180     if (isUInt<11>(FrameSize))
181       BuildMI(MBB, I, DL, get(Mips::SaveRaF16)).addImm(FrameSize);
182     else {
183       int Base = 2040; // should create template function like isUInt that
184                        // returns largest possible n bit unsigned integer
185       int64_t Remainder = FrameSize - Base;
186       BuildMI(MBB, I, DL, get(Mips::SaveRaF16)). addImm(Base);
187       if (isInt<16>(-Remainder))
188         BuildAddiuSpImm(MBB, I, -Remainder);
189       else
190         adjustStackPtrBig(SP, -Remainder, MBB, I, Mips::V0, Mips::V1);
191     }
192
193   }
194   else {
195     //
196     // sw ra, -4[sp]
197     // sw s1, -8[sp]
198     // sw s0, -12[sp]
199
200     MachineInstrBuilder MIB1 = BuildMI(MBB, I, DL, get(Mips::SwRxSpImmX16),
201                                        Mips::RA);
202     MIB1.addReg(Mips::SP);
203     MIB1.addImm(-4);
204     MachineInstrBuilder MIB2 = BuildMI(MBB, I, DL, get(Mips::SwRxSpImmX16),
205                                        Mips::S1);
206     MIB2.addReg(Mips::SP);
207     MIB2.addImm(-8);
208     MachineInstrBuilder MIB3 = BuildMI(MBB, I, DL, get(Mips::SwRxSpImmX16),
209                                        Mips::S0);
210     MIB3.addReg(Mips::SP);
211     MIB3.addImm(-12);
212     adjustStackPtrBig(SP, -FrameSize, MBB, I, Mips::V0, Mips::V1);
213   }
214 }
215
216 // Adjust SP by FrameSize bytes. Restore RA, S0, S1
217 void Mips16InstrInfo::restoreFrame(unsigned SP, int64_t FrameSize,
218                                    MachineBasicBlock &MBB,
219                                    MachineBasicBlock::iterator I) const {
220   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
221   if (!NeverUseSaveRestore) {
222     if (isUInt<11>(FrameSize))
223       BuildMI(MBB, I, DL, get(Mips::RestoreRaF16)).addImm(FrameSize);
224     else {
225       int Base = 2040; // should create template function like isUInt that
226                        // returns largest possible n bit unsigned integer
227       int64_t Remainder = FrameSize - Base;
228       if (isInt<16>(Remainder))
229         BuildAddiuSpImm(MBB, I, Remainder);
230       else
231         adjustStackPtrBig(SP, Remainder, MBB, I, Mips::A0, Mips::A1);
232       BuildMI(MBB, I, DL, get(Mips::RestoreRaF16)). addImm(Base);
233     }
234   }
235   else {
236     adjustStackPtrBig(SP, FrameSize, MBB, I, Mips::A0, Mips::A1);
237     // lw ra, -4[sp]
238     // lw s1, -8[sp]
239     // lw s0, -12[sp]
240     MachineInstrBuilder MIB1 = BuildMI(MBB, I, DL, get(Mips::LwRxSpImmX16),
241                                        Mips::A0);
242     MIB1.addReg(Mips::SP);
243     MIB1.addImm(-4);
244     MachineInstrBuilder MIB0 = BuildMI(MBB, I, DL, get(Mips::Move32R16),
245                                        Mips::RA);
246      MIB0.addReg(Mips::A0);
247     MachineInstrBuilder MIB2 = BuildMI(MBB, I, DL, get(Mips::LwRxSpImmX16),
248                                        Mips::S1);
249     MIB2.addReg(Mips::SP);
250     MIB2.addImm(-8);
251     MachineInstrBuilder MIB3 = BuildMI(MBB, I, DL, get(Mips::LwRxSpImmX16),
252                                        Mips::S0);
253     MIB3.addReg(Mips::SP);
254     MIB3.addImm(-12);
255   }
256
257 }
258
259 // Adjust SP by Amount bytes where bytes can be up to 32bit number.
260 // This can only be called at times that we know that there is at least one free
261 // register.
262 // This is clearly safe at prologue and epilogue.
263 //
264 void Mips16InstrInfo::adjustStackPtrBig(unsigned SP, int64_t Amount,
265                                         MachineBasicBlock &MBB,
266                                         MachineBasicBlock::iterator I,
267                                         unsigned Reg1, unsigned Reg2) const {
268   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
269 //  MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo();
270 //  unsigned Reg1 = RegInfo.createVirtualRegister(&Mips::CPU16RegsRegClass);
271 //  unsigned Reg2 = RegInfo.createVirtualRegister(&Mips::CPU16RegsRegClass);
272   //
273   // li reg1, constant
274   // move reg2, sp
275   // add reg1, reg1, reg2
276   // move sp, reg1
277   //
278   //
279   MachineInstrBuilder MIB1 = BuildMI(MBB, I, DL, get(Mips::LwConstant32), Reg1);
280   MIB1.addImm(Amount);
281   MachineInstrBuilder MIB2 = BuildMI(MBB, I, DL, get(Mips::MoveR3216), Reg2);
282   MIB2.addReg(Mips::SP, RegState::Kill);
283   MachineInstrBuilder MIB3 = BuildMI(MBB, I, DL, get(Mips::AdduRxRyRz16), Reg1);
284   MIB3.addReg(Reg1);
285   MIB3.addReg(Reg2, RegState::Kill);
286   MachineInstrBuilder MIB4 = BuildMI(MBB, I, DL, get(Mips::Move32R16),
287                                                      Mips::SP);
288   MIB4.addReg(Reg1, RegState::Kill);
289 }
290
291 void Mips16InstrInfo::adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount,
292                     MachineBasicBlock &MBB,
293                     MachineBasicBlock::iterator I) const {
294    assert(false && "adjust stack pointer amount exceeded");
295 }
296
297 /// Adjust SP by Amount bytes.
298 void Mips16InstrInfo::adjustStackPtr(unsigned SP, int64_t Amount,
299                                      MachineBasicBlock &MBB,
300                                      MachineBasicBlock::iterator I) const {
301   if (isInt<16>(Amount))  // need to change to addiu sp, ....and isInt<16>
302     BuildAddiuSpImm(MBB, I, Amount);
303   else
304     adjustStackPtrBigUnrestricted(SP, Amount, MBB, I);
305 }
306
307 /// This function generates the sequence of instructions needed to get the
308 /// result of adding register REG and immediate IMM.
309 unsigned
310 Mips16InstrInfo::loadImmediate(unsigned FrameReg,
311                                int64_t Imm, MachineBasicBlock &MBB,
312                                MachineBasicBlock::iterator II, DebugLoc DL,
313                                unsigned &NewImm) const {
314   //
315   // given original instruction is:
316   // Instr rx, T[offset] where offset is too big.
317   //
318   // lo = offset & 0xFFFF
319   // hi = ((offset >> 16) + (lo >> 15)) & 0xFFFF;
320   //
321   // let T = temporary register
322   // li T, hi
323   // shl T, 16
324   // add T, Rx, T
325   //
326   RegScavenger rs;
327   int32_t lo = Imm & 0xFFFF;
328   NewImm = lo;
329   int Reg =0;
330   int SpReg = 0;
331
332   rs.enterBasicBlock(&MBB);
333   rs.forward(II);
334   //
335   // We need to know which registers can be used, in the case where there
336   // are not enough free registers. We exclude all registers that
337   // are used in the instruction that we are helping.
338   //  // Consider all allocatable registers in the register class initially
339   BitVector Candidates =
340       RI.getAllocatableSet
341       (*II->getParent()->getParent(), &Mips::CPU16RegsRegClass);
342   // Exclude all the registers being used by the instruction.
343   for (unsigned i = 0, e = II->getNumOperands(); i != e; ++i) {
344     MachineOperand &MO = II->getOperand(i);
345     if (MO.isReg() && MO.getReg() != 0 && !MO.isDef() &&
346         !TargetRegisterInfo::isVirtualRegister(MO.getReg()))
347       Candidates.reset(MO.getReg());
348   }
349   //
350   // If the same register was used and defined in an instruction, then
351   // it will not be in the list of candidates.
352   //
353   // we need to analyze the instruction that we are helping.
354   // we need to know if it defines register x but register x is not
355   // present as an operand of the instruction. this tells
356   // whether the register is live before the instruction. if it's not
357   // then we don't need to save it in case there are no free registers.
358   //
359   int DefReg = 0;
360   for (unsigned i = 0, e = II->getNumOperands(); i != e; ++i) {
361     MachineOperand &MO = II->getOperand(i);
362     if (MO.isReg() && MO.isDef()) {
363       DefReg = MO.getReg();
364       break;
365     }
366   }
367   //
368   BitVector Available = rs.getRegsAvailable(&Mips::CPU16RegsRegClass);
369
370   Available &= Candidates;
371   //
372   // we use T0 for the first register, if we need to save something away.
373   // we use T1 for the second register, if we need to save something away.
374   //
375   unsigned FirstRegSaved =0, SecondRegSaved=0;
376   unsigned FirstRegSavedTo = 0, SecondRegSavedTo = 0;
377
378
379   Reg = Available.find_first();
380
381   if (Reg == -1) {
382     Reg = Candidates.find_first();
383     Candidates.reset(Reg);
384     if (DefReg != Reg) {
385       FirstRegSaved = Reg;
386       FirstRegSavedTo = Mips::T0;
387       copyPhysReg(MBB, II, DL, FirstRegSavedTo, FirstRegSaved, true);
388     }
389   }
390   else
391     Available.reset(Reg);
392   BuildMI(MBB, II, DL, get(Mips::LwConstant32), Reg).addImm(Imm);
393   NewImm = 0;
394   if (FrameReg == Mips::SP) {
395     SpReg = Available.find_first();
396     if (SpReg == -1) {
397       SpReg = Candidates.find_first();
398       // Candidates.reset(SpReg); // not really needed
399       if (DefReg!= SpReg) {
400         SecondRegSaved = SpReg;
401         SecondRegSavedTo = Mips::T1;
402       }
403       if (SecondRegSaved)
404         copyPhysReg(MBB, II, DL, SecondRegSavedTo, SecondRegSaved, true);
405     }
406    else
407      Available.reset(SpReg);
408     copyPhysReg(MBB, II, DL, SpReg, Mips::SP, false);
409     BuildMI(MBB, II, DL, get(Mips::  AdduRxRyRz16), Reg).addReg(SpReg, RegState::Kill)
410       .addReg(Reg);
411   }
412   else
413     BuildMI(MBB, II, DL, get(Mips::  AdduRxRyRz16), Reg).addReg(FrameReg)
414       .addReg(Reg, RegState::Kill);
415   if (FirstRegSaved || SecondRegSaved) {
416     II = llvm::next(II);
417     if (FirstRegSaved)
418       copyPhysReg(MBB, II, DL, FirstRegSaved, FirstRegSavedTo, true);
419     if (SecondRegSaved)
420       copyPhysReg(MBB, II, DL, SecondRegSaved, SecondRegSavedTo, true);
421   }
422   return Reg;
423 }
424
425 /// This function generates the sequence of instructions needed to get the
426 /// result of adding register REG and immediate IMM.
427 unsigned
428 Mips16InstrInfo::basicLoadImmediate(
429   unsigned FrameReg,
430   int64_t Imm, MachineBasicBlock &MBB,
431   MachineBasicBlock::iterator II, DebugLoc DL,
432   unsigned &NewImm) const {
433   const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass;
434   MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo();
435   unsigned Reg = RegInfo.createVirtualRegister(RC);
436   BuildMI(MBB, II, DL, get(Mips::LwConstant32), Reg).addImm(Imm);
437   NewImm = 0;
438   return Reg;
439 }
440
441 unsigned Mips16InstrInfo::getAnalyzableBrOpc(unsigned Opc) const {
442   return (Opc == Mips::BeqzRxImmX16   || Opc == Mips::BimmX16  ||
443           Opc == Mips::Bimm16  ||
444           Opc == Mips::BnezRxImmX16   || Opc == Mips::BteqzX16 ||
445           Opc == Mips::BteqzT8CmpX16  || Opc == Mips::BteqzT8CmpiX16 ||
446           Opc == Mips::BteqzT8SltX16  || Opc == Mips::BteqzT8SltuX16  ||
447           Opc == Mips::BteqzT8SltiX16 || Opc == Mips::BteqzT8SltiuX16 ||
448           Opc == Mips::BtnezX16       || Opc == Mips::BtnezT8CmpX16 ||
449           Opc == Mips::BtnezT8CmpiX16 || Opc == Mips::BtnezT8SltX16 ||
450           Opc == Mips::BtnezT8SltuX16 || Opc == Mips::BtnezT8SltiX16 ||
451           Opc == Mips::BtnezT8SltiuX16 ) ? Opc : 0;
452 }
453
454 void Mips16InstrInfo::ExpandRetRA16(MachineBasicBlock &MBB,
455                                   MachineBasicBlock::iterator I,
456                                   unsigned Opc) const {
457   BuildMI(MBB, I, I->getDebugLoc(), get(Opc));
458 }
459
460
461 const MCInstrDesc &Mips16InstrInfo::AddiuSpImm(int64_t Imm) const {
462   if (validSpImm8(Imm))
463     return get(Mips::AddiuSpImm16);
464   else
465     return get(Mips::AddiuSpImmX16);
466 }
467
468 void Mips16InstrInfo::BuildAddiuSpImm
469   (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const {
470   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
471   BuildMI(MBB, I, DL, AddiuSpImm(Imm)).addImm(Imm);
472 }
473
474 const MipsInstrInfo *llvm::createMips16InstrInfo(MipsTargetMachine &TM) {
475   return new Mips16InstrInfo(TM);
476 }
477
478 bool Mips16InstrInfo::validImmediate(unsigned Opcode, unsigned Reg,
479                                      int64_t Amount) {
480   switch (Opcode) {
481   case Mips::LbRxRyOffMemX16:
482   case Mips::LbuRxRyOffMemX16:
483   case Mips::LhRxRyOffMemX16:
484   case Mips::LhuRxRyOffMemX16:
485   case Mips::SbRxRyOffMemX16:
486   case Mips::ShRxRyOffMemX16:
487   case Mips::LwRxRyOffMemX16:
488   case Mips::SwRxRyOffMemX16:
489   case Mips::SwRxSpImmX16:
490   case Mips::LwRxSpImmX16:
491     return isInt<16>(Amount);
492   case Mips::AddiuRxRyOffMemX16:
493     if ((Reg == Mips::PC) || (Reg == Mips::SP))
494       return isInt<16>(Amount);
495     return isInt<15>(Amount);
496   }
497   llvm_unreachable("unexpected Opcode in validImmediate");
498 }
499
500 /// Measure the specified inline asm to determine an approximation of its
501 /// length.
502 /// Comments (which run till the next SeparatorString or newline) do not
503 /// count as an instruction.
504 /// Any other non-whitespace text is considered an instruction, with
505 /// multiple instructions separated by SeparatorString or newlines.
506 /// Variable-length instructions are not handled here; this function
507 /// may be overloaded in the target code to do that.
508 /// We implement the special case of the .space directive taking only an
509 /// integer argument, which is the size in bytes. This is used for creating
510 /// inline code spacing for testing purposes using inline assembly.
511 ///
512 unsigned Mips16InstrInfo::getInlineAsmLength(const char *Str,
513                                              const MCAsmInfo &MAI) const {
514
515
516   // Count the number of instructions in the asm.
517   bool atInsnStart = true;
518   unsigned Length = 0;
519   for (; *Str; ++Str) {
520     if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
521                                 strlen(MAI.getSeparatorString())) == 0)
522       atInsnStart = true;
523     if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) {
524       if (strncmp(Str, ".space", 6)==0) {
525         char *EStr; int Sz;
526         Sz = strtol(Str+6, &EStr, 10);
527         while (isspace(*EStr)) ++EStr;
528         if (*EStr=='\0') {
529           DEBUG(dbgs() << "parsed .space " << Sz << '\n');
530           return Sz;
531         }
532       }
533       Length += MAI.getMaxInstLength();
534       atInsnStart = false;
535     }
536     if (atInsnStart && strncmp(Str, MAI.getCommentString(),
537                                strlen(MAI.getCommentString())) == 0)
538       atInsnStart = false;
539   }
540
541   return Length;
542 }