@@ -68,6 +68,32 @@ enum {
68
68
69
69
} // end namespace RegState
70
70
71
+ // / Set of metadata that should be preserved when using BuildMI(). This provides
72
+ // / a more convenient way of preserving DebugLoc, PCSections and MMRA.
73
+ class MIMetadata {
74
+ public:
75
+ MIMetadata () = default ;
76
+ MIMetadata (DebugLoc DL, MDNode *PCSections = nullptr , MDNode *MMRA = nullptr )
77
+ : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA) {}
78
+ MIMetadata (const DILocation *DI, MDNode *PCSections = nullptr ,
79
+ MDNode *MMRA = nullptr )
80
+ : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
81
+ explicit MIMetadata (const Instruction &From)
82
+ : DL(From.getDebugLoc()),
83
+ PCSections(From.getMetadata(LLVMContext::MD_pcsections)) {}
84
+ explicit MIMetadata (const MachineInstr &From)
85
+ : DL(From.getDebugLoc()), PCSections(From.getPCSections()) {}
86
+
87
+ const DebugLoc &getDL () const { return DL; }
88
+ MDNode *getPCSections () const { return PCSections; }
89
+ MDNode *getMMRAMetadata () const { return MMRA; }
90
+
91
+ private:
92
+ DebugLoc DL;
93
+ MDNode *PCSections = nullptr ;
94
+ MDNode *MMRA = nullptr ;
95
+ };
96
+
71
97
class MachineInstrBuilder {
72
98
MachineFunction *MF = nullptr ;
73
99
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
@@ -398,8 +392,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
398
392
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
399
393
BB.insert (I, MI);
400
394
return MachineInstrBuilder (MF, MI)
401
- .setPCSections (MIMD.getPCSections ())
402
- .setMMRAMetadata (MIMD.getMMRAMetadata ())
395
+ .copyMIMetadata (MIMD)
403
396
.addReg (DestReg, RegState::Define);
404
397
}
405
398
@@ -417,8 +410,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
417
410
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
418
411
BB.insert (I, MI);
419
412
return MachineInstrBuilder (MF, MI)
420
- .setPCSections (MIMD.getPCSections ())
421
- .setMMRAMetadata (MIMD.getMMRAMetadata ())
413
+ .copyMIMetadata (MIMD)
422
414
.addReg (DestReg, RegState::Define);
423
415
}
424
416
@@ -450,8 +442,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
450
442
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
451
443
BB.insert (I, MI);
452
444
return MachineInstrBuilder (MF, MI)
453
- .setPCSections (MIMD.getPCSections ())
454
- .setMMRAMetadata (MIMD.getMMRAMetadata ());
445
+ .copyMIMetadata (MIMD);
455
446
}
456
447
457
448
inline MachineInstrBuilder BuildMI (MachineBasicBlock &BB,
@@ -462,8 +453,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
462
453
MachineInstr *MI = MF.CreateMachineInstr (MCID, MIMD.getDL ());
463
454
BB.insert (I, MI);
464
455
return MachineInstrBuilder (MF, MI)
465
- .setPCSections (MIMD.getPCSections ())
466
- .setMMRAMetadata (MIMD.getMMRAMetadata ());
456
+ .copyMIMetadata (MIMD);
467
457
}
468
458
469
459
inline MachineInstrBuilder BuildMI (MachineBasicBlock &BB, MachineInstr &I,
0 commit comments