Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 1 | //===- lib/CodeGen/MachineInstr.cpp ---------------------------------------===// |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Brian Gaeke | e8f7c2f | 2004-02-13 04:39:32 +0000 | [diff] [blame] | 9 | // |
| 10 | // Methods common to all machine instructions. |
| 11 | // |
Chris Lattner | 959a5fb | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | ab9e557 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 13 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineInstr.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/APFloat.h" |
| 16 | #include "llvm/ADT/ArrayRef.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/FoldingSet.h" |
| 18 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/None.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallBitVector.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallString.h" |
| 23 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/AliasAnalysis.h" |
Hiroshi Inoue | 95f24dc | 2017-06-24 15:17:38 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/Loads.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/MemoryLocation.h" |
| 27 | #include "llvm/CodeGen/GlobalISel/RegisterBank.h" |
| 28 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Chris Lattner | 63f41ab | 2004-02-19 16:17:08 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineFunction.h" |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineInstrBundle.h" |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineMemOperand.h" |
Jakob Stoklund Olesen | 25a404e | 2011-07-02 03:53:34 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineOperand.h" |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/PseudoSourceValue.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 39 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 40 | #include "llvm/IR/Constants.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 41 | #include "llvm/IR/DebugInfoMetadata.h" |
| 42 | #include "llvm/IR/DebugLoc.h" |
| 43 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 44 | #include "llvm/IR/Function.h" |
| 45 | #include "llvm/IR/InlineAsm.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 46 | #include "llvm/IR/InstrTypes.h" |
Tim Northover | 6b3bd61 | 2016-07-29 20:32:59 +0000 | [diff] [blame] | 47 | #include "llvm/IR/Intrinsics.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 48 | #include "llvm/IR/LLVMContext.h" |
| 49 | #include "llvm/IR/Metadata.h" |
| 50 | #include "llvm/IR/Module.h" |
Duncan P. N. Exon Smith | f48e982 | 2015-06-26 22:06:47 +0000 | [diff] [blame] | 51 | #include "llvm/IR/ModuleSlotTracker.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 52 | #include "llvm/IR/Type.h" |
| 53 | #include "llvm/IR/Value.h" |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 54 | #include "llvm/MC/MCInstrDesc.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 55 | #include "llvm/MC/MCRegisterInfo.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 56 | #include "llvm/MC/MCSymbol.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 57 | #include "llvm/Support/Casting.h" |
Daniel Sanders | 1e97a0b | 2015-08-19 12:03:04 +0000 | [diff] [blame] | 58 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 59 | #include "llvm/Support/Compiler.h" |
David Greene | 29388d6 | 2010-01-04 23:48:20 +0000 | [diff] [blame] | 60 | #include "llvm/Support/Debug.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 61 | #include "llvm/Support/ErrorHandling.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 62 | #include "llvm/Support/LowLevelTypeImpl.h" |
Dan Gohman | aedb4a6 | 2008-07-07 20:32:02 +0000 | [diff] [blame] | 63 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 64 | #include "llvm/Support/raw_ostream.h" |
Tim Northover | 6b3bd61 | 2016-07-29 20:32:59 +0000 | [diff] [blame] | 65 | #include "llvm/Target/TargetIntrinsicInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 66 | #include "llvm/Target/TargetMachine.h" |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 67 | #include <algorithm> |
| 68 | #include <cassert> |
| 69 | #include <cstddef> |
| 70 | #include <cstdint> |
| 71 | #include <cstring> |
| 72 | #include <iterator> |
| 73 | #include <utility> |
| 74 | |
Chris Lattner | 43df6c2 | 2004-02-23 18:38:20 +0000 | [diff] [blame] | 75 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 76 | |
Jakob Stoklund Olesen | ac4210e | 2012-12-20 22:53:58 +0000 | [diff] [blame] | 77 | void MachineInstr::addImplicitDefUseOperands(MachineFunction &MF) { |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 78 | if (MCID->ImplicitDefs) |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 79 | for (const MCPhysReg *ImpDefs = MCID->getImplicitDefs(); *ImpDefs; |
| 80 | ++ImpDefs) |
Jakob Stoklund Olesen | ac4210e | 2012-12-20 22:53:58 +0000 | [diff] [blame] | 81 | addOperand(MF, MachineOperand::CreateReg(*ImpDefs, true, true)); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 82 | if (MCID->ImplicitUses) |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 83 | for (const MCPhysReg *ImpUses = MCID->getImplicitUses(); *ImpUses; |
| 84 | ++ImpUses) |
Jakob Stoklund Olesen | ac4210e | 2012-12-20 22:53:58 +0000 | [diff] [blame] | 85 | addOperand(MF, MachineOperand::CreateReg(*ImpUses, false, true)); |
Evan Cheng | 77af6ac | 2006-11-13 23:34:06 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Bob Wilson | 406f270 | 2010-04-09 04:34:03 +0000 | [diff] [blame] | 88 | /// MachineInstr ctor - This constructor creates a MachineInstr and adds the |
| 89 | /// implicit operands. It reserves space for the number of operands specified by |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 90 | /// the MCInstrDesc. |
Jakob Stoklund Olesen | ac4210e | 2012-12-20 22:53:58 +0000 | [diff] [blame] | 91 | MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &tid, |
Benjamin Kramer | a9591b5 | 2015-02-07 12:28:15 +0000 | [diff] [blame] | 92 | DebugLoc dl, bool NoImp) |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 93 | : MCID(&tid), debugLoc(std::move(dl)) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 94 | assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor"); |
| 95 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 96 | // Reserve space for the expected number of operands. |
| 97 | if (unsigned NumOps = MCID->getNumOperands() + |
| 98 | MCID->getNumImplicitDefs() + MCID->getNumImplicitUses()) { |
| 99 | CapOperands = OperandCapacity::get(NumOps); |
| 100 | Operands = MF.allocateOperandArray(CapOperands); |
| 101 | } |
| 102 | |
Dale Johannesen | 4e04ef3 | 2009-01-27 23:20:29 +0000 | [diff] [blame] | 103 | if (!NoImp) |
Jakob Stoklund Olesen | ac4210e | 2012-12-20 22:53:58 +0000 | [diff] [blame] | 104 | addImplicitDefUseOperands(MF); |
Dale Johannesen | 4e04ef3 | 2009-01-27 23:20:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Misha Brukman | b47ab7a | 2004-07-09 14:45:17 +0000 | [diff] [blame] | 107 | /// MachineInstr ctor - Copies MachineInstr arg exactly |
| 108 | /// |
Evan Cheng | a7a20c4 | 2008-07-19 00:37:25 +0000 | [diff] [blame] | 109 | MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI) |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 110 | : MCID(&MI.getDesc()), NumMemRefs(MI.NumMemRefs), MemRefs(MI.MemRefs), |
| 111 | debugLoc(MI.getDebugLoc()) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 112 | assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor"); |
| 113 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 114 | CapOperands = OperandCapacity::get(MI.getNumOperands()); |
| 115 | Operands = MF.allocateOperandArray(CapOperands); |
Tanya Lattner | 9953d86 | 2004-05-23 20:58:02 +0000 | [diff] [blame] | 116 | |
Jakob Stoklund Olesen | dc5285f | 2013-01-05 05:05:51 +0000 | [diff] [blame] | 117 | // Copy operands. |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 118 | for (const MachineOperand &MO : MI.operands()) |
| 119 | addOperand(MF, MO); |
Tanya Lattner | bcee21b | 2004-05-24 03:14:18 +0000 | [diff] [blame] | 120 | |
Jakob Stoklund Olesen | a33f504 | 2012-12-18 21:36:05 +0000 | [diff] [blame] | 121 | // Copy all the sensible flags. |
| 122 | setFlags(MI.Flags); |
Alkis Evlogimenos | 14f3fe8 | 2004-02-16 07:17:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 125 | /// getRegInfo - If this instruction is embedded into a MachineFunction, |
| 126 | /// return the MachineRegisterInfo object for the current function, otherwise |
| 127 | /// return null. |
| 128 | MachineRegisterInfo *MachineInstr::getRegInfo() { |
| 129 | if (MachineBasicBlock *MBB = getParent()) |
Dan Gohman | f188fa4 | 2008-07-08 23:59:09 +0000 | [diff] [blame] | 130 | return &MBB->getParent()->getRegInfo(); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 131 | return nullptr; |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /// RemoveRegOperandsFromUseLists - Unlink all of the register operands in |
| 135 | /// this instruction from their respective use lists. This requires that the |
| 136 | /// operands already be on their use lists. |
Jakob Stoklund Olesen | c4102d4 | 2012-08-09 22:49:37 +0000 | [diff] [blame] | 137 | void MachineInstr::RemoveRegOperandsFromUseLists(MachineRegisterInfo &MRI) { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 138 | for (MachineOperand &MO : operands()) |
| 139 | if (MO.isReg()) |
| 140 | MRI.removeRegOperandFromUseList(&MO); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /// AddRegOperandsToUseLists - Add all of the register operands in |
| 144 | /// this instruction from their respective use lists. This requires that the |
| 145 | /// operands not be on their use lists yet. |
Jakob Stoklund Olesen | c4102d4 | 2012-08-09 22:49:37 +0000 | [diff] [blame] | 146 | void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &MRI) { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 147 | for (MachineOperand &MO : operands()) |
| 148 | if (MO.isReg()) |
| 149 | MRI.addRegOperandToUseList(&MO); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Jakob Stoklund Olesen | 2455b585 | 2012-12-20 22:54:05 +0000 | [diff] [blame] | 152 | void MachineInstr::addOperand(const MachineOperand &Op) { |
| 153 | MachineBasicBlock *MBB = getParent(); |
| 154 | assert(MBB && "Use MachineInstrBuilder to add operands to dangling instrs"); |
| 155 | MachineFunction *MF = MBB->getParent(); |
| 156 | assert(MF && "Use MachineInstrBuilder to add operands to dangling instrs"); |
| 157 | addOperand(*MF, Op); |
| 158 | } |
| 159 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 160 | /// Move NumOps MachineOperands from Src to Dst, with support for overlapping |
| 161 | /// ranges. If MRI is non-null also update use-def chains. |
| 162 | static void moveOperands(MachineOperand *Dst, MachineOperand *Src, |
| 163 | unsigned NumOps, MachineRegisterInfo *MRI) { |
| 164 | if (MRI) |
| 165 | return MRI->moveOperands(Dst, Src, NumOps); |
| 166 | |
JF Bastien | a874d1a | 2016-03-26 18:20:02 +0000 | [diff] [blame] | 167 | // MachineOperand is a trivially copyable type so we can just use memmove. |
Benjamin Kramer | 5c0e64f | 2015-02-21 16:22:48 +0000 | [diff] [blame] | 168 | std::memmove(Dst, Src, NumOps * sizeof(MachineOperand)); |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 171 | /// addOperand - Add the specified operand to the instruction. If it is an |
| 172 | /// implicit operand, it is added to the end of the operand list. If it is |
| 173 | /// an explicit operand it is added at the end of the explicit operand list |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 174 | /// (before the first implicit operand). |
Jakob Stoklund Olesen | 2455b585 | 2012-12-20 22:54:05 +0000 | [diff] [blame] | 175 | void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) { |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 176 | assert(MCID && "Cannot add operands before providing an instr descriptor"); |
Dan Gohman | 9356d8f | 2008-12-09 22:45:08 +0000 | [diff] [blame] | 177 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 178 | // Check if we're adding one of our existing operands. |
| 179 | if (&Op >= Operands && &Op < Operands + NumOperands) { |
| 180 | // This is unusual: MI->addOperand(MI->getOperand(i)). |
| 181 | // If adding Op requires reallocating or moving existing operands around, |
| 182 | // the Op reference could go stale. Support it by copying Op. |
| 183 | MachineOperand CopyOp(Op); |
| 184 | return addOperand(MF, CopyOp); |
| 185 | } |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 186 | |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 187 | // Find the insert location for the new operand. Implicit registers go at |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 188 | // the end, everything else goes before the implicit regs. |
| 189 | // |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 190 | // FIXME: Allow mixed explicit and implicit operands on inline asm. |
| 191 | // InstrEmitter::EmitSpecialNode() is marking inline asm clobbers as |
| 192 | // implicit-defs, but they must not be moved around. See the FIXME in |
| 193 | // InstrEmitter.cpp. |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 194 | unsigned OpNo = getNumOperands(); |
| 195 | bool isImpReg = Op.isReg() && Op.isImplicit(); |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 196 | if (!isImpReg && !isInlineAsm()) { |
| 197 | while (OpNo && Operands[OpNo-1].isReg() && Operands[OpNo-1].isImplicit()) { |
| 198 | --OpNo; |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 199 | assert(!Operands[OpNo].isTied() && "Cannot move tied operands"); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 202 | |
Pekka Jaaskelainen | eb4a6e7 | 2013-10-15 14:40:46 +0000 | [diff] [blame] | 203 | #ifndef NDEBUG |
Pekka Jaaskelainen | eb08e2e | 2013-10-15 14:18:10 +0000 | [diff] [blame] | 204 | bool isMetaDataOp = Op.getType() == MachineOperand::MO_Metadata; |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 205 | // OpNo now points as the desired insertion point. Unless this is a variadic |
| 206 | // instruction, only implicit regs are allowed beyond MCID->getNumOperands(). |
Jakob Stoklund Olesen | c300ef0 | 2012-07-04 23:53:23 +0000 | [diff] [blame] | 207 | // RegMask operands go between the explicit and implicit operands. |
| 208 | assert((isImpReg || Op.isRegMask() || MCID->isVariadic() || |
Pekka Jaaskelainen | eb08e2e | 2013-10-15 14:18:10 +0000 | [diff] [blame] | 209 | OpNo < MCID->getNumOperands() || isMetaDataOp) && |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 210 | "Trying to add an operand to a machine instr that is already done!"); |
Pekka Jaaskelainen | eb4a6e7 | 2013-10-15 14:40:46 +0000 | [diff] [blame] | 211 | #endif |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 212 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 213 | MachineRegisterInfo *MRI = getRegInfo(); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 214 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 215 | // Determine if the Operands array needs to be reallocated. |
| 216 | // Save the old capacity and operand array. |
| 217 | OperandCapacity OldCap = CapOperands; |
| 218 | MachineOperand *OldOperands = Operands; |
| 219 | if (!OldOperands || OldCap.getSize() == getNumOperands()) { |
| 220 | CapOperands = OldOperands ? OldCap.getNext() : OldCap.get(1); |
| 221 | Operands = MF.allocateOperandArray(CapOperands); |
| 222 | // Move the operands before the insertion point. |
| 223 | if (OpNo) |
| 224 | moveOperands(Operands, OldOperands, OpNo, MRI); |
| 225 | } |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 226 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 227 | // Move the operands following the insertion point. |
| 228 | if (OpNo != NumOperands) |
| 229 | moveOperands(Operands + OpNo + 1, OldOperands + OpNo, NumOperands - OpNo, |
| 230 | MRI); |
| 231 | ++NumOperands; |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 232 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 233 | // Deallocate the old operand array. |
| 234 | if (OldOperands != Operands && OldOperands) |
| 235 | MF.deallocateOperandArray(OldCap, OldOperands); |
| 236 | |
| 237 | // Copy Op into place. It still needs to be inserted into the MRI use lists. |
| 238 | MachineOperand *NewMO = new (Operands + OpNo) MachineOperand(Op); |
| 239 | NewMO->ParentMI = this; |
| 240 | |
| 241 | // When adding a register operand, tell MRI about it. |
| 242 | if (NewMO->isReg()) { |
Jakob Stoklund Olesen | c4102d4 | 2012-08-09 22:49:37 +0000 | [diff] [blame] | 243 | // Ensure isOnRegUseList() returns false, regardless of Op's status. |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 244 | NewMO->Contents.Reg.Prev = nullptr; |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 245 | // Ignore existing ties. This is not a property that can be copied. |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 246 | NewMO->TiedTo = 0; |
| 247 | // Add the new operand to MRI, but only for instructions in an MBB. |
| 248 | if (MRI) |
| 249 | MRI->addRegOperandToUseList(NewMO); |
Jakob Stoklund Olesen | 0eecbbe | 2012-08-30 14:39:06 +0000 | [diff] [blame] | 250 | // The MCID operand information isn't accurate until we start adding |
| 251 | // explicit operands. The implicit operands are added first, then the |
| 252 | // explicits are inserted before them. |
| 253 | if (!isImpReg) { |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 254 | // Tie uses to defs as indicated in MCInstrDesc. |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 255 | if (NewMO->isUse()) { |
Jakob Stoklund Olesen | 0eecbbe | 2012-08-30 14:39:06 +0000 | [diff] [blame] | 256 | int DefIdx = MCID->getOperandConstraint(OpNo, MCOI::TIED_TO); |
Jakob Stoklund Olesen | 5c8eda0 | 2012-08-31 20:50:53 +0000 | [diff] [blame] | 257 | if (DefIdx != -1) |
| 258 | tieOperands(DefIdx, OpNo); |
Jakob Stoklund Olesen | e56c60c | 2012-08-28 18:34:41 +0000 | [diff] [blame] | 259 | } |
Jakob Stoklund Olesen | 0eecbbe | 2012-08-30 14:39:06 +0000 | [diff] [blame] | 260 | // If the register operand is flagged as early, mark the operand as such. |
| 261 | if (MCID->getOperandConstraint(OpNo, MCOI::EARLY_CLOBBER) != -1) |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 262 | NewMO->setIsEarlyClobber(true); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 263 | } |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | /// RemoveOperand - Erase an operand from an instruction, leaving it with one |
| 268 | /// fewer operand than it started with. |
| 269 | /// |
| 270 | void MachineInstr::RemoveOperand(unsigned OpNo) { |
Jakob Stoklund Olesen | b089483 | 2012-12-22 17:13:06 +0000 | [diff] [blame] | 271 | assert(OpNo < getNumOperands() && "Invalid operand number"); |
Jakob Stoklund Olesen | 2b16664 | 2012-08-29 00:37:58 +0000 | [diff] [blame] | 272 | untieRegOperand(OpNo); |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 273 | |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 274 | #ifndef NDEBUG |
| 275 | // Moving tied operands would break the ties. |
Jakob Stoklund Olesen | b089483 | 2012-12-22 17:13:06 +0000 | [diff] [blame] | 276 | for (unsigned i = OpNo + 1, e = getNumOperands(); i != e; ++i) |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 277 | if (Operands[i].isReg()) |
| 278 | assert(!Operands[i].isTied() && "Cannot move tied operands"); |
| 279 | #endif |
| 280 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 281 | MachineRegisterInfo *MRI = getRegInfo(); |
| 282 | if (MRI && Operands[OpNo].isReg()) |
| 283 | MRI->removeRegOperandFromUseList(Operands + OpNo); |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 284 | |
Jakob Stoklund Olesen | 1bfeecb | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 285 | // Don't call the MachineOperand destructor. A lot of this code depends on |
| 286 | // MachineOperand having a trivial destructor anyway, and adding a call here |
| 287 | // wouldn't make it 'destructor-correct'. |
| 288 | |
| 289 | if (unsigned N = NumOperands - 1 - OpNo) |
| 290 | moveOperands(Operands + OpNo, Operands + OpNo + 1, N, MRI); |
| 291 | --NumOperands; |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 294 | /// addMemOperand - Add a MachineMemOperand to the machine instruction. |
| 295 | /// This function should be used only occasionally. The setMemRefs function |
| 296 | /// is the primary method for setting up a MachineInstr's MemRefs list. |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 297 | void MachineInstr::addMemOperand(MachineFunction &MF, |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 298 | MachineMemOperand *MO) { |
| 299 | mmo_iterator OldMemRefs = MemRefs; |
Jakob Stoklund Olesen | 5adc4a1 | 2013-01-07 23:21:41 +0000 | [diff] [blame] | 300 | unsigned OldNumMemRefs = NumMemRefs; |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 301 | |
Jakob Stoklund Olesen | 5adc4a1 | 2013-01-07 23:21:41 +0000 | [diff] [blame] | 302 | unsigned NewNum = NumMemRefs + 1; |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 303 | mmo_iterator NewMemRefs = MF.allocateMemRefsArray(NewNum); |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 304 | |
Benjamin Kramer | d03878b | 2012-03-16 16:39:27 +0000 | [diff] [blame] | 305 | std::copy(OldMemRefs, OldMemRefs + OldNumMemRefs, NewMemRefs); |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 306 | NewMemRefs[NewNum - 1] = MO; |
Jakob Stoklund Olesen | 5adc4a1 | 2013-01-07 23:21:41 +0000 | [diff] [blame] | 307 | setMemRefs(NewMemRefs, NewMemRefs + NewNum); |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 308 | } |
Chris Lattner | 961e742 | 2008-01-01 01:12:31 +0000 | [diff] [blame] | 309 | |
Philip Reames | 5eb90a7 | 2016-01-06 19:33:12 +0000 | [diff] [blame] | 310 | /// Check to see if the MMOs pointed to by the two MemRefs arrays are |
Junmo Park | 820e392 | 2016-02-26 02:07:36 +0000 | [diff] [blame] | 311 | /// identical. |
Philip Reames | 5eb90a7 | 2016-01-06 19:33:12 +0000 | [diff] [blame] | 312 | static bool hasIdenticalMMOs(const MachineInstr &MI1, const MachineInstr &MI2) { |
| 313 | auto I1 = MI1.memoperands_begin(), E1 = MI1.memoperands_end(); |
| 314 | auto I2 = MI2.memoperands_begin(), E2 = MI2.memoperands_end(); |
| 315 | if ((E1 - I1) != (E2 - I2)) |
| 316 | return false; |
| 317 | for (; I1 != E1; ++I1, ++I2) { |
| 318 | if (**I1 != **I2) |
| 319 | return false; |
| 320 | } |
| 321 | return true; |
| 322 | } |
| 323 | |
Philip Reames | c86ed00 | 2016-01-06 04:39:03 +0000 | [diff] [blame] | 324 | std::pair<MachineInstr::mmo_iterator, unsigned> |
| 325 | MachineInstr::mergeMemRefsWith(const MachineInstr& Other) { |
Philip Reames | 5eb90a7 | 2016-01-06 19:33:12 +0000 | [diff] [blame] | 326 | |
| 327 | // If either of the incoming memrefs are empty, we must be conservative and |
| 328 | // treat this as if we've exhausted our space for memrefs and dropped them. |
| 329 | if (memoperands_empty() || Other.memoperands_empty()) |
| 330 | return std::make_pair(nullptr, 0); |
| 331 | |
| 332 | // If both instructions have identical memrefs, we don't need to merge them. |
| 333 | // Since many instructions have a single memref, and we tend to merge things |
| 334 | // like pairs of loads from the same location, this catches a large number of |
| 335 | // cases in practice. |
| 336 | if (hasIdenticalMMOs(*this, Other)) |
| 337 | return std::make_pair(MemRefs, NumMemRefs); |
Junmo Park | 820e392 | 2016-02-26 02:07:36 +0000 | [diff] [blame] | 338 | |
Philip Reames | c86ed00 | 2016-01-06 04:39:03 +0000 | [diff] [blame] | 339 | // TODO: consider uniquing elements within the operand lists to reduce |
| 340 | // space usage and fall back to conservative information less often. |
Philip Reames | 5eb90a7 | 2016-01-06 19:33:12 +0000 | [diff] [blame] | 341 | size_t CombinedNumMemRefs = NumMemRefs + Other.NumMemRefs; |
| 342 | |
| 343 | // If we don't have enough room to store this many memrefs, be conservative |
| 344 | // and drop them. Otherwise, we'd fail asserts when trying to add them to |
| 345 | // the new instruction. |
| 346 | if (CombinedNumMemRefs != uint8_t(CombinedNumMemRefs)) |
| 347 | return std::make_pair(nullptr, 0); |
Philip Reames | c86ed00 | 2016-01-06 04:39:03 +0000 | [diff] [blame] | 348 | |
Justin Bogner | fdf9bf4 | 2017-10-10 23:50:49 +0000 | [diff] [blame] | 349 | MachineFunction *MF = getMF(); |
Philip Reames | c86ed00 | 2016-01-06 04:39:03 +0000 | [diff] [blame] | 350 | mmo_iterator MemBegin = MF->allocateMemRefsArray(CombinedNumMemRefs); |
| 351 | mmo_iterator MemEnd = std::copy(memoperands_begin(), memoperands_end(), |
| 352 | MemBegin); |
| 353 | MemEnd = std::copy(Other.memoperands_begin(), Other.memoperands_end(), |
| 354 | MemEnd); |
Philip Reames | 2d2fc4a | 2016-01-06 05:53:09 +0000 | [diff] [blame] | 355 | assert(MemEnd - MemBegin == (ptrdiff_t)CombinedNumMemRefs && |
| 356 | "missing memrefs"); |
Junmo Park | 820e392 | 2016-02-26 02:07:36 +0000 | [diff] [blame] | 357 | |
Philip Reames | c86ed00 | 2016-01-06 04:39:03 +0000 | [diff] [blame] | 358 | return std::make_pair(MemBegin, CombinedNumMemRefs); |
| 359 | } |
| 360 | |
Benjamin Kramer | 97f889f | 2012-03-17 17:03:45 +0000 | [diff] [blame] | 361 | bool MachineInstr::hasPropertyInBundle(unsigned Mask, QueryType Type) const { |
Jakob Stoklund Olesen | f0615c7 | 2013-01-10 18:42:44 +0000 | [diff] [blame] | 362 | assert(!isBundledWithPred() && "Must be called on bundle header"); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 363 | for (MachineBasicBlock::const_instr_iterator MII = getIterator();; ++MII) { |
Benjamin Kramer | 97f889f | 2012-03-17 17:03:45 +0000 | [diff] [blame] | 364 | if (MII->getDesc().getFlags() & Mask) { |
Evan Cheng | cdf89fd | 2011-12-08 19:23:10 +0000 | [diff] [blame] | 365 | if (Type == AnyInBundle) |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 366 | return true; |
| 367 | } else { |
Jakob Stoklund Olesen | 55a7be2 | 2013-01-10 01:29:42 +0000 | [diff] [blame] | 368 | if (Type == AllInBundle && !MII->isBundle()) |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 369 | return false; |
| 370 | } |
Jakob Stoklund Olesen | 55a7be2 | 2013-01-10 01:29:42 +0000 | [diff] [blame] | 371 | // This was the last instruction in the bundle. |
| 372 | if (!MII->isBundledWithSucc()) |
| 373 | return Type == AllInBundle; |
Evan Cheng | 2a81dd4 | 2011-12-06 22:12:01 +0000 | [diff] [blame] | 374 | } |
Evan Cheng | 2a81dd4 | 2011-12-06 22:12:01 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 377 | bool MachineInstr::isIdenticalTo(const MachineInstr &Other, |
Evan Cheng | e9c46c2 | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 378 | MICheckType Check) const { |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 379 | // If opcodes or number of operands are not the same then the two |
| 380 | // instructions are obviously not identical. |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 381 | if (Other.getOpcode() != getOpcode() || |
| 382 | Other.getNumOperands() != getNumOperands()) |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 383 | return false; |
| 384 | |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 385 | if (isBundle()) { |
Bjorn Pettersson | b29a15e | 2016-12-19 11:20:57 +0000 | [diff] [blame] | 386 | // We have passed the test above that both instructions have the same |
| 387 | // opcode, so we know that both instructions are bundles here. Let's compare |
| 388 | // MIs inside the bundle. |
| 389 | assert(Other.isBundle() && "Expected that both instructions are bundles."); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 390 | MachineBasicBlock::const_instr_iterator I1 = getIterator(); |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 391 | MachineBasicBlock::const_instr_iterator I2 = Other.getIterator(); |
Bjorn Pettersson | b29a15e | 2016-12-19 11:20:57 +0000 | [diff] [blame] | 392 | // Loop until we analysed the last intruction inside at least one of the |
| 393 | // bundles. |
| 394 | while (I1->isBundledWithSucc() && I2->isBundledWithSucc()) { |
| 395 | ++I1; |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 396 | ++I2; |
Bjorn Pettersson | b29a15e | 2016-12-19 11:20:57 +0000 | [diff] [blame] | 397 | if (!I1->isIdenticalTo(*I2, Check)) |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 398 | return false; |
| 399 | } |
Bjorn Pettersson | b29a15e | 2016-12-19 11:20:57 +0000 | [diff] [blame] | 400 | // If we've reached the end of just one of the two bundles, but not both, |
| 401 | // the instructions are not identical. |
| 402 | if (I1->isBundledWithSucc() || I2->isBundledWithSucc()) |
| 403 | return false; |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 406 | // Check operands to make sure they match. |
| 407 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 408 | const MachineOperand &MO = getOperand(i); |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 409 | const MachineOperand &OMO = Other.getOperand(i); |
Evan Cheng | cfdf339 | 2011-05-12 00:56:58 +0000 | [diff] [blame] | 410 | if (!MO.isReg()) { |
| 411 | if (!MO.isIdenticalTo(OMO)) |
| 412 | return false; |
| 413 | continue; |
| 414 | } |
| 415 | |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 416 | // Clients may or may not want to ignore defs when testing for equality. |
| 417 | // For example, machine CSE pass only cares about finding common |
| 418 | // subexpressions, so it's safe to ignore virtual register defs. |
Evan Cheng | cfdf339 | 2011-05-12 00:56:58 +0000 | [diff] [blame] | 419 | if (MO.isDef()) { |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 420 | if (Check == IgnoreDefs) |
| 421 | continue; |
Evan Cheng | cfdf339 | 2011-05-12 00:56:58 +0000 | [diff] [blame] | 422 | else if (Check == IgnoreVRegDefs) { |
Diana Picus | 4a5f522 | 2017-10-12 13:59:51 +0000 | [diff] [blame] | 423 | if (!TargetRegisterInfo::isVirtualRegister(MO.getReg()) || |
| 424 | !TargetRegisterInfo::isVirtualRegister(OMO.getReg())) |
| 425 | if (!MO.isIdenticalTo(OMO)) |
Evan Cheng | cfdf339 | 2011-05-12 00:56:58 +0000 | [diff] [blame] | 426 | return false; |
| 427 | } else { |
| 428 | if (!MO.isIdenticalTo(OMO)) |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 429 | return false; |
Evan Cheng | cfdf339 | 2011-05-12 00:56:58 +0000 | [diff] [blame] | 430 | if (Check == CheckKillDead && MO.isDead() != OMO.isDead()) |
| 431 | return false; |
| 432 | } |
| 433 | } else { |
| 434 | if (!MO.isIdenticalTo(OMO)) |
| 435 | return false; |
| 436 | if (Check == CheckKillDead && MO.isKill() != OMO.isKill()) |
| 437 | return false; |
| 438 | } |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 439 | } |
Devang Patel | bf8cc60 | 2011-07-07 17:45:33 +0000 | [diff] [blame] | 440 | // If DebugLoc does not match then two dbg.values are not identical. |
| 441 | if (isDebugValue()) |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 442 | if (getDebugLoc() && Other.getDebugLoc() && |
| 443 | getDebugLoc() != Other.getDebugLoc()) |
Devang Patel | bf8cc60 | 2011-07-07 17:45:33 +0000 | [diff] [blame] | 444 | return false; |
Evan Cheng | 0f260e1 | 2010-03-03 21:54:14 +0000 | [diff] [blame] | 445 | return true; |
Evan Cheng | e9c46c2 | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Justin Bogner | ec7cba5 | 2017-10-10 23:34:01 +0000 | [diff] [blame] | 448 | const MachineFunction *MachineInstr::getMF() const { |
| 449 | return getParent()->getParent(); |
| 450 | } |
| 451 | |
Chris Lattner | bec79b4 | 2006-04-17 21:35:41 +0000 | [diff] [blame] | 452 | MachineInstr *MachineInstr::removeFromParent() { |
| 453 | assert(getParent() && "Not embedded in a basic block!"); |
Jakob Stoklund Olesen | ccfb5fb | 2012-12-17 23:55:38 +0000 | [diff] [blame] | 454 | return getParent()->remove(this); |
Chris Lattner | bec79b4 | 2006-04-17 21:35:41 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Jakob Stoklund Olesen | ccfb5fb | 2012-12-17 23:55:38 +0000 | [diff] [blame] | 457 | MachineInstr *MachineInstr::removeFromBundle() { |
| 458 | assert(getParent() && "Not embedded in a basic block!"); |
| 459 | return getParent()->remove_instr(this); |
| 460 | } |
Chris Lattner | bec79b4 | 2006-04-17 21:35:41 +0000 | [diff] [blame] | 461 | |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 462 | void MachineInstr::eraseFromParent() { |
| 463 | assert(getParent() && "Not embedded in a basic block!"); |
Jakob Stoklund Olesen | ccfb5fb | 2012-12-17 23:55:38 +0000 | [diff] [blame] | 464 | getParent()->erase(this); |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Gerolf Hoflehner | caa8bfd | 2014-08-13 21:15:23 +0000 | [diff] [blame] | 467 | void MachineInstr::eraseFromParentAndMarkDBGValuesForRemoval() { |
| 468 | assert(getParent() && "Not embedded in a basic block!"); |
| 469 | MachineBasicBlock *MBB = getParent(); |
| 470 | MachineFunction *MF = MBB->getParent(); |
| 471 | assert(MF && "Not embedded in a function!"); |
| 472 | |
| 473 | MachineInstr *MI = (MachineInstr *)this; |
| 474 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 475 | |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 476 | for (const MachineOperand &MO : MI->operands()) { |
Gerolf Hoflehner | caa8bfd | 2014-08-13 21:15:23 +0000 | [diff] [blame] | 477 | if (!MO.isReg() || !MO.isDef()) |
| 478 | continue; |
| 479 | unsigned Reg = MO.getReg(); |
| 480 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) |
| 481 | continue; |
| 482 | MRI.markUsesInDebugValueAsUndef(Reg); |
| 483 | } |
| 484 | MI->eraseFromParent(); |
| 485 | } |
| 486 | |
Jakob Stoklund Olesen | ccfb5fb | 2012-12-17 23:55:38 +0000 | [diff] [blame] | 487 | void MachineInstr::eraseFromBundle() { |
| 488 | assert(getParent() && "Not embedded in a basic block!"); |
| 489 | getParent()->erase_instr(this); |
| 490 | } |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 491 | |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 492 | /// getNumExplicitOperands - Returns the number of non-implicit operands. |
| 493 | /// |
| 494 | unsigned MachineInstr::getNumExplicitOperands() const { |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 495 | unsigned NumOperands = MCID->getNumOperands(); |
| 496 | if (!MCID->isVariadic()) |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 497 | return NumOperands; |
| 498 | |
Dan Gohman | 3760853 | 2009-04-15 17:59:11 +0000 | [diff] [blame] | 499 | for (unsigned i = NumOperands, e = getNumOperands(); i != e; ++i) { |
| 500 | const MachineOperand &MO = getOperand(i); |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 501 | if (!MO.isReg() || !MO.isImplicit()) |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 502 | NumOperands++; |
| 503 | } |
| 504 | return NumOperands; |
| 505 | } |
| 506 | |
Jakob Stoklund Olesen | fead62d | 2012-12-07 04:23:29 +0000 | [diff] [blame] | 507 | void MachineInstr::bundleWithPred() { |
| 508 | assert(!isBundledWithPred() && "MI is already bundled with its predecessor"); |
| 509 | setFlag(BundledPred); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 510 | MachineBasicBlock::instr_iterator Pred = getIterator(); |
| 511 | --Pred; |
Jakob Stoklund Olesen | 00f6c77 | 2012-12-18 23:00:28 +0000 | [diff] [blame] | 512 | assert(!Pred->isBundledWithSucc() && "Inconsistent bundle flags"); |
Jakob Stoklund Olesen | fead62d | 2012-12-07 04:23:29 +0000 | [diff] [blame] | 513 | Pred->setFlag(BundledSucc); |
| 514 | } |
| 515 | |
| 516 | void MachineInstr::bundleWithSucc() { |
| 517 | assert(!isBundledWithSucc() && "MI is already bundled with its successor"); |
| 518 | setFlag(BundledSucc); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 519 | MachineBasicBlock::instr_iterator Succ = getIterator(); |
| 520 | ++Succ; |
Jakob Stoklund Olesen | 00f6c77 | 2012-12-18 23:00:28 +0000 | [diff] [blame] | 521 | assert(!Succ->isBundledWithPred() && "Inconsistent bundle flags"); |
Jakob Stoklund Olesen | fead62d | 2012-12-07 04:23:29 +0000 | [diff] [blame] | 522 | Succ->setFlag(BundledPred); |
| 523 | } |
| 524 | |
| 525 | void MachineInstr::unbundleFromPred() { |
| 526 | assert(isBundledWithPred() && "MI isn't bundled with its predecessor"); |
| 527 | clearFlag(BundledPred); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 528 | MachineBasicBlock::instr_iterator Pred = getIterator(); |
| 529 | --Pred; |
Jakob Stoklund Olesen | 00f6c77 | 2012-12-18 23:00:28 +0000 | [diff] [blame] | 530 | assert(Pred->isBundledWithSucc() && "Inconsistent bundle flags"); |
Jakob Stoklund Olesen | fead62d | 2012-12-07 04:23:29 +0000 | [diff] [blame] | 531 | Pred->clearFlag(BundledSucc); |
| 532 | } |
| 533 | |
| 534 | void MachineInstr::unbundleFromSucc() { |
| 535 | assert(isBundledWithSucc() && "MI isn't bundled with its successor"); |
| 536 | clearFlag(BundledSucc); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 537 | MachineBasicBlock::instr_iterator Succ = getIterator(); |
| 538 | ++Succ; |
Jakob Stoklund Olesen | 00f6c77 | 2012-12-18 23:00:28 +0000 | [diff] [blame] | 539 | assert(Succ->isBundledWithPred() && "Inconsistent bundle flags"); |
Jakob Stoklund Olesen | fead62d | 2012-12-07 04:23:29 +0000 | [diff] [blame] | 540 | Succ->clearFlag(BundledPred); |
| 541 | } |
| 542 | |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 543 | bool MachineInstr::isStackAligningInlineAsm() const { |
| 544 | if (isInlineAsm()) { |
| 545 | unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); |
| 546 | if (ExtraInfo & InlineAsm::Extra_IsAlignStack) |
| 547 | return true; |
| 548 | } |
| 549 | return false; |
| 550 | } |
Chris Lattner | 33f5af0 | 2006-10-20 22:39:59 +0000 | [diff] [blame] | 551 | |
Chad Rosier | 994f404 | 2012-09-05 21:00:58 +0000 | [diff] [blame] | 552 | InlineAsm::AsmDialect MachineInstr::getInlineAsmDialect() const { |
| 553 | assert(isInlineAsm() && "getInlineAsmDialect() only works for inline asms!"); |
| 554 | unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); |
Chad Rosier | e53314f | 2012-09-05 22:40:13 +0000 | [diff] [blame] | 555 | return InlineAsm::AsmDialect((ExtraInfo & InlineAsm::Extra_AsmDialect) != 0); |
Chad Rosier | 994f404 | 2012-09-05 21:00:58 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Jakob Stoklund Olesen | 1e73716 | 2011-10-12 23:37:33 +0000 | [diff] [blame] | 558 | int MachineInstr::findInlineAsmFlagIdx(unsigned OpIdx, |
| 559 | unsigned *GroupNo) const { |
| 560 | assert(isInlineAsm() && "Expected an inline asm instruction"); |
| 561 | assert(OpIdx < getNumOperands() && "OpIdx out of range"); |
| 562 | |
| 563 | // Ignore queries about the initial operands. |
| 564 | if (OpIdx < InlineAsm::MIOp_FirstOperand) |
| 565 | return -1; |
| 566 | |
| 567 | unsigned Group = 0; |
| 568 | unsigned NumOps; |
| 569 | for (unsigned i = InlineAsm::MIOp_FirstOperand, e = getNumOperands(); i < e; |
| 570 | i += NumOps) { |
| 571 | const MachineOperand &FlagMO = getOperand(i); |
| 572 | // If we reach the implicit register operands, stop looking. |
| 573 | if (!FlagMO.isImm()) |
| 574 | return -1; |
| 575 | NumOps = 1 + InlineAsm::getNumOperandRegisters(FlagMO.getImm()); |
| 576 | if (i + NumOps > OpIdx) { |
| 577 | if (GroupNo) |
| 578 | *GroupNo = Group; |
| 579 | return i; |
| 580 | } |
| 581 | ++Group; |
| 582 | } |
| 583 | return -1; |
| 584 | } |
| 585 | |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 586 | const DILocalVariable *MachineInstr::getDebugVariable() const { |
| 587 | assert(isDebugValue() && "not a DBG_VALUE"); |
| 588 | return cast<DILocalVariable>(getOperand(2).getMetadata()); |
| 589 | } |
| 590 | |
| 591 | const DIExpression *MachineInstr::getDebugExpression() const { |
| 592 | assert(isDebugValue() && "not a DBG_VALUE"); |
| 593 | return cast<DIExpression>(getOperand(3).getMetadata()); |
| 594 | } |
| 595 | |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 596 | const TargetRegisterClass* |
| 597 | MachineInstr::getRegClassConstraint(unsigned OpIdx, |
| 598 | const TargetInstrInfo *TII, |
| 599 | const TargetRegisterInfo *TRI) const { |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 600 | assert(getParent() && "Can't have an MBB reference here!"); |
Justin Bogner | fdf9bf4 | 2017-10-10 23:50:49 +0000 | [diff] [blame] | 601 | assert(getMF() && "Can't have an MF reference here!"); |
| 602 | const MachineFunction &MF = *getMF(); |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 603 | |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 604 | // Most opcodes have fixed constraints in their MCInstrDesc. |
| 605 | if (!isInlineAsm()) |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 606 | return TII->getRegClass(getDesc(), OpIdx, TRI, MF); |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 607 | |
| 608 | if (!getOperand(OpIdx).isReg()) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 609 | return nullptr; |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 610 | |
| 611 | // For tied uses on inline asm, get the constraint from the def. |
| 612 | unsigned DefIdx; |
| 613 | if (getOperand(OpIdx).isUse() && isRegTiedToDefOperand(OpIdx, &DefIdx)) |
| 614 | OpIdx = DefIdx; |
| 615 | |
| 616 | // Inline asm stores register class constraints in the flag word. |
| 617 | int FlagIdx = findInlineAsmFlagIdx(OpIdx); |
| 618 | if (FlagIdx < 0) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 619 | return nullptr; |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 620 | |
| 621 | unsigned Flag = getOperand(FlagIdx).getImm(); |
| 622 | unsigned RCID; |
Simon Dardis | d32a2d3 | 2016-07-18 13:17:31 +0000 | [diff] [blame] | 623 | if ((InlineAsm::getKind(Flag) == InlineAsm::Kind_RegUse || |
| 624 | InlineAsm::getKind(Flag) == InlineAsm::Kind_RegDef || |
| 625 | InlineAsm::getKind(Flag) == InlineAsm::Kind_RegDefEarlyClobber) && |
| 626 | InlineAsm::hasRegClassConstraint(Flag, RCID)) |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 627 | return TRI->getRegClass(RCID); |
| 628 | |
| 629 | // Assume that all registers in a memory operand are pointers. |
| 630 | if (InlineAsm::getKind(Flag) == InlineAsm::Kind_Mem) |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 631 | return TRI->getPointerRegClass(MF); |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 632 | |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 633 | return nullptr; |
Jakob Stoklund Olesen | 35b362f | 2011-10-12 23:37:36 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Quentin Colombet | 1fb3362a | 2014-01-02 22:47:22 +0000 | [diff] [blame] | 636 | const TargetRegisterClass *MachineInstr::getRegClassConstraintEffectForVReg( |
| 637 | unsigned Reg, const TargetRegisterClass *CurRC, const TargetInstrInfo *TII, |
| 638 | const TargetRegisterInfo *TRI, bool ExploreBundle) const { |
| 639 | // Check every operands inside the bundle if we have |
| 640 | // been asked to. |
| 641 | if (ExploreBundle) |
Duncan P. N. Exon Smith | f9ab416 | 2016-02-27 17:05:33 +0000 | [diff] [blame] | 642 | for (ConstMIBundleOperands OpndIt(*this); OpndIt.isValid() && CurRC; |
Quentin Colombet | 1fb3362a | 2014-01-02 22:47:22 +0000 | [diff] [blame] | 643 | ++OpndIt) |
| 644 | CurRC = OpndIt->getParent()->getRegClassConstraintEffectForVRegImpl( |
| 645 | OpndIt.getOperandNo(), Reg, CurRC, TII, TRI); |
| 646 | else |
| 647 | // Otherwise, just check the current operands. |
Matthias Braun | e41e146 | 2015-05-29 02:56:46 +0000 | [diff] [blame] | 648 | for (unsigned i = 0, e = NumOperands; i < e && CurRC; ++i) |
| 649 | CurRC = getRegClassConstraintEffectForVRegImpl(i, Reg, CurRC, TII, TRI); |
Quentin Colombet | 1fb3362a | 2014-01-02 22:47:22 +0000 | [diff] [blame] | 650 | return CurRC; |
| 651 | } |
| 652 | |
| 653 | const TargetRegisterClass *MachineInstr::getRegClassConstraintEffectForVRegImpl( |
| 654 | unsigned OpIdx, unsigned Reg, const TargetRegisterClass *CurRC, |
| 655 | const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const { |
| 656 | assert(CurRC && "Invalid initial register class"); |
| 657 | // Check if Reg is constrained by some of its use/def from MI. |
| 658 | const MachineOperand &MO = getOperand(OpIdx); |
| 659 | if (!MO.isReg() || MO.getReg() != Reg) |
| 660 | return CurRC; |
| 661 | // If yes, accumulate the constraints through the operand. |
| 662 | return getRegClassConstraintEffect(OpIdx, CurRC, TII, TRI); |
| 663 | } |
| 664 | |
| 665 | const TargetRegisterClass *MachineInstr::getRegClassConstraintEffect( |
| 666 | unsigned OpIdx, const TargetRegisterClass *CurRC, |
| 667 | const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const { |
| 668 | const TargetRegisterClass *OpRC = getRegClassConstraint(OpIdx, TII, TRI); |
| 669 | const MachineOperand &MO = getOperand(OpIdx); |
| 670 | assert(MO.isReg() && |
| 671 | "Cannot get register constraints for non-register operand"); |
| 672 | assert(CurRC && "Invalid initial register class"); |
| 673 | if (unsigned SubIdx = MO.getSubReg()) { |
| 674 | if (OpRC) |
| 675 | CurRC = TRI->getMatchingSuperRegClass(CurRC, OpRC, SubIdx); |
| 676 | else |
| 677 | CurRC = TRI->getSubClassWithSubReg(CurRC, SubIdx); |
| 678 | } else if (OpRC) |
| 679 | CurRC = TRI->getCommonSubClass(CurRC, OpRC); |
| 680 | return CurRC; |
| 681 | } |
| 682 | |
Jakob Stoklund Olesen | 68d752b | 2013-01-09 18:28:16 +0000 | [diff] [blame] | 683 | /// Return the number of instructions inside the MI bundle, not counting the |
| 684 | /// header instruction. |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 685 | unsigned MachineInstr::getBundleSize() const { |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 686 | MachineBasicBlock::const_instr_iterator I = getIterator(); |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 687 | unsigned Size = 0; |
Richard Trieu | 7a08381 | 2016-02-18 22:09:30 +0000 | [diff] [blame] | 688 | while (I->isBundledWithSucc()) { |
| 689 | ++Size; |
| 690 | ++I; |
| 691 | } |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 692 | return Size; |
| 693 | } |
| 694 | |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 695 | /// Returns true if the MachineInstr has an implicit-use operand of exactly |
| 696 | /// the given register (not considering sub/super-registers). |
| 697 | bool MachineInstr::hasRegisterImplicitUseOperand(unsigned Reg) const { |
| 698 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 699 | const MachineOperand &MO = getOperand(i); |
| 700 | if (MO.isReg() && MO.isUse() && MO.isImplicit() && MO.getReg() == Reg) |
| 701 | return true; |
| 702 | } |
| 703 | return false; |
| 704 | } |
| 705 | |
Evan Cheng | 910c808 | 2007-04-26 19:00:32 +0000 | [diff] [blame] | 706 | /// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of |
Jim Grosbach | 9632c14 | 2009-09-17 17:57:26 +0000 | [diff] [blame] | 707 | /// the specific register or -1 if it is not found. It further tightens |
Evan Cheng | 9965aeb | 2007-02-23 01:04:26 +0000 | [diff] [blame] | 708 | /// the search criteria to a use that kills the register if isKill is true. |
Fraser Cormack | 48d9fdc | 2016-10-11 09:09:21 +0000 | [diff] [blame] | 709 | int MachineInstr::findRegisterUseOperandIdx( |
| 710 | unsigned Reg, bool isKill, const TargetRegisterInfo *TRI) const { |
Evan Cheng | 75c2194 | 2006-12-06 08:27:42 +0000 | [diff] [blame] | 711 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
Evan Cheng | 5983bdb | 2007-05-29 18:35:22 +0000 | [diff] [blame] | 712 | const MachineOperand &MO = getOperand(i); |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 713 | if (!MO.isReg() || !MO.isUse()) |
Evan Cheng | 6325446 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 714 | continue; |
| 715 | unsigned MOReg = MO.getReg(); |
| 716 | if (!MOReg) |
| 717 | continue; |
Fraser Cormack | 48d9fdc | 2016-10-11 09:09:21 +0000 | [diff] [blame] | 718 | if (MOReg == Reg || (TRI && TargetRegisterInfo::isPhysicalRegister(MOReg) && |
| 719 | TargetRegisterInfo::isPhysicalRegister(Reg) && |
| 720 | TRI->isSubRegister(MOReg, Reg))) |
Evan Cheng | 9965aeb | 2007-02-23 01:04:26 +0000 | [diff] [blame] | 721 | if (!isKill || MO.isKill()) |
Evan Cheng | ec3ac31 | 2007-03-26 22:37:45 +0000 | [diff] [blame] | 722 | return i; |
Evan Cheng | 75c2194 | 2006-12-06 08:27:42 +0000 | [diff] [blame] | 723 | } |
Evan Cheng | ec3ac31 | 2007-03-26 22:37:45 +0000 | [diff] [blame] | 724 | return -1; |
Evan Cheng | 75c2194 | 2006-12-06 08:27:42 +0000 | [diff] [blame] | 725 | } |
Jakob Stoklund Olesen | 5d4c134 | 2010-05-19 20:36:22 +0000 | [diff] [blame] | 726 | |
Jakob Stoklund Olesen | 7d7f604 | 2010-05-21 20:02:01 +0000 | [diff] [blame] | 727 | /// readsWritesVirtualRegister - Return a pair of bools (reads, writes) |
| 728 | /// indicating if this instruction reads or writes Reg. This also considers |
| 729 | /// partial defines. |
| 730 | std::pair<bool,bool> |
| 731 | MachineInstr::readsWritesVirtualRegister(unsigned Reg, |
| 732 | SmallVectorImpl<unsigned> *Ops) const { |
| 733 | bool PartDef = false; // Partial redefine. |
| 734 | bool FullDef = false; // Full define. |
| 735 | bool Use = false; |
Jakob Stoklund Olesen | 5d4c134 | 2010-05-19 20:36:22 +0000 | [diff] [blame] | 736 | |
| 737 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 738 | const MachineOperand &MO = getOperand(i); |
| 739 | if (!MO.isReg() || MO.getReg() != Reg) |
| 740 | continue; |
Jakob Stoklund Olesen | 7d7f604 | 2010-05-21 20:02:01 +0000 | [diff] [blame] | 741 | if (Ops) |
| 742 | Ops->push_back(i); |
Jakob Stoklund Olesen | 5d4c134 | 2010-05-19 20:36:22 +0000 | [diff] [blame] | 743 | if (MO.isUse()) |
Jakob Stoklund Olesen | 7d7f604 | 2010-05-21 20:02:01 +0000 | [diff] [blame] | 744 | Use |= !MO.isUndef(); |
Jakob Stoklund Olesen | 9eb77bf | 2011-08-19 00:30:17 +0000 | [diff] [blame] | 745 | else if (MO.getSubReg() && !MO.isUndef()) |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 746 | // A partial def undef doesn't count as reading the register. |
Jakob Stoklund Olesen | 5d4c134 | 2010-05-19 20:36:22 +0000 | [diff] [blame] | 747 | PartDef = true; |
| 748 | else |
| 749 | FullDef = true; |
| 750 | } |
Jakob Stoklund Olesen | 7d7f604 | 2010-05-21 20:02:01 +0000 | [diff] [blame] | 751 | // A partial redefine uses Reg unless there is also a full define. |
| 752 | return std::make_pair(Use || (PartDef && !FullDef), PartDef || FullDef); |
Jakob Stoklund Olesen | 5d4c134 | 2010-05-19 20:36:22 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Evan Cheng | 6325446 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 755 | /// findRegisterDefOperandIdx() - Returns the operand index that is a def of |
Dan Gohman | 72a0bc1 | 2008-05-06 00:20:10 +0000 | [diff] [blame] | 756 | /// the specified register or -1 if it is not found. If isDead is true, defs |
| 757 | /// that are not dead are skipped. If TargetRegisterInfo is non-null, then it |
| 758 | /// also checks if there is a def of a super-register. |
Evan Cheng | 3858451 | 2010-05-21 20:53:24 +0000 | [diff] [blame] | 759 | int |
| 760 | MachineInstr::findRegisterDefOperandIdx(unsigned Reg, bool isDead, bool Overlap, |
| 761 | const TargetRegisterInfo *TRI) const { |
| 762 | bool isPhys = TargetRegisterInfo::isPhysicalRegister(Reg); |
Evan Cheng | f7ed82d | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 763 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
Evan Cheng | 6325446 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 764 | const MachineOperand &MO = getOperand(i); |
Jakob Stoklund Olesen | e7d3f44 | 2012-02-14 23:49:37 +0000 | [diff] [blame] | 765 | // Accept regmask operands when Overlap is set. |
| 766 | // Ignore them when looking for a specific def operand (Overlap == false). |
| 767 | if (isPhys && Overlap && MO.isRegMask() && MO.clobbersPhysReg(Reg)) |
| 768 | return i; |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 769 | if (!MO.isReg() || !MO.isDef()) |
Evan Cheng | 6325446 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 770 | continue; |
| 771 | unsigned MOReg = MO.getReg(); |
Evan Cheng | 3858451 | 2010-05-21 20:53:24 +0000 | [diff] [blame] | 772 | bool Found = (MOReg == Reg); |
| 773 | if (!Found && TRI && isPhys && |
| 774 | TargetRegisterInfo::isPhysicalRegister(MOReg)) { |
| 775 | if (Overlap) |
| 776 | Found = TRI->regsOverlap(MOReg, Reg); |
| 777 | else |
| 778 | Found = TRI->isSubRegister(MOReg, Reg); |
| 779 | } |
| 780 | if (Found && (!isDead || MO.isDead())) |
| 781 | return i; |
Evan Cheng | f7ed82d | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 782 | } |
Evan Cheng | 6325446 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 783 | return -1; |
Evan Cheng | f7ed82d | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 784 | } |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 785 | |
Evan Cheng | 5983bdb | 2007-05-29 18:35:22 +0000 | [diff] [blame] | 786 | /// findFirstPredOperandIdx() - Find the index of the first operand in the |
| 787 | /// operand list that is used to represent the predicate. It returns -1 if |
| 788 | /// none is found. |
| 789 | int MachineInstr::findFirstPredOperandIdx() const { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 790 | // Don't call MCID.findFirstPredOperandIdx() because this variant |
| 791 | // is sometimes called on an instruction that's not yet complete, and |
| 792 | // so the number of operands is less than the MCID indicates. In |
| 793 | // particular, the PTX target does this. |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 794 | const MCInstrDesc &MCID = getDesc(); |
| 795 | if (MCID.isPredicable()) { |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 796 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 797 | if (MCID.OpInfo[i].isPredicate()) |
Evan Cheng | 5983bdb | 2007-05-29 18:35:22 +0000 | [diff] [blame] | 798 | return i; |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Evan Cheng | 5983bdb | 2007-05-29 18:35:22 +0000 | [diff] [blame] | 801 | return -1; |
Evan Cheng | 4d728b0 | 2007-05-15 01:26:09 +0000 | [diff] [blame] | 802 | } |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 803 | |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 804 | // MachineOperand::TiedTo is 4 bits wide. |
| 805 | const unsigned TiedMax = 15; |
| 806 | |
| 807 | /// tieOperands - Mark operands at DefIdx and UseIdx as tied to each other. |
| 808 | /// |
| 809 | /// Use and def operands can be tied together, indicated by a non-zero TiedTo |
| 810 | /// field. TiedTo can have these values: |
| 811 | /// |
| 812 | /// 0: Operand is not tied to anything. |
| 813 | /// 1 to TiedMax-1: Tied to getOperand(TiedTo-1). |
| 814 | /// TiedMax: Tied to an operand >= TiedMax-1. |
| 815 | /// |
| 816 | /// The tied def must be one of the first TiedMax operands on a normal |
| 817 | /// instruction. INLINEASM instructions allow more tied defs. |
| 818 | /// |
Jakob Stoklund Olesen | 5c8eda0 | 2012-08-31 20:50:53 +0000 | [diff] [blame] | 819 | void MachineInstr::tieOperands(unsigned DefIdx, unsigned UseIdx) { |
Jakob Stoklund Olesen | 5c8eda0 | 2012-08-31 20:50:53 +0000 | [diff] [blame] | 820 | MachineOperand &DefMO = getOperand(DefIdx); |
| 821 | MachineOperand &UseMO = getOperand(UseIdx); |
| 822 | assert(DefMO.isDef() && "DefIdx must be a def operand"); |
| 823 | assert(UseMO.isUse() && "UseIdx must be a use operand"); |
| 824 | assert(!DefMO.isTied() && "Def is already tied to another use"); |
| 825 | assert(!UseMO.isTied() && "Use is already tied to another def"); |
| 826 | |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 827 | if (DefIdx < TiedMax) |
| 828 | UseMO.TiedTo = DefIdx + 1; |
| 829 | else { |
| 830 | // Inline asm can use the group descriptors to find tied operands, but on |
| 831 | // normal instruction, the tied def must be within the first TiedMax |
| 832 | // operands. |
| 833 | assert(isInlineAsm() && "DefIdx out of range"); |
| 834 | UseMO.TiedTo = TiedMax; |
| 835 | } |
| 836 | |
| 837 | // UseIdx can be out of range, we'll search for it in findTiedOperandIdx(). |
| 838 | DefMO.TiedTo = std::min(UseIdx + 1, TiedMax); |
Jakob Stoklund Olesen | 5c8eda0 | 2012-08-31 20:50:53 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Jakob Stoklund Olesen | 2b16664 | 2012-08-29 00:37:58 +0000 | [diff] [blame] | 841 | /// Given the index of a tied register operand, find the operand it is tied to. |
| 842 | /// Defs are tied to uses and vice versa. Returns the index of the tied operand |
| 843 | /// which must exist. |
| 844 | unsigned MachineInstr::findTiedOperandIdx(unsigned OpIdx) const { |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 845 | const MachineOperand &MO = getOperand(OpIdx); |
| 846 | assert(MO.isTied() && "Operand isn't tied"); |
Jakob Stoklund Olesen | 2b16664 | 2012-08-29 00:37:58 +0000 | [diff] [blame] | 847 | |
Jakob Stoklund Olesen | 0a09da8 | 2012-09-04 18:36:28 +0000 | [diff] [blame] | 848 | // Normally TiedTo is in range. |
| 849 | if (MO.TiedTo < TiedMax) |
| 850 | return MO.TiedTo - 1; |
| 851 | |
| 852 | // Uses on normal instructions can be out of range. |
| 853 | if (!isInlineAsm()) { |
| 854 | // Normal tied defs must be in the 0..TiedMax-1 range. |
| 855 | if (MO.isUse()) |
| 856 | return TiedMax - 1; |
| 857 | // MO is a def. Search for the tied use. |
| 858 | for (unsigned i = TiedMax - 1, e = getNumOperands(); i != e; ++i) { |
| 859 | const MachineOperand &UseMO = getOperand(i); |
| 860 | if (UseMO.isReg() && UseMO.isUse() && UseMO.TiedTo == OpIdx + 1) |
| 861 | return i; |
| 862 | } |
| 863 | llvm_unreachable("Can't find tied use"); |
| 864 | } |
| 865 | |
| 866 | // Now deal with inline asm by parsing the operand group descriptor flags. |
| 867 | // Find the beginning of each operand group. |
| 868 | SmallVector<unsigned, 8> GroupIdx; |
| 869 | unsigned OpIdxGroup = ~0u; |
| 870 | unsigned NumOps; |
| 871 | for (unsigned i = InlineAsm::MIOp_FirstOperand, e = getNumOperands(); i < e; |
| 872 | i += NumOps) { |
| 873 | const MachineOperand &FlagMO = getOperand(i); |
| 874 | assert(FlagMO.isImm() && "Invalid tied operand on inline asm"); |
| 875 | unsigned CurGroup = GroupIdx.size(); |
| 876 | GroupIdx.push_back(i); |
| 877 | NumOps = 1 + InlineAsm::getNumOperandRegisters(FlagMO.getImm()); |
| 878 | // OpIdx belongs to this operand group. |
| 879 | if (OpIdx > i && OpIdx < i + NumOps) |
| 880 | OpIdxGroup = CurGroup; |
| 881 | unsigned TiedGroup; |
| 882 | if (!InlineAsm::isUseOperandTiedToDef(FlagMO.getImm(), TiedGroup)) |
| 883 | continue; |
| 884 | // Operands in this group are tied to operands in TiedGroup which must be |
| 885 | // earlier. Find the number of operands between the two groups. |
| 886 | unsigned Delta = i - GroupIdx[TiedGroup]; |
| 887 | |
| 888 | // OpIdx is a use tied to TiedGroup. |
| 889 | if (OpIdxGroup == CurGroup) |
| 890 | return OpIdx - Delta; |
| 891 | |
| 892 | // OpIdx is a def tied to this use group. |
| 893 | if (OpIdxGroup == TiedGroup) |
| 894 | return OpIdx + Delta; |
| 895 | } |
| 896 | llvm_unreachable("Invalid tied operand on inline asm"); |
Jakob Stoklund Olesen | 2b16664 | 2012-08-29 00:37:58 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Dan Gohman | c90f51c | 2010-05-13 20:34:42 +0000 | [diff] [blame] | 899 | /// clearKillInfo - Clears kill flags on all operands. |
| 900 | /// |
| 901 | void MachineInstr::clearKillInfo() { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 902 | for (MachineOperand &MO : operands()) { |
Dan Gohman | c90f51c | 2010-05-13 20:34:42 +0000 | [diff] [blame] | 903 | if (MO.isReg() && MO.isUse()) |
| 904 | MO.setIsKill(false); |
| 905 | } |
| 906 | } |
| 907 | |
Jakob Stoklund Olesen | a8ad977 | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 908 | void MachineInstr::substituteRegister(unsigned FromReg, |
| 909 | unsigned ToReg, |
| 910 | unsigned SubIdx, |
| 911 | const TargetRegisterInfo &RegInfo) { |
| 912 | if (TargetRegisterInfo::isPhysicalRegister(ToReg)) { |
| 913 | if (SubIdx) |
| 914 | ToReg = RegInfo.getSubReg(ToReg, SubIdx); |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 915 | for (MachineOperand &MO : operands()) { |
Jakob Stoklund Olesen | a8ad977 | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 916 | if (!MO.isReg() || MO.getReg() != FromReg) |
| 917 | continue; |
| 918 | MO.substPhysReg(ToReg, RegInfo); |
| 919 | } |
| 920 | } else { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 921 | for (MachineOperand &MO : operands()) { |
Jakob Stoklund Olesen | a8ad977 | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 922 | if (!MO.isReg() || MO.getReg() != FromReg) |
| 923 | continue; |
| 924 | MO.substVirtReg(ToReg, SubIdx, RegInfo); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
Evan Cheng | 7d98a48 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 929 | /// isSafeToMove - Return true if it is safe to move this instruction. If |
| 930 | /// SawStore is set to true, it means that there is a store (or call) between |
| 931 | /// the instruction's location and its intended destination. |
Matthias Braun | 07066cc | 2015-05-19 21:22:20 +0000 | [diff] [blame] | 932 | bool MachineInstr::isSafeToMove(AliasAnalysis *AA, bool &SawStore) const { |
Evan Cheng | 399e110 | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 933 | // Ignore stuff that we obviously can't move. |
Jakob Stoklund Olesen | 813a109 | 2012-08-29 20:48:45 +0000 | [diff] [blame] | 934 | // |
| 935 | // Treat volatile loads as stores. This is not strictly necessary for |
Jakob Stoklund Olesen | d92e2bc | 2012-09-04 18:44:43 +0000 | [diff] [blame] | 936 | // volatiles, but it is required for atomic loads. It is not allowed to move |
Jakob Stoklund Olesen | 813a109 | 2012-08-29 20:48:45 +0000 | [diff] [blame] | 937 | // a load across an atomic load with Ordering > Monotonic. |
Alex Bradbury | fa18b9e | 2017-11-08 20:19:16 +0000 | [diff] [blame] | 938 | if (mayStore() || isCall() || isPHI() || |
Jakob Stoklund Olesen | cea3e77 | 2012-08-29 21:19:21 +0000 | [diff] [blame] | 939 | (mayLoad() && hasOrderedMemoryRef())) { |
Evan Cheng | 399e110 | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 940 | SawStore = true; |
| 941 | return false; |
| 942 | } |
Evan Cheng | 0638c20 | 2011-01-07 21:08:26 +0000 | [diff] [blame] | 943 | |
Rafael Espindola | b1f25f1 | 2014-03-07 06:08:31 +0000 | [diff] [blame] | 944 | if (isPosition() || isDebugValue() || isTerminator() || |
| 945 | hasUnmodeledSideEffects()) |
Evan Cheng | 399e110 | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 946 | return false; |
| 947 | |
| 948 | // See if this instruction does a load. If so, we have to guarantee that the |
| 949 | // loaded value doesn't change between the load and the its intended |
| 950 | // destination. The check for isInvariantLoad gives the targe the chance to |
| 951 | // classify the load as always returning a constant, e.g. a constant pool |
| 952 | // load. |
Justin Lebar | d98cf00 | 2016-09-10 01:03:20 +0000 | [diff] [blame] | 953 | if (mayLoad() && !isDereferenceableInvariantLoad(AA)) |
Evan Cheng | 399e110 | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 954 | // Otherwise, this is a real load. If there is a store between the load and |
Jakob Stoklund Olesen | 813a109 | 2012-08-29 20:48:45 +0000 | [diff] [blame] | 955 | // end of block, we can't move it. |
| 956 | return !SawStore; |
Dan Gohman | 7c59ed6 | 2008-09-24 00:06:15 +0000 | [diff] [blame] | 957 | |
Evan Cheng | 399e110 | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 958 | return true; |
| 959 | } |
| 960 | |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 961 | bool MachineInstr::mayAlias(AliasAnalysis *AA, MachineInstr &Other, |
| 962 | bool UseTBAA) { |
Justin Bogner | fdf9bf4 | 2017-10-10 23:50:49 +0000 | [diff] [blame] | 963 | const MachineFunction *MF = getMF(); |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 964 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
Balaram Makam | 42adadf | 2017-08-30 14:57:12 +0000 | [diff] [blame] | 965 | const MachineFrameInfo &MFI = MF->getFrameInfo(); |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 966 | |
| 967 | // If neither instruction stores to memory, they can't alias in any |
| 968 | // meaningful way, even if they read from the same address. |
| 969 | if (!mayStore() && !Other.mayStore()) |
| 970 | return false; |
| 971 | |
| 972 | // Let the target decide if memory accesses cannot possibly overlap. |
| 973 | if (TII->areMemAccessesTriviallyDisjoint(*this, Other, AA)) |
| 974 | return false; |
| 975 | |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 976 | // FIXME: Need to handle multiple memory operands to support all targets. |
| 977 | if (!hasOneMemOperand() || !Other.hasOneMemOperand()) |
| 978 | return true; |
| 979 | |
| 980 | MachineMemOperand *MMOa = *memoperands_begin(); |
| 981 | MachineMemOperand *MMOb = *Other.memoperands_begin(); |
| 982 | |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 983 | // The following interface to AA is fashioned after DAGCombiner::isAlias |
| 984 | // and operates with MachineMemOperand offset with some important |
| 985 | // assumptions: |
| 986 | // - LLVM fundamentally assumes flat address spaces. |
| 987 | // - MachineOperand offset can *only* result from legalization and |
| 988 | // cannot affect queries other than the trivial case of overlap |
| 989 | // checking. |
| 990 | // - These offsets never wrap and never step outside |
| 991 | // of allocated objects. |
| 992 | // - There should never be any negative offsets here. |
| 993 | // |
| 994 | // FIXME: Modify API to hide this math from "user" |
Balaram Makam | 42adadf | 2017-08-30 14:57:12 +0000 | [diff] [blame] | 995 | // Even before we go to AA we can reason locally about some |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 996 | // memory objects. It can save compile time, and possibly catch some |
| 997 | // corner cases not currently covered. |
| 998 | |
Balaram Makam | 42adadf | 2017-08-30 14:57:12 +0000 | [diff] [blame] | 999 | int64_t OffsetA = MMOa->getOffset(); |
| 1000 | int64_t OffsetB = MMOb->getOffset(); |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 1001 | |
Balaram Makam | 42adadf | 2017-08-30 14:57:12 +0000 | [diff] [blame] | 1002 | int64_t MinOffset = std::min(OffsetA, OffsetB); |
| 1003 | int64_t WidthA = MMOa->getSize(); |
| 1004 | int64_t WidthB = MMOb->getSize(); |
| 1005 | const Value *ValA = MMOa->getValue(); |
| 1006 | const Value *ValB = MMOb->getValue(); |
| 1007 | bool SameVal = (ValA && ValB && (ValA == ValB)); |
| 1008 | if (!SameVal) { |
| 1009 | const PseudoSourceValue *PSVa = MMOa->getPseudoValue(); |
| 1010 | const PseudoSourceValue *PSVb = MMOb->getPseudoValue(); |
| 1011 | if (PSVa && ValB && !PSVa->mayAlias(&MFI)) |
| 1012 | return false; |
| 1013 | if (PSVb && ValA && !PSVb->mayAlias(&MFI)) |
| 1014 | return false; |
| 1015 | if (PSVa && PSVb && (PSVa == PSVb)) |
| 1016 | SameVal = true; |
| 1017 | } |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 1018 | |
Balaram Makam | 42adadf | 2017-08-30 14:57:12 +0000 | [diff] [blame] | 1019 | if (SameVal) { |
| 1020 | int64_t MaxOffset = std::max(OffsetA, OffsetB); |
| 1021 | int64_t LowWidth = (MinOffset == OffsetA) ? WidthA : WidthB; |
| 1022 | return (MinOffset + LowWidth > MaxOffset); |
| 1023 | } |
| 1024 | |
| 1025 | if (!AA) |
| 1026 | return true; |
| 1027 | |
| 1028 | if (!ValA || !ValB) |
| 1029 | return true; |
| 1030 | |
| 1031 | assert((OffsetA >= 0) && "Negative MachineMemOperand offset"); |
| 1032 | assert((OffsetB >= 0) && "Negative MachineMemOperand offset"); |
| 1033 | |
| 1034 | int64_t Overlapa = WidthA + OffsetA - MinOffset; |
| 1035 | int64_t Overlapb = WidthB + OffsetB - MinOffset; |
| 1036 | |
| 1037 | AliasResult AAResult = AA->alias( |
| 1038 | MemoryLocation(ValA, Overlapa, |
| 1039 | UseTBAA ? MMOa->getAAInfo() : AAMDNodes()), |
| 1040 | MemoryLocation(ValB, Overlapb, |
| 1041 | UseTBAA ? MMOb->getAAInfo() : AAMDNodes())); |
Eli Friedman | 93f47e5 | 2017-03-09 23:33:36 +0000 | [diff] [blame] | 1042 | |
| 1043 | return (AAResult != NoAlias); |
| 1044 | } |
| 1045 | |
Jakob Stoklund Olesen | cea3e77 | 2012-08-29 21:19:21 +0000 | [diff] [blame] | 1046 | /// hasOrderedMemoryRef - Return true if this instruction may have an ordered |
| 1047 | /// or volatile memory reference, or if the information describing the memory |
| 1048 | /// reference is not available. Return false if it is known to have no ordered |
| 1049 | /// memory references. |
| 1050 | bool MachineInstr::hasOrderedMemoryRef() const { |
Dan Gohman | 7c59ed6 | 2008-09-24 00:06:15 +0000 | [diff] [blame] | 1051 | // An instruction known never to access memory won't have a volatile access. |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 1052 | if (!mayStore() && |
| 1053 | !mayLoad() && |
| 1054 | !isCall() && |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1055 | !hasUnmodeledSideEffects()) |
Dan Gohman | 7c59ed6 | 2008-09-24 00:06:15 +0000 | [diff] [blame] | 1056 | return false; |
| 1057 | |
| 1058 | // Otherwise, if the instruction has no memory reference information, |
| 1059 | // conservatively assume it wasn't preserved. |
| 1060 | if (memoperands_empty()) |
| 1061 | return true; |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 1062 | |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1063 | // Check if any of our memory operands are ordered. |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 1064 | return llvm::any_of(memoperands(), [](const MachineMemOperand *MMO) { |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1065 | return !MMO->isUnordered(); |
| 1066 | }); |
Dan Gohman | 7c59ed6 | 2008-09-24 00:06:15 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Justin Lebar | d98cf00 | 2016-09-10 01:03:20 +0000 | [diff] [blame] | 1069 | /// isDereferenceableInvariantLoad - Return true if this instruction will never |
| 1070 | /// trap and is loading from a location whose value is invariant across a run of |
| 1071 | /// this function. |
| 1072 | bool MachineInstr::isDereferenceableInvariantLoad(AliasAnalysis *AA) const { |
Dan Gohman | be8137b | 2009-10-07 17:38:06 +0000 | [diff] [blame] | 1073 | // If the instruction doesn't load at all, it isn't an invariant load. |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 1074 | if (!mayLoad()) |
Dan Gohman | be8137b | 2009-10-07 17:38:06 +0000 | [diff] [blame] | 1075 | return false; |
| 1076 | |
| 1077 | // If the instruction has lost its memoperands, conservatively assume that |
| 1078 | // it may not be an invariant load. |
| 1079 | if (memoperands_empty()) |
| 1080 | return false; |
| 1081 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1082 | const MachineFrameInfo &MFI = getParent()->getParent()->getFrameInfo(); |
Dan Gohman | be8137b | 2009-10-07 17:38:06 +0000 | [diff] [blame] | 1083 | |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1084 | for (MachineMemOperand *MMO : memoperands()) { |
| 1085 | if (MMO->isVolatile()) return false; |
| 1086 | if (MMO->isStore()) return false; |
Justin Lebar | adbf09e | 2016-09-11 01:38:58 +0000 | [diff] [blame] | 1087 | if (MMO->isInvariant() && MMO->isDereferenceable()) |
| 1088 | continue; |
Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 1089 | |
| 1090 | // A load from a constant PseudoSourceValue is invariant. |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1091 | if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1092 | if (PSV->isConstant(&MFI)) |
Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 1093 | continue; |
| 1094 | |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1095 | if (const Value *V = MMO->getValue()) { |
Dan Gohman | be8137b | 2009-10-07 17:38:06 +0000 | [diff] [blame] | 1096 | // If we have an AliasAnalysis, ask it whether the memory is constant. |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 1097 | if (AA && |
| 1098 | AA->pointsToConstantMemory( |
Justin Lebar | dede81e | 2016-07-13 22:35:19 +0000 | [diff] [blame] | 1099 | MemoryLocation(V, MMO->getSize(), MMO->getAAInfo()))) |
Dan Gohman | be8137b | 2009-10-07 17:38:06 +0000 | [diff] [blame] | 1100 | continue; |
| 1101 | } |
| 1102 | |
| 1103 | // Otherwise assume conservatively. |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | // Everything checks out. |
| 1108 | return true; |
| 1109 | } |
| 1110 | |
Evan Cheng | 7145382 | 2009-12-03 02:31:43 +0000 | [diff] [blame] | 1111 | /// isConstantValuePHI - If the specified instruction is a PHI that always |
| 1112 | /// merges together the same virtual register, return the register, otherwise |
| 1113 | /// return 0. |
| 1114 | unsigned MachineInstr::isConstantValuePHI() const { |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1115 | if (!isPHI()) |
Evan Cheng | 7145382 | 2009-12-03 02:31:43 +0000 | [diff] [blame] | 1116 | return 0; |
Evan Cheng | 5c668a2 | 2009-12-07 23:10:34 +0000 | [diff] [blame] | 1117 | assert(getNumOperands() >= 3 && |
| 1118 | "It's illegal to have a PHI without source operands"); |
Evan Cheng | 7145382 | 2009-12-03 02:31:43 +0000 | [diff] [blame] | 1119 | |
| 1120 | unsigned Reg = getOperand(1).getReg(); |
| 1121 | for (unsigned i = 3, e = getNumOperands(); i < e; i += 2) |
| 1122 | if (getOperand(i).getReg() != Reg) |
| 1123 | return 0; |
| 1124 | return Reg; |
| 1125 | } |
| 1126 | |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1127 | bool MachineInstr::hasUnmodeledSideEffects() const { |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 1128 | if (hasProperty(MCID::UnmodeledSideEffects)) |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1129 | return true; |
| 1130 | if (isInlineAsm()) { |
| 1131 | unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); |
| 1132 | if (ExtraInfo & InlineAsm::Extra_HasSideEffects) |
| 1133 | return true; |
| 1134 | } |
| 1135 | |
| 1136 | return false; |
| 1137 | } |
| 1138 | |
Michael Kuperstein | bc7f99a | 2015-08-12 10:14:58 +0000 | [diff] [blame] | 1139 | bool MachineInstr::isLoadFoldBarrier() const { |
| 1140 | return mayStore() || isCall() || hasUnmodeledSideEffects(); |
| 1141 | } |
| 1142 | |
Evan Cheng | b083c47 | 2010-04-08 20:02:37 +0000 | [diff] [blame] | 1143 | /// allDefsAreDead - Return true if all the defs of this instruction are dead. |
| 1144 | /// |
| 1145 | bool MachineInstr::allDefsAreDead() const { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1146 | for (const MachineOperand &MO : operands()) { |
Evan Cheng | b083c47 | 2010-04-08 20:02:37 +0000 | [diff] [blame] | 1147 | if (!MO.isReg() || MO.isUse()) |
| 1148 | continue; |
| 1149 | if (!MO.isDead()) |
| 1150 | return false; |
| 1151 | } |
| 1152 | return true; |
| 1153 | } |
| 1154 | |
Evan Cheng | 21eedfb | 2010-10-22 21:49:09 +0000 | [diff] [blame] | 1155 | /// copyImplicitOps - Copy implicit register operands from specified |
| 1156 | /// instruction to this instruction. |
Jakob Stoklund Olesen | 33f5d14 | 2012-12-20 22:54:02 +0000 | [diff] [blame] | 1157 | void MachineInstr::copyImplicitOps(MachineFunction &MF, |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 1158 | const MachineInstr &MI) { |
| 1159 | for (unsigned i = MI.getDesc().getNumOperands(), e = MI.getNumOperands(); |
Evan Cheng | 21eedfb | 2010-10-22 21:49:09 +0000 | [diff] [blame] | 1160 | i != e; ++i) { |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 1161 | const MachineOperand &MO = MI.getOperand(i); |
Lang Hames | 7c8189c | 2014-03-17 01:22:54 +0000 | [diff] [blame] | 1162 | if ((MO.isReg() && MO.isImplicit()) || MO.isRegMask()) |
Jakob Stoklund Olesen | 33f5d14 | 2012-12-20 22:54:02 +0000 | [diff] [blame] | 1163 | addOperand(MF, MO); |
Evan Cheng | 21eedfb | 2010-10-22 21:49:09 +0000 | [diff] [blame] | 1164 | } |
| 1165 | } |
| 1166 | |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1167 | bool MachineInstr::hasComplexRegisterTies() const { |
| 1168 | const MCInstrDesc &MCID = getDesc(); |
| 1169 | for (unsigned I = 0, E = getNumOperands(); I < E; ++I) { |
| 1170 | const auto &Operand = getOperand(I); |
| 1171 | if (!Operand.isReg() || Operand.isDef()) |
| 1172 | // Ignore the defined registers as MCID marks only the uses as tied. |
| 1173 | continue; |
| 1174 | int ExpectedTiedIdx = MCID.getOperandConstraint(I, MCOI::TIED_TO); |
| 1175 | int TiedIdx = Operand.isTied() ? int(findTiedOperandIdx(I)) : -1; |
| 1176 | if (ExpectedTiedIdx != TiedIdx) |
| 1177 | return true; |
| 1178 | } |
| 1179 | return false; |
| 1180 | } |
| 1181 | |
| 1182 | LLT MachineInstr::getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes, |
| 1183 | const MachineRegisterInfo &MRI) const { |
| 1184 | const MachineOperand &Op = getOperand(OpIdx); |
| 1185 | if (!Op.isReg()) |
| 1186 | return LLT{}; |
| 1187 | |
| 1188 | if (isVariadic() || OpIdx >= getNumExplicitOperands()) |
| 1189 | return MRI.getType(Op.getReg()); |
| 1190 | |
| 1191 | auto &OpInfo = getDesc().OpInfo[OpIdx]; |
| 1192 | if (!OpInfo.isGenericType()) |
| 1193 | return MRI.getType(Op.getReg()); |
| 1194 | |
| 1195 | if (PrintedTypes[OpInfo.getGenericTypeIndex()]) |
| 1196 | return LLT{}; |
| 1197 | |
| 1198 | PrintedTypes.set(OpInfo.getGenericTypeIndex()); |
| 1199 | return MRI.getType(Op.getReg()); |
| 1200 | } |
| 1201 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 1202 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Matthias Braun | a4976c6 | 2017-01-29 18:20:42 +0000 | [diff] [blame] | 1203 | LLVM_DUMP_METHOD void MachineInstr::dump() const { |
Sebastian Pop | 7779484 | 2016-12-21 01:41:12 +0000 | [diff] [blame] | 1204 | dbgs() << " "; |
Matthias Braun | a4976c6 | 2017-01-29 18:20:42 +0000 | [diff] [blame] | 1205 | print(dbgs()); |
Mon P Wang | dfcc1ff | 2008-10-10 01:43:55 +0000 | [diff] [blame] | 1206 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 1207 | #endif |
Mon P Wang | dfcc1ff | 2008-10-10 01:43:55 +0000 | [diff] [blame] | 1208 | |
Ahmed Bougacha | 4319224 | 2017-02-23 19:17:31 +0000 | [diff] [blame] | 1209 | void MachineInstr::print(raw_ostream &OS, bool SkipOpers, bool SkipDebugLoc, |
Sebastian Pop | 7779484 | 2016-12-21 01:41:12 +0000 | [diff] [blame] | 1210 | const TargetInstrInfo *TII) const { |
Duncan P. N. Exon Smith | c037452 | 2015-06-26 23:18:44 +0000 | [diff] [blame] | 1211 | const Module *M = nullptr; |
| 1212 | if (const MachineBasicBlock *MBB = getParent()) |
| 1213 | if (const MachineFunction *MF = MBB->getParent()) |
| 1214 | M = MF->getFunction()->getParent(); |
| 1215 | |
| 1216 | ModuleSlotTracker MST(M); |
Ahmed Bougacha | 4319224 | 2017-02-23 19:17:31 +0000 | [diff] [blame] | 1217 | print(OS, MST, SkipOpers, SkipDebugLoc, TII); |
Duncan P. N. Exon Smith | f48e982 | 2015-06-26 22:06:47 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, |
Ahmed Bougacha | 4319224 | 2017-02-23 19:17:31 +0000 | [diff] [blame] | 1221 | bool SkipOpers, bool SkipDebugLoc, |
| 1222 | const TargetInstrInfo *TII) const { |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1223 | // We can be a bit tidier if we know the MachineFunction. |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 1224 | const MachineFunction *MF = nullptr; |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1225 | const TargetRegisterInfo *TRI = nullptr; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 1226 | const MachineRegisterInfo *MRI = nullptr; |
Tim Northover | 6b3bd61 | 2016-07-29 20:32:59 +0000 | [diff] [blame] | 1227 | const TargetIntrinsicInfo *IntrinsicInfo = nullptr; |
| 1228 | |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1229 | if (const MachineBasicBlock *MBB = getParent()) { |
| 1230 | MF = MBB->getParent(); |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1231 | if (MF) { |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1232 | MRI = &MF->getRegInfo(); |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1233 | TRI = MF->getSubtarget().getRegisterInfo(); |
Sebastian Pop | 7779484 | 2016-12-21 01:41:12 +0000 | [diff] [blame] | 1234 | if (!TII) |
| 1235 | TII = MF->getSubtarget().getInstrInfo(); |
Tim Northover | 6b3bd61 | 2016-07-29 20:32:59 +0000 | [diff] [blame] | 1236 | IntrinsicInfo = MF->getTarget().getIntrinsicInfo(); |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1237 | } |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1238 | } |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1239 | |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1240 | // Save a list of virtual registers. |
| 1241 | SmallVector<unsigned, 8> VirtRegs; |
| 1242 | |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1243 | SmallBitVector PrintedTypes(8); |
| 1244 | bool ShouldPrintRegisterTies = hasComplexRegisterTies(); |
| 1245 | auto getTiedOperandIdx = [&](unsigned OpIdx) { |
| 1246 | if (!ShouldPrintRegisterTies) |
| 1247 | return 0U; |
| 1248 | const MachineOperand &MO = getOperand(OpIdx); |
| 1249 | if (MO.isReg() && MO.isTied() && !MO.isDef()) |
| 1250 | return findTiedOperandIdx(OpIdx); |
| 1251 | return 0U; |
| 1252 | }; |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1253 | // Print explicitly defined operands on the left of an assignment syntax. |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1254 | unsigned StartOp = 0, e = getNumOperands(); |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1255 | for (; StartOp < e && getOperand(StartOp).isReg() && |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1256 | getOperand(StartOp).isDef() && !getOperand(StartOp).isImplicit(); |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1257 | ++StartOp) { |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1258 | if (StartOp != 0) |
| 1259 | OS << ", "; |
| 1260 | LLT TypeToPrint = MRI ? getTypeToPrint(StartOp, PrintedTypes, *MRI) : LLT{}; |
| 1261 | unsigned TiedOperandIdx = getTiedOperandIdx(StartOp); |
| 1262 | getOperand(StartOp).print(OS, MST, TypeToPrint, /*PrintDef=*/false, |
| 1263 | ShouldPrintRegisterTies, TiedOperandIdx, TRI, |
| 1264 | IntrinsicInfo); |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1265 | unsigned Reg = getOperand(StartOp).getReg(); |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1266 | if (TargetRegisterInfo::isVirtualRegister(Reg)) |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1267 | VirtRegs.push_back(Reg); |
Chris Lattner | ac6e974 | 2002-10-30 01:55:38 +0000 | [diff] [blame] | 1268 | } |
Tanya Lattner | 23dbc81 | 2004-06-25 00:13:11 +0000 | [diff] [blame] | 1269 | |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1270 | if (StartOp != 0) |
| 1271 | OS << " = "; |
| 1272 | |
| 1273 | // Print the opcode name. |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1274 | if (TII) |
| 1275 | OS << TII->getName(getOpcode()); |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 1276 | else |
| 1277 | OS << "UNKNOWN"; |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1278 | |
Andrew Trick | b36388a | 2013-01-25 07:45:25 +0000 | [diff] [blame] | 1279 | if (SkipOpers) |
| 1280 | return; |
| 1281 | |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1282 | // Print the rest of the operands. |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1283 | bool FirstOp = true; |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1284 | unsigned AsmDescOp = ~0u; |
| 1285 | unsigned AsmOpCount = 0; |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1286 | |
Jakob Stoklund Olesen | 2318d1e | 2011-09-29 00:40:51 +0000 | [diff] [blame] | 1287 | if (isInlineAsm() && e >= InlineAsm::MIOp_FirstOperand) { |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1288 | // Print asm string. |
| 1289 | OS << " "; |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1290 | const unsigned OpIdx = InlineAsm::MIOp_AsmString; |
| 1291 | LLT TypeToPrint = MRI ? getTypeToPrint(OpIdx, PrintedTypes, *MRI) : LLT{}; |
Francis Visoiu Mistrih | e6fc3ce | 2017-12-07 17:12:30 +0000 | [diff] [blame] | 1292 | unsigned TiedOperandIdx = getTiedOperandIdx(OpIdx); |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1293 | getOperand(OpIdx).print(OS, MST, TypeToPrint, /*PrintDef=*/true, |
| 1294 | ShouldPrintRegisterTies, TiedOperandIdx, TRI, |
| 1295 | IntrinsicInfo); |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1296 | |
Eric Christopher | 0cb6fd9 | 2013-01-11 18:12:39 +0000 | [diff] [blame] | 1297 | // Print HasSideEffects, MayLoad, MayStore, IsAlignStack |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1298 | unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); |
| 1299 | if (ExtraInfo & InlineAsm::Extra_HasSideEffects) |
| 1300 | OS << " [sideeffect]"; |
Eric Christopher | 0cb6fd9 | 2013-01-11 18:12:39 +0000 | [diff] [blame] | 1301 | if (ExtraInfo & InlineAsm::Extra_MayLoad) |
| 1302 | OS << " [mayload]"; |
| 1303 | if (ExtraInfo & InlineAsm::Extra_MayStore) |
| 1304 | OS << " [maystore]"; |
Wei Ding | 0526e7f | 2016-06-22 18:51:08 +0000 | [diff] [blame] | 1305 | if (ExtraInfo & InlineAsm::Extra_IsConvergent) |
| 1306 | OS << " [isconvergent]"; |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1307 | if (ExtraInfo & InlineAsm::Extra_IsAlignStack) |
| 1308 | OS << " [alignstack]"; |
Chad Rosier | cbd2a19 | 2012-09-05 22:17:43 +0000 | [diff] [blame] | 1309 | if (getInlineAsmDialect() == InlineAsm::AD_ATT) |
Chad Rosier | 994f404 | 2012-09-05 21:00:58 +0000 | [diff] [blame] | 1310 | OS << " [attdialect]"; |
Chad Rosier | cbd2a19 | 2012-09-05 22:17:43 +0000 | [diff] [blame] | 1311 | if (getInlineAsmDialect() == InlineAsm::AD_Intel) |
Chad Rosier | 994f404 | 2012-09-05 21:00:58 +0000 | [diff] [blame] | 1312 | OS << " [inteldialect]"; |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1313 | |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1314 | StartOp = AsmDescOp = InlineAsm::MIOp_FirstOperand; |
Evan Cheng | 6eb516d | 2011-01-07 23:50:32 +0000 | [diff] [blame] | 1315 | FirstOp = false; |
| 1316 | } |
| 1317 | |
Chris Lattner | ac6e974 | 2002-10-30 01:55:38 +0000 | [diff] [blame] | 1318 | for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) { |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1319 | const MachineOperand &MO = getOperand(i); |
| 1320 | |
Jakob Stoklund Olesen | 2fb5b31 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1321 | if (MO.isReg() && TargetRegisterInfo::isVirtualRegister(MO.getReg())) |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1322 | VirtRegs.push_back(MO.getReg()); |
| 1323 | |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1324 | if (FirstOp) FirstOp = false; else OS << ","; |
Chris Lattner | ac6e974 | 2002-10-30 01:55:38 +0000 | [diff] [blame] | 1325 | OS << " "; |
Jakob Stoklund Olesen | e8800b8 | 2010-01-19 22:08:34 +0000 | [diff] [blame] | 1326 | if (i < getDesc().NumOperands) { |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1327 | const MCOperandInfo &MCOI = getDesc().OpInfo[i]; |
| 1328 | if (MCOI.isPredicate()) |
Jakob Stoklund Olesen | e8800b8 | 2010-01-19 22:08:34 +0000 | [diff] [blame] | 1329 | OS << "pred:"; |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1330 | if (MCOI.isOptionalDef()) |
Jakob Stoklund Olesen | e8800b8 | 2010-01-19 22:08:34 +0000 | [diff] [blame] | 1331 | OS << "opt:"; |
| 1332 | } |
Evan Cheng | d4d1a51 | 2010-04-28 20:03:13 +0000 | [diff] [blame] | 1333 | if (isDebugValue() && MO.isMetadata()) { |
| 1334 | // Pretty print DBG_VALUE instructions. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1335 | auto *DIV = dyn_cast<DILocalVariable>(MO.getMetadata()); |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 1336 | if (DIV && !DIV->getName().empty()) |
| 1337 | OS << "!\"" << DIV->getName() << '\"'; |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1338 | else { |
| 1339 | LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; |
Francis Visoiu Mistrih | e6fc3ce | 2017-12-07 17:12:30 +0000 | [diff] [blame] | 1340 | unsigned TiedOperandIdx = getTiedOperandIdx(i); |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1341 | MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, |
| 1342 | ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); |
| 1343 | } |
Matthias Braun | a374308 | 2017-01-09 21:38:10 +0000 | [diff] [blame] | 1344 | } else if (TRI && (isInsertSubreg() || isRegSequence() || |
| 1345 | (isSubregToReg() && i == 3)) && MO.isImm()) { |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1346 | OS << TRI->getSubRegIndexName(MO.getImm()); |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1347 | } else if (i == AsmDescOp && MO.isImm()) { |
| 1348 | // Pretty print the inline asm operand descriptor. |
| 1349 | OS << '$' << AsmOpCount++; |
| 1350 | unsigned Flag = MO.getImm(); |
| 1351 | switch (InlineAsm::getKind(Flag)) { |
Jakob Stoklund Olesen | 24abd9d | 2011-10-12 23:37:29 +0000 | [diff] [blame] | 1352 | case InlineAsm::Kind_RegUse: OS << ":[reguse"; break; |
| 1353 | case InlineAsm::Kind_RegDef: OS << ":[regdef"; break; |
| 1354 | case InlineAsm::Kind_RegDefEarlyClobber: OS << ":[regdef-ec"; break; |
| 1355 | case InlineAsm::Kind_Clobber: OS << ":[clobber"; break; |
| 1356 | case InlineAsm::Kind_Imm: OS << ":[imm"; break; |
| 1357 | case InlineAsm::Kind_Mem: OS << ":[mem"; break; |
| 1358 | default: OS << ":[??" << InlineAsm::getKind(Flag); break; |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Jakob Stoklund Olesen | 24abd9d | 2011-10-12 23:37:29 +0000 | [diff] [blame] | 1361 | unsigned RCID = 0; |
Simon Dardis | d32a2d3 | 2016-07-18 13:17:31 +0000 | [diff] [blame] | 1362 | if (!InlineAsm::isImmKind(Flag) && !InlineAsm::isMemKind(Flag) && |
| 1363 | InlineAsm::hasRegClassConstraint(Flag, RCID)) { |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 1364 | if (TRI) { |
| 1365 | OS << ':' << TRI->getRegClassName(TRI->getRegClass(RCID)); |
Craig Topper | cf0444b | 2014-11-17 05:50:14 +0000 | [diff] [blame] | 1366 | } else |
Jakob Stoklund Olesen | 24abd9d | 2011-10-12 23:37:29 +0000 | [diff] [blame] | 1367 | OS << ":RC" << RCID; |
Nick Lewycky | 8488225 | 2011-10-13 00:54:59 +0000 | [diff] [blame] | 1368 | } |
Jakob Stoklund Olesen | 24abd9d | 2011-10-12 23:37:29 +0000 | [diff] [blame] | 1369 | |
Simon Dardis | d32a2d3 | 2016-07-18 13:17:31 +0000 | [diff] [blame] | 1370 | if (InlineAsm::isMemKind(Flag)) { |
| 1371 | unsigned MCID = InlineAsm::getMemoryConstraintID(Flag); |
| 1372 | switch (MCID) { |
| 1373 | case InlineAsm::Constraint_es: OS << ":es"; break; |
| 1374 | case InlineAsm::Constraint_i: OS << ":i"; break; |
| 1375 | case InlineAsm::Constraint_m: OS << ":m"; break; |
| 1376 | case InlineAsm::Constraint_o: OS << ":o"; break; |
| 1377 | case InlineAsm::Constraint_v: OS << ":v"; break; |
| 1378 | case InlineAsm::Constraint_Q: OS << ":Q"; break; |
| 1379 | case InlineAsm::Constraint_R: OS << ":R"; break; |
| 1380 | case InlineAsm::Constraint_S: OS << ":S"; break; |
| 1381 | case InlineAsm::Constraint_T: OS << ":T"; break; |
| 1382 | case InlineAsm::Constraint_Um: OS << ":Um"; break; |
| 1383 | case InlineAsm::Constraint_Un: OS << ":Un"; break; |
| 1384 | case InlineAsm::Constraint_Uq: OS << ":Uq"; break; |
| 1385 | case InlineAsm::Constraint_Us: OS << ":Us"; break; |
| 1386 | case InlineAsm::Constraint_Ut: OS << ":Ut"; break; |
| 1387 | case InlineAsm::Constraint_Uv: OS << ":Uv"; break; |
| 1388 | case InlineAsm::Constraint_Uy: OS << ":Uy"; break; |
| 1389 | case InlineAsm::Constraint_X: OS << ":X"; break; |
| 1390 | case InlineAsm::Constraint_Z: OS << ":Z"; break; |
| 1391 | case InlineAsm::Constraint_ZC: OS << ":ZC"; break; |
| 1392 | case InlineAsm::Constraint_Zy: OS << ":Zy"; break; |
| 1393 | default: OS << ":?"; break; |
| 1394 | } |
| 1395 | } |
| 1396 | |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1397 | unsigned TiedTo = 0; |
| 1398 | if (InlineAsm::isUseOperandTiedToDef(Flag, TiedTo)) |
Jakob Stoklund Olesen | 24abd9d | 2011-10-12 23:37:29 +0000 | [diff] [blame] | 1399 | OS << " tiedto:$" << TiedTo; |
| 1400 | |
| 1401 | OS << ']'; |
Jakob Stoklund Olesen | 6b356b1 | 2011-06-27 04:08:29 +0000 | [diff] [blame] | 1402 | |
| 1403 | // Compute the index of the next operand descriptor. |
| 1404 | AsmDescOp += 1 + InlineAsm::getNumOperandRegisters(Flag); |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1405 | } else { |
| 1406 | LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; |
Francis Visoiu Mistrih | e6fc3ce | 2017-12-07 17:12:30 +0000 | [diff] [blame] | 1407 | unsigned TiedOperandIdx = getTiedOperandIdx(i); |
Francis Visoiu Mistrih | 440f69c | 2017-12-08 22:53:21 +0000 | [diff] [blame] | 1408 | if (MO.isImm() && isOperandSubregIdx(i)) |
| 1409 | MachineOperand::printSubregIdx(OS, MO.getImm(), TRI); |
| 1410 | else |
| 1411 | MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, |
| 1412 | ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 1413 | } |
Dan Gohman | 2745d19 | 2009-11-09 19:38:45 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1416 | bool HaveSemi = false; |
Michael Kuperstein | 098cd9f | 2015-09-16 11:18:25 +0000 | [diff] [blame] | 1417 | const unsigned PrintableFlags = FrameSetup | FrameDestroy; |
Jakob Stoklund Olesen | 6922e9c | 2013-01-09 18:35:09 +0000 | [diff] [blame] | 1418 | if (Flags & PrintableFlags) { |
Yaron Keren | c47c6ac | 2016-01-02 13:40:36 +0000 | [diff] [blame] | 1419 | if (!HaveSemi) { |
| 1420 | OS << ";"; |
| 1421 | HaveSemi = true; |
| 1422 | } |
Anton Korobeynikov | 65cff414 | 2011-03-05 18:43:04 +0000 | [diff] [blame] | 1423 | OS << " flags: "; |
| 1424 | |
| 1425 | if (Flags & FrameSetup) |
| 1426 | OS << "FrameSetup"; |
Michael Kuperstein | 098cd9f | 2015-09-16 11:18:25 +0000 | [diff] [blame] | 1427 | |
| 1428 | if (Flags & FrameDestroy) |
| 1429 | OS << "FrameDestroy"; |
Anton Korobeynikov | 65cff414 | 2011-03-05 18:43:04 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 1432 | if (!memoperands_empty()) { |
Yaron Keren | c47c6ac | 2016-01-02 13:40:36 +0000 | [diff] [blame] | 1433 | if (!HaveSemi) { |
| 1434 | OS << ";"; |
| 1435 | HaveSemi = true; |
| 1436 | } |
Dan Gohman | 34341e6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1437 | |
| 1438 | OS << " mem:"; |
Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 1439 | for (mmo_iterator i = memoperands_begin(), e = memoperands_end(); |
| 1440 | i != e; ++i) { |
Duncan P. N. Exon Smith | f48e982 | 2015-06-26 22:06:47 +0000 | [diff] [blame] | 1441 | (*i)->print(OS, MST); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 1442 | if (std::next(i) != e) |
Dan Gohman | c0353bf | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 1443 | OS << " "; |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1447 | // Print the regclass of any virtual registers encountered. |
| 1448 | if (MRI && !VirtRegs.empty()) { |
Yaron Keren | c47c6ac | 2016-01-02 13:40:36 +0000 | [diff] [blame] | 1449 | if (!HaveSemi) { |
| 1450 | OS << ";"; |
| 1451 | HaveSemi = true; |
| 1452 | } |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1453 | for (unsigned i = 0; i != VirtRegs.size(); ++i) { |
Quentin Colombet | 03c4196 | 2016-04-07 23:18:11 +0000 | [diff] [blame] | 1454 | const RegClassOrRegBank &RC = MRI->getRegClassOrRegBank(VirtRegs[i]); |
Quentin Colombet | e1494c3 | 2016-02-11 00:19:17 +0000 | [diff] [blame] | 1455 | if (!RC) |
| 1456 | continue; |
Quentin Colombet | 03c4196 | 2016-04-07 23:18:11 +0000 | [diff] [blame] | 1457 | // Generic virtual registers do not have register classes. |
| 1458 | if (RC.is<const RegisterBank *>()) |
| 1459 | OS << " " << RC.get<const RegisterBank *>()->getName(); |
| 1460 | else |
| 1461 | OS << " " |
| 1462 | << TRI->getRegClassName(RC.get<const TargetRegisterClass *>()); |
Francis Visoiu Mistrih | 9d419d3 | 2017-11-28 12:42:37 +0000 | [diff] [blame] | 1463 | OS << ':' << printReg(VirtRegs[i]); |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1464 | for (unsigned j = i+1; j != VirtRegs.size();) { |
Quentin Colombet | 03c4196 | 2016-04-07 23:18:11 +0000 | [diff] [blame] | 1465 | if (MRI->getRegClassOrRegBank(VirtRegs[j]) != RC) { |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1466 | ++j; |
| 1467 | continue; |
| 1468 | } |
| 1469 | if (VirtRegs[i] != VirtRegs[j]) |
Francis Visoiu Mistrih | 9d419d3 | 2017-11-28 12:42:37 +0000 | [diff] [blame] | 1470 | OS << "," << printReg(VirtRegs[j]); |
Jakob Stoklund Olesen | 0ff2c11 | 2010-07-28 18:35:46 +0000 | [diff] [blame] | 1471 | VirtRegs.erase(VirtRegs.begin()+j); |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | |
Anton Korobeynikov | 65cff414 | 2011-03-05 18:43:04 +0000 | [diff] [blame] | 1476 | // Print debug location information. |
Duncan P. N. Exon Smith | c5bd3e0 | 2015-04-03 16:23:04 +0000 | [diff] [blame] | 1477 | if (isDebugValue() && getOperand(e - 2).isMetadata()) { |
Yaron Keren | c47c6ac | 2016-01-02 13:40:36 +0000 | [diff] [blame] | 1478 | if (!HaveSemi) |
| 1479 | OS << ";"; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1480 | auto *DV = cast<DILocalVariable>(getOperand(e - 2).getMetadata()); |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 1481 | OS << " line no:" << DV->getLine(); |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 1482 | if (auto *InlinedAt = debugLoc->getInlinedAt()) { |
Duncan P. N. Exon Smith | 9dffcd0 | 2015-03-30 19:14:47 +0000 | [diff] [blame] | 1483 | DebugLoc InlinedAtDL(InlinedAt); |
| 1484 | if (InlinedAtDL && MF) { |
Devang Patel | d61b1d5 | 2011-08-04 20:44:26 +0000 | [diff] [blame] | 1485 | OS << " inlined @[ "; |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 1486 | InlinedAtDL.print(OS); |
Devang Patel | d61b1d5 | 2011-08-04 20:44:26 +0000 | [diff] [blame] | 1487 | OS << " ]"; |
| 1488 | } |
| 1489 | } |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1490 | if (isIndirectDebugValue()) |
| 1491 | OS << " indirect"; |
Ahmed Bougacha | 97119d4 | 2017-02-23 21:05:29 +0000 | [diff] [blame] | 1492 | } else if (SkipDebugLoc) { |
| 1493 | return; |
| 1494 | } else if (debugLoc && MF) { |
Yaron Keren | c47c6ac | 2016-01-02 13:40:36 +0000 | [diff] [blame] | 1495 | if (!HaveSemi) |
| 1496 | OS << ";"; |
Dan Gohman | 2e3f187 | 2009-11-23 21:29:08 +0000 | [diff] [blame] | 1497 | OS << " dbg:"; |
Eric Christopher | b9f0009 | 2015-02-26 23:32:17 +0000 | [diff] [blame] | 1498 | debugLoc.print(OS); |
Bill Wendling | 1a0a3d0 | 2009-02-19 21:44:55 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Anton Korobeynikov | 65cff414 | 2011-03-05 18:43:04 +0000 | [diff] [blame] | 1501 | OS << '\n'; |
Chris Lattner | 214808f | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1504 | bool MachineInstr::addRegisterKilled(unsigned IncomingReg, |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1505 | const TargetRegisterInfo *RegInfo, |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1506 | bool AddIfNotFound) { |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1507 | bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg); |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 1508 | bool hasAliases = isPhysReg && |
| 1509 | MCRegAliasIterator(IncomingReg, RegInfo, false).isValid(); |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1510 | bool Found = false; |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1511 | SmallVector<unsigned,4> DeadOps; |
Bill Wendling | 7921ad0 | 2008-03-03 22:14:33 +0000 | [diff] [blame] | 1512 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 1513 | MachineOperand &MO = getOperand(i); |
Jakob Stoklund Olesen | f465f06 | 2009-08-04 20:09:25 +0000 | [diff] [blame] | 1514 | if (!MO.isReg() || !MO.isUse() || MO.isUndef()) |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1515 | continue; |
Mandeep Singh Grang | e5a2f11 | 2016-05-10 17:57:27 +0000 | [diff] [blame] | 1516 | |
| 1517 | // DEBUG_VALUE nodes do not contribute to code generation and should |
| 1518 | // always be ignored. Failure to do so may result in trying to modify |
| 1519 | // KILL flags on DEBUG_VALUE nodes. |
| 1520 | if (MO.isDebug()) |
| 1521 | continue; |
| 1522 | |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1523 | unsigned Reg = MO.getReg(); |
| 1524 | if (!Reg) |
| 1525 | continue; |
Bill Wendling | 7921ad0 | 2008-03-03 22:14:33 +0000 | [diff] [blame] | 1526 | |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1527 | if (Reg == IncomingReg) { |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1528 | if (!Found) { |
| 1529 | if (MO.isKill()) |
| 1530 | // The register is already marked kill. |
| 1531 | return true; |
Jakob Stoklund Olesen | c59cd9b | 2009-08-02 19:13:03 +0000 | [diff] [blame] | 1532 | if (isPhysReg && isRegTiedToDefOperand(i)) |
| 1533 | // Two-address uses of physregs must not be marked kill. |
| 1534 | return true; |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1535 | MO.setIsKill(); |
| 1536 | Found = true; |
| 1537 | } |
| 1538 | } else if (hasAliases && MO.isKill() && |
| 1539 | TargetRegisterInfo::isPhysicalRegister(Reg)) { |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1540 | // A super-register kill already exists. |
| 1541 | if (RegInfo->isSuperRegister(IncomingReg, Reg)) |
Dan Gohman | b261292 | 2008-07-03 01:18:51 +0000 | [diff] [blame] | 1542 | return true; |
| 1543 | if (RegInfo->isSubRegister(IncomingReg, Reg)) |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1544 | DeadOps.push_back(i); |
Bill Wendling | 7921ad0 | 2008-03-03 22:14:33 +0000 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1548 | // Trim unneeded kill operands. |
| 1549 | while (!DeadOps.empty()) { |
| 1550 | unsigned OpIdx = DeadOps.back(); |
| 1551 | if (getOperand(OpIdx).isImplicit()) |
| 1552 | RemoveOperand(OpIdx); |
| 1553 | else |
| 1554 | getOperand(OpIdx).setIsKill(false); |
| 1555 | DeadOps.pop_back(); |
| 1556 | } |
| 1557 | |
Bill Wendling | 7921ad0 | 2008-03-03 22:14:33 +0000 | [diff] [blame] | 1558 | // If not found, this means an alias of one of the operands is killed. Add a |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1559 | // new implicit operand if required. |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1560 | if (!Found && AddIfNotFound) { |
Bill Wendling | 7921ad0 | 2008-03-03 22:14:33 +0000 | [diff] [blame] | 1561 | addOperand(MachineOperand::CreateReg(IncomingReg, |
| 1562 | false /*IsDef*/, |
| 1563 | true /*IsImp*/, |
| 1564 | true /*IsKill*/)); |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1565 | return true; |
| 1566 | } |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1567 | return Found; |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
Jakob Stoklund Olesen | 8c139a5 | 2012-01-26 17:52:15 +0000 | [diff] [blame] | 1570 | void MachineInstr::clearRegisterKills(unsigned Reg, |
| 1571 | const TargetRegisterInfo *RegInfo) { |
| 1572 | if (!TargetRegisterInfo::isPhysicalRegister(Reg)) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 1573 | RegInfo = nullptr; |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1574 | for (MachineOperand &MO : operands()) { |
Jakob Stoklund Olesen | 8c139a5 | 2012-01-26 17:52:15 +0000 | [diff] [blame] | 1575 | if (!MO.isReg() || !MO.isUse() || !MO.isKill()) |
| 1576 | continue; |
| 1577 | unsigned OpReg = MO.getReg(); |
Matthias Braun | aca625a | 2016-02-24 19:21:48 +0000 | [diff] [blame] | 1578 | if ((RegInfo && RegInfo->regsOverlap(Reg, OpReg)) || Reg == OpReg) |
Jakob Stoklund Olesen | 8c139a5 | 2012-01-26 17:52:15 +0000 | [diff] [blame] | 1579 | MO.setIsKill(false); |
| 1580 | } |
| 1581 | } |
| 1582 | |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1583 | bool MachineInstr::addRegisterDead(unsigned Reg, |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1584 | const TargetRegisterInfo *RegInfo, |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1585 | bool AddIfNotFound) { |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1586 | bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(Reg); |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 1587 | bool hasAliases = isPhysReg && |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1588 | MCRegAliasIterator(Reg, RegInfo, false).isValid(); |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1589 | bool Found = false; |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1590 | SmallVector<unsigned,4> DeadOps; |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1591 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 1592 | MachineOperand &MO = getOperand(i); |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1593 | if (!MO.isReg() || !MO.isDef()) |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1594 | continue; |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1595 | unsigned MOReg = MO.getReg(); |
| 1596 | if (!MOReg) |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1597 | continue; |
| 1598 | |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1599 | if (MOReg == Reg) { |
Jakob Stoklund Olesen | 76ad3de | 2011-04-05 16:53:50 +0000 | [diff] [blame] | 1600 | MO.setIsDead(); |
| 1601 | Found = true; |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1602 | } else if (hasAliases && MO.isDead() && |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1603 | TargetRegisterInfo::isPhysicalRegister(MOReg)) { |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1604 | // There exists a super-register that's marked dead. |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1605 | if (RegInfo->isSuperRegister(Reg, MOReg)) |
Dan Gohman | b261292 | 2008-07-03 01:18:51 +0000 | [diff] [blame] | 1606 | return true; |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1607 | if (RegInfo->isSubRegister(Reg, MOReg)) |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1608 | DeadOps.push_back(i); |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1609 | } |
| 1610 | } |
| 1611 | |
Evan Cheng | 6c17773 | 2008-04-16 09:41:59 +0000 | [diff] [blame] | 1612 | // Trim unneeded dead operands. |
| 1613 | while (!DeadOps.empty()) { |
| 1614 | unsigned OpIdx = DeadOps.back(); |
| 1615 | if (getOperand(OpIdx).isImplicit()) |
| 1616 | RemoveOperand(OpIdx); |
| 1617 | else |
| 1618 | getOperand(OpIdx).setIsDead(false); |
| 1619 | DeadOps.pop_back(); |
| 1620 | } |
| 1621 | |
Dan Gohman | c7367b4 | 2008-09-03 15:56:16 +0000 | [diff] [blame] | 1622 | // If not found, this means an alias of one of the operands is dead. Add a |
| 1623 | // new implicit operand if required. |
Chris Lattner | fd68280 | 2009-06-24 17:54:48 +0000 | [diff] [blame] | 1624 | if (Found || !AddIfNotFound) |
| 1625 | return Found; |
Jim Grosbach | dee9e8a | 2011-08-24 16:44:17 +0000 | [diff] [blame] | 1626 | |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1627 | addOperand(MachineOperand::CreateReg(Reg, |
Chris Lattner | fd68280 | 2009-06-24 17:54:48 +0000 | [diff] [blame] | 1628 | true /*IsDef*/, |
| 1629 | true /*IsImp*/, |
| 1630 | false /*IsKill*/, |
| 1631 | true /*IsDead*/)); |
| 1632 | return true; |
Owen Anderson | 2a8a485 | 2008-01-24 01:10:07 +0000 | [diff] [blame] | 1633 | } |
Jakob Stoklund Olesen | 7725526 | 2010-01-06 00:29:28 +0000 | [diff] [blame] | 1634 | |
Matthias Braun | 26e7ea6 | 2015-02-04 19:35:16 +0000 | [diff] [blame] | 1635 | void MachineInstr::clearRegisterDeads(unsigned Reg) { |
| 1636 | for (MachineOperand &MO : operands()) { |
| 1637 | if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg) |
| 1638 | continue; |
| 1639 | MO.setIsDead(false); |
| 1640 | } |
| 1641 | } |
| 1642 | |
Matthias Braun | 2c98d0f | 2015-11-11 00:41:58 +0000 | [diff] [blame] | 1643 | void MachineInstr::setRegisterDefReadUndef(unsigned Reg, bool IsUndef) { |
Matthias Braun | c1988f3 | 2015-01-21 22:55:13 +0000 | [diff] [blame] | 1644 | for (MachineOperand &MO : operands()) { |
| 1645 | if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg || MO.getSubReg() == 0) |
| 1646 | continue; |
Matthias Braun | 2c98d0f | 2015-11-11 00:41:58 +0000 | [diff] [blame] | 1647 | MO.setIsUndef(IsUndef); |
Matthias Braun | c1988f3 | 2015-01-21 22:55:13 +0000 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1651 | void MachineInstr::addRegisterDefined(unsigned Reg, |
Jakob Stoklund Olesen | 7725526 | 2010-01-06 00:29:28 +0000 | [diff] [blame] | 1652 | const TargetRegisterInfo *RegInfo) { |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1653 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) { |
| 1654 | MachineOperand *MO = findRegisterDefOperand(Reg, false, RegInfo); |
Jakob Stoklund Olesen | 1f38010 | 2010-05-21 16:32:16 +0000 | [diff] [blame] | 1655 | if (MO) |
| 1656 | return; |
| 1657 | } else { |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1658 | for (const MachineOperand &MO : operands()) { |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1659 | if (MO.isReg() && MO.getReg() == Reg && MO.isDef() && |
Jakob Stoklund Olesen | 1f38010 | 2010-05-21 16:32:16 +0000 | [diff] [blame] | 1660 | MO.getSubReg() == 0) |
| 1661 | return; |
| 1662 | } |
| 1663 | } |
Matthias Braun | 1965bfa | 2013-10-10 21:28:38 +0000 | [diff] [blame] | 1664 | addOperand(MachineOperand::CreateReg(Reg, |
Jakob Stoklund Olesen | 1f38010 | 2010-05-21 16:32:16 +0000 | [diff] [blame] | 1665 | true /*IsDef*/, |
| 1666 | true /*IsImp*/)); |
Jakob Stoklund Olesen | 7725526 | 2010-01-06 00:29:28 +0000 | [diff] [blame] | 1667 | } |
Evan Cheng | 59d27fe | 2010-03-03 23:37:30 +0000 | [diff] [blame] | 1668 | |
Jakob Stoklund Olesen | 4290be4 | 2012-02-03 20:43:39 +0000 | [diff] [blame] | 1669 | void MachineInstr::setPhysRegsDeadExcept(ArrayRef<unsigned> UsedRegs, |
Dan Gohman | 8693650 | 2010-06-18 23:28:01 +0000 | [diff] [blame] | 1670 | const TargetRegisterInfo &TRI) { |
Jakob Stoklund Olesen | 56fe2ed | 2012-02-03 21:23:14 +0000 | [diff] [blame] | 1671 | bool HasRegMask = false; |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1672 | for (MachineOperand &MO : operands()) { |
Jakob Stoklund Olesen | 56fe2ed | 2012-02-03 21:23:14 +0000 | [diff] [blame] | 1673 | if (MO.isRegMask()) { |
| 1674 | HasRegMask = true; |
| 1675 | continue; |
| 1676 | } |
Dan Gohman | 8693650 | 2010-06-18 23:28:01 +0000 | [diff] [blame] | 1677 | if (!MO.isReg() || !MO.isDef()) continue; |
| 1678 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | f650732 | 2012-02-03 20:43:35 +0000 | [diff] [blame] | 1679 | if (!TargetRegisterInfo::isPhysicalRegister(Reg)) continue; |
Dan Gohman | 8693650 | 2010-06-18 23:28:01 +0000 | [diff] [blame] | 1680 | // If there are no uses, including partial uses, the def is dead. |
Eugene Zelenko | 4e9736b | 2017-05-31 01:10:10 +0000 | [diff] [blame] | 1681 | if (llvm::none_of(UsedRegs, |
| 1682 | [&](unsigned Use) { return TRI.regsOverlap(Use, Reg); })) |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1683 | MO.setIsDead(); |
Dan Gohman | 8693650 | 2010-06-18 23:28:01 +0000 | [diff] [blame] | 1684 | } |
Jakob Stoklund Olesen | 56fe2ed | 2012-02-03 21:23:14 +0000 | [diff] [blame] | 1685 | |
| 1686 | // This is a call with a register mask operand. |
| 1687 | // Mask clobbers are always dead, so add defs for the non-dead defines. |
| 1688 | if (HasRegMask) |
| 1689 | for (ArrayRef<unsigned>::iterator I = UsedRegs.begin(), E = UsedRegs.end(); |
| 1690 | I != E; ++I) |
| 1691 | addRegisterDefined(*I, &TRI); |
Dan Gohman | 8693650 | 2010-06-18 23:28:01 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Evan Cheng | 59d27fe | 2010-03-03 23:37:30 +0000 | [diff] [blame] | 1694 | unsigned |
| 1695 | MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) { |
Chandler Carruth | 962152c | 2012-03-07 09:39:46 +0000 | [diff] [blame] | 1696 | // Build up a buffer of hash code components. |
Chandler Carruth | 962152c | 2012-03-07 09:39:46 +0000 | [diff] [blame] | 1697 | SmallVector<size_t, 8> HashComponents; |
| 1698 | HashComponents.reserve(MI->getNumOperands() + 1); |
| 1699 | HashComponents.push_back(MI->getOpcode()); |
Benjamin Kramer | 60c5bbf | 2015-02-21 17:08:08 +0000 | [diff] [blame] | 1700 | for (const MachineOperand &MO : MI->operands()) { |
Chandler Carruth | 264854f | 2012-07-05 11:06:22 +0000 | [diff] [blame] | 1701 | if (MO.isReg() && MO.isDef() && |
| 1702 | TargetRegisterInfo::isVirtualRegister(MO.getReg())) |
| 1703 | continue; // Skip virtual register defs. |
| 1704 | |
| 1705 | HashComponents.push_back(hash_value(MO)); |
Evan Cheng | 59d27fe | 2010-03-03 23:37:30 +0000 | [diff] [blame] | 1706 | } |
Chandler Carruth | 962152c | 2012-03-07 09:39:46 +0000 | [diff] [blame] | 1707 | return hash_combine_range(HashComponents.begin(), HashComponents.end()); |
Evan Cheng | 59d27fe | 2010-03-03 23:37:30 +0000 | [diff] [blame] | 1708 | } |
Jakob Stoklund Olesen | 25a404e | 2011-07-02 03:53:34 +0000 | [diff] [blame] | 1709 | |
| 1710 | void MachineInstr::emitError(StringRef Msg) const { |
| 1711 | // Find the source location cookie. |
| 1712 | unsigned LocCookie = 0; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 1713 | const MDNode *LocMD = nullptr; |
Jakob Stoklund Olesen | 25a404e | 2011-07-02 03:53:34 +0000 | [diff] [blame] | 1714 | for (unsigned i = getNumOperands(); i != 0; --i) { |
| 1715 | if (getOperand(i-1).isMetadata() && |
| 1716 | (LocMD = getOperand(i-1).getMetadata()) && |
| 1717 | LocMD->getNumOperands() != 0) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1718 | if (const ConstantInt *CI = |
| 1719 | mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) { |
Jakob Stoklund Olesen | 25a404e | 2011-07-02 03:53:34 +0000 | [diff] [blame] | 1720 | LocCookie = CI->getZExtValue(); |
| 1721 | break; |
| 1722 | } |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | if (const MachineBasicBlock *MBB = getParent()) |
| 1727 | if (const MachineFunction *MF = MBB->getParent()) |
| 1728 | return MF->getMMI().getModule()->getContext().emitError(LocCookie, Msg); |
| 1729 | report_fatal_error(Msg); |
| 1730 | } |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1731 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1732 | MachineInstrBuilder llvm::BuildMI(MachineFunction &MF, const DebugLoc &DL, |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1733 | const MCInstrDesc &MCID, bool IsIndirect, |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1734 | unsigned Reg, const MDNode *Variable, |
| 1735 | const MDNode *Expr) { |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1736 | assert(isa<DILocalVariable>(Variable) && "not a variable"); |
| 1737 | assert(cast<DIExpression>(Expr)->isValid() && "not an expression"); |
| 1738 | assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) && |
| 1739 | "Expected inlined-at fields to agree"); |
| 1740 | if (IsIndirect) |
| 1741 | return BuildMI(MF, DL, MCID) |
| 1742 | .addReg(Reg, RegState::Debug) |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1743 | .addImm(0U) |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1744 | .addMetadata(Variable) |
| 1745 | .addMetadata(Expr); |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1746 | else |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1747 | return BuildMI(MF, DL, MCID) |
| 1748 | .addReg(Reg, RegState::Debug) |
| 1749 | .addReg(0U, RegState::Debug) |
| 1750 | .addMetadata(Variable) |
| 1751 | .addMetadata(Expr); |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | MachineInstrBuilder llvm::BuildMI(MachineBasicBlock &BB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1755 | MachineBasicBlock::iterator I, |
| 1756 | const DebugLoc &DL, const MCInstrDesc &MCID, |
| 1757 | bool IsIndirect, unsigned Reg, |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1758 | const MDNode *Variable, const MDNode *Expr) { |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1759 | assert(isa<DILocalVariable>(Variable) && "not a variable"); |
| 1760 | assert(cast<DIExpression>(Expr)->isValid() && "not an expression"); |
| 1761 | MachineFunction &MF = *BB.getParent(); |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1762 | MachineInstr *MI = BuildMI(MF, DL, MCID, IsIndirect, Reg, Variable, Expr); |
Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 1763 | BB.insert(I, MI); |
| 1764 | return MachineInstrBuilder(MF, MI); |
| 1765 | } |
Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 1766 | |
Reid Kleckner | 9e6c309 | 2017-09-15 21:49:56 +0000 | [diff] [blame] | 1767 | /// Compute the new DIExpression to use with a DBG_VALUE for a spill slot. |
| 1768 | /// This prepends DW_OP_deref when spilling an indirect DBG_VALUE. |
| 1769 | static const DIExpression *computeExprForSpill(const MachineInstr &MI) { |
| 1770 | assert(MI.getOperand(0).isReg() && "can't spill non-register"); |
| 1771 | assert(MI.getDebugVariable()->isValidLocationForIntrinsic(MI.getDebugLoc()) && |
| 1772 | "Expected inlined-at fields to agree"); |
| 1773 | |
| 1774 | const DIExpression *Expr = MI.getDebugExpression(); |
| 1775 | if (MI.isIndirectDebugValue()) { |
| 1776 | assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset"); |
| 1777 | Expr = DIExpression::prepend(Expr, DIExpression::WithDeref); |
| 1778 | } |
| 1779 | return Expr; |
| 1780 | } |
| 1781 | |
Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 1782 | MachineInstr *llvm::buildDbgValueForSpill(MachineBasicBlock &BB, |
| 1783 | MachineBasicBlock::iterator I, |
| 1784 | const MachineInstr &Orig, |
| 1785 | int FrameIndex) { |
Reid Kleckner | 9e6c309 | 2017-09-15 21:49:56 +0000 | [diff] [blame] | 1786 | const DIExpression *Expr = computeExprForSpill(Orig); |
| 1787 | return BuildMI(BB, I, Orig.getDebugLoc(), Orig.getDesc()) |
Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 1788 | .addFrameIndex(FrameIndex) |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 1789 | .addImm(0U) |
Reid Kleckner | 9e6c309 | 2017-09-15 21:49:56 +0000 | [diff] [blame] | 1790 | .addMetadata(Orig.getDebugVariable()) |
Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 1791 | .addMetadata(Expr); |
| 1792 | } |
Reid Kleckner | 9e6c309 | 2017-09-15 21:49:56 +0000 | [diff] [blame] | 1793 | |
| 1794 | void llvm::updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex) { |
| 1795 | const DIExpression *Expr = computeExprForSpill(Orig); |
| 1796 | Orig.getOperand(0).ChangeToFrameIndex(FrameIndex); |
| 1797 | Orig.getOperand(1).ChangeToImmediate(0U); |
| 1798 | Orig.getOperand(3).setMetadata(Expr); |
| 1799 | } |