1
- // ===-- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly --===//
1
+ // ===- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly - --===//
2
2
//
3
3
// The LLVM Compiler Infrastructure
4
4
//
15
15
16
16
#include " HexagonAsmPrinter.h"
17
17
#include " Hexagon.h"
18
- #include " HexagonMachineFunctionInfo.h"
18
+ #include " HexagonInstrInfo.h"
19
+ #include " HexagonRegisterInfo.h"
19
20
#include " HexagonSubtarget.h"
20
- #include " HexagonTargetMachine.h"
21
21
#include " MCTargetDesc/HexagonInstPrinter.h"
22
+ #include " MCTargetDesc/HexagonMCExpr.h"
22
23
#include " MCTargetDesc/HexagonMCInstrInfo.h"
23
- #include " MCTargetDesc/HexagonMCShuffler .h"
24
+ #include " MCTargetDesc/HexagonMCTargetDesc .h"
24
25
#include " llvm/ADT/StringExtras.h"
25
- #include " llvm/Analysis/ConstantFolding.h"
26
+ #include " llvm/ADT/StringRef.h"
27
+ #include " llvm/ADT/Twine.h"
26
28
#include " llvm/BinaryFormat/ELF.h"
27
29
#include " llvm/CodeGen/AsmPrinter.h"
28
- #include " llvm/CodeGen/MachineFunctionPass.h"
30
+ #include " llvm/CodeGen/MachineBasicBlock.h"
31
+ #include " llvm/CodeGen/MachineFunction.h"
29
32
#include " llvm/CodeGen/MachineInstr.h"
30
- #include " llvm/CodeGen/MachineInstrBuilder.h"
31
- #include " llvm/CodeGen/MachineModuleInfo.h"
32
- #include " llvm/IR/Constants.h"
33
- #include " llvm/IR/DataLayout.h"
34
- #include " llvm/IR/DerivedTypes.h"
35
- #include " llvm/IR/Mangler.h"
36
- #include " llvm/IR/Module.h"
37
- #include " llvm/MC/MCAsmInfo.h"
33
+ #include " llvm/CodeGen/MachineOperand.h"
38
34
#include " llvm/MC/MCContext.h"
35
+ #include " llvm/MC/MCDirectives.h"
39
36
#include " llvm/MC/MCExpr.h"
40
37
#include " llvm/MC/MCInst.h"
41
- #include " llvm/MC/MCSection .h"
38
+ #include " llvm/MC/MCRegisterInfo .h"
42
39
#include " llvm/MC/MCSectionELF.h"
43
40
#include " llvm/MC/MCStreamer.h"
44
41
#include " llvm/MC/MCSymbol.h"
42
+ #include " llvm/Support/Casting.h"
45
43
#include " llvm/Support/CommandLine.h"
46
- #include " llvm/Support/Debug.h"
47
- #include " llvm/Support/Format.h"
48
- #include " llvm/Support/MathExtras.h"
44
+ #include " llvm/Support/ErrorHandling.h"
49
45
#include " llvm/Support/TargetRegistry.h"
50
46
#include " llvm/Support/raw_ostream.h"
51
- #include " llvm/Target/TargetInstrInfo.h"
52
- #include " llvm/Target/TargetLoweringObjectFile.h"
53
- #include " llvm/Target/TargetOptions.h"
54
47
#include " llvm/Target/TargetRegisterInfo.h"
48
+ #include " llvm/Target/TargetSubtargetInfo.h"
49
+ #include < algorithm>
50
+ #include < cassert>
51
+ #include < cstdint>
52
+ #include < string>
55
53
56
54
using namespace llvm ;
57
55
58
56
namespace llvm {
59
- void HexagonLowerToMC (const MCInstrInfo &MCII, const MachineInstr *MI,
60
- MCInst &MCB, HexagonAsmPrinter &AP);
61
- }
57
+
58
+ void HexagonLowerToMC (const MCInstrInfo &MCII, const MachineInstr *MI,
59
+ MCInst &MCB, HexagonAsmPrinter &AP);
60
+
61
+ } // end namespace llvm
62
62
63
63
#define DEBUG_TYPE " asm-printer"
64
64
@@ -78,7 +78,7 @@ inline static unsigned getHexagonRegisterPair(unsigned Reg,
78
78
79
79
HexagonAsmPrinter::HexagonAsmPrinter (TargetMachine &TM,
80
80
std::unique_ptr<MCStreamer> Streamer)
81
- : AsmPrinter(TM, std::move(Streamer)), Subtarget( nullptr ) {}
81
+ : AsmPrinter(TM, std::move(Streamer)) {}
82
82
83
83
void HexagonAsmPrinter::printOperand (const MachineInstr *MI, unsigned OpNo,
84
84
raw_ostream &O) {
@@ -106,24 +106,20 @@ void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
106
106
}
107
107
}
108
108
109
- //
110
109
// isBlockOnlyReachableByFallthrough - We need to override this since the
111
110
// default AsmPrinter does not print labels for any basic block that
112
111
// is only reachable by a fall through. That works for all cases except
113
112
// for the case in which the basic block is reachable by a fall through but
114
113
// through an indirect from a jump table. In this case, the jump table
115
114
// will contain a label not defined by AsmPrinter.
116
- //
117
115
bool HexagonAsmPrinter::
118
116
isBlockOnlyReachableByFallthrough (const MachineBasicBlock *MBB) const {
119
117
if (MBB->hasAddressTaken ())
120
118
return false ;
121
119
return AsmPrinter::isBlockOnlyReachableByFallthrough (MBB);
122
120
}
123
121
124
-
125
122
// / PrintAsmOperand - Print out an operand for an inline asm expression.
126
- // /
127
123
bool HexagonAsmPrinter::PrintAsmOperand (const MachineInstr *MI, unsigned OpNo,
128
124
unsigned AsmVariant,
129
125
const char *ExtraCode,
@@ -306,35 +302,30 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
306
302
break ;
307
303
}
308
304
309
- case Hexagon::A2_tfrf: {
305
+ case Hexagon::A2_tfrf:
310
306
Inst.setOpcode (Hexagon::A2_paddif);
311
307
Inst.addOperand (MCOperand::createExpr (MCConstantExpr::create (0 , OutContext)));
312
308
break ;
313
- }
314
309
315
- case Hexagon::A2_tfrt: {
310
+ case Hexagon::A2_tfrt:
316
311
Inst.setOpcode (Hexagon::A2_paddit);
317
312
Inst.addOperand (MCOperand::createExpr (MCConstantExpr::create (0 , OutContext)));
318
313
break ;
319
- }
320
314
321
- case Hexagon::A2_tfrfnew: {
315
+ case Hexagon::A2_tfrfnew:
322
316
Inst.setOpcode (Hexagon::A2_paddifnew);
323
317
Inst.addOperand (MCOperand::createExpr (MCConstantExpr::create (0 , OutContext)));
324
318
break ;
325
- }
326
319
327
- case Hexagon::A2_tfrtnew: {
320
+ case Hexagon::A2_tfrtnew:
328
321
Inst.setOpcode (Hexagon::A2_padditnew);
329
322
Inst.addOperand (MCOperand::createExpr (MCConstantExpr::create (0 , OutContext)));
330
323
break ;
331
- }
332
324
333
- case Hexagon::A2_zxtb: {
325
+ case Hexagon::A2_zxtb:
334
326
Inst.setOpcode (Hexagon::A2_andir);
335
327
Inst.addOperand (MCOperand::createExpr (MCConstantExpr::create (255 , OutContext)));
336
328
break ;
337
- }
338
329
339
330
// "$dst = CONST64(#$src1)",
340
331
case Hexagon::CONST64:
@@ -386,7 +377,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
386
377
// 3 register pairs.
387
378
case Hexagon::M2_vrcmpys_acc_s1: {
388
379
MCOperand &Rt = Inst.getOperand (3 );
389
- assert (Rt.isReg () && " Expected register and none was found" );
380
+ assert (Rt.isReg () && " Expected register and none was found" );
390
381
unsigned Reg = RI->getEncodingValue (Rt.getReg ());
391
382
if (Reg & 1 )
392
383
MappedInst.setOpcode (Hexagon::M2_vrcmpys_acc_s1_h);
@@ -397,7 +388,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
397
388
}
398
389
case Hexagon::M2_vrcmpys_s1: {
399
390
MCOperand &Rt = Inst.getOperand (2 );
400
- assert (Rt.isReg () && " Expected register and none was found" );
391
+ assert (Rt.isReg () && " Expected register and none was found" );
401
392
unsigned Reg = RI->getEncodingValue (Rt.getReg ());
402
393
if (Reg & 1 )
403
394
MappedInst.setOpcode (Hexagon::M2_vrcmpys_s1_h);
@@ -409,7 +400,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
409
400
410
401
case Hexagon::M2_vrcmpys_s1rp: {
411
402
MCOperand &Rt = Inst.getOperand (2 );
412
- assert (Rt.isReg () && " Expected register and none was found" );
403
+ assert (Rt.isReg () && " Expected register and none was found" );
413
404
unsigned Reg = RI->getEncodingValue (Rt.getReg ());
414
405
if (Reg & 1 )
415
406
MappedInst.setOpcode (Hexagon::M2_vrcmpys_s1rp_h);
@@ -421,7 +412,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
421
412
422
413
case Hexagon::A4_boundscheck: {
423
414
MCOperand &Rs = Inst.getOperand (1 );
424
- assert (Rs.isReg () && " Expected register and none was found" );
415
+ assert (Rs.isReg () && " Expected register and none was found" );
425
416
unsigned Reg = RI->getEncodingValue (Rs.getReg ());
426
417
if (Reg & 1 ) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
427
418
MappedInst.setOpcode (Hexagon::A4_boundscheck_hi);
@@ -430,15 +421,17 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
430
421
Rs.setReg (getHexagonRegisterPair (Rs.getReg (), RI));
431
422
return ;
432
423
}
424
+
433
425
case Hexagon::PS_call_nr:
434
426
Inst.setOpcode (Hexagon::J2_call);
435
427
break ;
428
+
436
429
case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
437
430
MCOperand &MO = MappedInst.getOperand (2 );
438
431
int64_t Imm;
439
432
MCExpr const *Expr = MO.getExpr ();
440
433
bool Success = Expr->evaluateAsAbsolute (Imm);
441
- assert (Success && " Expected immediate and none was found" );
434
+ assert (Success && " Expected immediate and none was found" );
442
435
(void )Success;
443
436
MCInst TmpInst;
444
437
if (Imm == 0 ) {
@@ -458,13 +451,14 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
458
451
MappedInst = TmpInst;
459
452
return ;
460
453
}
454
+
461
455
case Hexagon::S5_vasrhrnd_goodsyntax:
462
456
case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
463
457
MCOperand &MO2 = MappedInst.getOperand (2 );
464
458
MCExpr const *Expr = MO2.getExpr ();
465
459
int64_t Imm;
466
460
bool Success = Expr->evaluateAsAbsolute (Imm);
467
- assert (Success && " Expected immediate and none was found" );
461
+ assert (Success && " Expected immediate and none was found" );
468
462
(void )Success;
469
463
MCInst TmpInst;
470
464
if (Imm == 0 ) {
@@ -493,13 +487,14 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
493
487
MappedInst = TmpInst;
494
488
return ;
495
489
}
490
+
496
491
// if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd
497
492
case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
498
493
MCOperand &MO = Inst.getOperand (2 );
499
494
MCExpr const *Expr = MO.getExpr ();
500
495
int64_t Imm;
501
496
bool Success = Expr->evaluateAsAbsolute (Imm);
502
- assert (Success && " Expected immediate and none was found" );
497
+ assert (Success && " Expected immediate and none was found" );
503
498
(void )Success;
504
499
MCInst TmpInst;
505
500
if (Imm == 0 ) {
@@ -541,6 +536,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
541
536
MappedInst = TmpInst;
542
537
return ;
543
538
}
539
+
544
540
// Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
545
541
case Hexagon::A2_tfrp: {
546
542
MCOperand &MO = MappedInst.getOperand (1 );
@@ -566,6 +562,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
566
562
: Hexagon::C2_ccombinewf);
567
563
return ;
568
564
}
565
+
569
566
case Hexagon::A2_tfrptnew:
570
567
case Hexagon::A2_tfrpfnew: {
571
568
MCOperand &MO = MappedInst.getOperand (2 );
@@ -598,7 +595,7 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
598
595
599
596
case Hexagon::A2_addsp: {
600
597
MCOperand &Rt = Inst.getOperand (1 );
601
- assert (Rt.isReg () && " Expected register and none was found" );
598
+ assert (Rt.isReg () && " Expected register and none was found" );
602
599
unsigned Reg = RI->getEncodingValue (Rt.getReg ());
603
600
if (Reg & 1 )
604
601
MappedInst.setOpcode (Hexagon::A2_addsph);
@@ -607,11 +604,12 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
607
604
Rt.setReg (getHexagonRegisterPair (Rt.getReg (), RI));
608
605
return ;
609
606
}
607
+
610
608
case Hexagon::V6_vd0:
611
609
case Hexagon::V6_vd0_128B: {
612
610
MCInst TmpInst;
613
- assert (Inst.getOperand (0 ).isReg () &&
614
- " Expected register and none was found" );
611
+ assert (Inst.getOperand (0 ).isReg () &&
612
+ " Expected register and none was found" );
615
613
616
614
TmpInst.setOpcode (Hexagon::V6_vxor);
617
615
TmpInst.addOperand (Inst.getOperand (0 ));
@@ -799,10 +797,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
799
797
}
800
798
}
801
799
802
-
803
800
// / printMachineInstruction -- Print out a single Hexagon MI in Darwin syntax to
804
801
// / the current output stream.
805
- // /
806
802
void HexagonAsmPrinter::EmitInstruction (const MachineInstr *MI) {
807
803
MCInst MCB = HexagonMCInstrInfo::createBundle ();
808
804
const MCInstrInfo &MCII = *Subtarget->getInstrInfo ();
0 commit comments