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