@@ -113,10 +113,50 @@ bool AMDGPUMCInstLower::lowerOperand(const MachineOperand &MO,
113
113
llvm_unreachable (" unknown operand type" );
114
114
}
115
115
116
- void AMDGPUMCInstLower::lower (const MachineInstr *MI, MCInst &OutMI) const {
116
+ // Lower true16 D16 Pseudo instruction to d16_lo/d16_hi MCInst based on
117
+ // Dst/Data's .l/.h selection
118
+ void AMDGPUMCInstLower::lowerT16D16Helper (const MachineInstr *MI,
119
+ MCInst &OutMI) const {
117
120
unsigned Opcode = MI->getOpcode ();
118
121
const auto *TII = static_cast <const SIInstrInfo*>(ST.getInstrInfo ());
119
122
const SIRegisterInfo &TRI = TII->getRegisterInfo ();
123
+ const auto *Info = AMDGPU::getT16D16Helper (Opcode);
124
+
125
+ // select Dst/Data
126
+ int VDataIdx = AMDGPU::getNamedOperandIdx (Opcode, AMDGPU::OpName::vdata);
127
+ int VDstOrVDataIdx = VDataIdx != -1 ? VDataIdx : 0 ;
128
+ MachineOperand &MIVDstOrVData = MI->getOperand (VDstOrVDataIdx);
129
+
130
+ // select hi/lo MCInst
131
+ bool IsHi = AMDGPU::isHi16Reg (MIVDstOrVData.getReg (), TRI);
132
+ Opcode = IsHi ? Info->HiOp : Info->LoOp ;
133
+
134
+ int MCOpcode = TII->pseudoToMCOpcode (Opcode);
135
+ assert (MCOpcode != -1 &&
136
+ " Pseudo instruction doesn't have a target-specific version" );
137
+ OutMI.setOpcode (MCOpcode);
138
+
139
+ // lower operands
140
+ for (int I = 0 , E = MI->getNumExplicitOperands (); I < E; I++) {
141
+ const MachineOperand &MO = MI->getOperand (I);
142
+ MCOperand MCOp;
143
+ if (I == VDstOrVDataIdx)
144
+ MCOp = MCOperand::createReg (TRI.get32BitRegister (MIVDstOrVData.getReg ()));
145
+ else
146
+ lowerOperand (MO, MCOp);
147
+ OutMI.addOperand (MCOp);
148
+ }
149
+
150
+ if (AMDGPU::hasNamedOperand (MCOpcode, AMDGPU::OpName::vdst_in)) {
151
+ MCOperand MCOp;
152
+ lowerOperand (MIVDstOrVData, MCOp);
153
+ OutMI.addOperand (MCOp);
154
+ }
155
+ }
156
+
157
+ void AMDGPUMCInstLower::lower (const MachineInstr *MI, MCInst &OutMI) const {
158
+ unsigned Opcode = MI->getOpcode ();
159
+ const auto *TII = static_cast <const SIInstrInfo *>(ST.getInstrInfo ());
120
160
121
161
// FIXME: Should be able to handle this with lowerPseudoInstExpansion. We
122
162
// need to select it to the subtarget specific version, and there's no way to
@@ -133,39 +173,13 @@ void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
133
173
OutMI.addOperand (Dest);
134
174
OutMI.addOperand (Src);
135
175
return ;
136
- } else if (const auto *Info = AMDGPU::getT16D16Helper (Opcode)) {
137
- int VDataIdx = AMDGPU::getNamedOperandIdx (Opcode, AMDGPU::OpName::vdata);
138
- int VDstOrVDataIdx = VDataIdx != -1 ? VDataIdx : 0 ;
139
- MachineOperand MIVDstOrVData = MI->getOperand (VDstOrVDataIdx);
140
- bool IsHi = AMDGPU::isHi16Reg (MIVDstOrVData.getReg (), TRI);
141
- Opcode = IsHi ? Info->HiOp : Info->LoOp ;
142
- MIVDstOrVData.clearParent (); // Avoid use list error in setReg call
143
- MIVDstOrVData.setReg (TRI.get32BitRegister (MIVDstOrVData.getReg ()));
144
-
145
- int MCOpcode = TII->pseudoToMCOpcode (Opcode);
146
- assert (MCOpcode != -1 &&
147
- " Pseudo instruction doesn't have a target-specific version" );
148
- OutMI.setOpcode (MCOpcode);
149
- for (int I = 0 , E = MI->getNumExplicitOperands (); I < E; I++) {
150
- const MachineOperand &MO = MI->getOperand (I);
151
- MCOperand MCOp;
152
- if (I == VDstOrVDataIdx)
153
- lowerOperand (MIVDstOrVData, MCOp);
154
- else
155
- lowerOperand (MO, MCOp);
156
- OutMI.addOperand (MCOp);
157
- }
158
-
159
- if (AMDGPU::hasNamedOperand (MCOpcode, AMDGPU::OpName::vdst_in)) {
160
- MCOperand MCOp;
161
- lowerOperand (MIVDstOrVData, MCOp);
162
- OutMI.addOperand (MCOp);
163
- }
164
- return ;
165
176
} else if (Opcode == AMDGPU::SI_TCRETURN ||
166
177
Opcode == AMDGPU::SI_TCRETURN_GFX) {
167
178
// TODO: How to use branch immediate and avoid register+add?
168
179
Opcode = AMDGPU::S_SETPC_B64;
180
+ } else if (AMDGPU::getT16D16Helper (Opcode)) {
181
+ lowerT16D16Helper (MI, OutMI);
182
+ return ;
169
183
}
170
184
171
185
int MCOpcode = TII->pseudoToMCOpcode (Opcode);
0 commit comments