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

Side by Side Diff: src/IceTargetLoweringX86BaseImpl.h

Issue 1300993002: Use separate random number generator for each randomization pass (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Assign default value of ConstantBlindingCookie in its declaration Created 5 years, 4 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
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 4114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4125 if (Base && Addr != Base) { 4125 if (Base && Addr != Base) {
4126 Inst->setDeleted(); 4126 Inst->setDeleted();
4127 Constant *OffsetOp = Ctx->getConstantInt32(Offset); 4127 Constant *OffsetOp = Ctx->getConstantInt32(Offset);
4128 Addr = Traits::X86OperandMem::create(Func, Dest->getType(), Base, OffsetOp, 4128 Addr = Traits::X86OperandMem::create(Func, Dest->getType(), Base, OffsetOp,
4129 Index, Shift, SegmentReg); 4129 Index, Shift, SegmentReg);
4130 Context.insert(InstLoad::create(Func, Dest, Addr)); 4130 Context.insert(InstLoad::create(Func, Dest, Addr));
4131 } 4131 }
4132 } 4132 }
4133 4133
4134 template <class Machine> 4134 template <class Machine>
4135 void TargetX86Base<Machine>::randomlyInsertNop(float Probability) { 4135 void TargetX86Base<Machine>::randomlyInsertNop(float Probability,
4136 RandomNumberGeneratorWrapper RNG(Ctx->getRNG()); 4136 RandomNumberGenerator &RNG) {
4137 if (RNG.getTrueWithProbability(Probability)) { 4137 RandomNumberGeneratorWrapper RNGW(RNG);
4138 _nop(RNG(Traits::X86_NUM_NOP_VARIANTS)); 4138 if (RNGW.getTrueWithProbability(Probability)) {
4139 _nop(RNGW(Traits::X86_NUM_NOP_VARIANTS));
4139 } 4140 }
4140 } 4141 }
4141 4142
4142 template <class Machine> 4143 template <class Machine>
4143 void TargetX86Base<Machine>::lowerPhi(const InstPhi * /*Inst*/) { 4144 void TargetX86Base<Machine>::lowerPhi(const InstPhi * /*Inst*/) {
4144 Func->setError("Phi found in regular instruction list"); 4145 Func->setError("Phi found in regular instruction list");
4145 } 4146 }
4146 4147
4147 template <class Machine> 4148 template <class Machine>
4148 void TargetX86Base<Machine>::lowerSelect(const InstSelect *Inst) { 4149 void TargetX86Base<Machine>::lowerSelect(const InstSelect *Inst) {
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
5132 // => Reg 5133 // => Reg
5133 // If we have already assigned a phy register, we must come from 5134 // If we have already assigned a phy register, we must come from
5134 // andvancedPhiLowering()=>lowerAssign(). In this case we should reuse 5135 // andvancedPhiLowering()=>lowerAssign(). In this case we should reuse
5135 // the assigned register as this assignment is that start of its use-def 5136 // the assigned register as this assignment is that start of its use-def
5136 // chain. So we add RegNum argument here. 5137 // chain. So we add RegNum argument here.
5137 // Note we use 'lea' instruction instead of 'xor' to avoid affecting 5138 // Note we use 'lea' instruction instead of 'xor' to avoid affecting
5138 // the flags. 5139 // the flags.
5139 Variable *Reg = makeReg(IceType_i32, RegNum); 5140 Variable *Reg = makeReg(IceType_i32, RegNum);
5140 ConstantInteger32 *Integer = llvm::cast<ConstantInteger32>(Immediate); 5141 ConstantInteger32 *Integer = llvm::cast<ConstantInteger32>(Immediate);
5141 uint32_t Value = Integer->getValue(); 5142 uint32_t Value = Integer->getValue();
5142 uint32_t Cookie = Ctx->getRandomizationCookie(); 5143 uint32_t Cookie = Func->getConstantBlindingCookie();
5143 _mov(Reg, Ctx->getConstantInt(IceType_i32, Cookie + Value)); 5144 _mov(Reg, Ctx->getConstantInt(IceType_i32, Cookie + Value));
5144 Constant *Offset = Ctx->getConstantInt(IceType_i32, 0 - Cookie); 5145 Constant *Offset = Ctx->getConstantInt(IceType_i32, 0 - Cookie);
5145 _lea(Reg, Traits::X86OperandMem::create(Func, IceType_i32, Reg, Offset, 5146 _lea(Reg, Traits::X86OperandMem::create(Func, IceType_i32, Reg, Offset,
5146 nullptr, 0)); 5147 nullptr, 0));
5147 // make sure liveness analysis won't kill this variable, otherwise a 5148 // make sure liveness analysis won't kill this variable, otherwise a
5148 // liveness assertion will be triggered. 5149 // liveness assertion will be triggered.
5149 _set_dest_nonkillable(); 5150 _set_dest_nonkillable();
5150 if (Immediate->getType() != IceType_i32) { 5151 if (Immediate->getType() != IceType_i32) {
5151 Variable *TruncReg = makeReg(Immediate->getType(), RegNum); 5152 Variable *TruncReg = makeReg(Immediate->getType(), RegNum);
5152 _mov(TruncReg, Reg); 5153 _mov(TruncReg, Reg);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5211 RPI_Randomize) { 5212 RPI_Randomize) {
5212 // blind the constant offset 5213 // blind the constant offset
5213 // FROM: 5214 // FROM:
5214 // offset[base, index, shift] 5215 // offset[base, index, shift]
5215 // TO: 5216 // TO:
5216 // insert: lea offset+cookie[base], RegTemp 5217 // insert: lea offset+cookie[base], RegTemp
5217 // => -cookie[RegTemp, index, shift] 5218 // => -cookie[RegTemp, index, shift]
5218 uint32_t Value = 5219 uint32_t Value =
5219 llvm::dyn_cast<ConstantInteger32>(MemOperand->getOffset()) 5220 llvm::dyn_cast<ConstantInteger32>(MemOperand->getOffset())
5220 ->getValue(); 5221 ->getValue();
5221 uint32_t Cookie = Ctx->getRandomizationCookie(); 5222 uint32_t Cookie = Func->getConstantBlindingCookie();
5222 Constant *Mask1 = Ctx->getConstantInt( 5223 Constant *Mask1 = Ctx->getConstantInt(
5223 MemOperand->getOffset()->getType(), Cookie + Value); 5224 MemOperand->getOffset()->getType(), Cookie + Value);
5224 Constant *Mask2 = 5225 Constant *Mask2 =
5225 Ctx->getConstantInt(MemOperand->getOffset()->getType(), 0 - Cookie); 5226 Ctx->getConstantInt(MemOperand->getOffset()->getType(), 0 - Cookie);
5226 5227
5227 typename Traits::X86OperandMem *TempMemOperand = 5228 typename Traits::X86OperandMem *TempMemOperand =
5228 Traits::X86OperandMem::create(Func, MemOperand->getType(), 5229 Traits::X86OperandMem::create(Func, MemOperand->getType(),
5229 MemOperand->getBase(), Mask1); 5230 MemOperand->getBase(), Mask1);
5230 // If we have already assigned a physical register, we must come from 5231 // If we have already assigned a physical register, we must come from
5231 // advancedPhiLowering()=>lowerAssign(). In this case we should reuse 5232 // advancedPhiLowering()=>lowerAssign(). In this case we should reuse
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5306 } 5307 }
5307 // the offset is not eligible for blinding or pooling, return the original 5308 // the offset is not eligible for blinding or pooling, return the original
5308 // mem operand 5309 // mem operand
5309 return MemOperand; 5310 return MemOperand;
5310 } 5311 }
5311 5312
5312 } // end of namespace X86Internal 5313 } // end of namespace X86Internal
5313 } // end of namespace Ice 5314 } // end of namespace Ice
5314 5315
5315 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H 5316 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698