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