[PATCH] D115208: [NFC][MachineInstr] No need to std::move the DebugLoc

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 6 17:36:35 PST 2021


mtrofin created this revision.
mtrofin added a reviewer: dblaikie.
Herald added a subscriber: hiraditya.
mtrofin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This appeared in 2 places: the ctor and setDebugLoc.

In the ctor case, the only place that is called is
MachineFunction::CreateMachineInstr, which is being passed a const &, so
the semantics end up being copy.

Same ends up happening with setDebugLoc, too.

This change simplifies the API by getting the DebugLoc passed all the
way by const &, and then copied.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115208

Files:
  llvm/include/llvm/CodeGen/MachineInstr.h
  llvm/lib/CodeGen/MachineInstr.cpp


Index: llvm/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/lib/CodeGen/MachineInstr.cpp
+++ llvm/lib/CodeGen/MachineInstr.cpp
@@ -116,8 +116,8 @@
 /// implicit operands. It reserves space for the number of operands specified by
 /// the MCInstrDesc.
 MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
-                           DebugLoc DL, bool NoImp)
-    : MCID(&TID), DbgLoc(std::move(DL)), DebugInstrNum(0) {
+                           const DebugLoc &DL, bool NoImp)
+    : MCID(&TID), DbgLoc(DL), DebugInstrNum(0) {
   assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
 
   // Reserve space for the expected number of operands.
Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -267,7 +267,7 @@
   /// This constructor create a MachineInstr and add the implicit operands.
   /// It reserves space for number of operands specified by
   /// MCInstrDesc.  An explicit DebugLoc is supplied.
-  MachineInstr(MachineFunction &, const MCInstrDesc &TID, DebugLoc DL,
+  MachineInstr(MachineFunction &, const MCInstrDesc &TID, const DebugLoc &DL,
                bool NoImp = false);
 
   // MachineInstrs are pool-allocated and owned by MachineFunction.
@@ -1737,8 +1737,8 @@
 
   /// Replace current source information with new such.
   /// Avoid using this, the constructor argument is preferable.
-  void setDebugLoc(DebugLoc DL) {
-    DbgLoc = std::move(DL);
+  void setDebugLoc(const DebugLoc &DL) {
+    DbgLoc = DL;
     assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115208.392244.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211207/85da8e1f/attachment.bin>


More information about the llvm-commits mailing list