| 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 = applyToThunkedArgs( |
| 501 // We might have created an operation that needed a helper call. | 507 insertScalarInstruction, Res, |
| 508 [MakeExtract, Srcs]() { return MakeExtract(Srcs); }...); |
| 502 genTargetHelperCallFor(Arith); | 509 genTargetHelperCallFor(Arith); |
| 503 | 510 |
| 504 // Insert the result into position. | |
| 505 Variable *DestT = Func->makeVariable(DestTy); | 511 Variable *DestT = Func->makeVariable(DestTy); |
| 506 Context.insert<InstInsertElement>(DestT, T, Res, Index); | 512 Context.insert<InstInsertElement>(DestT, T, Res, Index); |
| 507 T = DestT; | 513 T = DestT; |
| 508 } | 514 } |
| 509 Context.insert<InstAssign>(Dest, T); | 515 Context.insert<InstAssign>(Dest, T); |
| 510 } | 516 } |
| 511 | 517 |
| 512 template <typename F> | 518 // applyToThunkedArgs is used by scalarizeInstruction. Ideally, we would just |
| 513 void scalarizeUnaryInstruction(Variable *Dest, Operand *Src0, | 519 // call insertScalarInstruction(Res, Srcs...), but C++ does not specify |
| 514 F &&MakeInstruction) { | 520 // evaluation order which means this leads to an unpredictable final |
| 515 const Type DestTy = Dest->getType(); | 521 // output. Instead, we wrap each of the Srcs in a thunk and these |
| 516 assert(isVectorType(DestTy)); | 522 // applyToThunkedArgs functions apply the thunks in a well defined order so we |
| 517 const Type DestElementTy = typeElementType(DestTy); | 523 // still get well-defined output. |
| 518 const SizeT NumElements = typeNumElements(DestTy); | 524 Inst *applyToThunkedArgs( |
| 519 const Type Src0ElementTy = typeElementType(Src0->getType()); | 525 std::function<Inst *(Variable *, Variable *)> insertScalarInstruction, |
| 526 Variable *Res, std::function<Variable *()> thunk0) { |
| 527 auto *Src0 = thunk0(); |
| 528 return insertScalarInstruction(Res, Src0); |
| 529 } |
| 520 | 530 |
| 521 assert(NumElements == typeNumElements(Src0->getType())); | 531 Inst * |
| 532 applyToThunkedArgs(std::function<Inst *(Variable *, Variable *, Variable *)> |
| 533 insertScalarInstruction, |
| 534 Variable *Res, std::function<Variable *()> thunk0, |
| 535 std::function<Variable *()> thunk1) { |
| 536 auto *Src0 = thunk0(); |
| 537 auto *Src1 = thunk1(); |
| 538 return insertScalarInstruction(Res, Src0, Src1); |
| 539 } |
| 522 | 540 |
| 523 Variable *T = Func->makeVariable(DestTy); | 541 Inst *applyToThunkedArgs( |
| 524 Context.insert<InstFakeDef>(T); | 542 std::function<Inst *(Variable *, Variable *, Variable *, Variable *)> |
| 525 for (SizeT I = 0; I < NumElements; ++I) { | 543 insertScalarInstruction, |
| 526 Constant *Index = Ctx->getConstantInt32(I); | 544 Variable *Res, std::function<Variable *()> thunk0, |
| 527 | 545 std::function<Variable *()> thunk1, std::function<Variable *()> thunk2) { |
| 528 // Extract the next two inputs. | 546 auto *Src0 = thunk0(); |
| 529 Variable *Op0 = Func->makeVariable(Src0ElementTy); | 547 auto *Src1 = thunk1(); |
| 530 Context.insert<InstExtractElement>(Op0, Src0, Index); | 548 auto *Src2 = thunk2(); |
| 531 | 549 return insertScalarInstruction(Res, Src0, Src1, Src2); |
| 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 } | |
| 543 Context.insert<InstAssign>(Dest, T); | |
| 544 } | 550 } |
| 545 | 551 |
| 546 /// SandboxType enumerates all possible sandboxing strategies that | 552 /// SandboxType enumerates all possible sandboxing strategies that |
| 547 enum SandboxType { | 553 enum SandboxType { |
| 548 ST_None, | 554 ST_None, |
| 549 ST_NaCl, | 555 ST_NaCl, |
| 550 ST_Nonsfi, | 556 ST_Nonsfi, |
| 551 }; | 557 }; |
| 552 | 558 |
| 553 static SandboxType determineSandboxTypeFromFlags(const ClFlags &Flags); | 559 static SandboxType determineSandboxTypeFromFlags(const ClFlags &Flags); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 virtual void lower() {} | 653 virtual void lower() {} |
| 648 | 654 |
| 649 protected: | 655 protected: |
| 650 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {} | 656 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {} |
| 651 GlobalContext *Ctx; | 657 GlobalContext *Ctx; |
| 652 }; | 658 }; |
| 653 | 659 |
| 654 } // end of namespace Ice | 660 } // end of namespace Ice |
| 655 | 661 |
| 656 #endif // SUBZERO_SRC_ICETARGETLOWERING_H | 662 #endif // SUBZERO_SRC_ICETARGETLOWERING_H |
| OLD | NEW |