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

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: rebase to master 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
« no previous file with comments | « src/IceTargetLoweringX86Base.h ('k') | tests_lit/llvm2ice_tests/nop-insertion.ll » ('j') | 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/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 4143 matching lines...) Expand 10 before | Expand all | Expand 10 after
4154 if (Base && Addr != Base) { 4154 if (Base && Addr != Base) {
4155 Inst->setDeleted(); 4155 Inst->setDeleted();
4156 Constant *OffsetOp = Ctx->getConstantInt32(Offset); 4156 Constant *OffsetOp = Ctx->getConstantInt32(Offset);
4157 Addr = Traits::X86OperandMem::create(Func, Dest->getType(), Base, OffsetOp, 4157 Addr = Traits::X86OperandMem::create(Func, Dest->getType(), Base, OffsetOp,
4158 Index, Shift, SegmentReg); 4158 Index, Shift, SegmentReg);
4159 Context.insert(InstLoad::create(Func, Dest, Addr)); 4159 Context.insert(InstLoad::create(Func, Dest, Addr));
4160 } 4160 }
4161 } 4161 }
4162 4162
4163 template <class Machine> 4163 template <class Machine>
4164 void TargetX86Base<Machine>::randomlyInsertNop(float Probability) { 4164 void TargetX86Base<Machine>::randomlyInsertNop(float Probability,
4165 RandomNumberGeneratorWrapper RNG(Ctx->getRNG()); 4165 RandomNumberGenerator &RNG) {
4166 if (RNG.getTrueWithProbability(Probability)) { 4166 RandomNumberGeneratorWrapper RNGW(RNG);
4167 _nop(RNG(Traits::X86_NUM_NOP_VARIANTS)); 4167 if (RNGW.getTrueWithProbability(Probability)) {
4168 _nop(RNGW(Traits::X86_NUM_NOP_VARIANTS));
4168 } 4169 }
4169 } 4170 }
4170 4171
4171 template <class Machine> 4172 template <class Machine>
4172 void TargetX86Base<Machine>::lowerPhi(const InstPhi * /*Inst*/) { 4173 void TargetX86Base<Machine>::lowerPhi(const InstPhi * /*Inst*/) {
4173 Func->setError("Phi found in regular instruction list"); 4174 Func->setError("Phi found in regular instruction list");
4174 } 4175 }
4175 4176
4176 template <class Machine> 4177 template <class Machine>
4177 void TargetX86Base<Machine>::lowerSelect(const InstSelect *Inst) { 4178 void TargetX86Base<Machine>::lowerSelect(const InstSelect *Inst) {
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
5112 5113
5113 template <class Machine> void TargetX86Base<Machine>::postLower() { 5114 template <class Machine> void TargetX86Base<Machine>::postLower() {
5114 if (Ctx->getFlags().getOptLevel() == Opt_m1) 5115 if (Ctx->getFlags().getOptLevel() == Opt_m1)
5115 return; 5116 return;
5116 inferTwoAddress(); 5117 inferTwoAddress();
5117 } 5118 }
5118 5119
5119 template <class Machine> 5120 template <class Machine>
5120 void TargetX86Base<Machine>::makeRandomRegisterPermutation( 5121 void TargetX86Base<Machine>::makeRandomRegisterPermutation(
5121 llvm::SmallVectorImpl<int32_t> &Permutation, 5122 llvm::SmallVectorImpl<int32_t> &Permutation,
5122 const llvm::SmallBitVector &ExcludeRegisters) const { 5123 const llvm::SmallBitVector &ExcludeRegisters, uint64_t Salt) const {
5123 Traits::makeRandomRegisterPermutation(Ctx, Func, Permutation, 5124 Traits::makeRandomRegisterPermutation(Ctx, Func, Permutation,
5124 ExcludeRegisters); 5125 ExcludeRegisters, Salt);
5125 } 5126 }
5126 5127
5127 template <class Machine> 5128 template <class Machine>
5128 void TargetX86Base<Machine>::emit(const ConstantInteger32 *C) const { 5129 void TargetX86Base<Machine>::emit(const ConstantInteger32 *C) const {
5129 if (!BuildDefs::dump()) 5130 if (!BuildDefs::dump())
5130 return; 5131 return;
5131 Ostream &Str = Ctx->getStrEmit(); 5132 Ostream &Str = Ctx->getStrEmit();
5132 Str << getConstantPrefix() << C->getValue(); 5133 Str << getConstantPrefix() << C->getValue();
5133 } 5134 }
5134 5135
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5189 // => Reg 5190 // => Reg
5190 // If we have already assigned a phy register, we must come from 5191 // If we have already assigned a phy register, we must come from
5191 // andvancedPhiLowering()=>lowerAssign(). In this case we should reuse 5192 // andvancedPhiLowering()=>lowerAssign(). In this case we should reuse
5192 // the assigned register as this assignment is that start of its use-def 5193 // the assigned register as this assignment is that start of its use-def
5193 // chain. So we add RegNum argument here. 5194 // chain. So we add RegNum argument here.
5194 // Note we use 'lea' instruction instead of 'xor' to avoid affecting 5195 // Note we use 'lea' instruction instead of 'xor' to avoid affecting
5195 // the flags. 5196 // the flags.
5196 Variable *Reg = makeReg(IceType_i32, RegNum); 5197 Variable *Reg = makeReg(IceType_i32, RegNum);
5197 ConstantInteger32 *Integer = llvm::cast<ConstantInteger32>(Immediate); 5198 ConstantInteger32 *Integer = llvm::cast<ConstantInteger32>(Immediate);
5198 uint32_t Value = Integer->getValue(); 5199 uint32_t Value = Integer->getValue();
5199 uint32_t Cookie = Ctx->getRandomizationCookie(); 5200 uint32_t Cookie = Func->getConstantBlindingCookie();
5200 _mov(Reg, Ctx->getConstantInt(IceType_i32, Cookie + Value)); 5201 _mov(Reg, Ctx->getConstantInt(IceType_i32, Cookie + Value));
5201 Constant *Offset = Ctx->getConstantInt(IceType_i32, 0 - Cookie); 5202 Constant *Offset = Ctx->getConstantInt(IceType_i32, 0 - Cookie);
5202 _lea(Reg, Traits::X86OperandMem::create(Func, IceType_i32, Reg, Offset, 5203 _lea(Reg, Traits::X86OperandMem::create(Func, IceType_i32, Reg, Offset,
5203 nullptr, 0)); 5204 nullptr, 0));
5204 // make sure liveness analysis won't kill this variable, otherwise a 5205 // make sure liveness analysis won't kill this variable, otherwise a
5205 // liveness assertion will be triggered. 5206 // liveness assertion will be triggered.
5206 _set_dest_nonkillable(); 5207 _set_dest_nonkillable();
5207 if (Immediate->getType() != IceType_i32) { 5208 if (Immediate->getType() != IceType_i32) {
5208 Variable *TruncReg = makeReg(Immediate->getType(), RegNum); 5209 Variable *TruncReg = makeReg(Immediate->getType(), RegNum);
5209 _mov(TruncReg, Reg); 5210 _mov(TruncReg, Reg);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5268 RPI_Randomize) { 5269 RPI_Randomize) {
5269 // blind the constant offset 5270 // blind the constant offset
5270 // FROM: 5271 // FROM:
5271 // offset[base, index, shift] 5272 // offset[base, index, shift]
5272 // TO: 5273 // TO:
5273 // insert: lea offset+cookie[base], RegTemp 5274 // insert: lea offset+cookie[base], RegTemp
5274 // => -cookie[RegTemp, index, shift] 5275 // => -cookie[RegTemp, index, shift]
5275 uint32_t Value = 5276 uint32_t Value =
5276 llvm::dyn_cast<ConstantInteger32>(MemOperand->getOffset()) 5277 llvm::dyn_cast<ConstantInteger32>(MemOperand->getOffset())
5277 ->getValue(); 5278 ->getValue();
5278 uint32_t Cookie = Ctx->getRandomizationCookie(); 5279 uint32_t Cookie = Func->getConstantBlindingCookie();
5279 Constant *Mask1 = Ctx->getConstantInt( 5280 Constant *Mask1 = Ctx->getConstantInt(
5280 MemOperand->getOffset()->getType(), Cookie + Value); 5281 MemOperand->getOffset()->getType(), Cookie + Value);
5281 Constant *Mask2 = 5282 Constant *Mask2 =
5282 Ctx->getConstantInt(MemOperand->getOffset()->getType(), 0 - Cookie); 5283 Ctx->getConstantInt(MemOperand->getOffset()->getType(), 0 - Cookie);
5283 5284
5284 typename Traits::X86OperandMem *TempMemOperand = 5285 typename Traits::X86OperandMem *TempMemOperand =
5285 Traits::X86OperandMem::create(Func, MemOperand->getType(), 5286 Traits::X86OperandMem::create(Func, MemOperand->getType(),
5286 MemOperand->getBase(), Mask1); 5287 MemOperand->getBase(), Mask1);
5287 // If we have already assigned a physical register, we must come from 5288 // If we have already assigned a physical register, we must come from
5288 // advancedPhiLowering()=>lowerAssign(). In this case we should reuse 5289 // advancedPhiLowering()=>lowerAssign(). In this case we should reuse
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5363 } 5364 }
5364 // the offset is not eligible for blinding or pooling, return the original 5365 // the offset is not eligible for blinding or pooling, return the original
5365 // mem operand 5366 // mem operand
5366 return MemOperand; 5367 return MemOperand;
5367 } 5368 }
5368 5369
5369 } // end of namespace X86Internal 5370 } // end of namespace X86Internal
5370 } // end of namespace Ice 5371 } // end of namespace Ice
5371 5372
5372 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H 5373 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX86Base.h ('k') | tests_lit/llvm2ice_tests/nop-insertion.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698