| OLD | NEW |
| 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// | 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// |
| 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 21 matching lines...) Expand all Loading... |
| 32 // (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the | 32 // (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the |
| 33 // following named constructors. For reference, each target Foo needs to | 33 // following named constructors. For reference, each target Foo needs to |
| 34 // implement the following named constructors and initializer: | 34 // implement the following named constructors and initializer: |
| 35 // | 35 // |
| 36 // namespace Foo { | 36 // namespace Foo { |
| 37 // unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *); | 37 // unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *); |
| 38 // unique_ptr<Ice::TargetDataLowering> | 38 // unique_ptr<Ice::TargetDataLowering> |
| 39 // createTargetDataLowering(Ice::GlobalContext*); | 39 // createTargetDataLowering(Ice::GlobalContext*); |
| 40 // unique_ptr<Ice::TargetHeaderLowering> | 40 // unique_ptr<Ice::TargetHeaderLowering> |
| 41 // createTargetHeaderLowering(Ice::GlobalContext *); | 41 // createTargetHeaderLowering(Ice::GlobalContext *); |
| 42 // void staticInit(); | 42 // void staticInit(const ::Ice::ClFlags &Flags); |
| 43 // } | 43 // } |
| 44 #define SUBZERO_TARGET(X) \ | 44 #define SUBZERO_TARGET(X) \ |
| 45 namespace X { \ | 45 namespace X { \ |
| 46 std::unique_ptr<::Ice::TargetLowering> \ | 46 std::unique_ptr<::Ice::TargetLowering> \ |
| 47 createTargetLowering(::Ice::Cfg *Func); \ | 47 createTargetLowering(::Ice::Cfg *Func); \ |
| 48 std::unique_ptr<::Ice::TargetDataLowering> \ | 48 std::unique_ptr<::Ice::TargetDataLowering> \ |
| 49 createTargetDataLowering(::Ice::GlobalContext *Ctx); \ | 49 createTargetDataLowering(::Ice::GlobalContext *Ctx); \ |
| 50 std::unique_ptr<::Ice::TargetHeaderLowering> \ | 50 std::unique_ptr<::Ice::TargetHeaderLowering> \ |
| 51 createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \ | 51 createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \ |
| 52 void staticInit(); \ | 52 void staticInit(const ::Ice::ClFlags &Flags); \ |
| 53 } // end of namespace X | 53 } // end of namespace X |
| 54 #include "llvm/Config/SZTargets.def" | 54 #include "llvm/Config/SZTargets.def" |
| 55 #undef SUBZERO_TARGET | 55 #undef SUBZERO_TARGET |
| 56 | 56 |
| 57 namespace Ice { | 57 namespace Ice { |
| 58 void LoweringContext::init(CfgNode *N) { | 58 void LoweringContext::init(CfgNode *N) { |
| 59 Node = N; | 59 Node = N; |
| 60 End = getNode()->getInsts().end(); | 60 End = getNode()->getInsts().end(); |
| 61 rewind(); | 61 rewind(); |
| 62 advanceForward(Next); | 62 advanceForward(Next); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 default: | 122 default: |
| 123 llvm::report_fatal_error("Unsupported target"); | 123 llvm::report_fatal_error("Unsupported target"); |
| 124 #define SUBZERO_TARGET(X) \ | 124 #define SUBZERO_TARGET(X) \ |
| 125 case Target_##X: \ | 125 case Target_##X: \ |
| 126 return ::X::createTargetLowering(Func); | 126 return ::X::createTargetLowering(Func); |
| 127 #include "llvm/Config/SZTargets.def" | 127 #include "llvm/Config/SZTargets.def" |
| 128 #undef SUBZERO_TARGET | 128 #undef SUBZERO_TARGET |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 void TargetLowering::staticInit(TargetArch Target) { | 132 void TargetLowering::staticInit(const ClFlags &Flags) { |
| 133 const TargetArch Target = Flags.getTargetArch(); |
| 133 // Call the specified target's static initializer. | 134 // Call the specified target's static initializer. |
| 134 switch (Target) { | 135 switch (Target) { |
| 135 default: | 136 default: |
| 136 llvm::report_fatal_error("Unsupported target"); | 137 llvm::report_fatal_error("Unsupported target"); |
| 137 #define SUBZERO_TARGET(X) \ | 138 #define SUBZERO_TARGET(X) \ |
| 138 case Target_##X: { \ | 139 case Target_##X: { \ |
| 139 static bool InitGuard##X = false; \ | 140 static bool InitGuard##X = false; \ |
| 140 if (InitGuard##X) { \ | 141 if (InitGuard##X) { \ |
| 141 return; \ | 142 return; \ |
| 142 } \ | 143 } \ |
| 143 InitGuard##X = true; \ | 144 InitGuard##X = true; \ |
| 144 ::X::staticInit(); \ | 145 ::X::staticInit(Flags); \ |
| 145 } | 146 } break; |
| 146 #include "llvm/Config/SZTargets.def" | 147 #include "llvm/Config/SZTargets.def" |
| 147 #undef SUBZERO_TARGET | 148 #undef SUBZERO_TARGET |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 | 151 |
| 151 TargetLowering::TargetLowering(Cfg *Func) | 152 TargetLowering::TargetLowering(Cfg *Func) |
| 152 : Func(Func), Ctx(Func->getContext()), Context() {} | 153 : Func(Func), Ctx(Func->getContext()), Context() {} |
| 153 | 154 |
| 154 void TargetLowering::genTargetHelperCalls() { | 155 void TargetLowering::genTargetHelperCalls() { |
| 155 for (CfgNode *Node : Func->getNodes()) { | 156 for (CfgNode *Node : Func->getNodes()) { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 InstCall *Call = | 519 InstCall *Call = |
| 519 InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall); | 520 InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall); |
| 520 return Call; | 521 return Call; |
| 521 } | 522 } |
| 522 | 523 |
| 523 bool TargetLowering::shouldOptimizeMemIntrins() { | 524 bool TargetLowering::shouldOptimizeMemIntrins() { |
| 524 return Ctx->getFlags().getOptLevel() >= Opt_1 || | 525 return Ctx->getFlags().getOptLevel() >= Opt_1 || |
| 525 Ctx->getFlags().getForceMemIntrinOpt(); | 526 Ctx->getFlags().getForceMemIntrinOpt(); |
| 526 } | 527 } |
| 527 | 528 |
| 528 void TargetLowering::emitWithoutPrefix(const ConstantRelocatable *C) const { | 529 void TargetLowering::emitWithoutPrefix(const ConstantRelocatable *C, |
| 530 const char *Suffix) const { |
| 529 if (!BuildDefs::dump()) | 531 if (!BuildDefs::dump()) |
| 530 return; | 532 return; |
| 531 Ostream &Str = Ctx->getStrEmit(); | 533 Ostream &Str = Ctx->getStrEmit(); |
| 532 if (C->getSuppressMangling()) | 534 if (C->getSuppressMangling()) |
| 533 Str << C->getName(); | 535 Str << C->getName(); |
| 534 else | 536 else |
| 535 Str << Ctx->mangleName(C->getName()); | 537 Str << Ctx->mangleName(C->getName()); |
| 538 Str << Suffix; |
| 536 RelocOffsetT Offset = C->getOffset(); | 539 RelocOffsetT Offset = C->getOffset(); |
| 537 if (Offset) { | 540 if (Offset) { |
| 538 if (Offset > 0) | 541 if (Offset > 0) |
| 539 Str << "+"; | 542 Str << "+"; |
| 540 Str << Offset; | 543 Str << Offset; |
| 541 } | 544 } |
| 542 } | 545 } |
| 543 | 546 |
| 544 void TargetLowering::emit(const ConstantRelocatable *C) const { | |
| 545 if (!BuildDefs::dump()) | |
| 546 return; | |
| 547 Ostream &Str = Ctx->getStrEmit(); | |
| 548 Str << getConstantPrefix(); | |
| 549 emitWithoutPrefix(C); | |
| 550 } | |
| 551 | |
| 552 std::unique_ptr<TargetDataLowering> | 547 std::unique_ptr<TargetDataLowering> |
| 553 TargetDataLowering::createLowering(GlobalContext *Ctx) { | 548 TargetDataLowering::createLowering(GlobalContext *Ctx) { |
| 554 TargetArch Target = Ctx->getFlags().getTargetArch(); | 549 TargetArch Target = Ctx->getFlags().getTargetArch(); |
| 555 switch (Target) { | 550 switch (Target) { |
| 556 default: | 551 default: |
| 557 llvm::report_fatal_error("Unsupported target"); | 552 llvm::report_fatal_error("Unsupported target"); |
| 558 #define SUBZERO_TARGET(X) \ | 553 #define SUBZERO_TARGET(X) \ |
| 559 case Target_##X: \ | 554 case Target_##X: \ |
| 560 return ::X::createTargetDataLowering(Ctx); | 555 return ::X::createTargetDataLowering(Ctx); |
| 561 #include "llvm/Config/SZTargets.def" | 556 #include "llvm/Config/SZTargets.def" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 597 |
| 603 Ostream &Str = Ctx->getStrEmit(); | 598 Ostream &Str = Ctx->getStrEmit(); |
| 604 const bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); | 599 const bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); |
| 605 const bool IsConstant = Var.getIsConstant(); | 600 const bool IsConstant = Var.getIsConstant(); |
| 606 const SizeT Size = Var.getNumBytes(); | 601 const SizeT Size = Var.getNumBytes(); |
| 607 const IceString MangledName = Var.mangleName(Ctx); | 602 const IceString MangledName = Var.mangleName(Ctx); |
| 608 | 603 |
| 609 Str << "\t.type\t" << MangledName << ",%object\n"; | 604 Str << "\t.type\t" << MangledName << ",%object\n"; |
| 610 | 605 |
| 611 const bool UseDataSections = Ctx->getFlags().getDataSections(); | 606 const bool UseDataSections = Ctx->getFlags().getDataSections(); |
| 607 const bool UseNonsfi = Ctx->getFlags().getUseNonsfi(); |
| 612 const IceString Suffix = | 608 const IceString Suffix = |
| 613 dataSectionSuffix(SectionSuffix, MangledName, UseDataSections); | 609 dataSectionSuffix(SectionSuffix, MangledName, UseDataSections); |
| 614 if (IsConstant) | 610 if (IsConstant && UseNonsfi) |
| 611 Str << "\t.section\t.data.rel.ro" << Suffix << ",\"aw\",%progbits\n"; |
| 612 else if (IsConstant) |
| 615 Str << "\t.section\t.rodata" << Suffix << ",\"a\",%progbits\n"; | 613 Str << "\t.section\t.rodata" << Suffix << ",\"a\",%progbits\n"; |
| 616 else if (HasNonzeroInitializer) | 614 else if (HasNonzeroInitializer) |
| 617 Str << "\t.section\t.data" << Suffix << ",\"aw\",%progbits\n"; | 615 Str << "\t.section\t.data" << Suffix << ",\"aw\",%progbits\n"; |
| 618 else | 616 else |
| 619 Str << "\t.section\t.bss" << Suffix << ",\"aw\",%nobits\n"; | 617 Str << "\t.section\t.bss" << Suffix << ",\"aw\",%nobits\n"; |
| 620 | 618 |
| 621 if (IsExternal) | 619 if (IsExternal) |
| 622 Str << "\t.globl\t" << MangledName << "\n"; | 620 Str << "\t.globl\t" << MangledName << "\n"; |
| 623 | 621 |
| 624 const uint32_t Align = Var.getAlignment(); | 622 const uint32_t Align = Var.getAlignment(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 case Target_##X: \ | 682 case Target_##X: \ |
| 685 return ::X::createTargetHeaderLowering(Ctx); | 683 return ::X::createTargetHeaderLowering(Ctx); |
| 686 #include "llvm/Config/SZTargets.def" | 684 #include "llvm/Config/SZTargets.def" |
| 687 #undef SUBZERO_TARGET | 685 #undef SUBZERO_TARGET |
| 688 } | 686 } |
| 689 } | 687 } |
| 690 | 688 |
| 691 TargetHeaderLowering::~TargetHeaderLowering() = default; | 689 TargetHeaderLowering::~TargetHeaderLowering() = default; |
| 692 | 690 |
| 693 } // end of namespace Ice | 691 } // end of namespace Ice |
| OLD | NEW |