OLD | NEW |
---|---|
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 5252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5263 // Base is Base=Var+Const || Base is Base=Const+Var ==> | 5263 // Base is Base=Var+Const || Base is Base=Const+Var ==> |
5264 // set Base=Var, Offset+=Const | 5264 // set Base=Var, Offset+=Const |
5265 // Base is Base=Var-Const ==> | 5265 // Base is Base=Var-Const ==> |
5266 // set Base=Var, Offset-=Const | 5266 // set Base=Var, Offset-=Const |
5267 // Index is Index=Var+Const ==> | 5267 // Index is Index=Var+Const ==> |
5268 // set Index=Var, Offset+=(Const<<Shift) | 5268 // set Index=Var, Offset+=(Const<<Shift) |
5269 // Index is Index=Const+Var ==> | 5269 // Index is Index=Const+Var ==> |
5270 // set Index=Var, Offset+=(Const<<Shift) | 5270 // set Index=Var, Offset+=(Const<<Shift) |
5271 // Index is Index=Var-Const ==> | 5271 // Index is Index=Var-Const ==> |
5272 // set Index=Var, Offset-=(Const<<Shift) | 5272 // set Index=Var, Offset-=(Const<<Shift) |
5273 // Treat Index=Var Or Const as Index=Var + Const | |
5274 // when Var = Var' << N and log2(Const) <= N | |
5275 // or when Var = (2^M) * (2^N) and log2(Const) <= (M+N) | |
5273 | 5276 |
5274 if (*IndexOrBase == nullptr) { | 5277 if (*IndexOrBase == nullptr) { |
5275 return nullptr; | 5278 return nullptr; |
5276 } | 5279 } |
5277 const Inst *Definition = VMetadata->getSingleDefinition(*IndexOrBase); | 5280 const Inst *Definition = VMetadata->getSingleDefinition(*IndexOrBase); |
5278 if (Definition == nullptr) { | 5281 if (Definition == nullptr) { |
5279 return nullptr; | 5282 return nullptr; |
5280 } | 5283 } |
5281 assert(!VMetadata->isMultiDef(*IndexOrBase)); | 5284 assert(!VMetadata->isMultiDef(*IndexOrBase)); |
5282 if (auto *ArithInst = llvm::dyn_cast<const InstArithmetic>(Definition)) { | 5285 if (auto *ArithInst = llvm::dyn_cast<const InstArithmetic>(Definition)) { |
5283 if (ArithInst->getOp() != InstArithmetic::Add && | 5286 switch (ArithInst->getOp()) { |
5284 ArithInst->getOp() != InstArithmetic::Sub) | 5287 case InstArithmetic::Add: |
5288 case InstArithmetic::Sub: | |
5289 case InstArithmetic::Or: | |
5290 break; | |
5291 default: | |
5285 return nullptr; | 5292 return nullptr; |
5286 bool IsAdd = ArithInst->getOp() == InstArithmetic::Add; | 5293 } |
5294 | |
5287 Operand *Src0 = ArithInst->getSrc(0); | 5295 Operand *Src0 = ArithInst->getSrc(0); |
5288 Operand *Src1 = ArithInst->getSrc(1); | 5296 Operand *Src1 = ArithInst->getSrc(1); |
5289 auto *Var0 = llvm::dyn_cast<Variable>(Src0); | 5297 auto *Var0 = llvm::dyn_cast<Variable>(Src0); |
5290 auto *Var1 = llvm::dyn_cast<Variable>(Src1); | 5298 auto *Var1 = llvm::dyn_cast<Variable>(Src1); |
5291 auto *Const0 = llvm::dyn_cast<ConstantInteger32>(Src0); | 5299 auto *Const0 = llvm::dyn_cast<ConstantInteger32>(Src0); |
5292 auto *Const1 = llvm::dyn_cast<ConstantInteger32>(Src1); | 5300 auto *Const1 = llvm::dyn_cast<ConstantInteger32>(Src1); |
5293 auto *Reloc0 = llvm::dyn_cast<ConstantRelocatable>(Src0); | 5301 auto *Reloc0 = llvm::dyn_cast<ConstantRelocatable>(Src0); |
5294 auto *Reloc1 = llvm::dyn_cast<ConstantRelocatable>(Src1); | 5302 auto *Reloc1 = llvm::dyn_cast<ConstantRelocatable>(Src1); |
5303 | |
5304 bool IsAdd = false; | |
5305 if (ArithInst->getOp() == InstArithmetic::Or) { | |
5306 Variable *Var = nullptr; | |
5307 ConstantInteger32 *Const = nullptr; | |
5308 if (Var0 && Const1) { | |
5309 Var = Var0; | |
5310 Const = Const1; | |
5311 } else if (Const0 && Var1) { | |
5312 Var = Var1; | |
5313 Const = Const0; | |
5314 } else | |
5315 return nullptr; | |
Jim Stichnoth
2016/06/27 20:33:05
Use braces around the return statement for consist
| |
5316 | |
5317 auto *VarDef = | |
5318 llvm::dyn_cast<InstArithmetic>(VMetadata->getSingleDefinition(Var)); | |
5319 if (VarDef == nullptr) | |
5320 return nullptr; | |
5321 | |
5322 SizeT ZeroesAvailable = 0; | |
5323 if (VarDef->getOp() == InstArithmetic::Shl) { | |
5324 if (auto *ConstInt = | |
5325 llvm::dyn_cast<ConstantInteger32>(VarDef->getSrc(1))) { | |
5326 ZeroesAvailable = ConstInt->getValue(); | |
5327 } | |
5328 } else if (VarDef->getOp() == InstArithmetic::Mul) { | |
5329 SizeT PowerOfTwo = 0; | |
5330 ConstantInteger32 *MultConst = | |
5331 llvm::dyn_cast<ConstantInteger32>(VarDef->getSrc(0)); | |
5332 if (llvm::isPowerOf2_32(MultConst->getValue())) { | |
5333 PowerOfTwo += MultConst->getValue(); | |
5334 } | |
5335 MultConst = llvm::dyn_cast<ConstantInteger32>(VarDef->getSrc(1)); | |
5336 if (llvm::isPowerOf2_32(MultConst->getValue())) { | |
5337 PowerOfTwo += MultConst->getValue(); | |
5338 } | |
5339 ZeroesAvailable = llvm::Log2_32(PowerOfTwo) + 1; | |
5340 } | |
5341 SizeT ZeroesNeeded = llvm::Log2_32(Const->getValue()) + 1; | |
5342 if (ZeroesNeeded == 0 || ZeroesNeeded > ZeroesAvailable) | |
5343 return nullptr; | |
5344 IsAdd = true; // treat it as an add if the above conditions hold | |
5345 } else { | |
5346 IsAdd = ArithInst->getOp() == InstArithmetic::Add; | |
5347 } | |
5348 | |
5295 Variable *NewIndexOrBase = nullptr; | 5349 Variable *NewIndexOrBase = nullptr; |
5296 int32_t NewOffset = 0; | 5350 int32_t NewOffset = 0; |
5297 ConstantRelocatable *NewRelocatable = *Relocatable; | 5351 ConstantRelocatable *NewRelocatable = *Relocatable; |
5298 if (Var0 && Var1) | 5352 if (Var0 && Var1) |
5299 // TODO(sehr): merge base/index splitting into here. | 5353 // TODO(sehr): merge base/index splitting into here. |
5300 return nullptr; | 5354 return nullptr; |
5301 if (!IsAdd && Var1) | 5355 if (!IsAdd && Var1) |
5302 return nullptr; | 5356 return nullptr; |
5303 if (Var0) | 5357 if (Var0) |
5304 NewIndexOrBase = Var0; | 5358 NewIndexOrBase = Var0; |
(...skipping 19 matching lines...) Expand all Loading... | |
5324 NewOffset += MoreOffset; | 5378 NewOffset += MoreOffset; |
5325 } | 5379 } |
5326 if (Const1) { | 5380 if (Const1) { |
5327 const int32_t MoreOffset = | 5381 const int32_t MoreOffset = |
5328 IsAdd ? Const1->getValue() : -Const1->getValue(); | 5382 IsAdd ? Const1->getValue() : -Const1->getValue(); |
5329 if (Utils::WouldOverflowAdd(*Offset + NewOffset, MoreOffset)) | 5383 if (Utils::WouldOverflowAdd(*Offset + NewOffset, MoreOffset)) |
5330 return nullptr; | 5384 return nullptr; |
5331 NewOffset += MoreOffset; | 5385 NewOffset += MoreOffset; |
5332 } | 5386 } |
5333 if (Utils::WouldOverflowAdd(*Offset, NewOffset << Shift)) | 5387 if (Utils::WouldOverflowAdd(*Offset, NewOffset << Shift)) |
5334 return nullptr; | 5388 return nullptr; |
5335 *IndexOrBase = NewIndexOrBase; | 5389 *IndexOrBase = NewIndexOrBase; |
5336 *Offset += (NewOffset << Shift); | 5390 *Offset += (NewOffset << Shift); |
5337 // Shift is always zero if this is called with the base | 5391 // Shift is always zero if this is called with the base |
5338 *Relocatable = NewRelocatable; | 5392 *Relocatable = NewRelocatable; |
5339 return Definition; | 5393 return Definition; |
5340 } | 5394 } |
5341 return nullptr; | 5395 return nullptr; |
5342 } | 5396 } |
5343 | 5397 |
5344 template <typename TypeTraits> | 5398 template <typename TypeTraits> |
(...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7974 emitGlobal(*Var, SectionSuffix); | 8028 emitGlobal(*Var, SectionSuffix); |
7975 } | 8029 } |
7976 } | 8030 } |
7977 } break; | 8031 } break; |
7978 } | 8032 } |
7979 } | 8033 } |
7980 } // end of namespace X86NAMESPACE | 8034 } // end of namespace X86NAMESPACE |
7981 } // end of namespace Ice | 8035 } // end of namespace Ice |
7982 | 8036 |
7983 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H | 8037 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H |
OLD | NEW |