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

Side by Side Diff: src/IceTargetLoweringX86BaseImpl.h

Issue 1411583007: Combine allocas (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix a typo. Created 5 years, 1 month 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
OLDNEW
1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==// 1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 283 }
284 } 284 }
285 285
286 template <class Machine> void TargetX86Base<Machine>::staticInit() { 286 template <class Machine> void TargetX86Base<Machine>::staticInit() {
287 Traits::initRegisterSet(&TypeToRegisterSet, &RegisterAliases, &ScratchRegs); 287 Traits::initRegisterSet(&TypeToRegisterSet, &RegisterAliases, &ScratchRegs);
288 } 288 }
289 289
290 template <class Machine> void TargetX86Base<Machine>::translateO2() { 290 template <class Machine> void TargetX86Base<Machine>::translateO2() {
291 TimerMarker T(TimerStack::TT_O2, Func); 291 TimerMarker T(TimerStack::TT_O2, Func);
292 292
293 // Merge Alloca instructions, and lay out the stack.
294 Func->processAllocas();
295 Func->dump("After Alloca combining");
296
293 if (!Ctx->getFlags().getPhiEdgeSplit()) { 297 if (!Ctx->getFlags().getPhiEdgeSplit()) {
294 // Lower Phi instructions. 298 // Lower Phi instructions.
295 Func->placePhiLoads(); 299 Func->placePhiLoads();
296 if (Func->hasError()) 300 if (Func->hasError())
297 return; 301 return;
298 Func->placePhiStores(); 302 Func->placePhiStores();
299 if (Func->hasError()) 303 if (Func->hasError())
300 return; 304 return;
301 Func->deletePhis(); 305 Func->deletePhis();
302 if (Func->hasError()) 306 if (Func->hasError())
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 // bit-manipulation problems below. 954 // bit-manipulation problems below.
951 AlignmentParam = std::max(AlignmentParam, 1u); 955 AlignmentParam = std::max(AlignmentParam, 1u);
952 956
953 // LLVM enforces power of 2 alignment. 957 // LLVM enforces power of 2 alignment.
954 assert(llvm::isPowerOf2_32(AlignmentParam)); 958 assert(llvm::isPowerOf2_32(AlignmentParam));
955 assert(llvm::isPowerOf2_32(Traits::X86_STACK_ALIGNMENT_BYTES)); 959 assert(llvm::isPowerOf2_32(Traits::X86_STACK_ALIGNMENT_BYTES));
956 960
957 uint32_t Alignment = 961 uint32_t Alignment =
958 std::max(AlignmentParam, Traits::X86_STACK_ALIGNMENT_BYTES); 962 std::max(AlignmentParam, Traits::X86_STACK_ALIGNMENT_BYTES);
959 if (Alignment > Traits::X86_STACK_ALIGNMENT_BYTES) { 963 if (Alignment > Traits::X86_STACK_ALIGNMENT_BYTES) {
964 setHasFramePointer();
960 _and(esp, Ctx->getConstantInt32(-Alignment)); 965 _and(esp, Ctx->getConstantInt32(-Alignment));
961 } 966 }
962 if (const auto *ConstantTotalSize = 967 if (const auto *ConstantTotalSize =
963 llvm::dyn_cast<ConstantInteger32>(TotalSize)) { 968 llvm::dyn_cast<ConstantInteger32>(TotalSize)) {
964 uint32_t Value = ConstantTotalSize->getValue(); 969 uint32_t Value = ConstantTotalSize->getValue();
965 Value = Utils::applyAlignment(Value, Alignment); 970 Value = Utils::applyAlignment(Value, Alignment);
966 if (Inst->getKnownFrameOffset()) { 971 if (Inst->getKnownFrameOffset()) {
967 _adjust_stack(Value); 972 _adjust_stack(Value);
968 FixedAllocaSizeBytes += Value; 973 FixedAllocaSizeBytes += Value;
969 } else { 974 } else {
(...skipping 4452 matching lines...) Expand 10 before | Expand all | Expand 10 after
5422 } 5427 }
5423 5428
5424 if (auto *Mem = llvm::dyn_cast<typename Traits::X86OperandMem>(From)) { 5429 if (auto *Mem = llvm::dyn_cast<typename Traits::X86OperandMem>(From)) {
5425 // Before doing anything with a Mem operand, we need to ensure that the 5430 // Before doing anything with a Mem operand, we need to ensure that the
5426 // Base and Index components are in physical registers. 5431 // Base and Index components are in physical registers.
5427 Variable *Base = Mem->getBase(); 5432 Variable *Base = Mem->getBase();
5428 Variable *Index = Mem->getIndex(); 5433 Variable *Index = Mem->getIndex();
5429 Variable *RegBase = nullptr; 5434 Variable *RegBase = nullptr;
5430 Variable *RegIndex = nullptr; 5435 Variable *RegIndex = nullptr;
5431 if (Base) { 5436 if (Base) {
5432 RegBase = legalizeToReg(Base); 5437 RegBase = llvm::cast<Variable>(
5438 legalize(Base, Legal_Reg | Legal_Rematerializable));
5433 } 5439 }
5434 if (Index) { 5440 if (Index) {
5441 RegIndex = llvm::cast<Variable>(
5442 legalize(Index, Legal_Reg | Legal_Rematerializable));
5435 RegIndex = legalizeToReg(Index); 5443 RegIndex = legalizeToReg(Index);
Jim Stichnoth 2015/11/11 17:39:45 This statement eliminates the effect of the previo
sehr 2015/11/11 22:14:11 Cursed cut/paste. I wanted the rematerializable v
5436 } 5444 }
5437 if (Base != RegBase || Index != RegIndex) { 5445 if (Base != RegBase || Index != RegIndex) {
5438 Mem = Traits::X86OperandMem::create(Func, Ty, RegBase, Mem->getOffset(), 5446 Mem = Traits::X86OperandMem::create(Func, Ty, RegBase, Mem->getOffset(),
5439 RegIndex, Mem->getShift(), 5447 RegIndex, Mem->getShift(),
5440 Mem->getSegmentRegister()); 5448 Mem->getSegmentRegister());
5441 } 5449 }
5442 5450
5443 // For all Memory Operands, we do randomization/pooling here 5451 // For all Memory Operands, we do randomization/pooling here
5444 From = randomizeOrPoolImmediate(Mem); 5452 From = randomizeOrPoolImmediate(Mem);
5445 5453
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
5497 if (NeedsReg) { 5505 if (NeedsReg) {
5498 From = copyToReg(From, RegNum); 5506 From = copyToReg(From, RegNum);
5499 } 5507 }
5500 return From; 5508 return From;
5501 } 5509 }
5502 if (auto *Var = llvm::dyn_cast<Variable>(From)) { 5510 if (auto *Var = llvm::dyn_cast<Variable>(From)) {
5503 // Check if the variable is guaranteed a physical register. This can happen 5511 // Check if the variable is guaranteed a physical register. This can happen
5504 // either when the variable is pre-colored or when it is assigned infinite 5512 // either when the variable is pre-colored or when it is assigned infinite
5505 // weight. 5513 // weight.
5506 bool MustHaveRegister = (Var->hasReg() || Var->mustHaveReg()); 5514 bool MustHaveRegister = (Var->hasReg() || Var->mustHaveReg());
5515 bool MustRematerialize =
5516 (Var->isRematerializable() && !(Allowed & Legal_Rematerializable));
5507 // We need a new physical register for the operand if: 5517 // We need a new physical register for the operand if:
5508 // Mem is not allowed and Var isn't guaranteed a physical 5518 // - Mem is not allowed and Var isn't guaranteed a physical
Jim Stichnoth 2015/11/11 17:39:45 reflow to 80-col
sehr 2015/11/11 22:14:11 Done.
5509 // register, or 5519 // register, or
5510 // RegNum is required and Var->getRegNum() doesn't match. 5520 // - RegNum is required and Var->getRegNum() doesn't match, or
5511 if ((!(Allowed & Legal_Mem) && !MustHaveRegister) || 5521 // - Var is a rematerializable variable and rematerializable pass-through
Jim Stichnoth 2015/11/11 17:39:45 reflow
sehr 2015/11/11 22:14:11 Done.
5512 (RegNum != Variable::NoRegister && RegNum != Var->getRegNum())) { 5522 // is not allowed (in which case we need an lea instruction).
5523 if (MustRematerialize) {
5524 assert(Ty == IceType_i32);
5525 Variable *NewVar = makeReg(Ty, RegNum);
5526 // Since Var is rematerializable, the offset will be added when the
Jim Stichnoth 2015/11/11 17:39:45 reflow
sehr 2015/11/11 22:14:11 Done.
5527 // lea is emitted.
5528 Constant *Offset = Ctx->getConstantInt(Ty, 0);
Jim Stichnoth 2015/11/11 17:39:45 John's cool new style: Constant *_0 = Ctx->getC
sehr 2015/11/11 22:14:11 Chose the latter. Fewer constant lookups is goo.
5529 auto *Mem = Traits::X86OperandMem::create(Func, Ty, Var, Offset);
5530 _lea(NewVar, Mem);
5531 From = NewVar;
5532 } else if ((!(Allowed & Legal_Mem) && !MustHaveRegister) ||
5533 (RegNum != Variable::NoRegister && RegNum != Var->getRegNum()) ||
5534 MustRematerialize) {
5513 From = copyToReg(From, RegNum); 5535 From = copyToReg(From, RegNum);
5514 } 5536 }
5515 return From; 5537 return From;
5516 } 5538 }
5517 llvm_unreachable("Unhandled operand kind in legalize()"); 5539 llvm_unreachable("Unhandled operand kind in legalize()");
5518 return From; 5540 return From;
5519 } 5541 }
5520 5542
5521 /// Provide a trivial wrapper to legalize() for this common usage. 5543 /// Provide a trivial wrapper to legalize() for this common usage.
5522 template <class Machine> 5544 template <class Machine>
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
5881 } 5903 }
5882 // the offset is not eligible for blinding or pooling, return the original 5904 // the offset is not eligible for blinding or pooling, return the original
5883 // mem operand 5905 // mem operand
5884 return MemOperand; 5906 return MemOperand;
5885 } 5907 }
5886 5908
5887 } // end of namespace X86Internal 5909 } // end of namespace X86Internal
5888 } // end of namespace Ice 5910 } // end of namespace Ice
5889 5911
5890 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H 5912 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698