Skip to content

Commit

Permalink
GlobalISel: Add a setInstrAndDebugLoc(MachineInstr&) convenience help…
Browse files Browse the repository at this point in the history
…er to MachineIRBuilder. NFC.

This saves doing two separate calls to set the Instr and DebugLoc from an existing MI.
  • Loading branch information
aemerson committed Apr 8, 2020
1 parent 67bdda6 commit befc788
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 7 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
Expand Up @@ -313,6 +313,13 @@ class MachineIRBuilder {
void setInstr(MachineInstr &MI);
/// @}

/// Set the insertion point to before MI, and set the debug loc to MI's loc.
/// \pre MI must be in getMF().
void setInstrAndDebugLoc(MachineInstr &MI) {
setInstr(MI);
setDebugLoc(MI.getDebugLoc());
}

void setChangeObserver(GISelChangeObserver &Observer);
void stopObservingChanges();
/// @}
Expand Down
15 changes: 5 additions & 10 deletions llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Expand Up @@ -633,8 +633,7 @@ LegalizerHelper::libcall(MachineInstr &MI) {
unsigned Size = LLTy.getSizeInBits();
auto &Ctx = MIRBuilder.getMF().getFunction().getContext();

MIRBuilder.setInstr(MI);
MIRBuilder.setDebugLoc(MI.getDebugLoc());
MIRBuilder.setInstrAndDebugLoc(MI);

switch (MI.getOpcode()) {
default:
Expand Down Expand Up @@ -731,8 +730,7 @@ LegalizerHelper::libcall(MachineInstr &MI) {
LegalizerHelper::LegalizeResult LegalizerHelper::narrowScalar(MachineInstr &MI,
unsigned TypeIdx,
LLT NarrowTy) {
MIRBuilder.setInstr(MI);
MIRBuilder.setDebugLoc(MI.getDebugLoc());
MIRBuilder.setInstrAndDebugLoc(MI);

uint64_t SizeOp0 = MRI.getType(MI.getOperand(0).getReg()).getSizeInBits();
uint64_t NarrowSize = NarrowTy.getSizeInBits();
Expand Down Expand Up @@ -1612,8 +1610,7 @@ LegalizerHelper::widenScalarInsert(MachineInstr &MI, unsigned TypeIdx,

LegalizerHelper::LegalizeResult
LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
MIRBuilder.setInstr(MI);
MIRBuilder.setDebugLoc(MI.getDebugLoc());
MIRBuilder.setInstrAndDebugLoc(MI);

switch (MI.getOpcode()) {
default:
Expand Down Expand Up @@ -2205,8 +2202,7 @@ LegalizerHelper::bitcast(MachineInstr &MI, unsigned TypeIdx, LLT CastTy) {
LegalizerHelper::LegalizeResult
LegalizerHelper::lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty) {
using namespace TargetOpcode;
MIRBuilder.setInstr(MI);
MIRBuilder.setDebugLoc(MI.getDebugLoc());
MIRBuilder.setInstrAndDebugLoc(MI);

switch(MI.getOpcode()) {
default:
Expand Down Expand Up @@ -3241,8 +3237,7 @@ LegalizerHelper::fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
LLT NarrowTy) {
using namespace TargetOpcode;

MIRBuilder.setInstr(MI);
MIRBuilder.setDebugLoc(MI.getDebugLoc());
MIRBuilder.setInstrAndDebugLoc(MI);
switch (MI.getOpcode()) {
case G_IMPLICIT_DEF:
return fewerElementsVectorImplicitDef(MI, TypeIdx, NarrowTy);
Expand Down

0 comments on commit befc788

Please sign in to comment.