OLD | NEW |
1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// | 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 Ice::Type convertToIceType(Type *LLVMTy) const { | 194 Ice::Type convertToIceType(Type *LLVMTy) const { |
195 Ice::Type IceTy = TypeConverter.convertToIceType(LLVMTy); | 195 Ice::Type IceTy = TypeConverter.convertToIceType(LLVMTy); |
196 if (IceTy == Ice::IceType_NUM) | 196 if (IceTy == Ice::IceType_NUM) |
197 report_fatal_error(std::string("Invalid PNaCl type ") + | 197 report_fatal_error(std::string("Invalid PNaCl type ") + |
198 LLVMObjectAsString(LLVMTy)); | 198 LLVMObjectAsString(LLVMTy)); |
199 return IceTy; | 199 return IceTy; |
200 } | 200 } |
201 | 201 |
202 // Given an LLVM instruction and an operand number, produce the Ice::Operand | 202 // Given an LLVM instruction and an operand number, produce the Ice::Operand |
203 // this refers to. If there's no such operand, return nullptr. | 203 // this refers to. If there's no such operand, return nullptr. |
204 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) { | 204 Ice::Operand *convertOperand(const Instruction *Instr, unsigned OpNum) { |
205 if (OpNum >= Inst->getNumOperands()) { | 205 if (OpNum >= Instr->getNumOperands()) { |
206 return nullptr; | 206 return nullptr; |
207 } | 207 } |
208 const Value *Op = Inst->getOperand(OpNum); | 208 const Value *Op = Instr->getOperand(OpNum); |
209 return convertValue(Op); | 209 return convertValue(Op); |
210 } | 210 } |
211 | 211 |
212 Ice::Operand *convertValue(const Value *Op) { | 212 Ice::Operand *convertValue(const Value *Op) { |
213 if (const auto Const = dyn_cast<Constant>(Op)) { | 213 if (const auto Const = dyn_cast<Constant>(Op)) { |
214 return convertConstant(Const); | 214 return convertConstant(Const); |
215 } else { | 215 } else { |
216 return mapValueToIceVar(Op); | 216 return mapValueToIceVar(Op); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice | 220 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice |
221 // instructions. | 221 // instructions. |
222 Ice::Inst *convertInstruction(const Instruction *Inst) { | 222 Ice::Inst *convertInstruction(const Instruction *Instr) { |
223 switch (Inst->getOpcode()) { | 223 switch (Instr->getOpcode()) { |
224 case Instruction::PHI: | 224 case Instruction::PHI: |
225 return convertPHINodeInstruction(cast<PHINode>(Inst)); | 225 return convertPHINodeInstruction(cast<PHINode>(Instr)); |
226 case Instruction::Br: | 226 case Instruction::Br: |
227 return convertBrInstruction(cast<BranchInst>(Inst)); | 227 return convertBrInstruction(cast<BranchInst>(Instr)); |
228 case Instruction::Ret: | 228 case Instruction::Ret: |
229 return convertRetInstruction(cast<ReturnInst>(Inst)); | 229 return convertRetInstruction(cast<ReturnInst>(Instr)); |
230 case Instruction::IntToPtr: | 230 case Instruction::IntToPtr: |
231 return convertIntToPtrInstruction(cast<IntToPtrInst>(Inst)); | 231 return convertIntToPtrInstruction(cast<IntToPtrInst>(Instr)); |
232 case Instruction::PtrToInt: | 232 case Instruction::PtrToInt: |
233 return convertPtrToIntInstruction(cast<PtrToIntInst>(Inst)); | 233 return convertPtrToIntInstruction(cast<PtrToIntInst>(Instr)); |
234 case Instruction::ICmp: | 234 case Instruction::ICmp: |
235 return convertICmpInstruction(cast<ICmpInst>(Inst)); | 235 return convertICmpInstruction(cast<ICmpInst>(Instr)); |
236 case Instruction::FCmp: | 236 case Instruction::FCmp: |
237 return convertFCmpInstruction(cast<FCmpInst>(Inst)); | 237 return convertFCmpInstruction(cast<FCmpInst>(Instr)); |
238 case Instruction::Select: | 238 case Instruction::Select: |
239 return convertSelectInstruction(cast<SelectInst>(Inst)); | 239 return convertSelectInstruction(cast<SelectInst>(Instr)); |
240 case Instruction::Switch: | 240 case Instruction::Switch: |
241 return convertSwitchInstruction(cast<SwitchInst>(Inst)); | 241 return convertSwitchInstruction(cast<SwitchInst>(Instr)); |
242 case Instruction::Load: | 242 case Instruction::Load: |
243 return convertLoadInstruction(cast<LoadInst>(Inst)); | 243 return convertLoadInstruction(cast<LoadInst>(Instr)); |
244 case Instruction::Store: | 244 case Instruction::Store: |
245 return convertStoreInstruction(cast<StoreInst>(Inst)); | 245 return convertStoreInstruction(cast<StoreInst>(Instr)); |
246 case Instruction::ZExt: | 246 case Instruction::ZExt: |
247 return convertCastInstruction(cast<ZExtInst>(Inst), Ice::InstCast::Zext); | 247 return convertCastInstruction(cast<ZExtInst>(Instr), Ice::InstCast::Zext); |
248 case Instruction::SExt: | 248 case Instruction::SExt: |
249 return convertCastInstruction(cast<SExtInst>(Inst), Ice::InstCast::Sext); | 249 return convertCastInstruction(cast<SExtInst>(Instr), Ice::InstCast::Sext); |
250 case Instruction::Trunc: | 250 case Instruction::Trunc: |
251 return convertCastInstruction(cast<TruncInst>(Inst), | 251 return convertCastInstruction(cast<TruncInst>(Instr), |
252 Ice::InstCast::Trunc); | 252 Ice::InstCast::Trunc); |
253 case Instruction::FPTrunc: | 253 case Instruction::FPTrunc: |
254 return convertCastInstruction(cast<FPTruncInst>(Inst), | 254 return convertCastInstruction(cast<FPTruncInst>(Instr), |
255 Ice::InstCast::Fptrunc); | 255 Ice::InstCast::Fptrunc); |
256 case Instruction::FPExt: | 256 case Instruction::FPExt: |
257 return convertCastInstruction(cast<FPExtInst>(Inst), | 257 return convertCastInstruction(cast<FPExtInst>(Instr), |
258 Ice::InstCast::Fpext); | 258 Ice::InstCast::Fpext); |
259 case Instruction::FPToSI: | 259 case Instruction::FPToSI: |
260 return convertCastInstruction(cast<FPToSIInst>(Inst), | 260 return convertCastInstruction(cast<FPToSIInst>(Instr), |
261 Ice::InstCast::Fptosi); | 261 Ice::InstCast::Fptosi); |
262 case Instruction::FPToUI: | 262 case Instruction::FPToUI: |
263 return convertCastInstruction(cast<FPToUIInst>(Inst), | 263 return convertCastInstruction(cast<FPToUIInst>(Instr), |
264 Ice::InstCast::Fptoui); | 264 Ice::InstCast::Fptoui); |
265 case Instruction::SIToFP: | 265 case Instruction::SIToFP: |
266 return convertCastInstruction(cast<SIToFPInst>(Inst), | 266 return convertCastInstruction(cast<SIToFPInst>(Instr), |
267 Ice::InstCast::Sitofp); | 267 Ice::InstCast::Sitofp); |
268 case Instruction::UIToFP: | 268 case Instruction::UIToFP: |
269 return convertCastInstruction(cast<UIToFPInst>(Inst), | 269 return convertCastInstruction(cast<UIToFPInst>(Instr), |
270 Ice::InstCast::Uitofp); | 270 Ice::InstCast::Uitofp); |
271 case Instruction::BitCast: | 271 case Instruction::BitCast: |
272 return convertCastInstruction(cast<BitCastInst>(Inst), | 272 return convertCastInstruction(cast<BitCastInst>(Instr), |
273 Ice::InstCast::Bitcast); | 273 Ice::InstCast::Bitcast); |
274 case Instruction::Add: | 274 case Instruction::Add: |
275 return convertArithInstruction(Inst, Ice::InstArithmetic::Add); | 275 return convertArithInstruction(Instr, Ice::InstArithmetic::Add); |
276 case Instruction::Sub: | 276 case Instruction::Sub: |
277 return convertArithInstruction(Inst, Ice::InstArithmetic::Sub); | 277 return convertArithInstruction(Instr, Ice::InstArithmetic::Sub); |
278 case Instruction::Mul: | 278 case Instruction::Mul: |
279 return convertArithInstruction(Inst, Ice::InstArithmetic::Mul); | 279 return convertArithInstruction(Instr, Ice::InstArithmetic::Mul); |
280 case Instruction::UDiv: | 280 case Instruction::UDiv: |
281 return convertArithInstruction(Inst, Ice::InstArithmetic::Udiv); | 281 return convertArithInstruction(Instr, Ice::InstArithmetic::Udiv); |
282 case Instruction::SDiv: | 282 case Instruction::SDiv: |
283 return convertArithInstruction(Inst, Ice::InstArithmetic::Sdiv); | 283 return convertArithInstruction(Instr, Ice::InstArithmetic::Sdiv); |
284 case Instruction::URem: | 284 case Instruction::URem: |
285 return convertArithInstruction(Inst, Ice::InstArithmetic::Urem); | 285 return convertArithInstruction(Instr, Ice::InstArithmetic::Urem); |
286 case Instruction::SRem: | 286 case Instruction::SRem: |
287 return convertArithInstruction(Inst, Ice::InstArithmetic::Srem); | 287 return convertArithInstruction(Instr, Ice::InstArithmetic::Srem); |
288 case Instruction::Shl: | 288 case Instruction::Shl: |
289 return convertArithInstruction(Inst, Ice::InstArithmetic::Shl); | 289 return convertArithInstruction(Instr, Ice::InstArithmetic::Shl); |
290 case Instruction::LShr: | 290 case Instruction::LShr: |
291 return convertArithInstruction(Inst, Ice::InstArithmetic::Lshr); | 291 return convertArithInstruction(Instr, Ice::InstArithmetic::Lshr); |
292 case Instruction::AShr: | 292 case Instruction::AShr: |
293 return convertArithInstruction(Inst, Ice::InstArithmetic::Ashr); | 293 return convertArithInstruction(Instr, Ice::InstArithmetic::Ashr); |
294 case Instruction::FAdd: | 294 case Instruction::FAdd: |
295 return convertArithInstruction(Inst, Ice::InstArithmetic::Fadd); | 295 return convertArithInstruction(Instr, Ice::InstArithmetic::Fadd); |
296 case Instruction::FSub: | 296 case Instruction::FSub: |
297 return convertArithInstruction(Inst, Ice::InstArithmetic::Fsub); | 297 return convertArithInstruction(Instr, Ice::InstArithmetic::Fsub); |
298 case Instruction::FMul: | 298 case Instruction::FMul: |
299 return convertArithInstruction(Inst, Ice::InstArithmetic::Fmul); | 299 return convertArithInstruction(Instr, Ice::InstArithmetic::Fmul); |
300 case Instruction::FDiv: | 300 case Instruction::FDiv: |
301 return convertArithInstruction(Inst, Ice::InstArithmetic::Fdiv); | 301 return convertArithInstruction(Instr, Ice::InstArithmetic::Fdiv); |
302 case Instruction::FRem: | 302 case Instruction::FRem: |
303 return convertArithInstruction(Inst, Ice::InstArithmetic::Frem); | 303 return convertArithInstruction(Instr, Ice::InstArithmetic::Frem); |
304 case Instruction::And: | 304 case Instruction::And: |
305 return convertArithInstruction(Inst, Ice::InstArithmetic::And); | 305 return convertArithInstruction(Instr, Ice::InstArithmetic::And); |
306 case Instruction::Or: | 306 case Instruction::Or: |
307 return convertArithInstruction(Inst, Ice::InstArithmetic::Or); | 307 return convertArithInstruction(Instr, Ice::InstArithmetic::Or); |
308 case Instruction::Xor: | 308 case Instruction::Xor: |
309 return convertArithInstruction(Inst, Ice::InstArithmetic::Xor); | 309 return convertArithInstruction(Instr, Ice::InstArithmetic::Xor); |
310 case Instruction::ExtractElement: | 310 case Instruction::ExtractElement: |
311 return convertExtractElementInstruction(cast<ExtractElementInst>(Inst)); | 311 return convertExtractElementInstruction(cast<ExtractElementInst>(Instr)); |
312 case Instruction::InsertElement: | 312 case Instruction::InsertElement: |
313 return convertInsertElementInstruction(cast<InsertElementInst>(Inst)); | 313 return convertInsertElementInstruction(cast<InsertElementInst>(Instr)); |
314 case Instruction::Call: | 314 case Instruction::Call: |
315 return convertCallInstruction(cast<CallInst>(Inst)); | 315 return convertCallInstruction(cast<CallInst>(Instr)); |
316 case Instruction::Alloca: | 316 case Instruction::Alloca: |
317 return convertAllocaInstruction(cast<AllocaInst>(Inst)); | 317 return convertAllocaInstruction(cast<AllocaInst>(Instr)); |
318 case Instruction::Unreachable: | 318 case Instruction::Unreachable: |
319 return convertUnreachableInstruction(cast<UnreachableInst>(Inst)); | 319 return convertUnreachableInstruction(cast<UnreachableInst>(Instr)); |
320 default: | 320 default: |
321 report_fatal_error(std::string("Invalid PNaCl instruction: ") + | 321 report_fatal_error(std::string("Invalid PNaCl instruction: ") + |
322 LLVMObjectAsString(Inst)); | 322 LLVMObjectAsString(Instr)); |
323 } | 323 } |
324 | 324 |
325 llvm_unreachable("convertInstruction"); | 325 llvm_unreachable("convertInstruction"); |
326 return nullptr; | 326 return nullptr; |
327 } | 327 } |
328 | 328 |
329 Ice::Inst *convertLoadInstruction(const LoadInst *Inst) { | 329 Ice::Inst *convertLoadInstruction(const LoadInst *Instr) { |
330 Ice::Operand *Src = convertOperand(Inst, 0); | 330 Ice::Operand *Src = convertOperand(Instr, 0); |
331 Ice::Variable *Dest = mapValueToIceVar(Inst); | 331 Ice::Variable *Dest = mapValueToIceVar(Instr); |
332 return Ice::InstLoad::create(Func.get(), Dest, Src); | 332 return Ice::InstLoad::create(Func.get(), Dest, Src); |
333 } | 333 } |
334 | 334 |
335 Ice::Inst *convertStoreInstruction(const StoreInst *Inst) { | 335 Ice::Inst *convertStoreInstruction(const StoreInst *Instr) { |
336 Ice::Operand *Addr = convertOperand(Inst, 1); | 336 Ice::Operand *Addr = convertOperand(Instr, 1); |
337 Ice::Operand *Val = convertOperand(Inst, 0); | 337 Ice::Operand *Val = convertOperand(Instr, 0); |
338 return Ice::InstStore::create(Func.get(), Val, Addr); | 338 return Ice::InstStore::create(Func.get(), Val, Addr); |
339 } | 339 } |
340 | 340 |
341 Ice::Inst *convertArithInstruction(const Instruction *Inst, | 341 Ice::Inst *convertArithInstruction(const Instruction *Instr, |
342 Ice::InstArithmetic::OpKind Opcode) { | 342 Ice::InstArithmetic::OpKind Opcode) { |
343 const auto BinOp = cast<BinaryOperator>(Inst); | 343 const auto BinOp = cast<BinaryOperator>(Instr); |
344 Ice::Operand *Src0 = convertOperand(Inst, 0); | 344 Ice::Operand *Src0 = convertOperand(Instr, 0); |
345 Ice::Operand *Src1 = convertOperand(Inst, 1); | 345 Ice::Operand *Src1 = convertOperand(Instr, 1); |
346 Ice::Variable *Dest = mapValueToIceVar(BinOp); | 346 Ice::Variable *Dest = mapValueToIceVar(BinOp); |
347 return Ice::InstArithmetic::create(Func.get(), Opcode, Dest, Src0, Src1); | 347 return Ice::InstArithmetic::create(Func.get(), Opcode, Dest, Src0, Src1); |
348 } | 348 } |
349 | 349 |
350 Ice::Inst *convertPHINodeInstruction(const PHINode *Inst) { | 350 Ice::Inst *convertPHINodeInstruction(const PHINode *Instr) { |
351 unsigned NumValues = Inst->getNumIncomingValues(); | 351 unsigned NumValues = Instr->getNumIncomingValues(); |
352 Ice::InstPhi *IcePhi = | 352 Ice::InstPhi *IcePhi = |
353 Ice::InstPhi::create(Func.get(), NumValues, mapValueToIceVar(Inst)); | 353 Ice::InstPhi::create(Func.get(), NumValues, mapValueToIceVar(Instr)); |
354 for (unsigned N = 0, E = NumValues; N != E; ++N) { | 354 for (unsigned N = 0, E = NumValues; N != E; ++N) { |
355 IcePhi->addArgument(convertOperand(Inst, N), | 355 IcePhi->addArgument(convertOperand(Instr, N), |
356 mapBasicBlockToNode(Inst->getIncomingBlock(N))); | 356 mapBasicBlockToNode(Instr->getIncomingBlock(N))); |
357 } | 357 } |
358 return IcePhi; | 358 return IcePhi; |
359 } | 359 } |
360 | 360 |
361 Ice::Inst *convertBrInstruction(const BranchInst *Inst) { | 361 Ice::Inst *convertBrInstruction(const BranchInst *Instr) { |
362 if (Inst->isConditional()) { | 362 if (Instr->isConditional()) { |
363 Ice::Operand *Src = convertOperand(Inst, 0); | 363 Ice::Operand *Src = convertOperand(Instr, 0); |
364 BasicBlock *BBThen = Inst->getSuccessor(0); | 364 BasicBlock *BBThen = Instr->getSuccessor(0); |
365 BasicBlock *BBElse = Inst->getSuccessor(1); | 365 BasicBlock *BBElse = Instr->getSuccessor(1); |
366 Ice::CfgNode *NodeThen = mapBasicBlockToNode(BBThen); | 366 Ice::CfgNode *NodeThen = mapBasicBlockToNode(BBThen); |
367 Ice::CfgNode *NodeElse = mapBasicBlockToNode(BBElse); | 367 Ice::CfgNode *NodeElse = mapBasicBlockToNode(BBElse); |
368 return Ice::InstBr::create(Func.get(), Src, NodeThen, NodeElse); | 368 return Ice::InstBr::create(Func.get(), Src, NodeThen, NodeElse); |
369 } else { | 369 } else { |
370 BasicBlock *BBSucc = Inst->getSuccessor(0); | 370 BasicBlock *BBSucc = Instr->getSuccessor(0); |
371 return Ice::InstBr::create(Func.get(), mapBasicBlockToNode(BBSucc)); | 371 return Ice::InstBr::create(Func.get(), mapBasicBlockToNode(BBSucc)); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Inst) { | 375 Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Instr) { |
376 Ice::Operand *Src = convertOperand(Inst, 0); | 376 Ice::Operand *Src = convertOperand(Instr, 0); |
377 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); | 377 Ice::Variable *Dest = mapValueToIceVar(Instr, Ice::getPointerType()); |
378 return Ice::InstAssign::create(Func.get(), Dest, Src); | 378 return Ice::InstAssign::create(Func.get(), Dest, Src); |
379 } | 379 } |
380 | 380 |
381 Ice::Inst *convertPtrToIntInstruction(const PtrToIntInst *Inst) { | 381 Ice::Inst *convertPtrToIntInstruction(const PtrToIntInst *Instr) { |
382 Ice::Operand *Src = convertOperand(Inst, 0); | 382 Ice::Operand *Src = convertOperand(Instr, 0); |
383 Ice::Variable *Dest = mapValueToIceVar(Inst); | 383 Ice::Variable *Dest = mapValueToIceVar(Instr); |
384 return Ice::InstAssign::create(Func.get(), Dest, Src); | 384 return Ice::InstAssign::create(Func.get(), Dest, Src); |
385 } | 385 } |
386 | 386 |
387 Ice::Inst *convertRetInstruction(const ReturnInst *Inst) { | 387 Ice::Inst *convertRetInstruction(const ReturnInst *Instr) { |
388 Ice::Operand *RetOperand = convertOperand(Inst, 0); | 388 Ice::Operand *RetOperand = convertOperand(Instr, 0); |
389 if (RetOperand) { | 389 if (RetOperand) { |
390 return Ice::InstRet::create(Func.get(), RetOperand); | 390 return Ice::InstRet::create(Func.get(), RetOperand); |
391 } else { | 391 } else { |
392 return Ice::InstRet::create(Func.get()); | 392 return Ice::InstRet::create(Func.get()); |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 Ice::Inst *convertCastInstruction(const Instruction *Inst, | 396 Ice::Inst *convertCastInstruction(const Instruction *Instr, |
397 Ice::InstCast::OpKind CastKind) { | 397 Ice::InstCast::OpKind CastKind) { |
398 Ice::Operand *Src = convertOperand(Inst, 0); | 398 Ice::Operand *Src = convertOperand(Instr, 0); |
399 Ice::Variable *Dest = mapValueToIceVar(Inst); | 399 Ice::Variable *Dest = mapValueToIceVar(Instr); |
400 return Ice::InstCast::create(Func.get(), CastKind, Dest, Src); | 400 return Ice::InstCast::create(Func.get(), CastKind, Dest, Src); |
401 } | 401 } |
402 | 402 |
403 Ice::Inst *convertICmpInstruction(const ICmpInst *Inst) { | 403 Ice::Inst *convertICmpInstruction(const ICmpInst *Instr) { |
404 Ice::Operand *Src0 = convertOperand(Inst, 0); | 404 Ice::Operand *Src0 = convertOperand(Instr, 0); |
405 Ice::Operand *Src1 = convertOperand(Inst, 1); | 405 Ice::Operand *Src1 = convertOperand(Instr, 1); |
406 Ice::Variable *Dest = mapValueToIceVar(Inst); | 406 Ice::Variable *Dest = mapValueToIceVar(Instr); |
407 | 407 |
408 Ice::InstIcmp::ICond Cond; | 408 Ice::InstIcmp::ICond Cond; |
409 switch (Inst->getPredicate()) { | 409 switch (Instr->getPredicate()) { |
410 default: | 410 default: |
411 llvm_unreachable("ICmpInst predicate"); | 411 llvm_unreachable("ICmpInst predicate"); |
412 case CmpInst::ICMP_EQ: | 412 case CmpInst::ICMP_EQ: |
413 Cond = Ice::InstIcmp::Eq; | 413 Cond = Ice::InstIcmp::Eq; |
414 break; | 414 break; |
415 case CmpInst::ICMP_NE: | 415 case CmpInst::ICMP_NE: |
416 Cond = Ice::InstIcmp::Ne; | 416 Cond = Ice::InstIcmp::Ne; |
417 break; | 417 break; |
418 case CmpInst::ICMP_UGT: | 418 case CmpInst::ICMP_UGT: |
419 Cond = Ice::InstIcmp::Ugt; | 419 Cond = Ice::InstIcmp::Ugt; |
(...skipping 17 matching lines...) Expand all Loading... |
437 Cond = Ice::InstIcmp::Slt; | 437 Cond = Ice::InstIcmp::Slt; |
438 break; | 438 break; |
439 case CmpInst::ICMP_SLE: | 439 case CmpInst::ICMP_SLE: |
440 Cond = Ice::InstIcmp::Sle; | 440 Cond = Ice::InstIcmp::Sle; |
441 break; | 441 break; |
442 } | 442 } |
443 | 443 |
444 return Ice::InstIcmp::create(Func.get(), Cond, Dest, Src0, Src1); | 444 return Ice::InstIcmp::create(Func.get(), Cond, Dest, Src0, Src1); |
445 } | 445 } |
446 | 446 |
447 Ice::Inst *convertFCmpInstruction(const FCmpInst *Inst) { | 447 Ice::Inst *convertFCmpInstruction(const FCmpInst *Instr) { |
448 Ice::Operand *Src0 = convertOperand(Inst, 0); | 448 Ice::Operand *Src0 = convertOperand(Instr, 0); |
449 Ice::Operand *Src1 = convertOperand(Inst, 1); | 449 Ice::Operand *Src1 = convertOperand(Instr, 1); |
450 Ice::Variable *Dest = mapValueToIceVar(Inst); | 450 Ice::Variable *Dest = mapValueToIceVar(Instr); |
451 | 451 |
452 Ice::InstFcmp::FCond Cond; | 452 Ice::InstFcmp::FCond Cond; |
453 switch (Inst->getPredicate()) { | 453 switch (Instr->getPredicate()) { |
454 | 454 |
455 default: | 455 default: |
456 llvm_unreachable("FCmpInst predicate"); | 456 llvm_unreachable("FCmpInst predicate"); |
457 | 457 |
458 case CmpInst::FCMP_FALSE: | 458 case CmpInst::FCMP_FALSE: |
459 Cond = Ice::InstFcmp::False; | 459 Cond = Ice::InstFcmp::False; |
460 break; | 460 break; |
461 case CmpInst::FCMP_OEQ: | 461 case CmpInst::FCMP_OEQ: |
462 Cond = Ice::InstFcmp::Oeq; | 462 Cond = Ice::InstFcmp::Oeq; |
463 break; | 463 break; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 Cond = Ice::InstFcmp::Uno; | 501 Cond = Ice::InstFcmp::Uno; |
502 break; | 502 break; |
503 case CmpInst::FCMP_TRUE: | 503 case CmpInst::FCMP_TRUE: |
504 Cond = Ice::InstFcmp::True; | 504 Cond = Ice::InstFcmp::True; |
505 break; | 505 break; |
506 } | 506 } |
507 | 507 |
508 return Ice::InstFcmp::create(Func.get(), Cond, Dest, Src0, Src1); | 508 return Ice::InstFcmp::create(Func.get(), Cond, Dest, Src0, Src1); |
509 } | 509 } |
510 | 510 |
511 Ice::Inst *convertExtractElementInstruction(const ExtractElementInst *Inst) { | 511 Ice::Inst *convertExtractElementInstruction(const ExtractElementInst *Instr) { |
512 Ice::Variable *Dest = mapValueToIceVar(Inst); | 512 Ice::Variable *Dest = mapValueToIceVar(Instr); |
513 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); | 513 Ice::Operand *Source1 = convertValue(Instr->getOperand(0)); |
514 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); | 514 Ice::Operand *Source2 = convertValue(Instr->getOperand(1)); |
515 return Ice::InstExtractElement::create(Func.get(), Dest, Source1, Source2); | 515 return Ice::InstExtractElement::create(Func.get(), Dest, Source1, Source2); |
516 } | 516 } |
517 | 517 |
518 Ice::Inst *convertInsertElementInstruction(const InsertElementInst *Inst) { | 518 Ice::Inst *convertInsertElementInstruction(const InsertElementInst *Instr) { |
519 Ice::Variable *Dest = mapValueToIceVar(Inst); | 519 Ice::Variable *Dest = mapValueToIceVar(Instr); |
520 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); | 520 Ice::Operand *Source1 = convertValue(Instr->getOperand(0)); |
521 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); | 521 Ice::Operand *Source2 = convertValue(Instr->getOperand(1)); |
522 Ice::Operand *Source3 = convertValue(Inst->getOperand(2)); | 522 Ice::Operand *Source3 = convertValue(Instr->getOperand(2)); |
523 return Ice::InstInsertElement::create(Func.get(), Dest, Source1, Source2, | 523 return Ice::InstInsertElement::create(Func.get(), Dest, Source1, Source2, |
524 Source3); | 524 Source3); |
525 } | 525 } |
526 | 526 |
527 Ice::Inst *convertSelectInstruction(const SelectInst *Inst) { | 527 Ice::Inst *convertSelectInstruction(const SelectInst *Instr) { |
528 Ice::Variable *Dest = mapValueToIceVar(Inst); | 528 Ice::Variable *Dest = mapValueToIceVar(Instr); |
529 Ice::Operand *Cond = convertValue(Inst->getCondition()); | 529 Ice::Operand *Cond = convertValue(Instr->getCondition()); |
530 Ice::Operand *Source1 = convertValue(Inst->getTrueValue()); | 530 Ice::Operand *Source1 = convertValue(Instr->getTrueValue()); |
531 Ice::Operand *Source2 = convertValue(Inst->getFalseValue()); | 531 Ice::Operand *Source2 = convertValue(Instr->getFalseValue()); |
532 return Ice::InstSelect::create(Func.get(), Dest, Cond, Source1, Source2); | 532 return Ice::InstSelect::create(Func.get(), Dest, Cond, Source1, Source2); |
533 } | 533 } |
534 | 534 |
535 Ice::Inst *convertSwitchInstruction(const SwitchInst *Inst) { | 535 Ice::Inst *convertSwitchInstruction(const SwitchInst *Instr) { |
536 Ice::Operand *Source = convertValue(Inst->getCondition()); | 536 Ice::Operand *Source = convertValue(Instr->getCondition()); |
537 Ice::CfgNode *LabelDefault = mapBasicBlockToNode(Inst->getDefaultDest()); | 537 Ice::CfgNode *LabelDefault = mapBasicBlockToNode(Instr->getDefaultDest()); |
538 unsigned NumCases = Inst->getNumCases(); | 538 unsigned NumCases = Instr->getNumCases(); |
539 Ice::InstSwitch *Switch = | 539 Ice::InstSwitch *Switch = |
540 Ice::InstSwitch::create(Func.get(), NumCases, Source, LabelDefault); | 540 Ice::InstSwitch::create(Func.get(), NumCases, Source, LabelDefault); |
541 unsigned CurrentCase = 0; | 541 unsigned CurrentCase = 0; |
542 for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end(); | 542 for (SwitchInst::ConstCaseIt I = Instr->case_begin(), E = Instr->case_end(); |
543 I != E; ++I, ++CurrentCase) { | 543 I != E; ++I, ++CurrentCase) { |
544 uint64_t CaseValue = I.getCaseValue()->getSExtValue(); | 544 uint64_t CaseValue = I.getCaseValue()->getSExtValue(); |
545 Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor()); | 545 Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor()); |
546 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor); | 546 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor); |
547 } | 547 } |
548 return Switch; | 548 return Switch; |
549 } | 549 } |
550 | 550 |
551 Ice::Inst *convertCallInstruction(const CallInst *Inst) { | 551 Ice::Inst *convertCallInstruction(const CallInst *Instr) { |
552 Ice::Variable *Dest = mapValueToIceVar(Inst); | 552 Ice::Variable *Dest = mapValueToIceVar(Instr); |
553 Ice::Operand *CallTarget = convertValue(Inst->getCalledValue()); | 553 Ice::Operand *CallTarget = convertValue(Instr->getCalledValue()); |
554 unsigned NumArgs = Inst->getNumArgOperands(); | 554 unsigned NumArgs = Instr->getNumArgOperands(); |
555 // Note: Subzero doesn't (yet) do anything special with the Tail flag in | 555 // Note: Subzero doesn't (yet) do anything special with the Tail flag in |
556 // the bitcode, i.e. CallInst::isTailCall(). | 556 // the bitcode, i.e. CallInst::isTailCall(). |
557 Ice::InstCall *NewInst = nullptr; | 557 Ice::InstCall *NewInst = nullptr; |
558 const Ice::Intrinsics::FullIntrinsicInfo *Info = nullptr; | 558 const Ice::Intrinsics::FullIntrinsicInfo *Info = nullptr; |
559 | 559 |
560 if (const auto Target = dyn_cast<Ice::ConstantRelocatable>(CallTarget)) { | 560 if (const auto Target = dyn_cast<Ice::ConstantRelocatable>(CallTarget)) { |
561 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 561 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
562 bool BadIntrinsic; | 562 bool BadIntrinsic; |
563 Info = Ctx->getIntrinsicsInfo().find(Target->getName(), BadIntrinsic); | 563 Info = Ctx->getIntrinsicsInfo().find(Target->getName(), BadIntrinsic); |
564 if (BadIntrinsic) { | 564 if (BadIntrinsic) { |
565 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + | 565 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + |
566 LLVMObjectAsString(Inst)); | 566 LLVMObjectAsString(Instr)); |
567 } | 567 } |
568 if (Info) | 568 if (Info) |
569 NewInst = Ice::InstIntrinsicCall::create(Func.get(), NumArgs, Dest, | 569 NewInst = Ice::InstIntrinsicCall::create(Func.get(), NumArgs, Dest, |
570 CallTarget, Info->Info); | 570 CallTarget, Info->Info); |
571 } | 571 } |
572 | 572 |
573 // Not an intrinsic call. | 573 // Not an intrinsic call. |
574 if (NewInst == nullptr) { | 574 if (NewInst == nullptr) { |
575 NewInst = Ice::InstCall::create(Func.get(), NumArgs, Dest, CallTarget, | 575 NewInst = Ice::InstCall::create(Func.get(), NumArgs, Dest, CallTarget, |
576 Inst->isTailCall()); | 576 Instr->isTailCall()); |
577 } | 577 } |
578 for (unsigned i = 0; i < NumArgs; ++i) { | 578 for (unsigned i = 0; i < NumArgs; ++i) { |
579 NewInst->addArg(convertOperand(Inst, i)); | 579 NewInst->addArg(convertOperand(Instr, i)); |
580 } | 580 } |
581 if (Info) { | 581 if (Info) { |
582 validateIntrinsicCall(NewInst, Info); | 582 validateIntrinsicCall(NewInst, Info); |
583 } | 583 } |
584 return NewInst; | 584 return NewInst; |
585 } | 585 } |
586 | 586 |
587 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) { | 587 Ice::Inst *convertAllocaInstruction(const AllocaInst *Instr) { |
588 // PNaCl bitcode only contains allocas of byte-granular objects. | 588 // PNaCl bitcode only contains allocas of byte-granular objects. |
589 Ice::Operand *ByteCount = convertValue(Inst->getArraySize()); | 589 Ice::Operand *ByteCount = convertValue(Instr->getArraySize()); |
590 uint32_t Align = Inst->getAlignment(); | 590 uint32_t Align = Instr->getAlignment(); |
591 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); | 591 Ice::Variable *Dest = mapValueToIceVar(Instr, Ice::getPointerType()); |
592 | 592 |
593 return Ice::InstAlloca::create(Func.get(), Dest, ByteCount, Align); | 593 return Ice::InstAlloca::create(Func.get(), Dest, ByteCount, Align); |
594 } | 594 } |
595 | 595 |
596 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) { | 596 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Instr*/) { |
597 return Ice::InstUnreachable::create(Func.get()); | 597 return Ice::InstUnreachable::create(Func.get()); |
598 } | 598 } |
599 | 599 |
600 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { | 600 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { |
601 Ice::CfgNode *Node = mapBasicBlockToNode(BB); | 601 Ice::CfgNode *Node = mapBasicBlockToNode(BB); |
602 for (const Instruction &II : *BB) { | 602 for (const Instruction &II : *BB) { |
603 Ice::Inst *Inst = convertInstruction(&II); | 603 Ice::Inst *Instr = convertInstruction(&II); |
604 Node->appendInst(Inst); | 604 Node->appendInst(Instr); |
605 } | 605 } |
606 return Node; | 606 return Node; |
607 } | 607 } |
608 | 608 |
609 void validateIntrinsicCall(const Ice::InstCall *Call, | 609 void validateIntrinsicCall(const Ice::InstCall *Call, |
610 const Ice::Intrinsics::FullIntrinsicInfo *I) { | 610 const Ice::Intrinsics::FullIntrinsicInfo *I) { |
611 Ice::SizeT ArgIndex = 0; | 611 Ice::SizeT ArgIndex = 0; |
612 switch (I->validateCall(Call, ArgIndex)) { | 612 switch (I->validateCall(Call, ArgIndex)) { |
613 case Ice::Intrinsics::IsValidCall: | 613 case Ice::Intrinsics::IsValidCall: |
614 break; | 614 break; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 Ctx->pushTimer(TimerID, StackID); | 924 Ctx->pushTimer(TimerID, StackID); |
925 } | 925 } |
926 LLVM2ICEFunctionConverter FunctionConverter(*this); | 926 LLVM2ICEFunctionConverter FunctionConverter(*this); |
927 FunctionConverter.convertFunction(&I); | 927 FunctionConverter.convertFunction(&I); |
928 if (TimeThisFunction) | 928 if (TimeThisFunction) |
929 Ctx->popTimer(TimerID, StackID); | 929 Ctx->popTimer(TimerID, StackID); |
930 } | 930 } |
931 } | 931 } |
932 | 932 |
933 } // end of namespace Ice | 933 } // end of namespace Ice |
OLD | NEW |