@@ -336,14 +336,22 @@ void X86AsmPrinter::PrintMemReference(const MachineInstr *MI, unsigned OpNo,
336
336
PrintLeaMemReference (MI, OpNo, O, Modifier);
337
337
}
338
338
339
+
339
340
void X86AsmPrinter::PrintIntelMemReference (const MachineInstr *MI,
340
- unsigned OpNo, raw_ostream &O) {
341
+ unsigned OpNo, raw_ostream &O,
342
+ const char *Modifier) {
341
343
const MachineOperand &BaseReg = MI->getOperand (OpNo + X86::AddrBaseReg);
342
344
unsigned ScaleVal = MI->getOperand (OpNo + X86::AddrScaleAmt).getImm ();
343
345
const MachineOperand &IndexReg = MI->getOperand (OpNo + X86::AddrIndexReg);
344
346
const MachineOperand &DispSpec = MI->getOperand (OpNo + X86::AddrDisp);
345
347
const MachineOperand &SegReg = MI->getOperand (OpNo + X86::AddrSegmentReg);
346
348
349
+ // If we really don't want to print out (rip), don't.
350
+ bool HasBaseReg = BaseReg.getReg () != 0 ;
351
+ if (HasBaseReg && Modifier && !strcmp (Modifier, " no-rip" ) &&
352
+ BaseReg.getReg () == X86::RIP)
353
+ HasBaseReg = false ;
354
+
347
355
// If this has a segment register, print it.
348
356
if (SegReg.getReg ()) {
349
357
PrintOperand (MI, OpNo + X86::AddrSegmentReg, O);
@@ -353,7 +361,7 @@ void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
353
361
O << ' [' ;
354
362
355
363
bool NeedPlus = false ;
356
- if (BaseReg. getReg () ) {
364
+ if (HasBaseReg ) {
357
365
PrintOperand (MI, OpNo + X86::AddrBaseReg, O);
358
366
NeedPlus = true ;
359
367
}
@@ -371,7 +379,7 @@ void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
371
379
PrintOperand (MI, OpNo + X86::AddrDisp, O);
372
380
} else {
373
381
int64_t DispVal = DispSpec.getImm ();
374
- if (DispVal || (!IndexReg.getReg () && !BaseReg. getReg () )) {
382
+ if (DispVal || (!IndexReg.getReg () && !HasBaseReg )) {
375
383
if (NeedPlus) {
376
384
if (DispVal > 0 )
377
385
O << " + " ;
@@ -389,7 +397,7 @@ void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
389
397
static bool printAsmMRegister (X86AsmPrinter &P, const MachineOperand &MO,
390
398
char Mode, raw_ostream &O) {
391
399
unsigned Reg = MO.getReg ();
392
- bool EmitPercent = true ;
400
+ bool EmitPercent = MO. getParent ()-> getInlineAsmDialect () == InlineAsm::AD_ATT ;
393
401
394
402
if (!X86::GR8RegClass.contains (Reg) &&
395
403
!X86::GR16RegClass.contains (Reg) &&
@@ -428,6 +436,42 @@ static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
428
436
return false ;
429
437
}
430
438
439
+ static bool printAsmVRegister (X86AsmPrinter &P, const MachineOperand &MO,
440
+ char Mode, raw_ostream &O) {
441
+ unsigned Reg = MO.getReg ();
442
+ bool EmitPercent = MO.getParent ()->getInlineAsmDialect () == InlineAsm::AD_ATT;
443
+
444
+ unsigned Index;
445
+ if (X86::VR128XRegClass.contains (Reg))
446
+ Index = Reg - X86::XMM0;
447
+ else if (X86::VR256XRegClass.contains (Reg))
448
+ Index = Reg - X86::YMM0;
449
+ else if (X86::VR512RegClass.contains (Reg))
450
+ Index = Reg - X86::ZMM0;
451
+ else
452
+ return true ;
453
+
454
+ switch (Mode) {
455
+ default : // Unknown mode.
456
+ return true ;
457
+ case ' x' : // Print V4SFmode register
458
+ Reg = X86::XMM0 + Index;
459
+ break ;
460
+ case ' t' : // Print V8SFmode register
461
+ Reg = X86::YMM0 + Index;
462
+ break ;
463
+ case ' g' : // Print V16SFmode register
464
+ Reg = X86::ZMM0 + Index;
465
+ break ;
466
+ }
467
+
468
+ if (EmitPercent)
469
+ O << ' %' ;
470
+
471
+ O << X86ATTInstPrinter::getRegisterName (Reg);
472
+ return false ;
473
+ }
474
+
431
475
// / PrintAsmOperand - Print out an operand for an inline asm expression.
432
476
// /
433
477
bool X86AsmPrinter::PrintAsmOperand (const MachineInstr *MI, unsigned OpNo,
@@ -502,6 +546,14 @@ bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
502
546
PrintOperand (MI, OpNo, O);
503
547
return false ;
504
548
549
+ case ' x' : // Print V4SFmode register
550
+ case ' t' : // Print V8SFmode register
551
+ case ' g' : // Print V16SFmode register
552
+ if (MO.isReg ())
553
+ return printAsmVRegister (*this , MO, ExtraCode[0 ], O);
554
+ PrintOperand (MI, OpNo, O);
555
+ return false ;
556
+
505
557
case ' P' : // This is the operand of a call, treat specially.
506
558
PrintPCRelImm (MI, OpNo, O);
507
559
return false ;
@@ -524,11 +576,6 @@ bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
524
576
bool X86AsmPrinter::PrintAsmMemoryOperand (const MachineInstr *MI, unsigned OpNo,
525
577
const char *ExtraCode,
526
578
raw_ostream &O) {
527
- if (MI->getInlineAsmDialect () == InlineAsm::AD_Intel) {
528
- PrintIntelMemReference (MI, OpNo, O);
529
- return false ;
530
- }
531
-
532
579
if (ExtraCode && ExtraCode[0 ]) {
533
580
if (ExtraCode[1 ] != 0 ) return true ; // Unknown modifier.
534
581
@@ -542,14 +589,26 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
542
589
// These only apply to registers, ignore on mem.
543
590
break ;
544
591
case ' H' :
545
- PrintMemReference (MI, OpNo, O, " H" );
592
+ if (MI->getInlineAsmDialect () == InlineAsm::AD_Intel) {
593
+ return true ; // Unsupported modifier in Intel inline assembly.
594
+ } else {
595
+ PrintMemReference (MI, OpNo, O, " H" );
596
+ }
546
597
return false ;
547
598
case ' P' : // Don't print @PLT, but do print as memory.
548
- PrintMemReference (MI, OpNo, O, " no-rip" );
599
+ if (MI->getInlineAsmDialect () == InlineAsm::AD_Intel) {
600
+ PrintIntelMemReference (MI, OpNo, O, " no-rip" );
601
+ } else {
602
+ PrintMemReference (MI, OpNo, O, " no-rip" );
603
+ }
549
604
return false ;
550
605
}
551
606
}
552
- PrintMemReference (MI, OpNo, O, nullptr );
607
+ if (MI->getInlineAsmDialect () == InlineAsm::AD_Intel) {
608
+ PrintIntelMemReference (MI, OpNo, O, nullptr );
609
+ } else {
610
+ PrintMemReference (MI, OpNo, O, nullptr );
611
+ }
553
612
return false ;
554
613
}
555
614
0 commit comments