121 bool changed =
false;
122 for (MachineFunction::iterator i = mf.begin(); i != mf.end(); i++) {
123 MachineBasicBlock& mbb = *i;
124 for (MachineBasicBlock::iterator j = mbb.begin();
125 j != mbb.end(); j++) {
126 const llvm::MachineInstr* mi = &*j;
127 unsigned opc = mi->getOpcode();
129 const llvm::MCInstrDesc& opDesc = mi->getDesc();
130 if (opDesc.isReturn()) {
133 if (opc == llvm::TargetOpcode::DBG_VALUE
134 || opc == llvm::TargetOpcode::DBG_LABEL
135 || opc == llvm::TargetOpcode::DBG_INSTR_REF
136 || opc == llvm::TargetOpcode::DBG_VALUE_LIST
137 || opc == llvm::TargetOpcode::DBG_PHI
138 || opc == llvm::TargetOpcode::KILL) {
143 if (opname ==
"")
continue;
144 bool hasGuard = opname[0] ==
'?' || opname[0] ==
'!';
145 if (hasGuard) opname = opname.substr(1);
163 for (
unsigned operandI = 0; operandI < mi->getNumOperands();
166 const MachineOperand& mo = mi->getOperand(operandI);
167 if (!mo.isImm())
continue;
170 if (inputIndex == 0)
continue;
175 <<
"Input " << inputIndex
176 <<
" not found for operation "
177 << opname << std::endl;
181 size_t operandWidth = operand.
width();
184 mach_, mo.getImm(), operandWidth))
continue;
190 mach_, -mo.getImm()) &&
193 const llvm::MCInstrInfo* iinfo =
194 mf.getTarget().getSubtargetImpl(
195 mf.getFunction())->getInstrInfo();
198 mbb, j, j->getDebugLoc(), iinfo->get(plugin.
opcode(
sub)),
203 llvm::MachineInstrBuilder mib =
204 BuildMI(mbb, j, j->getDebugLoc(), j->getDesc());
205 for (
unsigned opr = 0; opr < j->getNumOperands(); ++opr) {
206 MachineOperand& orig = j->getOperand(opr);
207 if (opr == operandI) {
208 mib.add(MachineOperand::CreateReg(
217 j->eraseFromParent();
224 std::ostringstream errMsg;
225 errMsg <<
"Program uses constant '"
226 << mo.getImm() <<
"'";
228 errMsg <<
" -> " << opname
229 <<
" (llvm opc = " << opc <<
")";
231 errMsg <<
" that cannot be encoded "
232 <<
"for the machine by the current compiler.";
234 __FILE__, __LINE__,
__func__, errMsg.str());