113 {
114
118
120
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();
128
129 const llvm::MCInstrDesc& opDesc = mi->getDesc();
130 if (opDesc.isReturn()) {
131 continue;
132 }
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) {
139 continue;
140 }
141
143 if (opname == "") continue;
144 bool hasGuard = opname[0] == '?' || opname[0] == '!';
145 if (hasGuard) opname = opname.substr(1);
146
150
151
152
153
154
155
156
157
158
159
160 continue;
161 }
162
163 for (unsigned operandI = 0; operandI < mi->getNumOperands();
164 ++operandI) {
165
166 const MachineOperand& mo = mi->getOperand(operandI);
167 if (!mo.isImm()) continue;
168
170 if (inputIndex == 0) continue;
173 continue;
175 << "Input " << inputIndex
176 << " not found for operation "
177 << opname << std::endl;
179 }
181 size_t operandWidth = operand.
width();
182
184 mach_, mo.getImm(), operandWidth))
continue;
185
186
187
190 mach_, -mo.getImm()) &&
192
193 const llvm::MCInstrInfo* iinfo =
194 mf.getTarget().getSubtargetImpl(
195 mf.getFunction())->getInstrInfo();
196
197 BuildMI(
198 mbb, j, j->getDebugLoc(), iinfo->get(plugin.
opcode(
sub)),
200
201
202
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(
210 continue;
211 }
212 mib.add(orig);
213 orig.clearParent();
214 }
215
216
217 j->eraseFromParent();
218
219
220
221 j = mbb.begin();
222 changed = true;
223 } else {
224 std::ostringstream errMsg;
225 errMsg << "Program uses constant '"
226 << mo.getImm() << "'";
228 errMsg << " -> " << opname
229 << " (llvm opc = " << opc << ")";
230 }
231 errMsg << " that cannot be encoded "
232 << "for the machine by the current compiler.";
234 __FILE__, __LINE__,
__func__, errMsg.str());
235 }
236 }
237 }
238
239 }
240 return changed;
241}
#define assert(condition)
static std::ostream & errorStream()
static int verboseLevel()
static bool canEncodeImmediateInteger(const TTAMachine::Machine &mach, int64_t imm, unsigned destWidth=UINT_MAX)
static bool supportsOperation(const TTAMachine::Machine &mach, TCEString operation)
virtual bool isInput() const
virtual int width() const
virtual bool isNull() const
Operation & operation(const char *name)
virtual bool readsMemory() const
virtual bool isCall() const
virtual bool isBranch() const
virtual Operand & operand(int id) const
virtual unsigned rvHighDRegNum()=0
virtual unsigned opcode(TCEString operationName) const =0
Returns the opcode for the given osal operation, undefined if not found.
std::string operationName(unsigned opc) const
virtual TCETargetMachinePlugin & targetPlugin() const