| OLD | NEW |
| 1 //===- subzero/src/IceTargetLowering.h - Lowering interface -----*- C++ -*-===// | 1 //===- subzero/src/IceTargetLowering.h - Lowering interface -----*- 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 virtual void addProlog(CfgNode *Node) = 0; | 318 virtual void addProlog(CfgNode *Node) = 0; |
| 319 virtual void addEpilog(CfgNode *Node) = 0; | 319 virtual void addEpilog(CfgNode *Node) = 0; |
| 320 | 320 |
| 321 virtual ~TargetLowering() = default; | 321 virtual ~TargetLowering() = default; |
| 322 | 322 |
| 323 private: | 323 private: |
| 324 // This control variable is used by AutoBundle (RAII-style bundle | 324 // This control variable is used by AutoBundle (RAII-style bundle |
| 325 // locking/unlocking) to prevent nested bundles. | 325 // locking/unlocking) to prevent nested bundles. |
| 326 bool AutoBundling = false; | 326 bool AutoBundling = false; |
| 327 | 327 |
| 328 /// This indicates whether we are in the genTargetHelperCalls phase, and |
| 329 /// therefore can do things like scalarization. |
| 330 bool GeneratingTargetHelpers = false; |
| 331 |
| 328 // _bundle_lock(), and _bundle_unlock(), were made private to force subtargets | 332 // _bundle_lock(), and _bundle_unlock(), were made private to force subtargets |
| 329 // to use the AutoBundle helper. | 333 // to use the AutoBundle helper. |
| 330 void | 334 void |
| 331 _bundle_lock(InstBundleLock::Option BundleOption = InstBundleLock::Opt_None) { | 335 _bundle_lock(InstBundleLock::Option BundleOption = InstBundleLock::Opt_None) { |
| 332 Context.insert<InstBundleLock>(BundleOption); | 336 Context.insert<InstBundleLock>(BundleOption); |
| 333 } | 337 } |
| 334 void _bundle_unlock() { Context.insert<InstBundleUnlock>(); } | 338 void _bundle_unlock() { Context.insert<InstBundleUnlock>(); } |
| 335 | 339 |
| 336 protected: | 340 protected: |
| 337 /// AutoBundle provides RIAA-style bundling. Sub-targets are expected to use | 341 /// AutoBundle provides RIAA-style bundling. Sub-targets are expected to use |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 466 |
| 463 void _set_dest_redefined() { Context.getLastInserted()->setDestRedefined(); } | 467 void _set_dest_redefined() { Context.getLastInserted()->setDestRedefined(); } |
| 464 | 468 |
| 465 bool shouldOptimizeMemIntrins(); | 469 bool shouldOptimizeMemIntrins(); |
| 466 | 470 |
| 467 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest, | 471 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest, |
| 468 Operand *Src0, Operand *Src1); | 472 Operand *Src0, Operand *Src1); |
| 469 | 473 |
| 470 /// Generalizes scalarizeArithmetic to support other instruction types. | 474 /// Generalizes scalarizeArithmetic to support other instruction types. |
| 471 /// | 475 /// |
| 472 /// MakeInstruction is a function-like object with signature | 476 /// insertScalarInstruction is a function-like object with signature |
| 473 /// (Variable *Dest, Variable *Src0, Variable *Src1) -> Instr *. | 477 /// (Variable *Dest, Variable *Src0, Variable *Src1) -> Instr *. |
| 474 template <typename F> | 478 template <typename... Operands, |
| 475 void scalarizeInstruction(Variable *Dest, Operand *Src0, Operand *Src1, | 479 typename F = std::function<Inst *(Variable *, Operands *...)>> |
| 476 F &&MakeInstruction) { | 480 void scalarizeInstruction(Variable *Dest, F insertScalarInstruction, |
| 481 Operands *... Srcs) { |
| 482 assert(GeneratingTargetHelpers && |
| 483 "scalarizeInstruction called during incorrect phase"); |
| 477 const Type DestTy = Dest->getType(); | 484 const Type DestTy = Dest->getType(); |
| 478 assert(isVectorType(DestTy)); | 485 assert(isVectorType(DestTy)); |
| 479 const Type DestElementTy = typeElementType(DestTy); | 486 const Type DestElementTy = typeElementType(DestTy); |
| 480 const SizeT NumElements = typeNumElements(DestTy); | 487 const SizeT NumElements = typeNumElements(DestTy); |
| 481 const Type Src0ElementTy = typeElementType(Src0->getType()); | |
| 482 const Type Src1ElementTy = typeElementType(Src1->getType()); | |
| 483 | |
| 484 assert(NumElements == typeNumElements(Src0->getType())); | |
| 485 assert(NumElements == typeNumElements(Src1->getType())); | |
| 486 | 488 |
| 487 Variable *T = Func->makeVariable(DestTy); | 489 Variable *T = Func->makeVariable(DestTy); |
| 488 Context.insert<InstFakeDef>(T); | 490 Context.insert<InstFakeDef>(T); |
| 491 |
| 489 for (SizeT I = 0; I < NumElements; ++I) { | 492 for (SizeT I = 0; I < NumElements; ++I) { |
| 490 Constant *Index = Ctx->getConstantInt32(I); | 493 auto *Index = Ctx->getConstantInt32(I); |
| 491 | 494 |
| 492 // Extract the next two inputs. | 495 auto MakeExtract = [this, Index, NumElements](Operand *Src) { |
| 493 Variable *Op0 = Func->makeVariable(Src0ElementTy); | 496 assert(typeNumElements(Src->getType()) == NumElements); |
| 494 Context.insert<InstExtractElement>(Op0, Src0, Index); | 497 |
| 495 Variable *Op1 = Func->makeVariable(Src1ElementTy); | 498 const auto ElementTy = typeElementType(Src->getType()); |
| 496 Context.insert<InstExtractElement>(Op1, Src1, Index); | 499 auto *Op = Func->makeVariable(ElementTy); |
| 500 Context.insert<InstExtractElement>(Op, Src, Index); |
| 501 return Op; |
| 502 }; |
| 497 | 503 |
| 498 // Perform the operation as a scalar operation. | 504 // Perform the operation as a scalar operation. |
| 499 Variable *Res = Func->makeVariable(DestElementTy); | 505 auto *Res = Func->makeVariable(DestElementTy); |
| 500 auto Arith = MakeInstruction(Res, Op0, Op1); | 506 auto *Arith = insertScalarInstruction(Res, MakeExtract(Srcs)...); |
| 501 // We might have created an operation that needed a helper call. | |
| 502 genTargetHelperCallFor(Arith); | 507 genTargetHelperCallFor(Arith); |
| 503 | 508 |
| 504 // Insert the result into position. | |
| 505 Variable *DestT = Func->makeVariable(DestTy); | 509 Variable *DestT = Func->makeVariable(DestTy); |
| 506 Context.insert<InstInsertElement>(DestT, T, Res, Index); | 510 Context.insert<InstInsertElement>(DestT, T, Res, Index); |
| 507 T = DestT; | 511 T = DestT; |
| 508 } | |
| 509 Context.insert<InstAssign>(Dest, T); | |
| 510 } | |
| 511 | |
| 512 template <typename F> | |
| 513 void scalarizeUnaryInstruction(Variable *Dest, Operand *Src0, | |
| 514 F &&MakeInstruction) { | |
| 515 const Type DestTy = Dest->getType(); | |
| 516 assert(isVectorType(DestTy)); | |
| 517 const Type DestElementTy = typeElementType(DestTy); | |
| 518 const SizeT NumElements = typeNumElements(DestTy); | |
| 519 const Type Src0ElementTy = typeElementType(Src0->getType()); | |
| 520 | |
| 521 assert(NumElements == typeNumElements(Src0->getType())); | |
| 522 | |
| 523 Variable *T = Func->makeVariable(DestTy); | |
| 524 Context.insert<InstFakeDef>(T); | |
| 525 for (SizeT I = 0; I < NumElements; ++I) { | |
| 526 Constant *Index = Ctx->getConstantInt32(I); | |
| 527 | |
| 528 // Extract the next two inputs. | |
| 529 Variable *Op0 = Func->makeVariable(Src0ElementTy); | |
| 530 Context.insert<InstExtractElement>(Op0, Src0, Index); | |
| 531 | |
| 532 // Perform the operation as a scalar operation. | |
| 533 Variable *Res = Func->makeVariable(DestElementTy); | |
| 534 auto Arith = MakeInstruction(Res, Op0); | |
| 535 // We might have created an operation that needed a helper call. | |
| 536 genTargetHelperCallFor(Arith); | |
| 537 | |
| 538 // Insert the result into position. | |
| 539 Variable *DestT = Func->makeVariable(DestTy); | |
| 540 Context.insert<InstInsertElement>(DestT, T, Res, Index); | |
| 541 T = DestT; | |
| 542 } | 512 } |
| 543 Context.insert<InstAssign>(Dest, T); | 513 Context.insert<InstAssign>(Dest, T); |
| 544 } | 514 } |
| 545 | 515 |
| 546 /// SandboxType enumerates all possible sandboxing strategies that | 516 /// SandboxType enumerates all possible sandboxing strategies that |
| 547 enum SandboxType { | 517 enum SandboxType { |
| 548 ST_None, | 518 ST_None, |
| 549 ST_NaCl, | 519 ST_NaCl, |
| 550 ST_Nonsfi, | 520 ST_Nonsfi, |
| 551 }; | 521 }; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 virtual void lower() {} | 617 virtual void lower() {} |
| 648 | 618 |
| 649 protected: | 619 protected: |
| 650 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {} | 620 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {} |
| 651 GlobalContext *Ctx; | 621 GlobalContext *Ctx; |
| 652 }; | 622 }; |
| 653 | 623 |
| 654 } // end of namespace Ice | 624 } // end of namespace Ice |
| 655 | 625 |
| 656 #endif // SUBZERO_SRC_ICETARGETLOWERING_H | 626 #endif // SUBZERO_SRC_ICETARGETLOWERING_H |
| OLD | NEW |