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

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

Powered by Google App Engine
This is Rietveld 408576698