Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: lib/Target/X86/X86FastISel.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Target/X86/X86CallingConv.td ('k') | lib/Target/X86/X86FrameLowering.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===-- X86FastISel.cpp - X86 FastISel implementation ---------------------===// 1 //===-- X86FastISel.cpp - X86 FastISel implementation ---------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
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 defines the X86-specific support for the FastISel class. Much 10 // This file defines the X86-specific support for the FastISel class. Much
(...skipping 21 matching lines...) Expand all
32 #include "llvm/IR/CallingConv.h" 32 #include "llvm/IR/CallingConv.h"
33 #include "llvm/IR/DerivedTypes.h" 33 #include "llvm/IR/DerivedTypes.h"
34 #include "llvm/IR/GetElementPtrTypeIterator.h" 34 #include "llvm/IR/GetElementPtrTypeIterator.h"
35 #include "llvm/IR/GlobalAlias.h" 35 #include "llvm/IR/GlobalAlias.h"
36 #include "llvm/IR/GlobalVariable.h" 36 #include "llvm/IR/GlobalVariable.h"
37 #include "llvm/IR/Instructions.h" 37 #include "llvm/IR/Instructions.h"
38 #include "llvm/IR/IntrinsicInst.h" 38 #include "llvm/IR/IntrinsicInst.h"
39 #include "llvm/IR/Operator.h" 39 #include "llvm/IR/Operator.h"
40 #include "llvm/Support/ErrorHandling.h" 40 #include "llvm/Support/ErrorHandling.h"
41 #include "llvm/Target/TargetOptions.h" 41 #include "llvm/Target/TargetOptions.h"
42 #include "llvm/ADT/Statistic.h" // @LOCALMOD
42 using namespace llvm; 43 using namespace llvm;
43 44
45 // @LOCALMOD-BEGIN
46 #define DEBUG_TYPE "isel"
47 STATISTIC(NumFastIselNaClFailures, "Number of instructions fast isel failed on f or NaCl illegality");
48 // @LOCALMOD-END
49
44 namespace { 50 namespace {
45 51
46 class X86FastISel final : public FastISel { 52 class X86FastISel final : public FastISel {
47 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can 53 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
48 /// make the right decision when generating code for different targets. 54 /// make the right decision when generating code for different targets.
49 const X86Subtarget *Subtarget; 55 const X86Subtarget *Subtarget;
50 56
51 /// X86ScalarSSEf32, X86ScalarSSEf64 - Select between SSE or x87 57 /// X86ScalarSSEf32, X86ScalarSSEf64 - Select between SSE or x87
52 /// floating point ops. 58 /// floating point ops.
53 /// When SSE is available, use it for f32 operations. 59 /// When SSE is available, use it for f32 operations.
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 unsigned &ResultReg) { 500 unsigned &ResultReg) {
495 unsigned RR = fastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc, 501 unsigned RR = fastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc,
496 Src, /*TODO: Kill=*/false); 502 Src, /*TODO: Kill=*/false);
497 if (RR == 0) 503 if (RR == 0)
498 return false; 504 return false;
499 505
500 ResultReg = RR; 506 ResultReg = RR;
501 return true; 507 return true;
502 } 508 }
503 509
510 /// @LOCALMOD-BEGIN
511 /// isLegalAddressingModeForNaCl - Determine if the addressing mode is
512 /// legal for NaCl translation. If not, the caller is expected to
513 /// reject the instruction for fast-ISel code generation.
514 ///
515 /// The logic for the test is translated from the corresponding logic
516 /// in X86DAGToDAGISel::LegalizeAddressingModeForNaCl(). It can't be
517 /// used directly due to the X86AddressMode vs X86ISelAddressMode
518 /// types. As such, any changes to isLegalAddressingModeForNaCl() and
519 /// X86DAGToDAGISel::LegalizeAddressingModeForNaCl() need to be
520 /// synchronized. The original conditions are indicated in comments.
521 static bool isLegalAddressingModeForNaCl(const X86Subtarget *Subtarget,
522 const X86AddressMode &AM) {
523 if (Subtarget->isTargetNaCl64()) {
524 // Return true (i.e., is legal) if the equivalent of
525 // X86ISelAddressMode::isRIPRelative() is true.
526 if (AM.BaseType == X86AddressMode::RegBase &&
527 AM.Base.Reg == X86::RIP)
528 return true;
529
530 // Check for the equivalent of
531 // (!AM.hasBaseOrIndexReg() &&
532 // !AM.hasSymbolicDisplacement() &&
533 // AM.Disp < 0)
534 if (!((AM.BaseType == X86AddressMode::RegBase && AM.Base.Reg) ||
535 AM.IndexReg) &&
536 !AM.GV &&
537 AM.Disp < 0) {
538 ++NumFastIselNaClFailures;
539 return false;
540 }
541
542 // At this point in the LegalizeAddressingModeForNaCl() code, it
543 // normalizes an addressing mode with a base register and no index
544 // register into an equivalent mode with an index register and no
545 // base register. Since we don't modify AM, we may have to check
546 // both the base and index register fields in the remainder of the
547 // tests.
548
549 // Check for the equivalent of
550 // ((AM.BaseType == X86ISelAddressMode::FrameIndexBase || AM.GV || AM.CP) &&
551 // AM.IndexReg.getNode() &&
552 // AM.Disp > 0)
553 // Note: X86AddressMode doesn't have a CP analogue
554 if ((AM.BaseType == X86AddressMode::FrameIndexBase || AM.GV) &&
555 ((AM.BaseType == X86AddressMode::RegBase && AM.Base.Reg) ||
556 AM.IndexReg) &&
557 AM.Disp > 0) {
558 ++NumFastIselNaClFailures;
559 return false;
560 }
561
562 // Check for the equivalent of
563 // ((AM.BaseType == X86ISelAddressMode::RegBase) &&
564 // AM.Base_Reg.getNode() &&
565 // AM.IndexReg.getNode())
566 if ((AM.BaseType == X86AddressMode::RegBase) &&
567 AM.Base.Reg &&
568 AM.IndexReg) {
569 ++NumFastIselNaClFailures;
570 return false;
571 }
572
573 // See X86DAGToDAGISel::FoldOffsetIntoAddress().
574 // Check for the equivalent of
575 // ((AM.BaseType == X86ISelAddressMode::RegBase ||
576 // AM.BaseType == X86ISelAddressMode::FrameIndexBase) &&
577 // (Val > 65535 || Val < -65536))
578 if ((AM.BaseType == X86AddressMode::RegBase ||
579 AM.BaseType == X86AddressMode::FrameIndexBase) &&
580 (AM.Disp > 65535 || AM.Disp < -65536)) {
581 ++NumFastIselNaClFailures;
582 return false;
583 }
584 }
585
586 return true;
587 }
588
504 bool X86FastISel::handleConstantAddresses(const Value *V, X86AddressMode &AM) { 589 bool X86FastISel::handleConstantAddresses(const Value *V, X86AddressMode &AM) {
505 // Handle constant address. 590 // Handle constant address.
506 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { 591 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
507 // Can't handle alternate code models yet. 592 // Can't handle alternate code models yet.
508 if (TM.getCodeModel() != CodeModel::Small) 593 if (TM.getCodeModel() != CodeModel::Small)
509 return false; 594 return false;
510 595
511 // Can't handle TLS yet. 596 // Can't handle TLS yet.
512 if (GV->isThreadLocal()) 597 if (GV->isThreadLocal())
513 return false; 598 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 644
560 // Prepare for inserting code in the local-value area. 645 // Prepare for inserting code in the local-value area.
561 SavePoint SaveInsertPt = enterLocalValueArea(); 646 SavePoint SaveInsertPt = enterLocalValueArea();
562 647
563 if (TLI.getPointerTy() == MVT::i64) { 648 if (TLI.getPointerTy() == MVT::i64) {
564 Opc = X86::MOV64rm; 649 Opc = X86::MOV64rm;
565 RC = &X86::GR64RegClass; 650 RC = &X86::GR64RegClass;
566 651
567 if (Subtarget->isPICStyleRIPRel()) 652 if (Subtarget->isPICStyleRIPRel())
568 StubAM.Base.Reg = X86::RIP; 653 StubAM.Base.Reg = X86::RIP;
654 // @LOCALMOD-BEGIN
655 } else if (Subtarget->isTargetNaCl64()) {
656 Opc = X86::MOV32rm;
657 RC = &X86::GR32RegClass;
658
659 if (Subtarget->isPICStyleRIPRel())
660 StubAM.Base.Reg = X86::RIP;
661 // @LOCALMOD-END
569 } else { 662 } else {
570 Opc = X86::MOV32rm; 663 Opc = X86::MOV32rm;
571 RC = &X86::GR32RegClass; 664 RC = &X86::GR32RegClass;
572 } 665 }
573 666
574 LoadReg = createResultReg(RC); 667 LoadReg = createResultReg(RC);
575 MachineInstrBuilder LoadMI = 668 MachineInstrBuilder LoadMI =
576 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), LoadRe g); 669 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), LoadRe g);
577 addFullAddress(LoadMI, StubAM); 670 addFullAddress(LoadMI, StubAM);
578 671
579 // Ok, back to normal mode. 672 // Ok, back to normal mode.
580 leaveLocalValueArea(SaveInsertPt); 673 leaveLocalValueArea(SaveInsertPt);
581 674
582 // Prevent loading GV stub multiple times in same MBB. 675 // Prevent loading GV stub multiple times in same MBB.
583 LocalValueMap[V] = LoadReg; 676 LocalValueMap[V] = LoadReg;
584 } 677 }
585 678
586 // Now construct the final address. Note that the Disp, Scale, 679 // Now construct the final address. Note that the Disp, Scale,
587 // and Index values may already be set here. 680 // and Index values may already be set here.
588 AM.Base.Reg = LoadReg; 681 AM.Base.Reg = LoadReg;
589 AM.GV = nullptr; 682 AM.GV = nullptr;
590 return true; 683 return true;
591 } 684 }
592 } 685 }
593 686
594 // If all else fails, try to materialize the value in a register. 687 // If all else fails, try to materialize the value in a register.
595 if (!AM.GV || !Subtarget->isPICStyleRIPRel()) { 688 if (!AM.GV || !Subtarget->isPICStyleRIPRel()) {
689 // @LOCALMOD-START
690 if (Subtarget->isTargetNaCl64()) {
691 // We are about use a register in an addressing mode. However, x86-64
692 // NaCl does not allow arbitrary r+r addressing. One of the regs must
693 // be %r15 (inserted by the NaClRewritePass). Check that we will only
694 // end up with one reg defined after this.
695 if ((AM.Base.Reg == 0) && (AM.IndexReg == 0)) {
696 // Put into index register so that the NaCl rewrite pass will
697 // convert this to a 64-bit address.
698 AM.IndexReg = getRegForValue(V);
699 return AM.IndexReg != 0;
700 }
701 return false;
702 }
703 // @LOCALMOD-END
596 if (AM.Base.Reg == 0) { 704 if (AM.Base.Reg == 0) {
597 AM.Base.Reg = getRegForValue(V); 705 AM.Base.Reg = getRegForValue(V);
598 return AM.Base.Reg != 0; 706 return AM.Base.Reg != 0;
599 } 707 }
600 if (AM.IndexReg == 0) { 708 if (AM.IndexReg == 0) {
601 assert(AM.Scale == 1 && "Scale with no index!"); 709 assert(AM.Scale == 1 && "Scale with no index!");
602 AM.IndexReg = getRegForValue(V); 710 AM.IndexReg = getRegForValue(V);
603 return AM.IndexReg != 0; 711 return AM.IndexReg != 0;
604 } 712 }
605 } 713 }
606 714
607 return false; 715 return false;
608 } 716 }
609 717
610 /// X86SelectAddress - Attempt to fill in an address from the given value. 718 /// X86SelectAddress - Attempt to fill in an address from the given value.
611 /// 719 ///
720 /// @LOCALMOD-BEGIN
721 /// All "return v;" statements must be converted to
722 /// "return (v) && isLegalAddressingModeForNaCl(Subtarget, AM);"
723 /// except that "return false;" can of course be left unchanged.
724 ///
725 /// Since X86SelectAddress() recursively builds up the AM result
726 /// object, there is a risk that an intermediate result could be
727 /// rejected in a situation where the final result was in fact legal,
728 /// though it is hard to imagine this happening.
729 /// @LOCALMOD-END
612 bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) { 730 bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) {
613 SmallVector<const Value *, 32> GEPs; 731 SmallVector<const Value *, 32> GEPs;
614 redo_gep: 732 redo_gep:
615 const User *U = nullptr; 733 const User *U = nullptr;
616 unsigned Opcode = Instruction::UserOp1; 734 unsigned Opcode = Instruction::UserOp1;
617 if (const Instruction *I = dyn_cast<Instruction>(V)) { 735 if (const Instruction *I = dyn_cast<Instruction>(V)) {
618 // Don't walk into other basic blocks; it's possible we haven't 736 // Don't walk into other basic blocks; it's possible we haven't
619 // visited them yet, so the instructions may not yet be assigned 737 // visited them yet, so the instructions may not yet be assigned
620 // virtual registers. 738 // virtual registers.
621 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(V)) || 739 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(V)) ||
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 break; 771 break;
654 772
655 case Instruction::Alloca: { 773 case Instruction::Alloca: {
656 // Do static allocas. 774 // Do static allocas.
657 const AllocaInst *A = cast<AllocaInst>(V); 775 const AllocaInst *A = cast<AllocaInst>(V);
658 DenseMap<const AllocaInst*, int>::iterator SI = 776 DenseMap<const AllocaInst*, int>::iterator SI =
659 FuncInfo.StaticAllocaMap.find(A); 777 FuncInfo.StaticAllocaMap.find(A);
660 if (SI != FuncInfo.StaticAllocaMap.end()) { 778 if (SI != FuncInfo.StaticAllocaMap.end()) {
661 AM.BaseType = X86AddressMode::FrameIndexBase; 779 AM.BaseType = X86AddressMode::FrameIndexBase;
662 AM.Base.FrameIndex = SI->second; 780 AM.Base.FrameIndex = SI->second;
663 return true; 781 return isLegalAddressingModeForNaCl(Subtarget, AM); // @LOCALMOD
664 } 782 }
665 break; 783 break;
666 } 784 }
667 785
668 case Instruction::Add: { 786 case Instruction::Add: {
669 // Adds of constants are common and easy enough. 787 // Adds of constants are common and easy enough.
670 if (const ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) { 788 if (const ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) {
671 uint64_t Disp = (int32_t)AM.Disp + (uint64_t)CI->getSExtValue(); 789 uint64_t Disp = (int32_t)AM.Disp + (uint64_t)CI->getSExtValue();
672 // They have to fit in the 32-bit signed displacement field though. 790 // They have to fit in the 32-bit signed displacement field though.
673 if (isInt<32>(Disp)) { 791 if (isInt<32>(Disp)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 AM.Disp = (uint32_t)Disp; 857 AM.Disp = (uint32_t)Disp;
740 GEPs.push_back(V); 858 GEPs.push_back(V);
741 859
742 if (const GetElementPtrInst *GEP = 860 if (const GetElementPtrInst *GEP =
743 dyn_cast<GetElementPtrInst>(U->getOperand(0))) { 861 dyn_cast<GetElementPtrInst>(U->getOperand(0))) {
744 // Ok, the GEP indices were covered by constant-offset and scaled-index 862 // Ok, the GEP indices were covered by constant-offset and scaled-index
745 // addressing. Update the address state and move on to examining the base. 863 // addressing. Update the address state and move on to examining the base.
746 V = GEP; 864 V = GEP;
747 goto redo_gep; 865 goto redo_gep;
748 } else if (X86SelectAddress(U->getOperand(0), AM)) { 866 } else if (X86SelectAddress(U->getOperand(0), AM)) {
749 return true; 867 return isLegalAddressingModeForNaCl(Subtarget, AM); // @LOCALMOD
750 } 868 }
751 869
752 // If we couldn't merge the gep value into this addr mode, revert back to 870 // If we couldn't merge the gep value into this addr mode, revert back to
753 // our address and just match the value instead of completely failing. 871 // our address and just match the value instead of completely failing.
754 AM = SavedAM; 872 AM = SavedAM;
755 873
756 for (SmallVectorImpl<const Value *>::reverse_iterator 874 for (SmallVectorImpl<const Value *>::reverse_iterator
757 I = GEPs.rbegin(), E = GEPs.rend(); I != E; ++I) 875 I = GEPs.rbegin(), E = GEPs.rend(); I != E; ++I)
758 if (handleConstantAddresses(*I, AM)) 876 if (handleConstantAddresses(*I, AM))
759 return true; 877 return isLegalAddressingModeForNaCl(Subtarget, AM); // @LOCALMOD
760 878
761 return false; 879 return false;
762 unsupported_gep: 880 unsupported_gep:
763 // Ok, the GEP indices weren't all covered. 881 // Ok, the GEP indices weren't all covered.
764 break; 882 break;
765 } 883 }
766 } 884 }
767 885
768 return handleConstantAddresses(V, AM); 886 // @LOCALMOD-START
887 if (handleConstantAddresses(V, AM))
888 return isLegalAddressingModeForNaCl(Subtarget, AM);
889 return false;
890 // @LOCALMOD-END
769 } 891 }
770 892
771 /// X86SelectCallAddress - Attempt to fill in an address from the given value. 893 /// X86SelectCallAddress - Attempt to fill in an address from the given value.
772 /// 894 ///
773 bool X86FastISel::X86SelectCallAddress(const Value *V, X86AddressMode &AM) { 895 bool X86FastISel::X86SelectCallAddress(const Value *V, X86AddressMode &AM) {
774 const User *U = nullptr; 896 const User *U = nullptr;
775 unsigned Opcode = Instruction::UserOp1; 897 unsigned Opcode = Instruction::UserOp1;
776 const Instruction *I = dyn_cast<Instruction>(V); 898 const Instruction *I = dyn_cast<Instruction>(V);
777 // Record if the value is defined in the same basic block. 899 // Record if the value is defined in the same basic block.
778 // 900 //
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1144
1023 // The x86-64 ABI for returning structs by value requires that we copy 1145 // The x86-64 ABI for returning structs by value requires that we copy
1024 // the sret argument into %rax for the return. We saved the argument into 1146 // the sret argument into %rax for the return. We saved the argument into
1025 // a virtual register in the entry block, so now we copy the value out 1147 // a virtual register in the entry block, so now we copy the value out
1026 // and into %rax. We also do the same with %eax for Win32. 1148 // and into %rax. We also do the same with %eax for Win32.
1027 if (F.hasStructRetAttr() && 1149 if (F.hasStructRetAttr() &&
1028 (Subtarget->is64Bit() || Subtarget->isTargetKnownWindowsMSVC())) { 1150 (Subtarget->is64Bit() || Subtarget->isTargetKnownWindowsMSVC())) {
1029 unsigned Reg = X86MFInfo->getSRetReturnReg(); 1151 unsigned Reg = X86MFInfo->getSRetReturnReg();
1030 assert(Reg && 1152 assert(Reg &&
1031 "SRetReturnReg should have been set in LowerFormalArguments()!"); 1153 "SRetReturnReg should have been set in LowerFormalArguments()!");
1032 unsigned RetReg = Subtarget->is64Bit() ? X86::RAX : X86::EAX; 1154 // @LOCALMOD-BEGIN -- Ensure that the register classes match.
1155 // At this point, SRetReturnReg is EDI, because PointerTy() for NaCl
1156 // is i32. We then copy to EAX instead of RAX. Alternatively, we could
1157 // have zero-extended EDI to RDI then copy to RAX, but this has a smaller
1158 // encoding (2 bytes vs 3 bytes).
1159 unsigned CopyTo = Subtarget->isTarget64BitLP64() ? X86::RAX : X86::EAX;
1033 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TargetOpcode::COPY ), 1160 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TargetOpcode::COPY ),
1034 RetReg).addReg(Reg); 1161 CopyTo).addReg(Reg);
1035 RetRegs.push_back(RetReg); 1162 // @LOCALMOD-END
1036 } 1163 }
1037 1164
1038 // Now emit the RET. 1165 // Now emit the RET.
1039 MachineInstrBuilder MIB = 1166 MachineInstrBuilder MIB =
1040 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Subtarget->is64Bit () ? X86::RETQ : X86::RETL)); 1167 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Subtarget->is64Bit () ? X86::RETQ : X86::RETL));
1041 for (unsigned i = 0, e = RetRegs.size(); i != e; ++i) 1168 for (unsigned i = 0, e = RetRegs.size(); i != e; ++i)
1042 MIB.addReg(RetRegs[i], RegState::Implicit); 1169 MIB.addReg(RetRegs[i], RegState::Implicit);
1043 return true; 1170 return true;
1044 } 1171 }
1045 1172
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 // We don't care about alignment here since we just emit integer accesses. 2227 // We don't care about alignment here since we just emit integer accesses.
2101 while (Len) { 2228 while (Len) {
2102 MVT VT; 2229 MVT VT;
2103 if (Len >= 8 && i64Legal) 2230 if (Len >= 8 && i64Legal)
2104 VT = MVT::i64; 2231 VT = MVT::i64;
2105 else if (Len >= 4) 2232 else if (Len >= 4)
2106 VT = MVT::i32; 2233 VT = MVT::i32;
2107 else if (Len >= 2) 2234 else if (Len >= 2)
2108 VT = MVT::i16; 2235 VT = MVT::i16;
2109 else { 2236 else {
2237 assert(Len == 1);
2110 VT = MVT::i8; 2238 VT = MVT::i8;
2111 } 2239 }
2112 2240
2113 unsigned Reg; 2241 unsigned Reg;
2114 bool RV = X86FastEmitLoad(VT, SrcAM, nullptr, Reg); 2242 bool RV = X86FastEmitLoad(VT, SrcAM, nullptr, Reg);
2115 RV &= X86FastEmitStore(VT, Reg, /*Kill=*/true, DestAM); 2243 RV &= X86FastEmitStore(VT, Reg, /*Kill=*/true, DestAM);
2116 assert(RV && "Failed to emit load or store??"); 2244 assert(RV && "Failed to emit load or store??");
2117 2245
2118 unsigned Size = VT.getSizeInBits()/8; 2246 unsigned Size = VT.getSizeInBits()/8;
2119 Len -= Size; 2247 Len -= Size;
(...skipping 17 matching lines...) Expand all
2137 2265
2138 unsigned Opc; 2266 unsigned Opc;
2139 const TargetRegisterClass *RC = nullptr; 2267 const TargetRegisterClass *RC = nullptr;
2140 2268
2141 switch (VT.SimpleTy) { 2269 switch (VT.SimpleTy) {
2142 default: llvm_unreachable("Invalid result type for frameaddress."); 2270 default: llvm_unreachable("Invalid result type for frameaddress.");
2143 case MVT::i32: Opc = X86::MOV32rm; RC = &X86::GR32RegClass; break; 2271 case MVT::i32: Opc = X86::MOV32rm; RC = &X86::GR32RegClass; break;
2144 case MVT::i64: Opc = X86::MOV64rm; RC = &X86::GR64RegClass; break; 2272 case MVT::i64: Opc = X86::MOV64rm; RC = &X86::GR64RegClass; break;
2145 } 2273 }
2146 2274
2147 // This needs to be set before we call getFrameRegister, otherwise we get 2275 // This needs to be set before we call getPtrSizedFrameRegister, otherwise
2148 // the wrong frame register. 2276 // we get the wrong frame register.
2149 MachineFrameInfo *MFI = FuncInfo.MF->getFrameInfo(); 2277 MachineFrameInfo *MFI = FuncInfo.MF->getFrameInfo();
2150 MFI->setFrameAddressIsTaken(true); 2278 MFI->setFrameAddressIsTaken(true);
2151 2279
2152 const X86RegisterInfo *RegInfo = static_cast<const X86RegisterInfo *>( 2280 const X86RegisterInfo *RegInfo = static_cast<const X86RegisterInfo *>(
2153 TM.getSubtargetImpl()->getRegisterInfo()); 2281 TM.getSubtargetImpl()->getRegisterInfo());
2154 unsigned FrameReg = RegInfo->getFrameRegister(*(FuncInfo.MF)); 2282 unsigned FrameReg = RegInfo->getPtrSizedFrameRegister(*(FuncInfo.MF));
2155 assert(((FrameReg == X86::RBP && VT == MVT::i64) || 2283 assert(((FrameReg == X86::RBP && VT == MVT::i64) ||
2156 (FrameReg == X86::EBP && VT == MVT::i32)) && 2284 (FrameReg == X86::EBP && VT == MVT::i32)) &&
2157 "Invalid Frame Register!"); 2285 "Invalid Frame Register!");
2158 2286
2159 // Always make a copy of the frame register to to a vreg first, so that we 2287 // Always make a copy of the frame register to to a vreg first, so that we
2160 // never directly reference the frame register (the TwoAddressInstruction- 2288 // never directly reference the frame register (the TwoAddressInstruction-
2161 // Pass doesn't like that). 2289 // Pass doesn't like that).
2162 unsigned SrcReg = createResultReg(RC); 2290 unsigned SrcReg = createResultReg(RC);
2163 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, 2291 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2164 TII.get(TargetOpcode::COPY), SrcReg).addReg(FrameReg); 2292 TII.get(TargetOpcode::COPY), SrcReg).addReg(FrameReg);
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 GV = CalleeAM.GV; 3021 GV = CalleeAM.GV;
2894 } else if (CalleeAM.Base.Reg != 0) { 3022 } else if (CalleeAM.Base.Reg != 0) {
2895 CalleeOp = CalleeAM.Base.Reg; 3023 CalleeOp = CalleeAM.Base.Reg;
2896 } else 3024 } else
2897 return false; 3025 return false;
2898 3026
2899 // Issue the call. 3027 // Issue the call.
2900 MachineInstrBuilder MIB; 3028 MachineInstrBuilder MIB;
2901 if (CalleeOp) { 3029 if (CalleeOp) {
2902 // Register-indirect call. 3030 // Register-indirect call.
2903 unsigned CallOpc = Is64Bit ? X86::CALL64r : X86::CALL32r; 3031 unsigned CallOpc;
3032 if (Subtarget->is64Bit()) {
3033 // @LOCALMOD-BEGIN: zero extend the register like in the non-O0 case:
3034 // http://reviews.llvm.org/D5355
3035 // TODO: upstream this for x32 also (add a test).
3036 if (Subtarget->isTarget64BitILP32()) {
3037 unsigned CalleeOp32 = CalleeOp;
3038 CalleeOp = createResultReg(&X86::GR64RegClass);
3039 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3040 TII.get(TargetOpcode::SUBREG_TO_REG), CalleeOp)
3041 .addImm(0).addReg(CalleeOp32).addImm(X86::sub_32bit);
3042 }
3043 // @LOCALMOD-END
3044 CallOpc = X86::CALL64r;
3045 } else
3046 CallOpc = X86::CALL32r;
2904 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(CallOpc)) 3047 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(CallOpc))
2905 .addReg(CalleeOp); 3048 .addReg(CalleeOp);
2906 } else { 3049 } else {
2907 // Direct call. 3050 // Direct call.
2908 assert(GV && "Not a direct call"); 3051 assert(GV && "Not a direct call");
2909 unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32; 3052 unsigned CallOpc;
3053 if (Subtarget->is64Bit())
3054 CallOpc = Subtarget->isTargetNaCl() ? X86::NACL_CG_CALL64pcrel32 : X86::CA LL64pcrel32; // @LOCALMOD
3055 else
3056 CallOpc = X86::CALLpcrel32;
2910 3057
2911 // See if we need any target-specific flags on the GV operand. 3058 // See if we need any target-specific flags on the GV operand.
2912 unsigned char OpFlags = 0; 3059 unsigned char OpFlags = 0;
2913 3060
2914 // On ELF targets, in both X86-64 and X86-32 mode, direct calls to 3061 // On ELF targets, in both X86-64 and X86-32 mode, direct calls to
2915 // external symbols most go through the PLT in PIC mode. If the symbol 3062 // external symbols most go through the PLT in PIC mode. If the symbol
2916 // has hidden or protected visibility, or if it is static or local, then 3063 // has hidden or protected visibility, or if it is static or local, then
2917 // we don't need to use the PLT - we can directly call it. 3064 // we don't need to use the PLT - we can directly call it.
2918 if (Subtarget->isTargetELF() && 3065 if (Subtarget->isTargetELF() &&
2919 TM.getRelocationModel() == Reloc::PIC_ && 3066 TM.getRelocationModel() == Reloc::PIC_ &&
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3347 return true; 3494 return true;
3348 } 3495 }
3349 3496
3350 3497
3351 namespace llvm { 3498 namespace llvm {
3352 FastISel *X86::createFastISel(FunctionLoweringInfo &funcInfo, 3499 FastISel *X86::createFastISel(FunctionLoweringInfo &funcInfo,
3353 const TargetLibraryInfo *libInfo) { 3500 const TargetLibraryInfo *libInfo) {
3354 return new X86FastISel(funcInfo, libInfo); 3501 return new X86FastISel(funcInfo, libInfo);
3355 } 3502 }
3356 } 3503 }
OLDNEW
« no previous file with comments | « lib/Target/X86/X86CallingConv.td ('k') | lib/Target/X86/X86FrameLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698