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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 1113683002: Subzero: Produce actually correct code in -asm-verbose mode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 7 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
« src/IceInstX8632.cpp ('K') | « src/IceInstX8632.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===//
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 TargetLoweringX8632 class, which 10 // This file implements the TargetLoweringX8632 class, which
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 791
792 // Generate "push ebp; mov ebp, esp" 792 // Generate "push ebp; mov ebp, esp"
793 if (IsEbpBasedFrame) { 793 if (IsEbpBasedFrame) {
794 assert((RegsUsed & getRegisterSet(RegSet_FramePointer, RegSet_None)) 794 assert((RegsUsed & getRegisterSet(RegSet_FramePointer, RegSet_None))
795 .count() == 0); 795 .count() == 0);
796 PreservedRegsSizeBytes += 4; 796 PreservedRegsSizeBytes += 4;
797 Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp); 797 Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp);
798 Variable *esp = getPhysicalRegister(RegX8632::Reg_esp); 798 Variable *esp = getPhysicalRegister(RegX8632::Reg_esp);
799 _push(ebp); 799 _push(ebp);
800 _mov(ebp, esp); 800 _mov(ebp, esp);
801 // Keep ebp live in asm-verbose mode.
802 Context.insert(InstFakeUse::create(Func, ebp));
801 } 803 }
802 804
803 // Align the variables area. SpillAreaPaddingBytes is the size of 805 // Align the variables area. SpillAreaPaddingBytes is the size of
804 // the region after the preserved registers and before the spill 806 // the region after the preserved registers and before the spill
805 // areas. 807 // areas.
806 uint32_t SpillAreaPaddingBytes = 0; 808 uint32_t SpillAreaPaddingBytes = 0;
807 if (SpillAreaAlignmentBytes) { 809 if (SpillAreaAlignmentBytes) {
808 assert(SpillAreaAlignmentBytes <= X86_STACK_ALIGNMENT_BYTES); 810 assert(SpillAreaAlignmentBytes <= X86_STACK_ALIGNMENT_BYTES);
809 uint32_t PaddingStart = X86_RET_IP_SIZE_BYTES + PreservedRegsSizeBytes; 811 uint32_t PaddingStart = X86_RET_IP_SIZE_BYTES + PreservedRegsSizeBytes;
810 uint32_t SpillAreaStart = 812 uint32_t SpillAreaStart =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // Convert the reverse_iterator position into its corresponding 935 // Convert the reverse_iterator position into its corresponding
934 // (forward) iterator position. 936 // (forward) iterator position.
935 InstList::iterator InsertPoint = RI.base(); 937 InstList::iterator InsertPoint = RI.base();
936 --InsertPoint; 938 --InsertPoint;
937 Context.init(Node); 939 Context.init(Node);
938 Context.setInsertPoint(InsertPoint); 940 Context.setInsertPoint(InsertPoint);
939 941
940 Variable *esp = getPhysicalRegister(RegX8632::Reg_esp); 942 Variable *esp = getPhysicalRegister(RegX8632::Reg_esp);
941 if (IsEbpBasedFrame) { 943 if (IsEbpBasedFrame) {
942 Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp); 944 Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp);
945 // For asm-verbose mode, adding a fake use of esp before the
946 // assignment of esp=ebp keeps previous esp adjustments from being
947 // dead-code eliminated.
948 Context.insert(InstFakeUse::create(Func, esp));
943 _mov(esp, ebp); 949 _mov(esp, ebp);
944 _pop(ebp); 950 _pop(ebp);
945 } else { 951 } else {
946 // add esp, SpillAreaSizeBytes 952 // add esp, SpillAreaSizeBytes
947 if (SpillAreaSizeBytes) 953 if (SpillAreaSizeBytes)
948 _add(esp, Ctx->getConstantInt32(SpillAreaSizeBytes)); 954 _add(esp, Ctx->getConstantInt32(SpillAreaSizeBytes));
949 } 955 }
950 956
951 // Add pop instructions for preserved registers. 957 // Add pop instructions for preserved registers.
952 llvm::SmallBitVector CalleeSaves = 958 llvm::SmallBitVector CalleeSaves =
(...skipping 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after
4302 // TODO(stichnot): Opportunity for register randomization. 4308 // TODO(stichnot): Opportunity for register randomization.
4303 int32_t RegNum = AvailRegsForType.find_first(); 4309 int32_t RegNum = AvailRegsForType.find_first();
4304 bool IsVector = isVectorType(Dest->getType()); 4310 bool IsVector = isVectorType(Dest->getType());
4305 bool NeedSpill = (RegNum == -1); 4311 bool NeedSpill = (RegNum == -1);
4306 if (NeedSpill) { 4312 if (NeedSpill) {
4307 // Pick some register to spill and update RegNum. 4313 // Pick some register to spill and update RegNum.
4308 // TODO(stichnot): Opportunity for register randomization. 4314 // TODO(stichnot): Opportunity for register randomization.
4309 RegNum = RegsForType.find_first(); 4315 RegNum = RegsForType.find_first();
4310 Preg = getPhysicalRegister(RegNum, Dest->getType()); 4316 Preg = getPhysicalRegister(RegNum, Dest->getType());
4311 SpillLoc = Func->makeVariable(Dest->getType()); 4317 SpillLoc = Func->makeVariable(Dest->getType());
4318 // Create a fake def of the physical register to avoid
4319 // liveness inconsistency problems in asm-verbose mode.
4320 Context.insert(InstFakeDef::create(Func, Preg));
4312 if (IsVector) 4321 if (IsVector)
4313 _movp(SpillLoc, Preg); 4322 _movp(SpillLoc, Preg);
4314 else 4323 else
4315 _mov(SpillLoc, Preg); 4324 _mov(SpillLoc, Preg);
4316 } 4325 }
4317 assert(RegNum >= 0); 4326 assert(RegNum >= 0);
4318 if (llvm::isa<ConstantUndef>(Src)) 4327 if (llvm::isa<ConstantUndef>(Src))
4319 // Materialize an actual constant instead of undef. RegNum is 4328 // Materialize an actual constant instead of undef. RegNum is
4320 // passed in for vector types because undef vectors are 4329 // passed in for vector types because undef vectors are
4321 // lowered to vector register of zeroes. 4330 // lowered to vector register of zeroes.
4322 Src = 4331 Src =
4323 legalize(Src, Legal_All, IsVector ? RegNum : Variable::NoRegister); 4332 legalize(Src, Legal_All, IsVector ? RegNum : Variable::NoRegister);
4324 Variable *Tmp = makeReg(Dest->getType(), RegNum); 4333 Variable *Tmp = makeReg(Dest->getType(), RegNum);
4325 if (IsVector) { 4334 if (IsVector) {
4326 _movp(Tmp, Src); 4335 _movp(Tmp, Src);
4327 _movp(Dest, Tmp); 4336 _movp(Dest, Tmp);
4328 } else { 4337 } else {
4329 _mov(Tmp, Src); 4338 _mov(Tmp, Src);
4330 _mov(Dest, Tmp); 4339 _mov(Dest, Tmp);
4331 } 4340 }
4332 if (NeedSpill) { 4341 if (NeedSpill) {
4333 // Restore the spilled register. 4342 // Restore the spilled register.
4334 if (IsVector) 4343 if (IsVector)
4335 _movp(Preg, SpillLoc); 4344 _movp(Preg, SpillLoc);
4336 else 4345 else
4337 _mov(Preg, SpillLoc); 4346 _mov(Preg, SpillLoc);
4347 // Create a fake use of the physical register to keep it live
4348 // in asm-verbose mode.
4349 Context.insert(InstFakeUse::create(Func, Preg));
4338 } 4350 }
4339 } 4351 }
4340 // Update register availability before moving to the previous 4352 // Update register availability before moving to the previous
4341 // instruction on the Assignments list. 4353 // instruction on the Assignments list.
4342 if (Dest->hasReg()) 4354 if (Dest->hasReg())
4343 Available[Dest->getRegNum()] = true; 4355 Available[Dest->getRegNum()] = true;
4344 if (SrcVar && SrcVar->hasReg()) 4356 if (SrcVar && SrcVar->hasReg())
4345 Available[SrcVar->getRegNum()] = false; 4357 Available[SrcVar->getRegNum()] = false;
4346 } 4358 }
4347 4359
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
4873 case FT_Asm: 4885 case FT_Asm:
4874 case FT_Iasm: { 4886 case FT_Iasm: {
4875 OstreamLocker L(Ctx); 4887 OstreamLocker L(Ctx);
4876 emitConstantPool<PoolTypeConverter<float>>(Ctx); 4888 emitConstantPool<PoolTypeConverter<float>>(Ctx);
4877 emitConstantPool<PoolTypeConverter<double>>(Ctx); 4889 emitConstantPool<PoolTypeConverter<double>>(Ctx);
4878 } break; 4890 } break;
4879 } 4891 }
4880 } 4892 }
4881 4893
4882 } // end of namespace Ice 4894 } // end of namespace Ice
OLDNEW
« src/IceInstX8632.cpp ('K') | « src/IceInstX8632.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698