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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 807293003: Subzero: Randomize register assignment. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Simply; fix a bug; add the lit test Created 6 years 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/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 4512 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 if (Variable *Dest = Inst->getDest()) { 4523 if (Variable *Dest = Inst->getDest()) {
4524 // TODO(stichnot): We may need to consider all source 4524 // TODO(stichnot): We may need to consider all source
4525 // operands, not just the first one, if using 3-address 4525 // operands, not just the first one, if using 3-address
4526 // instructions. 4526 // instructions.
4527 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest) 4527 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest)
4528 Inst->setDestNonKillable(); 4528 Inst->setDestNonKillable();
4529 } 4529 }
4530 } 4530 }
4531 } 4531 }
4532 4532
4533 void TargetX8632::makeRandomRegisterPermutation(
4534 llvm::SmallVectorImpl<int32_t> &Permutation,
4535 const llvm::SmallBitVector &ExcludeRegisters) const {
4536 assert(Permutation.size() >= RegX8632::Reg_NUM);
4537 typedef llvm::SmallVector<int32_t, 8> RegisterList;
JF 2014/12/17 18:56:19 Make 8 a constant somewhere, with an explanation.
Jim Stichnoth 2014/12/18 18:52:03 Done.
4538 typedef std::map<unsigned, RegisterList> EquivalenceClassMap;
4539 EquivalenceClassMap EquivalenceClasses;
4540 SizeT NumShuffled = 0, NumPreserved = 0;
4541
4542 // Build up the equivalence classes of registers by looking at the
4543 // register properties as well as whether the registers should be
4544 // explicitly excluded from shuffling.
4545 #define X(val, encode, name, name16, name8, scratch, preserved, stackptr, \
4546 frameptr, isI8, isInt, isFP) \
4547 if (ExcludeRegisters[RegX8632::val]) { \
4548 /* val stays the same in the resulting permutation. */ \
4549 Permutation[RegX8632::val] = RegX8632::val; \
4550 ++NumPreserved; \
4551 } else { \
4552 union { \
4553 unsigned ClassNum; \
4554 struct { \
4555 unsigned IsScratch : 1; \
4556 unsigned IsPreserved : 1; \
4557 unsigned IsI8 : 1; \
4558 unsigned IsInt : 1; \
4559 unsigned IsFP : 1; \
4560 } Bits; \
4561 } Class = { 0 }; \
4562 Class.Bits.IsScratch = scratch; \
4563 Class.Bits.IsPreserved = preserved; \
4564 Class.Bits.IsI8 = isI8; \
4565 Class.Bits.IsInt = isInt; \
4566 Class.Bits.IsFP = isFP; \
4567 /* val is assigned to an equivalence class based on its properties. */ \
4568 EquivalenceClasses[Class.ClassNum].push_back(RegX8632::val); \
JF 2014/12/17 18:56:19 You can't access Class.ClassNum here: the union's
Jim Stichnoth 2014/12/18 18:52:03 Done.
4569 }
4570 REGX8632_TABLE
4571 #undef X
JF 2014/12/17 18:56:19 Can't this table be in rodata?
Jim Stichnoth 2014/12/18 18:52:03 Not so readily, since the table is dependent on th
4572
4573 RandomNumberGeneratorWrapper RNG(Ctx->getRNG());
4574
4575 // Shuffle the resulting equivalence classes.
4576 for (EquivalenceClassMap::const_iterator I = EquivalenceClasses.begin(),
4577 E = EquivalenceClasses.end();
4578 I != E; ++I) {
JF 2014/12/17 18:56:19 C++11.
Jim Stichnoth 2014/12/18 18:52:03 Done.
4579 const RegisterList &List = I->second;
4580 RegisterList Shuffled(List);
4581 std::random_shuffle(Shuffled.begin(), Shuffled.end(), RNG);
4582 for (size_t SI = 0, SE = Shuffled.size(); SI < SE; ++SI) {
JF 2014/12/17 18:56:19 C++11.
Jim Stichnoth 2014/12/18 18:52:03 I don't think much can be done here, since the ind
4583 Permutation[List[SI]] = Shuffled[SI];
4584 ++NumShuffled;
4585 }
4586 }
4587
4588 assert(NumShuffled + NumPreserved == RegX8632::Reg_NUM);
4589
4590 if (Func->getContext()->isVerbose(IceV_Random)) {
4591 Ostream &Str = Func->getContext()->getStrDump();
4592 Str << "Register equivalence classes:\n";
4593 for (EquivalenceClassMap::const_iterator I = EquivalenceClasses.begin(),
4594 E = EquivalenceClasses.end();
4595 I != E; ++I) {
JF 2014/12/17 18:56:18 C++11.
Jim Stichnoth 2014/12/18 18:52:03 Done.
4596 Str << "{";
4597 const RegisterList &List = I->second;
4598 for (SizeT RI = 0, RE = List.size(); RI != RE; ++RI) {
JF 2014/12/17 18:56:19 C++11.
Jim Stichnoth 2014/12/18 18:52:03 Done.
4599 if (RI > 0)
4600 Str << " ";
4601 Str << getRegName(List[RI], IceType_i32);
4602 }
4603 Str << "}\n";
4604 }
4605 }
4606 }
4607
4533 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const { 4608 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const {
4534 if (!ALLOW_DUMP) 4609 if (!ALLOW_DUMP)
4535 return; 4610 return;
4536 Ostream &Str = Ctx->getStrEmit(); 4611 Ostream &Str = Ctx->getStrEmit();
4537 Str << "$" << (int32_t)getValue(); 4612 Str << "$" << (int32_t)getValue();
4538 } 4613 }
4539 4614
4540 template <> void ConstantInteger64::emit(GlobalContext *) const { 4615 template <> void ConstantInteger64::emit(GlobalContext *) const {
4541 llvm_unreachable("Not expecting to emit 64-bit integers"); 4616 llvm_unreachable("Not expecting to emit 64-bit integers");
4542 } 4617 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
4652 } else if (IsConstant || IsExternal) 4727 } else if (IsConstant || IsExternal)
4653 Str << "\t.zero\t" << Size << "\n"; 4728 Str << "\t.zero\t" << Size << "\n";
4654 // Size is part of .comm. 4729 // Size is part of .comm.
4655 4730
4656 if (IsConstant || HasNonzeroInitializer || IsExternal) 4731 if (IsConstant || HasNonzeroInitializer || IsExternal)
4657 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 4732 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
4658 // Size is part of .comm. 4733 // Size is part of .comm.
4659 } 4734 }
4660 4735
4661 } // end of namespace Ice 4736 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698