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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1551633002: Subzero. Refactoring. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses comments. Created 4 years, 11 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/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.h » ('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/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
11 /// \brief Implements the skeleton of the TargetLowering class. 11 /// \brief Implements the skeleton of the TargetLowering class.
12 /// 12 ///
13 /// Specifically this invokes the appropriate lowering method for a given 13 /// Specifically this invokes the appropriate lowering method for a given
14 /// instruction kind and driving global register allocation. It also implements 14 /// instruction kind and driving global register allocation. It also implements
15 /// the non-deleted instruction iteration in LoweringContext. 15 /// the non-deleted instruction iteration in LoweringContext.
16 /// 16 ///
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 18
19 #include "IceTargetLowering.h" 19 #include "IceTargetLowering.h"
20 20
21 #include "IceAssemblerARM32.h"
22 #include "IceAssemblerMIPS32.h"
23 #include "IceAssemblerX8632.h"
24 #include "IceAssemblerX8664.h"
25 #include "IceCfg.h" // setError() 21 #include "IceCfg.h" // setError()
26 #include "IceCfgNode.h" 22 #include "IceCfgNode.h"
23 #include "IceGlobalContext.h"
27 #include "IceGlobalInits.h" 24 #include "IceGlobalInits.h"
28 #include "IceInstVarIter.h" 25 #include "IceInstVarIter.h"
29 #include "IceOperand.h" 26 #include "IceOperand.h"
30 #include "IceRegAlloc.h" 27 #include "IceRegAlloc.h"
31 #include "IceTargetLoweringARM32.h" 28
32 #include "IceTargetLoweringMIPS32.h" 29 // We prevent target-specific implementation details from leaking outside their
33 #include "IceTargetLoweringX8632.h" 30 // implementations by forbidding #include of target-specific header files
34 #include "IceTargetLoweringX8664.h" 31 // anywhere outside their own files. To create target-specific objects
32 // (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the
33 // following named constructors. For reference, each target Foo needs to
34 // implement the following named constructors and initializer:
35 //
36 // namespace Foo {
37 // unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *);
38 // unique_ptr<Ice::TargetDataLowering>
39 // createTargetDataLowering(Ice::GlobalContext*);
40 // unique_ptr<Ice::TargetHeaderLowering>
41 // createTargetHeaderLowering(Ice::GlobalContext *);
42 // void staticInit();
43 // }
44 #define SUBZERO_TARGET(X) \
45 namespace X { \
46 std::unique_ptr<::Ice::TargetLowering> \
47 createTargetLowering(::Ice::Cfg *Func); \
48 std::unique_ptr<::Ice::TargetDataLowering> \
49 createTargetDataLowering(::Ice::GlobalContext *Ctx); \
50 std::unique_ptr<::Ice::TargetHeaderLowering> \
51 createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \
52 void staticInit(); \
53 } // end of namespace X
54 #include "llvm/Config/SZTargets.def"
55 #undef SUBZERO_TARGET
35 56
36 namespace Ice { 57 namespace Ice {
37
38 void LoweringContext::init(CfgNode *N) { 58 void LoweringContext::init(CfgNode *N) {
39 Node = N; 59 Node = N;
40 End = getNode()->getInsts().end(); 60 End = getNode()->getInsts().end();
41 rewind(); 61 rewind();
42 advanceForward(Next); 62 advanceForward(Next);
43 } 63 }
44 64
45 void LoweringContext::rewind() { 65 void LoweringContext::rewind() {
46 Begin = getNode()->getInsts().begin(); 66 Begin = getNode()->getInsts().begin();
47 Cur = Begin; 67 Cur = Begin;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 LastSrc = llvm::cast<Variable>(Instr->getSrc(0)); 109 LastSrc = llvm::cast<Variable>(Instr->getSrc(0));
90 } 110 }
91 111
92 Variable *LoweringContext::availabilityGet(Operand *Src) const { 112 Variable *LoweringContext::availabilityGet(Operand *Src) const {
93 assert(Src); 113 assert(Src);
94 if (Src == LastDest) 114 if (Src == LastDest)
95 return LastSrc; 115 return LastSrc;
96 return nullptr; 116 return nullptr;
97 } 117 }
98 118
99 TargetLowering *TargetLowering::createLowering(TargetArch Target, Cfg *Func) { 119 std::unique_ptr<TargetLowering>
120 TargetLowering::createLowering(TargetArch Target, Cfg *Func) {
121 switch (Target) {
122 default:
123 llvm::report_fatal_error("Unsupported target");
100 #define SUBZERO_TARGET(X) \ 124 #define SUBZERO_TARGET(X) \
101 if (Target == Target_##X) \ 125 case Target_##X: \
102 return Target##X::create(Func); 126 return ::X::createTargetLowering(Func);
103 #include "llvm/Config/SZTargets.def" 127 #include "llvm/Config/SZTargets.def"
104 128 #undef SUBZERO_TARGET
105 Func->setError("Unsupported target"); 129 }
106 return nullptr;
107 } 130 }
108 131
109 void TargetLowering::staticInit(TargetArch Target) { 132 void TargetLowering::staticInit(TargetArch Target) {
110 // Call the specified target's static initializer. 133 // Call the specified target's static initializer.
111 switch (Target) { 134 switch (Target) {
112 default: 135 default:
113 llvm::report_fatal_error("Unsupported target"); 136 llvm::report_fatal_error("Unsupported target");
114 break;
115 #define SUBZERO_TARGET(X) \ 137 #define SUBZERO_TARGET(X) \
116 case Target_##X: { \ 138 case Target_##X: { \
117 static bool InitGuard##X = false; \ 139 static bool InitGuard##X = false; \
118 if (InitGuard##X) \ 140 if (InitGuard##X) { \
119 return; \ 141 return; \
142 } \
120 InitGuard##X = true; \ 143 InitGuard##X = true; \
121 Target##X::staticInit(); \ 144 ::X::staticInit(); \
122 } break; 145 }
123 #include "llvm/Config/SZTargets.def" 146 #include "llvm/Config/SZTargets.def"
147 #undef SUBZERO_TARGET
124 } 148 }
125 } 149 }
126 150
127 TargetLowering::TargetLowering(Cfg *Func) 151 TargetLowering::TargetLowering(Cfg *Func)
128 : Func(Func), Ctx(Func->getContext()), Context() {} 152 : Func(Func), Ctx(Func->getContext()), Context() {}
129 153
130 std::unique_ptr<Assembler> TargetLowering::createAssembler(TargetArch Target,
131 Cfg *Func) {
132 #define SUBZERO_TARGET(X) \
133 if (Target == Target_##X) \
134 return std::unique_ptr<Assembler>(new X::Assembler##X());
135 #include "llvm/Config/SZTargets.def"
136
137 Func->setError("Unsupported target assembler");
138 return nullptr;
139 }
140
141 void TargetLowering::genTargetHelperCalls() { 154 void TargetLowering::genTargetHelperCalls() {
142 for (CfgNode *Node : Func->getNodes()) { 155 for (CfgNode *Node : Func->getNodes()) {
143 Context.init(Node); 156 Context.init(Node);
144 while (!Context.atEnd()) { 157 while (!Context.atEnd()) {
145 PostIncrLoweringContext _(Context); 158 PostIncrLoweringContext _(Context);
146 genTargetHelperCallFor(Context.getCur()); 159 genTargetHelperCallFor(Context.getCur());
147 } 160 }
148 } 161 }
149 } 162 }
150 163
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (!BuildDefs::dump()) 545 if (!BuildDefs::dump())
533 return; 546 return;
534 Ostream &Str = Ctx->getStrEmit(); 547 Ostream &Str = Ctx->getStrEmit();
535 Str << getConstantPrefix(); 548 Str << getConstantPrefix();
536 emitWithoutPrefix(C); 549 emitWithoutPrefix(C);
537 } 550 }
538 551
539 std::unique_ptr<TargetDataLowering> 552 std::unique_ptr<TargetDataLowering>
540 TargetDataLowering::createLowering(GlobalContext *Ctx) { 553 TargetDataLowering::createLowering(GlobalContext *Ctx) {
541 TargetArch Target = Ctx->getFlags().getTargetArch(); 554 TargetArch Target = Ctx->getFlags().getTargetArch();
555 switch (Target) {
556 default:
557 llvm::report_fatal_error("Unsupported target");
542 #define SUBZERO_TARGET(X) \ 558 #define SUBZERO_TARGET(X) \
543 if (Target == Target_##X) \ 559 case Target_##X: \
544 return TargetData##X::create(Ctx); 560 return ::X::createTargetDataLowering(Ctx);
545 #include "llvm/Config/SZTargets.def" 561 #include "llvm/Config/SZTargets.def"
546 562 #undef SUBZERO_TARGET
547 llvm::report_fatal_error("Unsupported target data lowering"); 563 }
548 } 564 }
549 565
550 TargetDataLowering::~TargetDataLowering() = default; 566 TargetDataLowering::~TargetDataLowering() = default;
551 567
552 namespace { 568 namespace {
553 569
554 // dataSectionSuffix decides whether to use SectionSuffix or MangledVarName as 570 // dataSectionSuffix decides whether to use SectionSuffix or MangledVarName as
555 // data section suffix. Essentially, when using separate data sections for 571 // data section suffix. Essentially, when using separate data sections for
556 // globals SectionSuffix is not necessary. 572 // globals SectionSuffix is not necessary.
557 IceString dataSectionSuffix(const IceString &SectionSuffix, 573 IceString dataSectionSuffix(const IceString &SectionSuffix,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // to advance offsets. 670 // to advance offsets.
655 Str << "\t.zero\t" << Size << "\n"; 671 Str << "\t.zero\t" << Size << "\n";
656 } 672 }
657 673
658 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 674 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
659 } 675 }
660 676
661 std::unique_ptr<TargetHeaderLowering> 677 std::unique_ptr<TargetHeaderLowering>
662 TargetHeaderLowering::createLowering(GlobalContext *Ctx) { 678 TargetHeaderLowering::createLowering(GlobalContext *Ctx) {
663 TargetArch Target = Ctx->getFlags().getTargetArch(); 679 TargetArch Target = Ctx->getFlags().getTargetArch();
680 switch (Target) {
681 default:
682 llvm::report_fatal_error("Unsupported target");
664 #define SUBZERO_TARGET(X) \ 683 #define SUBZERO_TARGET(X) \
665 if (Target == Target_##X) \ 684 case Target_##X: \
666 return TargetHeader##X::create(Ctx); 685 return ::X::createTargetHeaderLowering(Ctx);
667 #include "llvm/Config/SZTargets.def" 686 #include "llvm/Config/SZTargets.def"
668 687 #undef SUBZERO_TARGET
669 llvm::report_fatal_error("Unsupported target header lowering"); 688 }
670 } 689 }
671 690
672 TargetHeaderLowering::~TargetHeaderLowering() = default; 691 TargetHeaderLowering::~TargetHeaderLowering() = default;
673 692
674 } // end of namespace Ice 693 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698