Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// |
| 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 // This file implements the InstX8632 and OperandX8632 classes, | 10 // This file implements the InstX8632 and OperandX8632 classes, |
| 11 // primarily the constructors and the dump()/emit() methods. | 11 // primarily the constructors and the dump()/emit() methods. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "assembler_ia32.h" | |
| 15 #include "IceCfg.h" | 16 #include "IceCfg.h" |
| 16 #include "IceCfgNode.h" | 17 #include "IceCfgNode.h" |
| 17 #include "IceInst.h" | 18 #include "IceInst.h" |
| 18 #include "IceInstX8632.h" | 19 #include "IceInstX8632.h" |
| 19 #include "IceTargetLoweringX8632.h" | 20 #include "IceTargetLoweringX8632.h" |
| 20 #include "IceOperand.h" | 21 #include "IceOperand.h" |
| 21 | 22 |
| 22 namespace Ice { | 23 namespace Ice { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 ICETYPEX8632_TABLE | 57 ICETYPEX8632_TABLE |
| 57 #undef X | 58 #undef X |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 const char *InstX8632SegmentRegNames[] = { | 61 const char *InstX8632SegmentRegNames[] = { |
| 61 #define X(val, name) name, | 62 #define X(val, name) name, |
| 62 SEG_REGX8632_TABLE | 63 SEG_REGX8632_TABLE |
| 63 #undef X | 64 #undef X |
| 64 }; | 65 }; |
| 65 | 66 |
| 67 x86::Condition convertToAsmCondition(InstX8632::BrCond Cond) { | |
| 68 return x86::Condition(Cond); | |
| 69 } | |
| 70 | |
| 71 x86::Register convertToAsmGPR(int32_t RegNum) { | |
| 72 assert(TargetX8632::Reg_eax <= RegNum && RegNum <= TargetX8632::Reg_edi); | |
| 73 return x86::Register(RegNum); | |
| 74 } | |
| 75 | |
| 76 x86::ByteRegister convertToAsmByteRegister(int32_t RegNum) { | |
| 77 if (RegNum == TargetX8632::Reg_ah) { | |
| 78 return x86::AH; | |
| 79 } | |
| 80 assert(TargetX8632::Reg_eax <= RegNum && RegNum <= TargetX8632::Reg_ebx); | |
| 81 return x86::ByteRegister(RegNum); | |
| 82 } | |
| 83 | |
| 84 x86::Immediate convertIntImmToAsmImm(const ConstantInteger *CI) { | |
| 85 int32_t V = static_cast<int32_t>(CI->getValue()); | |
| 86 // Check that it's really 32-bit. | |
| 87 // Sometimes Subzero stores negative values as sign-extended 64-bit | |
| 88 // and sometimes it's zero-extended to 64-bit. | |
| 89 // Should we just make a ConstantInteger32? | |
|
Jim Stichnoth
2014/09/09 14:58:41
I was also thinking that maybe constant integers n
jvoung (off chromium)
2014/09/15 17:19:15
Hmm, we could add signed/unsigned, but I'm not yet
| |
| 90 assert((CI->getValue() >> 32) == 0 || (CI->getValue() >> 32) == 0xffffffff); | |
| 91 return x86::Immediate(V); | |
| 92 } | |
| 93 | |
| 94 x86::XmmRegister convertToAsmXMMReg(int32_t RegNum) { | |
| 95 assert(TargetX8632::Reg_xmm0 <= RegNum && RegNum <= TargetX8632::Reg_xmm7); | |
| 96 return x86::XmmRegister(RegNum - TargetX8632::Reg_xmm0); | |
| 97 } | |
| 98 | |
| 99 // Convert a float or double immediate to an Address Operand. | |
| 100 // Modifies SymbolicOffset to contain the symbol. | |
| 101 x86::Address convertFloatImmToAsmAddr(const Constant *Imm, | |
| 102 IceString &SymbolicOffset) { | |
| 103 std::string Buffer; | |
| 104 llvm::raw_string_ostream StrBuf(Buffer); | |
| 105 Type Ty = Imm->getType(); | |
| 106 assert(llvm::isa<ConstantFloat>(Imm) || llvm::isa<ConstantDouble>(Imm)); | |
| 107 StrBuf << "L$" << Ty << "$" << Imm->getPoolEntryID(); | |
| 108 SymbolicOffset = StrBuf.str(); | |
| 109 return x86::Address::Absolute(0); | |
| 110 } | |
| 111 | |
| 66 } // end of anonymous namespace | 112 } // end of anonymous namespace |
| 67 | 113 |
| 68 const char *InstX8632::getWidthString(Type Ty) { | 114 const char *InstX8632::getWidthString(Type Ty) { |
| 69 return TypeX8632Attributes[Ty].WidthString; | 115 return TypeX8632Attributes[Ty].WidthString; |
| 70 } | 116 } |
| 71 | 117 |
| 72 OperandX8632Mem::OperandX8632Mem(Cfg *Func, Type Ty, Variable *Base, | 118 OperandX8632Mem::OperandX8632Mem(Cfg *Func, Type Ty, Variable *Base, |
| 73 Constant *Offset, Variable *Index, | 119 Constant *Offset, Variable *Index, |
| 74 uint16_t Shift, SegmentRegisters SegmentReg) | 120 uint16_t Shift, SegmentRegisters SegmentReg) |
| 75 : OperandX8632(kMem, Ty), Base(Base), Offset(Offset), Index(Index), | 121 : OperandX8632(kMem, Ty), Base(Base), Offset(Offset), Index(Index), |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 } | 324 } |
| 279 | 325 |
| 280 InstX8632Xchg::InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source) | 326 InstX8632Xchg::InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source) |
| 281 : InstX8632(Func, InstX8632::Xchg, 2, llvm::dyn_cast<Variable>(Dest)) { | 327 : InstX8632(Func, InstX8632::Xchg, 2, llvm::dyn_cast<Variable>(Dest)) { |
| 282 addSource(Dest); | 328 addSource(Dest); |
| 283 addSource(Source); | 329 addSource(Source); |
| 284 } | 330 } |
| 285 | 331 |
| 286 // ======================== Dump routines ======================== // | 332 // ======================== Dump routines ======================== // |
| 287 | 333 |
| 334 namespace { | |
| 335 | |
| 336 void emitIASBytes(Ostream &Str, const x86::AssemblerX86 *Asm, | |
| 337 intptr_t StartPosition, | |
| 338 const IceString &SymbolicOffset = IceString("")) { | |
| 339 intptr_t EndPosition = Asm->GetPosition(); | |
| 340 if (!SymbolicOffset.empty()) { | |
| 341 const intptr_t OffsetSize = 4; | |
| 342 EndPosition -= OffsetSize; | |
| 343 } | |
| 344 for (intptr_t i = 0; i < EndPosition - StartPosition; ++i) { | |
| 345 Str << "\t.byte " | |
| 346 << static_cast<uint32_t>(Asm->LoadBuffer<uint8_t>(StartPosition + i)) | |
| 347 << "\n"; | |
| 348 } | |
| 349 if (!SymbolicOffset.empty()) { | |
| 350 int32_t Disp = Asm->LoadBuffer<int32_t>(EndPosition); | |
| 351 if (Disp) | |
| 352 Str << "\t.long " << SymbolicOffset << " + " << Disp << "\n"; | |
| 353 else | |
| 354 Str << "\t.long " << SymbolicOffset << "\n"; | |
| 355 } | |
| 356 } | |
| 357 | |
| 358 void emitIASVarOperandInt(const Cfg *Func, const Variable *Var, | |
| 359 const Operand *Src, | |
| 360 x86::AssemblerX86::EmitTyRegReg EmitRegReg, | |
| 361 x86::AssemblerX86::EmitTyRegAddr EmitRegAddr, | |
| 362 x86::AssemblerX86::EmitTyRegImm EmitRegImm) { | |
| 363 // For now, we assume Var is reg, since most of the time we use: | |
| 364 // _add(T, foo) | |
| 365 // _mov(Var, T) | |
| 366 // where T is a register. | |
| 367 // | |
| 368 // Otherwise, if Var can be mem, use the emitIASTwoOperandInt function.. | |
| 369 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 370 intptr_t StartPosition = Asm->GetPosition(); | |
| 371 IceString SymbolicOffset = ""; | |
| 372 Type Ty = Var->getType(); | |
| 373 // Classify Var. | |
| 374 x86::Register VarReg; | |
| 375 assert(Var->hasReg()); | |
| 376 if (typeWidthInBytes(Ty) == 1) { | |
| 377 // We fudge a bit, and use Register for ByteRegister. | |
| 378 // This avoids having to add another assembler method, | |
| 379 // just for ByteRegisters. The register encoding is the same. | |
| 380 VarReg = convertToAsmGPR(convertToAsmByteRegister(Var->getRegNum())); | |
| 381 } else { | |
| 382 VarReg = convertToAsmGPR(Var->getRegNum()); | |
| 383 } | |
| 384 | |
| 385 // Classify Src. | |
| 386 if (const Variable *SrcVar = llvm::dyn_cast<Variable>(Src)) { | |
| 387 if (SrcVar->hasReg()) { | |
| 388 x86::Register SrcReg; | |
| 389 if (typeWidthInBytes(Ty) == 1) { | |
| 390 SrcReg = convertToAsmGPR(convertToAsmByteRegister(SrcVar->getRegNum())); | |
| 391 } else { | |
| 392 SrcReg = convertToAsmGPR(SrcVar->getRegNum()); | |
| 393 } | |
| 394 (Asm->*EmitRegReg)(Ty, VarReg, SrcReg); | |
| 395 } else { | |
| 396 x86::Address SrcAddr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 397 ->stackVarToAsmOperand(SrcVar); | |
| 398 (Asm->*EmitRegAddr)(Ty, VarReg, SrcAddr); | |
| 399 } | |
| 400 } else if (const OperandX8632Mem *Mem = | |
| 401 llvm::dyn_cast<OperandX8632Mem>(Src)) { | |
| 402 x86::Address SrcAddr = Mem->convertToAsmAddress(SymbolicOffset); | |
| 403 (Asm->*EmitRegAddr)(Ty, VarReg, SrcAddr); | |
| 404 } else if (const ConstantInteger *CI = llvm::dyn_cast<ConstantInteger>(Src)) { | |
| 405 x86::Immediate Imm = convertIntImmToAsmImm(CI); | |
| 406 (Asm->*EmitRegImm)(Ty, VarReg, Imm); | |
| 407 } | |
| 408 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 409 emitIASBytes(Str, Asm, StartPosition, SymbolicOffset); | |
| 410 } | |
| 411 | |
| 412 void emitIASTwoOperandInt(const Cfg *Func, const Operand *Src0, | |
| 413 const Operand *Src1, | |
| 414 x86::AssemblerX86::EmitTyRegReg EmitRegReg, | |
| 415 x86::AssemblerX86::EmitTyRegAddr EmitRegAddr, | |
| 416 x86::AssemblerX86::EmitTyRegImm EmitRegImm, | |
| 417 x86::AssemblerX86::EmitTyAddrReg EmitAddrReg, | |
| 418 x86::AssemblerX86::EmitTyAddrImm EmitAddrImm) { | |
| 419 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 420 intptr_t StartPosition = Asm->GetPosition(); | |
| 421 IceString SymbolicOffset = ""; | |
| 422 Type Ty = Src0->getType(); | |
| 423 | |
| 424 // Classify Src0 (Reg or Mem). | |
| 425 // Could use a lambda/functional to curry the first parameter. | |
| 426 bool Src0IsReg = false; | |
| 427 x86::Register Src0Reg = x86::kNoRegister; | |
| 428 x86::Address Src0Addr = x86::Address::Absolute(0); | |
| 429 if (const Variable *Src0Var = llvm::dyn_cast<Variable>(Src0)) { | |
| 430 if (Src0Var->hasReg()) { | |
| 431 Src0IsReg = true; | |
| 432 if (typeWidthInBytes(Ty) == 1) { | |
| 433 Src0Reg = | |
| 434 convertToAsmGPR(convertToAsmByteRegister(Src0Var->getRegNum())); | |
| 435 } else { | |
| 436 Src0Reg = convertToAsmGPR(Src0Var->getRegNum()); | |
| 437 } | |
| 438 } else { | |
| 439 Src0Addr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 440 ->stackVarToAsmOperand(Src0Var); | |
| 441 } | |
| 442 } else if (const OperandX8632Mem *Mem = | |
| 443 llvm::dyn_cast<OperandX8632Mem>(Src0)) { | |
| 444 Src0Addr = Mem->convertToAsmAddress(SymbolicOffset); | |
| 445 } | |
| 446 | |
| 447 // Classify Src1 (Reg, Mem, or Imm). | |
| 448 if (const Variable *Src1Var = llvm::dyn_cast<Variable>(Src1)) { | |
| 449 if (Src1Var->hasReg()) { | |
| 450 x86::Register Src1Reg; | |
| 451 if (typeWidthInBytes(Ty) == 1) { | |
| 452 Src1Reg = | |
| 453 convertToAsmGPR(convertToAsmByteRegister(Src1Var->getRegNum())); | |
| 454 } else { | |
| 455 Src1Reg = convertToAsmGPR(Src1Var->getRegNum()); | |
| 456 } | |
| 457 if (Src0IsReg) | |
| 458 (Asm->*EmitRegReg)(Ty, Src0Reg, Src1Reg); | |
| 459 else | |
| 460 (Asm->*EmitAddrReg)(Ty, Src0Addr, Src1Reg); | |
| 461 } else { | |
| 462 x86::Address Src1Addr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 463 ->stackVarToAsmOperand(Src1Var); | |
| 464 assert(Src0IsReg); | |
| 465 (Asm->*EmitRegAddr)(Ty, Src0Reg, Src1Addr); | |
| 466 } | |
| 467 } else if (const OperandX8632Mem *Mem = | |
| 468 llvm::dyn_cast<OperandX8632Mem>(Src1)) { | |
| 469 x86::Address Src1Addr = Mem->convertToAsmAddress(SymbolicOffset); | |
| 470 assert(Src0IsReg); | |
| 471 (Asm->*EmitRegAddr)(Ty, Src0Reg, Src1Addr); | |
| 472 } else if (const ConstantInteger *CI = | |
| 473 llvm::dyn_cast<ConstantInteger>(Src1)) { | |
| 474 x86::Immediate Imm = convertIntImmToAsmImm(CI); | |
| 475 if (Src0IsReg) | |
| 476 (Asm->*EmitRegImm)(Ty, Src0Reg, Imm); | |
| 477 else | |
| 478 (Asm->*EmitAddrImm)(Ty, Src0Addr, Imm); | |
| 479 // TODO(jvoung): Record the buffer position containing the relocation, | |
| 480 // instead of just assuming it's the last 4 bytes. That would not be | |
| 481 // true if Src0 is Memory w/ a symbolic displacement, and Src1 | |
| 482 // is an immediate. The immediate would take up the last few bytes | |
| 483 // and the memory operand's displacement would come before those imm bytes. | |
| 484 // | |
| 485 // Perhaps the "Address" Operand type could indicate that it's a | |
| 486 // relocatable, and then the emitOperand() methods will check | |
| 487 // and create Fixups inline while the buffer is in the correct position. | |
| 488 assert(SymbolicOffset.empty()); | |
| 489 } | |
| 490 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 491 emitIASBytes(Str, Asm, StartPosition, SymbolicOffset); | |
| 492 } | |
| 493 | |
| 494 void emitIASVarOperandXMM(const Cfg *Func, const Variable *Var, | |
| 495 const Operand *Src, | |
| 496 x86::AssemblerX86::EmitXmmXmm EmitXmmXmm, | |
| 497 x86::AssemblerX86::EmitXmmAddr EmitXmmAddr) { | |
| 498 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 499 intptr_t StartPosition = Asm->GetPosition(); | |
| 500 assert(Var->hasReg()); | |
| 501 x86::XmmRegister VarReg = convertToAsmXMMReg(Var->getRegNum()); | |
| 502 IceString SymbolicOffset = ""; | |
| 503 if (const Variable *SrcVar = llvm::dyn_cast<Variable>(Src)) { | |
| 504 if (SrcVar->hasReg()) { | |
| 505 x86::XmmRegister SrcReg = convertToAsmXMMReg(SrcVar->getRegNum()); | |
| 506 (Asm->*EmitXmmXmm)(VarReg, SrcReg); | |
| 507 } else { | |
| 508 x86::Address SrcStackAddr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 509 ->stackVarToAsmOperand(SrcVar); | |
| 510 (Asm->*EmitXmmAddr)(VarReg, SrcStackAddr); | |
| 511 } | |
| 512 } else if (const OperandX8632Mem *Mem = | |
| 513 llvm::dyn_cast<OperandX8632Mem>(Src)) { | |
| 514 x86::Address SrcAddr = Mem->convertToAsmAddress(SymbolicOffset); | |
| 515 (Asm->*EmitXmmAddr)(VarReg, SrcAddr); | |
| 516 } else if (const Constant *Imm = llvm::dyn_cast<Constant>(Src)) { | |
| 517 (Asm->*EmitXmmAddr)(VarReg, convertFloatImmToAsmAddr(Imm, SymbolicOffset)); | |
| 518 } else { | |
| 519 llvm_unreachable("Unexpected operand type"); | |
| 520 } | |
| 521 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 522 emitIASBytes(Str, Asm, StartPosition, SymbolicOffset); | |
| 523 } | |
| 524 | |
| 525 } // end of anonymous namespace | |
| 526 | |
| 288 void InstX8632::dump(const Cfg *Func) const { | 527 void InstX8632::dump(const Cfg *Func) const { |
| 289 Ostream &Str = Func->getContext()->getStrDump(); | 528 Ostream &Str = Func->getContext()->getStrDump(); |
| 290 Str << "[X8632] "; | 529 Str << "[X8632] "; |
| 291 Inst::dump(Func); | 530 Inst::dump(Func); |
| 292 } | 531 } |
| 293 | 532 |
| 533 void InstX8632::emitIAS(const Cfg *Func) const { emit(Func); } | |
| 534 | |
| 294 void InstX8632Label::emit(const Cfg *Func) const { | 535 void InstX8632Label::emit(const Cfg *Func) const { |
| 295 Ostream &Str = Func->getContext()->getStrEmit(); | 536 Ostream &Str = Func->getContext()->getStrEmit(); |
| 296 Str << getName(Func) << ":\n"; | 537 Str << getName(Func) << ":\n"; |
| 297 } | 538 } |
| 298 | 539 |
| 299 void InstX8632Label::dump(const Cfg *Func) const { | 540 void InstX8632Label::dump(const Cfg *Func) const { |
| 300 Ostream &Str = Func->getContext()->getStrDump(); | 541 Ostream &Str = Func->getContext()->getStrDump(); |
| 301 Str << getName(Func) << ":"; | 542 Str << getName(Func) << ":"; |
| 302 } | 543 } |
| 303 | 544 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 | 589 |
| 349 void InstX8632Call::emit(const Cfg *Func) const { | 590 void InstX8632Call::emit(const Cfg *Func) const { |
| 350 Ostream &Str = Func->getContext()->getStrEmit(); | 591 Ostream &Str = Func->getContext()->getStrEmit(); |
| 351 assert(getSrcSize() == 1); | 592 assert(getSrcSize() == 1); |
| 352 Str << "\tcall\t"; | 593 Str << "\tcall\t"; |
| 353 getCallTarget()->emit(Func); | 594 getCallTarget()->emit(Func); |
| 354 Str << "\n"; | 595 Str << "\n"; |
| 355 Func->getTarget()->resetStackAdjustment(); | 596 Func->getTarget()->resetStackAdjustment(); |
| 356 } | 597 } |
| 357 | 598 |
| 599 void InstX8632Call::emitIAS(const Cfg *Func) const { | |
| 600 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 601 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 602 intptr_t StartPosition = Asm->GetPosition(); | |
| 603 Operand *Target = getCallTarget(); | |
| 604 IceString SymbolicOffset = ""; | |
| 605 if (Variable *Var = llvm::dyn_cast<Variable>(Target)) { | |
| 606 if (Var->hasReg()) { | |
| 607 Asm->call(convertToAsmGPR(Var->getRegNum())); | |
| 608 } else { | |
| 609 Asm->call(static_cast<TargetX8632 *>(Func->getTarget()) | |
| 610 ->stackVarToAsmOperand(Var)); | |
| 611 } | |
| 612 } else if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Target)) { | |
| 613 Asm->call(Mem->convertToAsmAddress(SymbolicOffset)); | |
| 614 } else if (ConstantRelocatable *CR = | |
| 615 llvm::dyn_cast<ConstantRelocatable>(Target)) { | |
| 616 assert(CR->getOffset() == 0 && "We only support calling a function"); | |
| 617 SymbolicOffset = CR->getName(); | |
| 618 Asm->call(CR); | |
| 619 } | |
| 620 if (!SymbolicOffset.empty()) { | |
| 621 // TODO(jvoung): This .byte and .long hack doesn't work, since we need | |
| 622 // a pc-rel relocation, and we also need the section contents to be | |
| 623 // -4 instead of 0. | |
| 624 // | |
| 625 // Still, we have at least filled the assembler buffer so that the | |
| 626 // instruction sizes/positions are correct for jumps. | |
| 627 // | |
| 628 // For now, fall back to the regular .s emission. | |
| 629 emit(Func); | |
| 630 } else { | |
| 631 emitIASBytes(Str, Asm, StartPosition, SymbolicOffset); | |
| 632 } | |
| 633 Func->getTarget()->resetStackAdjustment(); | |
| 634 } | |
| 635 | |
| 358 void InstX8632Call::dump(const Cfg *Func) const { | 636 void InstX8632Call::dump(const Cfg *Func) const { |
| 359 Ostream &Str = Func->getContext()->getStrDump(); | 637 Ostream &Str = Func->getContext()->getStrDump(); |
| 360 if (getDest()) { | 638 if (getDest()) { |
| 361 dumpDest(Func); | 639 dumpDest(Func); |
| 362 Str << " = "; | 640 Str << " = "; |
| 363 } | 641 } |
| 364 Str << "call "; | 642 Str << "call "; |
| 365 getCallTarget()->dump(Func); | 643 getCallTarget()->dump(Func); |
| 366 } | 644 } |
| 367 | 645 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 assert(getSrcSize() == 1); | 749 assert(getSrcSize() == 1); |
| 472 Type Ty = getSrc(0)->getType(); | 750 Type Ty = getSrc(0)->getType(); |
| 473 assert(Ty == IceType_f32 || Ty == IceType_f64); | 751 assert(Ty == IceType_f32 || Ty == IceType_f64); |
| 474 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t"; | 752 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t"; |
| 475 getDest()->emit(Func); | 753 getDest()->emit(Func); |
| 476 Str << ", "; | 754 Str << ", "; |
| 477 getSrc(0)->emit(Func); | 755 getSrc(0)->emit(Func); |
| 478 Str << "\n"; | 756 Str << "\n"; |
| 479 } | 757 } |
| 480 | 758 |
| 759 template <> void InstX8632Sqrtss::emitIAS(const Cfg *Func) const { | |
| 760 Type Ty = getDest()->getType(); | |
| 761 assert(getSrcSize() == 1); | |
| 762 assert(Ty == IceType_f32 || Ty == IceType_f64); | |
| 763 if (Ty == IceType_f64) { | |
| 764 emitIASVarOperandXMM(Func, getDest(), getSrc(0), &x86::AssemblerX86::sqrtsd, | |
| 765 &x86::AssemblerX86::sqrtsd); | |
| 766 } else { | |
| 767 emitIASVarOperandXMM(Func, getDest(), getSrc(0), &x86::AssemblerX86::sqrtss, | |
| 768 &x86::AssemblerX86::sqrtss); | |
| 769 } | |
| 770 } | |
| 771 | |
| 772 template <> void InstX8632Adc::emitIAS(const Cfg *Func) const { | |
| 773 assert(getSrcSize() == 2); | |
| 774 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::adc, | |
| 775 &x86::AssemblerX86::adc, &x86::AssemblerX86::adc); | |
| 776 } | |
| 777 | |
| 778 template <> void InstX8632Add::emitIAS(const Cfg *Func) const { | |
| 779 assert(getSrcSize() == 2); | |
| 780 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::add, | |
| 781 &x86::AssemblerX86::add, &x86::AssemblerX86::add); | |
| 782 } | |
| 783 | |
| 784 template <> void InstX8632Addps::emitIAS(const Cfg *Func) const { | |
| 785 assert(getSrcSize() == 2); | |
| 786 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::addps, | |
| 787 &x86::AssemblerX86::addps); | |
| 788 } | |
| 789 | |
| 481 template <> void InstX8632Addss::emit(const Cfg *Func) const { | 790 template <> void InstX8632Addss::emit(const Cfg *Func) const { |
| 482 char buf[30]; | 791 char buf[30]; |
| 483 snprintf(buf, llvm::array_lengthof(buf), "add%s", | 792 snprintf(buf, llvm::array_lengthof(buf), "add%s", |
| 484 TypeX8632Attributes[getDest()->getType()].SdSsString); | 793 TypeX8632Attributes[getDest()->getType()].SdSsString); |
| 485 emitTwoAddress(buf, this, Func); | 794 emitTwoAddress(buf, this, Func); |
| 486 } | 795 } |
| 487 | 796 |
| 797 template <> void InstX8632Addss::emitIAS(const Cfg *Func) const { | |
| 798 Type Ty = getDest()->getType(); | |
| 799 assert(getSrcSize() == 2); | |
| 800 if (Ty == IceType_f64) { | |
| 801 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::addsd, | |
| 802 &x86::AssemblerX86::addsd); | |
| 803 } else { | |
| 804 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::addss, | |
| 805 &x86::AssemblerX86::addss); | |
| 806 } | |
| 807 } | |
| 808 | |
| 809 template <> void InstX8632And::emitIAS(const Cfg *Func) const { | |
| 810 assert(getSrcSize() == 2); | |
| 811 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::_and, | |
| 812 &x86::AssemblerX86::_and, &x86::AssemblerX86::_and); | |
| 813 } | |
| 814 | |
| 488 template <> void InstX8632Padd::emit(const Cfg *Func) const { | 815 template <> void InstX8632Padd::emit(const Cfg *Func) const { |
| 489 char buf[30]; | 816 char buf[30]; |
| 490 snprintf(buf, llvm::array_lengthof(buf), "padd%s", | 817 snprintf(buf, llvm::array_lengthof(buf), "padd%s", |
| 491 TypeX8632Attributes[getDest()->getType()].PackString); | 818 TypeX8632Attributes[getDest()->getType()].PackString); |
| 492 emitTwoAddress(buf, this, Func); | 819 emitTwoAddress(buf, this, Func); |
| 493 } | 820 } |
| 494 | 821 |
| 495 template <> void InstX8632Pmull::emit(const Cfg *Func) const { | 822 template <> void InstX8632Pmull::emit(const Cfg *Func) const { |
| 496 char buf[30]; | 823 char buf[30]; |
| 497 bool TypesAreValid = getDest()->getType() == IceType_v4i32 || | 824 bool TypesAreValid = getDest()->getType() == IceType_v4i32 || |
| 498 getDest()->getType() == IceType_v8i16; | 825 getDest()->getType() == IceType_v8i16; |
| 499 bool InstructionSetIsValid = | 826 bool InstructionSetIsValid = |
| 500 getDest()->getType() == IceType_v8i16 || | 827 getDest()->getType() == IceType_v8i16 || |
| 501 static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >= | 828 static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >= |
| 502 TargetX8632::SSE4_1; | 829 TargetX8632::SSE4_1; |
| 503 (void)TypesAreValid; | 830 (void)TypesAreValid; |
| 504 (void)InstructionSetIsValid; | 831 (void)InstructionSetIsValid; |
| 505 assert(TypesAreValid); | 832 assert(TypesAreValid); |
| 506 assert(InstructionSetIsValid); | 833 assert(InstructionSetIsValid); |
| 507 snprintf(buf, llvm::array_lengthof(buf), "pmull%s", | 834 snprintf(buf, llvm::array_lengthof(buf), "pmull%s", |
| 508 TypeX8632Attributes[getDest()->getType()].PackString); | 835 TypeX8632Attributes[getDest()->getType()].PackString); |
| 509 emitTwoAddress(buf, this, Func); | 836 emitTwoAddress(buf, this, Func); |
| 510 } | 837 } |
| 511 | 838 |
| 839 template <> void InstX8632Sbb::emitIAS(const Cfg *Func) const { | |
| 840 assert(getSrcSize() == 2); | |
| 841 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::sbb, | |
| 842 &x86::AssemblerX86::sbb, &x86::AssemblerX86::sbb); | |
| 843 } | |
| 844 | |
| 845 template <> void InstX8632Sub::emitIAS(const Cfg *Func) const { | |
| 846 assert(getSrcSize() == 2); | |
| 847 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::sub, | |
| 848 &x86::AssemblerX86::sub, &x86::AssemblerX86::sub); | |
| 849 } | |
| 850 | |
| 851 template <> void InstX8632Subps::emitIAS(const Cfg *Func) const { | |
| 852 assert(getSrcSize() == 2); | |
| 853 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::subps, | |
| 854 &x86::AssemblerX86::subps); | |
| 855 } | |
| 856 | |
| 512 template <> void InstX8632Subss::emit(const Cfg *Func) const { | 857 template <> void InstX8632Subss::emit(const Cfg *Func) const { |
| 513 char buf[30]; | 858 char buf[30]; |
| 514 snprintf(buf, llvm::array_lengthof(buf), "sub%s", | 859 snprintf(buf, llvm::array_lengthof(buf), "sub%s", |
| 515 TypeX8632Attributes[getDest()->getType()].SdSsString); | 860 TypeX8632Attributes[getDest()->getType()].SdSsString); |
| 516 emitTwoAddress(buf, this, Func); | 861 emitTwoAddress(buf, this, Func); |
| 517 } | 862 } |
| 518 | 863 |
| 864 template <> void InstX8632Subss::emitIAS(const Cfg *Func) const { | |
| 865 Type Ty = getDest()->getType(); | |
| 866 assert(getSrcSize() == 2); | |
| 867 if (Ty == IceType_f64) { | |
| 868 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::subsd, | |
| 869 &x86::AssemblerX86::subsd); | |
| 870 } else { | |
| 871 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::subss, | |
| 872 &x86::AssemblerX86::subss); | |
| 873 } | |
| 874 } | |
| 875 | |
| 519 template <> void InstX8632Psub::emit(const Cfg *Func) const { | 876 template <> void InstX8632Psub::emit(const Cfg *Func) const { |
| 520 char buf[30]; | 877 char buf[30]; |
| 521 snprintf(buf, llvm::array_lengthof(buf), "psub%s", | 878 snprintf(buf, llvm::array_lengthof(buf), "psub%s", |
| 522 TypeX8632Attributes[getDest()->getType()].PackString); | 879 TypeX8632Attributes[getDest()->getType()].PackString); |
| 523 emitTwoAddress(buf, this, Func); | 880 emitTwoAddress(buf, this, Func); |
| 524 } | 881 } |
| 525 | 882 |
| 883 template <> void InstX8632Mulps::emitIAS(const Cfg *Func) const { | |
| 884 assert(getSrcSize() == 2); | |
| 885 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::mulps, | |
| 886 &x86::AssemblerX86::mulps); | |
| 887 } | |
| 888 | |
| 526 template <> void InstX8632Mulss::emit(const Cfg *Func) const { | 889 template <> void InstX8632Mulss::emit(const Cfg *Func) const { |
| 527 char buf[30]; | 890 char buf[30]; |
| 528 snprintf(buf, llvm::array_lengthof(buf), "mul%s", | 891 snprintf(buf, llvm::array_lengthof(buf), "mul%s", |
| 529 TypeX8632Attributes[getDest()->getType()].SdSsString); | 892 TypeX8632Attributes[getDest()->getType()].SdSsString); |
| 530 emitTwoAddress(buf, this, Func); | 893 emitTwoAddress(buf, this, Func); |
| 531 } | 894 } |
| 532 | 895 |
| 896 template <> void InstX8632Mulss::emitIAS(const Cfg *Func) const { | |
| 897 Type Ty = getDest()->getType(); | |
| 898 assert(getSrcSize() == 2); | |
| 899 if (Ty == IceType_f64) { | |
| 900 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::mulsd, | |
| 901 &x86::AssemblerX86::mulsd); | |
| 902 } else { | |
| 903 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::mulss, | |
| 904 &x86::AssemblerX86::mulss); | |
| 905 } | |
| 906 } | |
| 907 | |
| 533 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const { | 908 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const { |
| 534 assert(getSrc(0)->getType() == IceType_v4i32 && | 909 assert(getSrc(0)->getType() == IceType_v4i32 && |
| 535 getSrc(1)->getType() == IceType_v4i32); | 910 getSrc(1)->getType() == IceType_v4i32); |
| 536 emitTwoAddress(Opcode, this, Func); | 911 emitTwoAddress(Opcode, this, Func); |
| 537 } | 912 } |
| 538 | 913 |
| 914 template <> void InstX8632Divps::emitIAS(const Cfg *Func) const { | |
| 915 assert(getSrcSize() == 2); | |
| 916 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::divps, | |
| 917 &x86::AssemblerX86::divps); | |
| 918 } | |
| 919 | |
| 539 template <> void InstX8632Divss::emit(const Cfg *Func) const { | 920 template <> void InstX8632Divss::emit(const Cfg *Func) const { |
| 540 char buf[30]; | 921 char buf[30]; |
| 541 snprintf(buf, llvm::array_lengthof(buf), "div%s", | 922 snprintf(buf, llvm::array_lengthof(buf), "div%s", |
| 542 TypeX8632Attributes[getDest()->getType()].SdSsString); | 923 TypeX8632Attributes[getDest()->getType()].SdSsString); |
| 543 emitTwoAddress(buf, this, Func); | 924 emitTwoAddress(buf, this, Func); |
| 544 } | 925 } |
| 545 | 926 |
| 927 template <> void InstX8632Divss::emitIAS(const Cfg *Func) const { | |
| 928 Type Ty = getDest()->getType(); | |
| 929 assert(getSrcSize() == 2); | |
| 930 if (Ty == IceType_f64) { | |
| 931 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::divsd, | |
| 932 &x86::AssemblerX86::divsd); | |
| 933 } else { | |
| 934 emitIASVarOperandXMM(Func, getDest(), getSrc(1), &x86::AssemblerX86::divss, | |
| 935 &x86::AssemblerX86::divss); | |
| 936 } | |
| 937 } | |
| 938 | |
| 546 template <> void InstX8632Div::emit(const Cfg *Func) const { | 939 template <> void InstX8632Div::emit(const Cfg *Func) const { |
| 547 Ostream &Str = Func->getContext()->getStrEmit(); | 940 Ostream &Str = Func->getContext()->getStrEmit(); |
| 548 assert(getSrcSize() == 3); | 941 assert(getSrcSize() == 3); |
| 549 Str << "\t" << Opcode << "\t"; | 942 Str << "\t" << Opcode << "\t"; |
| 550 getSrc(1)->emit(Func); | 943 getSrc(1)->emit(Func); |
| 551 Str << "\n"; | 944 Str << "\n"; |
| 552 } | 945 } |
| 553 | 946 |
| 554 template <> void InstX8632Idiv::emit(const Cfg *Func) const { | 947 template <> void InstX8632Idiv::emit(const Cfg *Func) const { |
| 555 Ostream &Str = Func->getContext()->getStrEmit(); | 948 Ostream &Str = Func->getContext()->getStrEmit(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | 1026 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); |
| 634 Str << "\tcwd\n"; | 1027 Str << "\tcwd\n"; |
| 635 break; | 1028 break; |
| 636 case IceType_i32: | 1029 case IceType_i32: |
| 637 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | 1030 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); |
| 638 Str << "\tcdq\n"; | 1031 Str << "\tcdq\n"; |
| 639 break; | 1032 break; |
| 640 } | 1033 } |
| 641 } | 1034 } |
| 642 | 1035 |
| 1036 template <> void InstX8632Cbwdq::emitIAS(const Cfg *Func) const { | |
| 1037 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1038 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1039 intptr_t StartPosition = Asm->GetPosition(); | |
| 1040 assert(getSrcSize() == 1); | |
| 1041 Operand *Src0 = getSrc(0); | |
| 1042 assert(llvm::isa<Variable>(Src0)); | |
| 1043 assert(llvm::cast<Variable>(Src0)->getRegNum() == TargetX8632::Reg_eax); | |
| 1044 switch (Src0->getType()) { | |
| 1045 default: | |
| 1046 llvm_unreachable("unexpected source type!"); | |
| 1047 break; | |
| 1048 case IceType_i8: | |
| 1049 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); | |
| 1050 Asm->cbw(); | |
| 1051 break; | |
| 1052 case IceType_i16: | |
| 1053 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | |
| 1054 Asm->cwd(); | |
| 1055 break; | |
| 1056 case IceType_i32: | |
| 1057 assert(getDest()->getRegNum() == TargetX8632::Reg_edx); | |
| 1058 Asm->cdq(); | |
| 1059 break; | |
| 1060 } | |
| 1061 emitIASBytes(Str, Asm, StartPosition); | |
| 1062 } | |
| 1063 | |
| 643 void InstX8632Mul::emit(const Cfg *Func) const { | 1064 void InstX8632Mul::emit(const Cfg *Func) const { |
| 644 Ostream &Str = Func->getContext()->getStrEmit(); | 1065 Ostream &Str = Func->getContext()->getStrEmit(); |
| 645 assert(getSrcSize() == 2); | 1066 assert(getSrcSize() == 2); |
| 646 assert(llvm::isa<Variable>(getSrc(0))); | 1067 assert(llvm::isa<Variable>(getSrc(0))); |
| 647 assert(llvm::dyn_cast<Variable>(getSrc(0))->getRegNum() == | 1068 assert(llvm::dyn_cast<Variable>(getSrc(0))->getRegNum() == |
| 648 TargetX8632::Reg_eax); | 1069 TargetX8632::Reg_eax); |
| 649 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); // TODO: allow edx? | 1070 assert(getDest()->getRegNum() == TargetX8632::Reg_eax); // TODO: allow edx? |
| 650 Str << "\tmul\t"; | 1071 Str << "\tmul\t"; |
| 651 getSrc(1)->emit(Func); | 1072 getSrc(1)->emit(Func); |
| 652 Str << "\n"; | 1073 Str << "\n"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 Str << "\t"; | 1137 Str << "\t"; |
| 717 assert(Condition != Br_None); | 1138 assert(Condition != Br_None); |
| 718 assert(getDest()->hasReg()); | 1139 assert(getDest()->hasReg()); |
| 719 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "\t"; | 1140 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "\t"; |
| 720 getDest()->emit(Func); | 1141 getDest()->emit(Func); |
| 721 Str << ", "; | 1142 Str << ", "; |
| 722 getSrc(1)->emit(Func); | 1143 getSrc(1)->emit(Func); |
| 723 Str << "\n"; | 1144 Str << "\n"; |
| 724 } | 1145 } |
| 725 | 1146 |
| 1147 void InstX8632Cmov::emitIAS(const Cfg *Func) const { | |
| 1148 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1149 assert(Condition != Br_None); | |
| 1150 assert(getDest()->hasReg()); | |
| 1151 assert(getSrcSize() == 2); | |
| 1152 const Variable *Src = llvm::cast<Variable>(getSrc(1)); | |
| 1153 // Only need the 32-bit register form right now. | |
| 1154 assert(Src->hasReg()); | |
| 1155 assert(Src->getType() == IceType_i32); | |
| 1156 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1157 intptr_t StartPosition = Asm->GetPosition(); | |
| 1158 Asm->cmov(convertToAsmCondition(Condition), | |
| 1159 convertToAsmGPR(getDest()->getRegNum()), | |
| 1160 convertToAsmGPR(Src->getRegNum())); | |
| 1161 emitIASBytes(Str, Asm, StartPosition); | |
| 1162 } | |
| 1163 | |
| 726 void InstX8632Cmov::dump(const Cfg *Func) const { | 1164 void InstX8632Cmov::dump(const Cfg *Func) const { |
| 727 Ostream &Str = Func->getContext()->getStrDump(); | 1165 Ostream &Str = Func->getContext()->getStrDump(); |
| 728 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "."; | 1166 Str << "cmov" << InstX8632BrAttributes[Condition].DisplayString << "."; |
| 729 Str << getDest()->getType() << " "; | 1167 Str << getDest()->getType() << " "; |
| 730 dumpDest(Func); | 1168 dumpDest(Func); |
| 731 Str << ", "; | 1169 Str << ", "; |
| 732 dumpSources(Func); | 1170 dumpSources(Func); |
| 733 } | 1171 } |
| 734 | 1172 |
| 735 void InstX8632Cmpps::emit(const Cfg *Func) const { | 1173 void InstX8632Cmpps::emit(const Cfg *Func) const { |
| 736 Ostream &Str = Func->getContext()->getStrEmit(); | 1174 Ostream &Str = Func->getContext()->getStrEmit(); |
| 737 assert(getSrcSize() == 2); | 1175 assert(getSrcSize() == 2); |
| 738 assert(Condition < Cmpps_Invalid); | 1176 assert(Condition < Cmpps_Invalid); |
| 739 Str << "\t"; | 1177 Str << "\t"; |
| 740 Str << "cmp" << InstX8632CmppsAttributes[Condition].EmitString << "ps" | 1178 Str << "cmp" << InstX8632CmppsAttributes[Condition].EmitString << "ps" |
| 741 << "\t"; | 1179 << "\t"; |
| 742 getDest()->emit(Func); | 1180 getDest()->emit(Func); |
| 743 Str << ", "; | 1181 Str << ", "; |
| 744 getSrc(1)->emit(Func); | 1182 getSrc(1)->emit(Func); |
| 745 Str << "\n"; | 1183 Str << "\n"; |
| 746 } | 1184 } |
| 747 | 1185 |
| 1186 void InstX8632Cmpps::emitIAS(const Cfg *Func) const { | |
| 1187 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1188 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1189 intptr_t StartPosition = Asm->GetPosition(); | |
| 1190 assert(getSrcSize() == 2); | |
| 1191 assert(Condition < Cmpps_Invalid); | |
| 1192 // Assuming there isn't any load folding for cmpps, and vector constants | |
| 1193 // are not allowed in PNaCl. | |
| 1194 assert(llvm::isa<Variable>(getSrc(1))); | |
| 1195 const Variable *SrcVar = llvm::cast<Variable>(getSrc(1)); | |
| 1196 if (SrcVar->hasReg()) { | |
| 1197 Asm->cmpps(convertToAsmXMMReg(getDest()->getRegNum()), | |
| 1198 convertToAsmXMMReg(SrcVar->getRegNum()), Condition); | |
| 1199 } else { | |
| 1200 x86::Address SrcStackAddr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 1201 ->stackVarToAsmOperand(SrcVar); | |
| 1202 Asm->cmpps(convertToAsmXMMReg(getDest()->getRegNum()), SrcStackAddr, | |
| 1203 Condition); | |
| 1204 } | |
| 1205 emitIASBytes(Str, Asm, StartPosition); | |
| 1206 } | |
| 1207 | |
| 748 void InstX8632Cmpps::dump(const Cfg *Func) const { | 1208 void InstX8632Cmpps::dump(const Cfg *Func) const { |
| 749 Ostream &Str = Func->getContext()->getStrDump(); | 1209 Ostream &Str = Func->getContext()->getStrDump(); |
| 750 assert(Condition < Cmpps_Invalid); | 1210 assert(Condition < Cmpps_Invalid); |
| 751 dumpDest(Func); | 1211 dumpDest(Func); |
| 752 Str << " = cmp" << InstX8632CmppsAttributes[Condition].EmitString << "ps" | 1212 Str << " = cmp" << InstX8632CmppsAttributes[Condition].EmitString << "ps" |
| 753 << "\t"; | 1213 << "\t"; |
| 754 dumpSources(Func); | 1214 dumpSources(Func); |
| 755 } | 1215 } |
| 756 | 1216 |
| 757 void InstX8632Cmpxchg::emit(const Cfg *Func) const { | 1217 void InstX8632Cmpxchg::emit(const Cfg *Func) const { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 void InstX8632Icmp::emit(const Cfg *Func) const { | 1284 void InstX8632Icmp::emit(const Cfg *Func) const { |
| 825 Ostream &Str = Func->getContext()->getStrEmit(); | 1285 Ostream &Str = Func->getContext()->getStrEmit(); |
| 826 assert(getSrcSize() == 2); | 1286 assert(getSrcSize() == 2); |
| 827 Str << "\tcmp\t"; | 1287 Str << "\tcmp\t"; |
| 828 getSrc(0)->emit(Func); | 1288 getSrc(0)->emit(Func); |
| 829 Str << ", "; | 1289 Str << ", "; |
| 830 getSrc(1)->emit(Func); | 1290 getSrc(1)->emit(Func); |
| 831 Str << "\n"; | 1291 Str << "\n"; |
| 832 } | 1292 } |
| 833 | 1293 |
| 1294 void InstX8632Icmp::emitIAS(const Cfg *Func) const { | |
| 1295 assert(getSrcSize() == 2); | |
| 1296 emitIASTwoOperandInt(Func, getSrc(0), getSrc(1), &x86::AssemblerX86::cmp, | |
| 1297 &x86::AssemblerX86::cmp, &x86::AssemblerX86::cmp, | |
| 1298 &x86::AssemblerX86::cmp, &x86::AssemblerX86::cmp); | |
| 1299 } | |
| 1300 | |
| 834 void InstX8632Icmp::dump(const Cfg *Func) const { | 1301 void InstX8632Icmp::dump(const Cfg *Func) const { |
| 835 Ostream &Str = Func->getContext()->getStrDump(); | 1302 Ostream &Str = Func->getContext()->getStrDump(); |
| 836 Str << "cmp." << getSrc(0)->getType() << " "; | 1303 Str << "cmp." << getSrc(0)->getType() << " "; |
| 837 dumpSources(Func); | 1304 dumpSources(Func); |
| 838 } | 1305 } |
| 839 | 1306 |
| 840 void InstX8632Ucomiss::emit(const Cfg *Func) const { | 1307 void InstX8632Ucomiss::emit(const Cfg *Func) const { |
| 841 Ostream &Str = Func->getContext()->getStrEmit(); | 1308 Ostream &Str = Func->getContext()->getStrEmit(); |
| 842 assert(getSrcSize() == 2); | 1309 assert(getSrcSize() == 2); |
| 843 Str << "\tucomi" << TypeX8632Attributes[getSrc(0)->getType()].SdSsString | 1310 Str << "\tucomi" << TypeX8632Attributes[getSrc(0)->getType()].SdSsString |
| 844 << "\t"; | 1311 << "\t"; |
| 845 getSrc(0)->emit(Func); | 1312 getSrc(0)->emit(Func); |
| 846 Str << ", "; | 1313 Str << ", "; |
| 847 getSrc(1)->emit(Func); | 1314 getSrc(1)->emit(Func); |
| 848 Str << "\n"; | 1315 Str << "\n"; |
| 849 } | 1316 } |
| 850 | 1317 |
| 1318 void InstX8632Ucomiss::emitIAS(const Cfg *Func) const { | |
| 1319 assert(getSrcSize() == 2); | |
| 1320 // Currently src0 is always a variable by convention, to avoid having | |
| 1321 // two memory operands. | |
| 1322 assert(llvm::isa<Variable>(getSrc(0))); | |
| 1323 const Variable *Src0 = llvm::cast<Variable>(getSrc(0)); | |
| 1324 Type Ty = Src0->getType(); | |
| 1325 if (Ty == IceType_f64) { | |
| 1326 emitIASVarOperandXMM(Func, Src0, getSrc(1), &x86::AssemblerX86::ucomisd, | |
| 1327 &x86::AssemblerX86::ucomisd); | |
| 1328 } else { | |
| 1329 emitIASVarOperandXMM(Func, Src0, getSrc(1), &x86::AssemblerX86::ucomiss, | |
| 1330 &x86::AssemblerX86::ucomiss); | |
| 1331 } | |
| 1332 } | |
| 1333 | |
| 851 void InstX8632Ucomiss::dump(const Cfg *Func) const { | 1334 void InstX8632Ucomiss::dump(const Cfg *Func) const { |
| 852 Ostream &Str = Func->getContext()->getStrDump(); | 1335 Ostream &Str = Func->getContext()->getStrDump(); |
| 853 Str << "ucomiss." << getSrc(0)->getType() << " "; | 1336 Str << "ucomiss." << getSrc(0)->getType() << " "; |
| 854 dumpSources(Func); | 1337 dumpSources(Func); |
| 855 } | 1338 } |
| 856 | 1339 |
| 857 void InstX8632UD2::emit(const Cfg *Func) const { | 1340 void InstX8632UD2::emit(const Cfg *Func) const { |
| 858 Ostream &Str = Func->getContext()->getStrEmit(); | 1341 Ostream &Str = Func->getContext()->getStrEmit(); |
| 859 assert(getSrcSize() == 0); | 1342 assert(getSrcSize() == 0); |
| 860 Str << "\tud2\n"; | 1343 Str << "\tud2\n"; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 Str << "\n"; | 1494 Str << "\n"; |
| 1012 Str << ".intel_syntax\n"; | 1495 Str << ".intel_syntax\n"; |
| 1013 } else { | 1496 } else { |
| 1014 getDest()->asType(Src->getType()).emit(Func); | 1497 getDest()->asType(Src->getType()).emit(Func); |
| 1015 Str << ", "; | 1498 Str << ", "; |
| 1016 Src->emit(Func); | 1499 Src->emit(Func); |
| 1017 Str << "\n"; | 1500 Str << "\n"; |
| 1018 } | 1501 } |
| 1019 } | 1502 } |
| 1020 | 1503 |
| 1504 template <> void InstX8632Mov::emitIAS(const Cfg *Func) const { | |
| 1505 // Could be movss/sd, or movb/movw/movl. | |
| 1506 emit(Func); | |
| 1507 } | |
| 1508 | |
| 1021 template <> void InstX8632Movp::emit(const Cfg *Func) const { | 1509 template <> void InstX8632Movp::emit(const Cfg *Func) const { |
| 1022 // TODO(wala,stichnot): movups works with all vector operands, but | 1510 // TODO(wala,stichnot): movups works with all vector operands, but |
| 1023 // there exist other instructions (movaps, movdqa, movdqu) that may | 1511 // there exist other instructions (movaps, movdqa, movdqu) that may |
| 1024 // perform better, depending on the data type and alignment of the | 1512 // perform better, depending on the data type and alignment of the |
| 1025 // operands. | 1513 // operands. |
| 1026 Ostream &Str = Func->getContext()->getStrEmit(); | 1514 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1027 assert(getSrcSize() == 1); | 1515 assert(getSrcSize() == 1); |
| 1028 Str << "\tmovups\t"; | 1516 Str << "\tmovups\t"; |
| 1029 getDest()->emit(Func); | 1517 getDest()->emit(Func); |
| 1030 Str << ", "; | 1518 Str << ", "; |
| 1031 getSrc(0)->emit(Func); | 1519 getSrc(0)->emit(Func); |
| 1032 Str << "\n"; | 1520 Str << "\n"; |
| 1033 } | 1521 } |
| 1034 | 1522 |
| 1035 template <> void InstX8632Movq::emit(const Cfg *Func) const { | 1523 template <> void InstX8632Movq::emit(const Cfg *Func) const { |
| 1036 Ostream &Str = Func->getContext()->getStrEmit(); | 1524 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1037 assert(getSrcSize() == 1); | 1525 assert(getSrcSize() == 1); |
| 1038 assert(getDest()->getType() == IceType_i64 || | 1526 assert(getDest()->getType() == IceType_i64 || |
| 1039 getDest()->getType() == IceType_f64); | 1527 getDest()->getType() == IceType_f64); |
| 1040 Str << "\tmovq\t"; | 1528 Str << "\tmovq\t"; |
| 1041 getDest()->emit(Func); | 1529 getDest()->emit(Func); |
| 1042 Str << ", "; | 1530 Str << ", "; |
| 1043 getSrc(0)->emit(Func); | 1531 getSrc(0)->emit(Func); |
| 1044 Str << "\n"; | 1532 Str << "\n"; |
| 1045 } | 1533 } |
| 1046 | 1534 |
| 1535 static void emitIASSignZeroExt(const Cfg *Func, const Variable *Dest, | |
| 1536 const Operand *Src0, | |
| 1537 x86::AssemblerX86::EmitRegByteR EmitByte, | |
| 1538 x86::AssemblerX86::EmitRegReg EmitWord, | |
| 1539 x86::AssemblerX86::EmitRegAddr EmitAddress) { | |
| 1540 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1541 assert(Dest->hasReg()); | |
| 1542 x86::Register DestReg = convertToAsmGPR(Dest->getRegNum()); | |
| 1543 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1544 intptr_t StartPosition = Asm->GetPosition(); | |
| 1545 IceString SymbolicOffset = ""; | |
| 1546 Type SrcType = Src0->getType(); | |
| 1547 // Source is ByteReg, WordReg, or stack slot, or other memory operand. | |
| 1548 if (const Variable *SrcVar = llvm::dyn_cast<Variable>(Src0)) { | |
| 1549 if (SrcVar->hasReg()) { | |
| 1550 if (SrcType == IceType_i8 || SrcType == IceType_i1) { | |
| 1551 (Asm->*EmitByte)(DestReg, | |
| 1552 convertToAsmByteRegister(SrcVar->getRegNum())); | |
| 1553 } else { | |
| 1554 assert(SrcType == IceType_i16); | |
| 1555 (Asm->*EmitWord)(DestReg, convertToAsmGPR(SrcVar->getRegNum())); | |
| 1556 } | |
| 1557 } else { | |
| 1558 x86::Address StackAddr = static_cast<TargetX8632 *>(Func->getTarget()) | |
| 1559 ->stackVarToAsmOperand(SrcVar); | |
| 1560 (Asm->*EmitAddress)(DestReg, StackAddr); | |
| 1561 } | |
| 1562 } else if (const OperandX8632Mem *Mem = | |
| 1563 llvm::dyn_cast<OperandX8632Mem>(Src0)) { | |
| 1564 x86::Address SrcAddr = Mem->convertToAsmAddress(SymbolicOffset); | |
| 1565 (Asm->*EmitAddress)(DestReg, SrcAddr); | |
| 1566 } else { | |
| 1567 llvm_unreachable("Unexpected operand type for Movzx"); | |
| 1568 } | |
| 1569 emitIASBytes(Str, Asm, StartPosition, SymbolicOffset); | |
| 1570 } | |
| 1571 | |
| 1047 void InstX8632Movsx::emit(const Cfg *Func) const { | 1572 void InstX8632Movsx::emit(const Cfg *Func) const { |
| 1048 Ostream &Str = Func->getContext()->getStrEmit(); | 1573 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1049 assert(getSrcSize() == 1); | 1574 assert(getSrcSize() == 1); |
| 1050 Str << "\tmovsx\t"; | 1575 Str << "\tmovsx\t"; |
| 1051 getDest()->emit(Func); | 1576 getDest()->emit(Func); |
| 1052 Str << ", "; | 1577 Str << ", "; |
| 1053 getSrc(0)->emit(Func); | 1578 getSrc(0)->emit(Func); |
| 1054 Str << "\n"; | 1579 Str << "\n"; |
| 1055 } | 1580 } |
| 1056 | 1581 |
| 1582 void InstX8632Movsx::emitIAS(const Cfg *Func) const { | |
| 1583 assert(getSrcSize() == 1); | |
| 1584 const Operand *Src0 = getSrc(0); | |
| 1585 Type SrcType = Src0->getType(); | |
| 1586 if (SrcType == IceType_i8 || SrcType == IceType_i1) { | |
| 1587 emitIASSignZeroExt(Func, getDest(), Src0, &x86::AssemblerX86::movsxb, | |
| 1588 &x86::AssemblerX86::movsxw, &x86::AssemblerX86::movsxb); | |
| 1589 } else { | |
| 1590 assert(SrcType == IceType_i16); | |
| 1591 emitIASSignZeroExt(Func, getDest(), Src0, &x86::AssemblerX86::movsxb, | |
| 1592 &x86::AssemblerX86::movsxw, &x86::AssemblerX86::movsxw); | |
| 1593 } | |
| 1594 } | |
| 1595 | |
| 1057 void InstX8632Movsx::dump(const Cfg *Func) const { | 1596 void InstX8632Movsx::dump(const Cfg *Func) const { |
| 1058 Ostream &Str = Func->getContext()->getStrDump(); | 1597 Ostream &Str = Func->getContext()->getStrDump(); |
| 1059 Str << "movsx." << getDest()->getType() << "." << getSrc(0)->getType(); | 1598 Str << "movsx." << getDest()->getType() << "." << getSrc(0)->getType(); |
| 1060 Str << " "; | 1599 Str << " "; |
| 1061 dumpDest(Func); | 1600 dumpDest(Func); |
| 1062 Str << ", "; | 1601 Str << ", "; |
| 1063 dumpSources(Func); | 1602 dumpSources(Func); |
| 1064 } | 1603 } |
| 1065 | 1604 |
| 1066 void InstX8632Movzx::emit(const Cfg *Func) const { | 1605 void InstX8632Movzx::emit(const Cfg *Func) const { |
| 1067 Ostream &Str = Func->getContext()->getStrEmit(); | 1606 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1068 assert(getSrcSize() == 1); | 1607 assert(getSrcSize() == 1); |
| 1069 Str << "\tmovzx\t"; | 1608 Str << "\tmovzx\t"; |
| 1070 getDest()->emit(Func); | 1609 getDest()->emit(Func); |
| 1071 Str << ", "; | 1610 Str << ", "; |
| 1072 getSrc(0)->emit(Func); | 1611 getSrc(0)->emit(Func); |
| 1073 Str << "\n"; | 1612 Str << "\n"; |
| 1074 } | 1613 } |
| 1075 | 1614 |
| 1615 void InstX8632Movzx::emitIAS(const Cfg *Func) const { | |
| 1616 assert(getSrcSize() == 1); | |
| 1617 const Operand *Src0 = getSrc(0); | |
| 1618 Type SrcType = Src0->getType(); | |
| 1619 if (SrcType == IceType_i8 || SrcType == IceType_i1) { | |
| 1620 emitIASSignZeroExt(Func, getDest(), Src0, &x86::AssemblerX86::movzxb, | |
| 1621 &x86::AssemblerX86::movzxw, &x86::AssemblerX86::movzxb); | |
| 1622 } else { | |
| 1623 assert(SrcType == IceType_i16); | |
| 1624 emitIASSignZeroExt(Func, getDest(), Src0, &x86::AssemblerX86::movzxb, | |
| 1625 &x86::AssemblerX86::movzxw, &x86::AssemblerX86::movzxw); | |
| 1626 } | |
| 1627 } | |
| 1628 | |
| 1076 void InstX8632Movzx::dump(const Cfg *Func) const { | 1629 void InstX8632Movzx::dump(const Cfg *Func) const { |
| 1077 Ostream &Str = Func->getContext()->getStrDump(); | 1630 Ostream &Str = Func->getContext()->getStrDump(); |
| 1078 Str << "movzx." << getDest()->getType() << "." << getSrc(0)->getType(); | 1631 Str << "movzx." << getDest()->getType() << "." << getSrc(0)->getType(); |
| 1079 Str << " "; | 1632 Str << " "; |
| 1080 dumpDest(Func); | 1633 dumpDest(Func); |
| 1081 Str << ", "; | 1634 Str << ", "; |
| 1082 dumpSources(Func); | 1635 dumpSources(Func); |
| 1083 } | 1636 } |
| 1084 | 1637 |
| 1085 void InstX8632Nop::emit(const Cfg *Func) const { | 1638 void InstX8632Nop::emit(const Cfg *Func) const { |
| 1086 Ostream &Str = Func->getContext()->getStrEmit(); | 1639 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1087 // TODO: Emit the right code for each variant. | 1640 // TODO: Emit the right code for each variant. |
| 1088 Str << "\tnop\t# variant = " << Variant << "\n"; | 1641 Str << "\tnop\t# variant = " << Variant << "\n"; |
| 1089 } | 1642 } |
| 1090 | 1643 |
| 1644 void InstX8632Nop::emitIAS(const Cfg *Func) const { | |
| 1645 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1646 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1647 intptr_t StartPosition = Asm->GetPosition(); | |
| 1648 // TODO: Emit the right code for the variant. | |
| 1649 Asm->nop(); | |
| 1650 emitIASBytes(Str, Asm, StartPosition); | |
| 1651 } | |
| 1652 | |
| 1091 void InstX8632Nop::dump(const Cfg *Func) const { | 1653 void InstX8632Nop::dump(const Cfg *Func) const { |
| 1092 Ostream &Str = Func->getContext()->getStrDump(); | 1654 Ostream &Str = Func->getContext()->getStrDump(); |
| 1093 Str << "nop (variant = " << Variant << ")"; | 1655 Str << "nop (variant = " << Variant << ")"; |
| 1094 } | 1656 } |
| 1095 | 1657 |
| 1658 template <> void InstX8632Or::emitIAS(const Cfg *Func) const { | |
| 1659 assert(getSrcSize() == 2); | |
| 1660 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::_or, | |
| 1661 &x86::AssemblerX86::_or, &x86::AssemblerX86::_or); | |
| 1662 } | |
| 1663 | |
| 1096 void InstX8632Fld::emit(const Cfg *Func) const { | 1664 void InstX8632Fld::emit(const Cfg *Func) const { |
| 1097 Ostream &Str = Func->getContext()->getStrEmit(); | 1665 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1098 assert(getSrcSize() == 1); | 1666 assert(getSrcSize() == 1); |
| 1099 Type Ty = getSrc(0)->getType(); | 1667 Type Ty = getSrc(0)->getType(); |
| 1100 Variable *Var = llvm::dyn_cast<Variable>(getSrc(0)); | 1668 Variable *Var = llvm::dyn_cast<Variable>(getSrc(0)); |
| 1101 if (Var && Var->hasReg()) { | 1669 if (Var && Var->hasReg()) { |
| 1102 // This is a physical xmm register, so we need to spill it to a | 1670 // This is a physical xmm register, so we need to spill it to a |
| 1103 // temporary stack slot. | 1671 // temporary stack slot. |
| 1104 SizeT Width = typeWidthInBytes(Ty); | 1672 SizeT Width = typeWidthInBytes(Ty); |
| 1105 Str << "\tsub\tesp, " << Width << "\n"; | 1673 Str << "\tsub\tesp, " << Width << "\n"; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1215 Src1->emit(Func); | 1783 Src1->emit(Func); |
| 1216 } | 1784 } |
| 1217 Str << ", "; | 1785 Str << ", "; |
| 1218 getSrc(2)->emit(Func); | 1786 getSrc(2)->emit(Func); |
| 1219 Str << "\n"; | 1787 Str << "\n"; |
| 1220 } | 1788 } |
| 1221 | 1789 |
| 1222 void InstX8632Pop::emit(const Cfg *Func) const { | 1790 void InstX8632Pop::emit(const Cfg *Func) const { |
| 1223 Ostream &Str = Func->getContext()->getStrEmit(); | 1791 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1224 assert(getSrcSize() == 0); | 1792 assert(getSrcSize() == 0); |
| 1793 assert(getDest()->getType() == IceType_i32); | |
| 1225 Str << "\tpop\t"; | 1794 Str << "\tpop\t"; |
| 1226 getDest()->emit(Func); | 1795 getDest()->emit(Func); |
| 1227 Str << "\n"; | 1796 Str << "\n"; |
| 1228 } | 1797 } |
| 1229 | 1798 |
| 1799 void InstX8632Pop::emitIAS(const Cfg *Func) const { | |
| 1800 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1801 assert(getSrcSize() == 0); | |
| 1802 assert(getDest()->getType() == IceType_i32); | |
| 1803 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1804 intptr_t StartPosition = Asm->GetPosition(); | |
| 1805 if (getDest()->hasReg()) { | |
| 1806 Asm->popl(convertToAsmGPR(getDest()->getRegNum())); | |
| 1807 } else { | |
| 1808 Asm->popl(static_cast<TargetX8632 *>(Func->getTarget()) | |
| 1809 ->stackVarToAsmOperand(getDest())); | |
| 1810 } | |
| 1811 emitIASBytes(Str, Asm, StartPosition); | |
| 1812 } | |
| 1813 | |
| 1230 void InstX8632Pop::dump(const Cfg *Func) const { | 1814 void InstX8632Pop::dump(const Cfg *Func) const { |
| 1231 Ostream &Str = Func->getContext()->getStrDump(); | 1815 Ostream &Str = Func->getContext()->getStrDump(); |
| 1232 dumpDest(Func); | 1816 dumpDest(Func); |
| 1233 Str << " = pop." << getDest()->getType() << " "; | 1817 Str << " = pop." << getDest()->getType() << " "; |
| 1234 } | 1818 } |
| 1235 | 1819 |
| 1236 void InstX8632AdjustStack::emit(const Cfg *Func) const { | 1820 void InstX8632AdjustStack::emit(const Cfg *Func) const { |
| 1237 Ostream &Str = Func->getContext()->getStrEmit(); | 1821 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1238 Str << "\tsub\tesp, " << Amount << "\n"; | 1822 Str << "\tsub\tesp, " << Amount << "\n"; |
| 1239 Func->getTarget()->updateStackAdjustment(Amount); | 1823 Func->getTarget()->updateStackAdjustment(Amount); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1304 snprintf(buf, llvm::array_lengthof(buf), "psra%s", | 1888 snprintf(buf, llvm::array_lengthof(buf), "psra%s", |
| 1305 TypeX8632Attributes[getDest()->getType()].PackString); | 1889 TypeX8632Attributes[getDest()->getType()].PackString); |
| 1306 emitTwoAddress(buf, this, Func); | 1890 emitTwoAddress(buf, this, Func); |
| 1307 } | 1891 } |
| 1308 | 1892 |
| 1309 void InstX8632Ret::emit(const Cfg *Func) const { | 1893 void InstX8632Ret::emit(const Cfg *Func) const { |
| 1310 Ostream &Str = Func->getContext()->getStrEmit(); | 1894 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1311 Str << "\tret\n"; | 1895 Str << "\tret\n"; |
| 1312 } | 1896 } |
| 1313 | 1897 |
| 1898 void InstX8632Ret::emitIAS(const Cfg *Func) const { | |
| 1899 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 1900 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); | |
| 1901 intptr_t StartPosition = Asm->GetPosition(); | |
| 1902 Asm->ret(); | |
| 1903 emitIASBytes(Str, Asm, StartPosition); | |
| 1904 } | |
| 1905 | |
| 1314 void InstX8632Ret::dump(const Cfg *Func) const { | 1906 void InstX8632Ret::dump(const Cfg *Func) const { |
| 1315 Ostream &Str = Func->getContext()->getStrDump(); | 1907 Ostream &Str = Func->getContext()->getStrDump(); |
| 1316 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType()); | 1908 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType()); |
| 1317 Str << "ret." << Ty << " "; | 1909 Str << "ret." << Ty << " "; |
| 1318 dumpSources(Func); | 1910 dumpSources(Func); |
| 1319 } | 1911 } |
| 1320 | 1912 |
| 1321 void InstX8632Xadd::emit(const Cfg *Func) const { | 1913 void InstX8632Xadd::emit(const Cfg *Func) const { |
| 1322 Ostream &Str = Func->getContext()->getStrEmit(); | 1914 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1323 if (Locked) { | 1915 if (Locked) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1349 Str << "\n"; | 1941 Str << "\n"; |
| 1350 } | 1942 } |
| 1351 | 1943 |
| 1352 void InstX8632Xchg::dump(const Cfg *Func) const { | 1944 void InstX8632Xchg::dump(const Cfg *Func) const { |
| 1353 Ostream &Str = Func->getContext()->getStrDump(); | 1945 Ostream &Str = Func->getContext()->getStrDump(); |
| 1354 Type Ty = getSrc(0)->getType(); | 1946 Type Ty = getSrc(0)->getType(); |
| 1355 Str << "xchg." << Ty << " "; | 1947 Str << "xchg." << Ty << " "; |
| 1356 dumpSources(Func); | 1948 dumpSources(Func); |
| 1357 } | 1949 } |
| 1358 | 1950 |
| 1951 template <> void InstX8632Xor::emitIAS(const Cfg *Func) const { | |
| 1952 assert(getSrcSize() == 2); | |
| 1953 emitIASVarOperandInt(Func, getDest(), getSrc(1), &x86::AssemblerX86::_xor, | |
| 1954 &x86::AssemblerX86::_xor, &x86::AssemblerX86::_xor); | |
| 1955 } | |
| 1956 | |
| 1359 void OperandX8632::dump(const Cfg *Func) const { | 1957 void OperandX8632::dump(const Cfg *Func) const { |
| 1360 Ostream &Str = Func->getContext()->getStrDump(); | 1958 Ostream &Str = Func->getContext()->getStrDump(); |
| 1361 Str << "<OperandX8632>"; | 1959 Str << "<OperandX8632>"; |
| 1362 } | 1960 } |
| 1363 | 1961 |
| 1364 void OperandX8632Mem::emit(const Cfg *Func) const { | 1962 void OperandX8632Mem::emit(const Cfg *Func) const { |
| 1365 Ostream &Str = Func->getContext()->getStrEmit(); | 1963 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1366 Str << TypeX8632Attributes[getType()].WidthString << " "; | 1964 Str << TypeX8632Attributes[getType()].WidthString << " "; |
| 1367 if (SegmentReg != DefaultSegment) { | 1965 if (SegmentReg != DefaultSegment) { |
| 1368 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); | 1966 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 Str << "+"; | 2038 Str << "+"; |
| 1441 Offset->dump(Func); | 2039 Offset->dump(Func); |
| 1442 } | 2040 } |
| 1443 } else { | 2041 } else { |
| 1444 // There is only the offset. | 2042 // There is only the offset. |
| 1445 Offset->dump(Func); | 2043 Offset->dump(Func); |
| 1446 } | 2044 } |
| 1447 Str << "]"; | 2045 Str << "]"; |
| 1448 } | 2046 } |
| 1449 | 2047 |
| 2048 x86::Address | |
| 2049 OperandX8632Mem::convertToAsmAddress(IceString &SymbolicOffset) const { | |
| 2050 int32_t Disp = 0; | |
| 2051 // Determine the offset (is it relocatable?) | |
| 2052 if (getOffset()) { | |
| 2053 if (ConstantInteger *CI = llvm::dyn_cast<ConstantInteger>(getOffset())) { | |
| 2054 Disp = static_cast<int32_t>(CI->getValue()); | |
| 2055 // Check that it's really 32-bit. | |
| 2056 // Sometimes Subzero stores negative values as sign-extended 64-bit | |
| 2057 // and sometimes it's zero-extended to 64-bit. | |
| 2058 // Should we just make a ConstantInteger32? | |
| 2059 assert((CI->getValue() >> 32) == 0 || | |
| 2060 (CI->getValue() >> 32) == 0xffffffff); | |
| 2061 } else if (ConstantRelocatable *CR = | |
| 2062 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | |
| 2063 SymbolicOffset = CR->getName(); | |
| 2064 // TODO(jvoung): this isn't really tested yet, since none of the | |
| 2065 // arithmetic, etc. ops have the addressing mode optimization | |
| 2066 // for ConstantRelocatable. | |
| 2067 assert(CR->getOffset() == 0); | |
| 2068 // Check that the int64_t only really has 32-bits. | |
| 2069 // Should we just the displacement 32-bit? | |
| 2070 assert((CR->getOffset() >> 32) == 0 || | |
| 2071 (CR->getOffset() >> 32) == 0xffffffff); | |
| 2072 Disp = CR->getOffset(); | |
| 2073 } | |
| 2074 } | |
| 2075 | |
| 2076 // Now convert to the various possible forms. | |
| 2077 if (getBase() && getIndex()) { | |
| 2078 return x86::Address(convertToAsmGPR(getBase()->getRegNum()), | |
| 2079 convertToAsmGPR(getIndex()->getRegNum()), | |
| 2080 x86::ScaleFactor(getShift()), Disp); | |
| 2081 } else if (getBase()) { | |
| 2082 return x86::Address(convertToAsmGPR(getBase()->getRegNum()), Disp); | |
| 2083 } else if (getIndex()) { | |
| 2084 return x86::Address(convertToAsmGPR(getIndex()->getRegNum()), | |
| 2085 x86::ScaleFactor(getShift()), Disp); | |
| 2086 } else { | |
| 2087 return x86::Address::Absolute(Disp); | |
| 2088 } | |
| 2089 } | |
| 2090 | |
| 1450 void VariableSplit::emit(const Cfg *Func) const { | 2091 void VariableSplit::emit(const Cfg *Func) const { |
| 1451 Ostream &Str = Func->getContext()->getStrEmit(); | 2092 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1452 assert(Var->getLocalUseNode() == NULL || | 2093 assert(Var->getLocalUseNode() == NULL || |
| 1453 Var->getLocalUseNode() == Func->getCurrentNode()); | 2094 Var->getLocalUseNode() == Func->getCurrentNode()); |
| 1454 assert(!Var->hasReg()); | 2095 assert(!Var->hasReg()); |
| 1455 // The following is copied/adapted from TargetX8632::emitVariable(). | 2096 // The following is copied/adapted from TargetX8632::emitVariable(). |
| 1456 const TargetLowering *Target = Func->getTarget(); | 2097 const TargetLowering *Target = Func->getTarget(); |
| 1457 const Type Ty = IceType_i32; | 2098 const Type Ty = IceType_i32; |
| 1458 Str << TypeX8632Attributes[Ty].WidthString << " [" | 2099 Str << TypeX8632Attributes[Ty].WidthString << " [" |
| 1459 << Target->getRegName(Target->getFrameOrStackReg(), Ty); | 2100 << Target->getRegName(Target->getFrameOrStackReg(), Ty); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1480 default: | 2121 default: |
| 1481 Str << "???"; | 2122 Str << "???"; |
| 1482 break; | 2123 break; |
| 1483 } | 2124 } |
| 1484 Str << "("; | 2125 Str << "("; |
| 1485 Var->dump(Func); | 2126 Var->dump(Func); |
| 1486 Str << ")"; | 2127 Str << ")"; |
| 1487 } | 2128 } |
| 1488 | 2129 |
| 1489 } // end of namespace Ice | 2130 } // end of namespace Ice |
| OLD | NEW |