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

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: Fixes MIPS32 regression. 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
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 forbidden #include of target-specific header files
Jim Stichnoth 2015/12/30 01:26:42 forbidding
John 2016/01/19 20:37:30 Done.
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.
111 switch (Target) { 133 switch (Target) {
112 default: 134 default:
113 llvm::report_fatal_error("Unsupported target"); 135 llvm::report_fatal_error("Unsupported target");
114 break;
115 #define SUBZERO_TARGET(X) \ 136 #define SUBZERO_TARGET(X) \
116 case Target_##X: { \ 137 case Target_##X: { \
117 static bool InitGuard##X = false; \ 138 static bool InitGuard##X = false; \
118 if (InitGuard##X) \ 139 if (InitGuard##X) { \
119 return; \ 140 return; \
141 } \
120 InitGuard##X = true; \ 142 InitGuard##X = true; \
121 Target##X::staticInit(); \ 143 ::X::staticInit(); \
122 } break; 144 }
123 #include "llvm/Config/SZTargets.def" 145 #include "llvm/Config/SZTargets.def"
124 } 146 #undef SUBZERO_TARGET
147 } // Call the specified target's static initializer.
Jim Stichnoth 2015/12/30 01:26:42 Is this comment out of place?
John 2016/01/19 20:37:30 Done.
125 } 148 }
126 149
127 TargetLowering::TargetLowering(Cfg *Func) 150 TargetLowering::TargetLowering(Cfg *Func)
128 : Func(Func), Ctx(Func->getContext()), Context() {} 151 : Func(Func), Ctx(Func->getContext()), Context() {}
129 152
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() { 153 void TargetLowering::genTargetHelperCalls() {
142 for (CfgNode *Node : Func->getNodes()) { 154 for (CfgNode *Node : Func->getNodes()) {
143 Context.init(Node); 155 Context.init(Node);
144 while (!Context.atEnd()) { 156 while (!Context.atEnd()) {
145 PostIncrLoweringContext _(Context); 157 PostIncrLoweringContext _(Context);
146 genTargetHelperCallFor(Context.getCur()); 158 genTargetHelperCallFor(Context.getCur());
147 } 159 }
148 } 160 }
149 } 161 }
150 162
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (!BuildDefs::dump()) 544 if (!BuildDefs::dump())
533 return; 545 return;
534 Ostream &Str = Ctx->getStrEmit(); 546 Ostream &Str = Ctx->getStrEmit();
535 Str << getConstantPrefix(); 547 Str << getConstantPrefix();
536 emitWithoutPrefix(C); 548 emitWithoutPrefix(C);
537 } 549 }
538 550
539 std::unique_ptr<TargetDataLowering> 551 std::unique_ptr<TargetDataLowering>
540 TargetDataLowering::createLowering(GlobalContext *Ctx) { 552 TargetDataLowering::createLowering(GlobalContext *Ctx) {
541 TargetArch Target = Ctx->getFlags().getTargetArch(); 553 TargetArch Target = Ctx->getFlags().getTargetArch();
554 switch (Target) {
555 default:
556 llvm::report_fatal_error("Unsupported target");
542 #define SUBZERO_TARGET(X) \ 557 #define SUBZERO_TARGET(X) \
543 if (Target == Target_##X) \ 558 case Target_##X: \
544 return TargetData##X::create(Ctx); 559 return ::X::createTargetDataLowering(Ctx);
545 #include "llvm/Config/SZTargets.def" 560 #include "llvm/Config/SZTargets.def"
546 561 #undef SUBZERO_TARGET
547 llvm::report_fatal_error("Unsupported target data lowering"); 562 }
548 } 563 }
549 564
550 TargetDataLowering::~TargetDataLowering() = default; 565 TargetDataLowering::~TargetDataLowering() = default;
551 566
552 namespace { 567 namespace {
553 568
554 // dataSectionSuffix decides whether to use SectionSuffix or MangledVarName as 569 // dataSectionSuffix decides whether to use SectionSuffix or MangledVarName as
555 // data section suffix. Essentially, when using separate data sections for 570 // data section suffix. Essentially, when using separate data sections for
556 // globals SectionSuffix is not necessary. 571 // globals SectionSuffix is not necessary.
557 IceString dataSectionSuffix(const IceString &SectionSuffix, 572 IceString dataSectionSuffix(const IceString &SectionSuffix,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // to advance offsets. 669 // to advance offsets.
655 Str << "\t.zero\t" << Size << "\n"; 670 Str << "\t.zero\t" << Size << "\n";
656 } 671 }
657 672
658 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 673 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
659 } 674 }
660 675
661 std::unique_ptr<TargetHeaderLowering> 676 std::unique_ptr<TargetHeaderLowering>
662 TargetHeaderLowering::createLowering(GlobalContext *Ctx) { 677 TargetHeaderLowering::createLowering(GlobalContext *Ctx) {
663 TargetArch Target = Ctx->getFlags().getTargetArch(); 678 TargetArch Target = Ctx->getFlags().getTargetArch();
679 switch (Target) {
680 default:
681 llvm::report_fatal_error("Unsupported target");
664 #define SUBZERO_TARGET(X) \ 682 #define SUBZERO_TARGET(X) \
665 if (Target == Target_##X) \ 683 case Target_##X: \
666 return TargetHeader##X::create(Ctx); 684 return ::X::createTargetHeaderLowering(Ctx);
667 #include "llvm/Config/SZTargets.def" 685 #include "llvm/Config/SZTargets.def"
668 686 #undef SUBZERO_TARGET
669 llvm::report_fatal_error("Unsupported target header lowering"); 687 }
670 } 688 }
671 689
672 TargetHeaderLowering::~TargetHeaderLowering() = default; 690 TargetHeaderLowering::~TargetHeaderLowering() = default;
673 691
674 } // end of namespace Ice 692 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698