@@ -69,6 +69,32 @@ enum {
69
69
70
70
} // end namespace RegState
71
71
72
+ // / Set of metadata that should be preserved when using BuildMI(). This provides
73
+ // / a more convenient way of preserving DebugLoc, PCSections and MMRA.
74
+ class MIMetadata {
75
+ public:
76
+ MIMetadata () = default ;
77
+ MIMetadata (DebugLoc DL, MDNode *PCSections = nullptr , MDNode *MMRA = nullptr )
78
+ : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA) {}
79
+ MIMetadata (const DILocation *DI, MDNode *PCSections = nullptr ,
80
+ MDNode *MMRA = nullptr )
81
+ : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
82
+ explicit MIMetadata (const Instruction &From)
83
+ : DL(From.getDebugLoc()),
84
+ PCSections(From.getMetadata(LLVMContext::MD_pcsections)) {}
85
+ explicit MIMetadata (const MachineInstr &From)
86
+ : DL(From.getDebugLoc()), PCSections(From.getPCSections()) {}
87
+
88
+ const DebugLoc &getDL () const { return DL; }
89
+ MDNode *getPCSections () const { return PCSections; }
90
+ MDNode *getMMRAMetadata () const { return MMRA; }
91
+
92
+ private:
93
+ DebugLoc DL;
94
+ MDNode *PCSections = nullptr ;
95
+ MDNode *MMRA = nullptr ;
96
+ };
97
+
72
98
class MachineInstrBuilder {
73
99
MachineFunction *MF = nullptr ;
74
100
MachineInstr *MI = nullptr ;
@@ -317,15 +343,11 @@ class MachineInstrBuilder {
317
343
}
318
344
}
319
345
320
- const MachineInstrBuilder &setPCSections (MDNode *MD) const {
321
- if (MD)
322
- MI->setPCSections (*MF, MD);
323
- return *this ;
324
- }
325
-
326
- const MachineInstrBuilder &setMMRAMetadata (MDNode *MMRA) const {
327
- if (MMRA)
328
- MI->setMMRAMetadata (*MF, MMRA);
346
+ const MachineInstrBuilder ©MIMetadata (const MIMetadata &MIMD) const {
347
+ if (MIMD.getPCSections ())
348
+ MI->setPCSections (*MF, MIMD.getPCSections ());
349
+ if (MIMD.getMMRAMetadata ())
350
+ MI->setMMRAMetadata (*MF, MIMD.getMMRAMetadata ());
329
351
return *this ;
330
352
}
331
353
@@ -343,47 +365,19 @@ class MachineInstrBuilder {
343
365
}
344
366
};
345
367
346
- // / Set of metadata that should be preserved when using BuildMI(). This provides
347
- // / a more convenient way of preserving DebugLoc, PCSections and MMRA.
348
- class MIMetadata {
349
- public:
350
- MIMetadata () = default ;
351
- MIMetadata (DebugLoc DL, MDNode *PCSections = nullptr , MDNode *MMRA = nullptr )
352
- : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA) {}
353
- MIMetadata (const DILocation *DI, MDNode *PCSections = nullptr ,
354
- MDNode *MMRA = nullptr )
355
- : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
356
- explicit MIMetadata (const Instruction &From)
357
- : DL(From.getDebugLoc()),
358
- PCSections(From.getMetadata(LLVMContext::MD_pcsections)) {}
359
- explicit MIMetadata (const MachineInstr &From)
360
- : DL(From.getDebugLoc()), PCSections(From.getPCSections()) {}
361
-
362
- const DebugLoc &getDL () const { return DL; }
363
- MDNode *getPCSections () const { return PCSections; }
364
- MDNode *getMMRAMetadata () const { return MMRA; }
365
-
366
- private:
367
- DebugLoc DL;
368
- MDNode *PCSections = nullptr ;
369
- MDNode *MMRA = nullptr ;
370
- };
371
-
372
368
// / Builder interface. Specify how to create the initial instruction itself.
373
369
inline MachineInstrBuilder BuildMI (MachineFunction &MF, const MIMetadata &MIMD,
374
370
const MCInstrDesc &MCID) {
375
371
return MachineInstrBuilder (MF, MF.CreateMachineInstr (MCID, MIMD.getDL ()))
376
- .setPCSections (MIMD.getPCSections ())
377
- .setMMRAMetadata (MIMD.getMMRAMetadata ());
372
+ .copyMIMetadata (MIMD);
378
373
}
379
374
380
375
// / This version of the builder sets up the first operand as a
381
376
// / destination virtual register.
382
377
inline MachineInstrBuilder BuildMI (MachineFunction &MF, const MIMetadata &MIMD,
383
378
const MCInstrDesc &MCID, Register DestReg) {
384
379
return MachineInstrBuilder (MF, MF.CreateMachineInstr (MCID, MIMD.getDL ()))
385
- .setPCSections (MIMD.getPCSections ())
386
- .setMMRAMetadata (MIMD.getMMRAMetadata ())
380
+ .copyMIMetadata (MIMD)
387
381
.addReg (DestReg, RegState::Define);
388
382
}
389
383
@@ -397,10 +391,8 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
397
391
MachineFunction &MF = *BB.getParent ();
398
392
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
399
393
BB.insert (I, MI);
400
- return MachineInstrBuilder (MF, MI)
401
- .setPCSections (MIMD.getPCSections ())
402
- .setMMRAMetadata (MIMD.getMMRAMetadata ())
403
- .addReg (DestReg, RegState::Define);
394
+ return MachineInstrBuilder (MF, MI).copyMIMetadata (MIMD).addReg (
395
+ DestReg, RegState::Define);
404
396
}
405
397
406
398
// / This version of the builder inserts the newly-built instruction before
@@ -416,10 +408,8 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
416
408
MachineFunction &MF = *BB.getParent ();
417
409
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
418
410
BB.insert (I, MI);
419
- return MachineInstrBuilder (MF, MI)
420
- .setPCSections (MIMD.getPCSections ())
421
- .setMMRAMetadata (MIMD.getMMRAMetadata ())
422
- .addReg (DestReg, RegState::Define);
411
+ return MachineInstrBuilder (MF, MI).copyMIMetadata (MIMD).addReg (
412
+ DestReg, RegState::Define);
423
413
}
424
414
425
415
inline MachineInstrBuilder BuildMI (MachineBasicBlock &BB, MachineInstr &I,
@@ -449,9 +439,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
449
439
MachineFunction &MF = *BB.getParent ();
450
440
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
451
441
BB.insert (I, MI);
452
- return MachineInstrBuilder (MF, MI)
453
- .setPCSections (MIMD.getPCSections ())
454
- .setMMRAMetadata (MIMD.getMMRAMetadata ());
442
+ return MachineInstrBuilder (MF, MI).copyMIMetadata (MIMD);
455
443
}
456
444
457
445
inline MachineInstrBuilder BuildMI (MachineBasicBlock &BB,
@@ -461,9 +449,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
461
449
MachineFunction &MF = *BB.getParent ();
462
450
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
463
451
BB.insert (I, MI);
464
- return MachineInstrBuilder (MF, MI)
465
- .setPCSections (MIMD.getPCSections ())
466
- .setMMRAMetadata (MIMD.getMMRAMetadata ());
452
+ return MachineInstrBuilder (MF, MI).copyMIMetadata (MIMD);
467
453
}
468
454
469
455
inline MachineInstrBuilder BuildMI (MachineBasicBlock &BB, MachineInstr &I,
0 commit comments