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

Side by Side Diff: src/IceTargetLoweringMIPS32.h

Issue 1993773004: [Subzero][MIPS32] Addition of bool folding machinery and implementation of conditional branches (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addressed review comments Created 4 years, 6 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/IceTargetLoweringMIPS32.h - MIPS32 lowering ---*- C++-*-===// 1 //===- subzero/src/IceTargetLoweringMIPS32.h - MIPS32 lowering ---*- 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 28 matching lines...) Expand all
39 return false; 39 return false;
40 } 40 }
41 static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) { 41 static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) {
42 return makeUnique<TargetMIPS32>(Func); 42 return makeUnique<TargetMIPS32>(Func);
43 } 43 }
44 44
45 std::unique_ptr<::Ice::Assembler> createAssembler() const override { 45 std::unique_ptr<::Ice::Assembler> createAssembler() const override {
46 return makeUnique<MIPS32::AssemblerMIPS32>(); 46 return makeUnique<MIPS32::AssemblerMIPS32>();
47 } 47 }
48 48
49 void initNodeForLowering(CfgNode *Node) override {
50 Computations.forgetProducers();
51 Computations.recordProducers(Node);
52 Computations.dump(Func);
53 }
54
49 void translateOm1() override; 55 void translateOm1() override;
50 void translateO2() override; 56 void translateO2() override;
51 bool doBranchOpt(Inst *Instr, const CfgNode *NextNode) override; 57 bool doBranchOpt(Inst *Instr, const CfgNode *NextNode) override;
52 58
53 SizeT getNumRegisters() const override { return RegMIPS32::Reg_NUM; } 59 SizeT getNumRegisters() const override { return RegMIPS32::Reg_NUM; }
54 Variable *getPhysicalRegister(RegNumT RegNum, 60 Variable *getPhysicalRegister(RegNumT RegNum,
55 Type Ty = IceType_void) override; 61 Type Ty = IceType_void) override;
56 const char *getRegName(RegNumT RegNum, Type Ty) const override; 62 const char *getRegName(RegNumT RegNum, Type Ty) const override;
57 SmallBitVector getRegisterSet(RegSetMask Include, 63 SmallBitVector getRegisterSet(RegSetMask Include,
58 RegSetMask Exclude) const override; 64 RegSetMask Exclude) const override;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void _addu(Variable *Dest, Variable *Src0, Variable *Src1) { 151 void _addu(Variable *Dest, Variable *Src0, Variable *Src1) {
146 Context.insert<InstMIPS32Addu>(Dest, Src0, Src1); 152 Context.insert<InstMIPS32Addu>(Dest, Src0, Src1);
147 } 153 }
148 154
149 void _and(Variable *Dest, Variable *Src0, Variable *Src1) { 155 void _and(Variable *Dest, Variable *Src0, Variable *Src1) {
150 Context.insert<InstMIPS32And>(Dest, Src0, Src1); 156 Context.insert<InstMIPS32And>(Dest, Src0, Src1);
151 } 157 }
152 158
153 void _br(CfgNode *Target) { Context.insert<InstMIPS32Br>(Target); } 159 void _br(CfgNode *Target) { Context.insert<InstMIPS32Br>(Target); }
154 160
161 void _br(CfgNode *TargetTrue, CfgNode *TargetFalse, Operand *Src0,
162 Operand *Src1, CondMIPS32::Cond Condition) {
163 Context.insert<InstMIPS32Br>(TargetTrue, TargetFalse, Src0, Src1,
164 Condition);
165 }
166
167 void _br(CfgNode *TargetTrue, CfgNode *TargetFalse, Operand *Src0,
168 CondMIPS32::Cond Condition) {
169 Context.insert<InstMIPS32Br>(TargetTrue, TargetFalse, Src0, Condition);
170 }
171
155 void _ret(Variable *RA, Variable *Src0 = nullptr) { 172 void _ret(Variable *RA, Variable *Src0 = nullptr) {
156 Context.insert<InstMIPS32Ret>(RA, Src0); 173 Context.insert<InstMIPS32Ret>(RA, Src0);
157 } 174 }
158 175
159 void _addiu(Variable *Dest, Variable *Src, uint32_t Imm) { 176 void _addiu(Variable *Dest, Variable *Src, uint32_t Imm) {
160 Context.insert<InstMIPS32Addiu>(Dest, Src, Imm); 177 Context.insert<InstMIPS32Addiu>(Dest, Src, Imm);
161 } 178 }
162 179
163 void _lui(Variable *Dest, uint32_t Imm) { 180 void _lui(Variable *Dest, uint32_t Imm) {
164 Context.insert<InstMIPS32Lui>(Dest, Imm); 181 Context.insert<InstMIPS32Lui>(Dest, Imm);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 bool UsesFramePointer = false; 359 bool UsesFramePointer = false;
343 bool NeedsStackAlignment = false; 360 bool NeedsStackAlignment = false;
344 static SmallBitVector TypeToRegisterSet[RCMIPS32_NUM]; 361 static SmallBitVector TypeToRegisterSet[RCMIPS32_NUM];
345 static SmallBitVector TypeToRegisterSetUnfiltered[RCMIPS32_NUM]; 362 static SmallBitVector TypeToRegisterSetUnfiltered[RCMIPS32_NUM];
346 static SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM]; 363 static SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM];
347 SmallBitVector RegsUsed; 364 SmallBitVector RegsUsed;
348 VarList PhysicalRegisters[IceType_NUM]; 365 VarList PhysicalRegisters[IceType_NUM];
349 366
350 private: 367 private:
351 ENABLE_MAKE_UNIQUE; 368 ENABLE_MAKE_UNIQUE;
369
370 class ComputationTracker {
371 public:
372 ComputationTracker() = default;
373 ~ComputationTracker() = default;
374
375 void forgetProducers() { KnownComputations.clear(); }
376 void recordProducers(CfgNode *Node);
377
378 const Inst *getProducerOf(const Operand *Opnd) const {
379 auto *Var = llvm::dyn_cast<Variable>(Opnd);
380 if (Var == nullptr) {
381 return nullptr;
382 }
383
384 auto Iter = KnownComputations.find(Var->getIndex());
385 if (Iter == KnownComputations.end()) {
386 return nullptr;
387 }
388
389 return Iter->second.Instr;
390 }
391
392 void dump(const Cfg *Func) const {
393 if (!BuildDefs::dump() || !Func->isVerbose(IceV_Folding))
394 return;
395 OstreamLocker L(Func->getContext());
396 Ostream &Str = Func->getContext()->getStrDump();
397 Str << "foldable producer:\n";
398 for (const auto &Computation : KnownComputations) {
399 Str << " ";
400 Computation.second.Instr->dump(Func);
401 Str << "\n";
402 }
403 Str << "\n";
404 }
405
406 private:
407 class ComputationEntry {
408 public:
409 ComputationEntry(Inst *I, Type Ty) : Instr(I), ComputationType(Ty) {}
410 Inst *const Instr;
411 // Boolean folding is disabled for variables whose live range is multi
412 // block. We conservatively initialize IsLiveOut to true, and set it to
413 // false once we find the end of the live range for the variable defined
414 // by this instruction. If liveness analysis is not performed (e.g., in
415 // Om1 mode) IsLiveOut will never be set to false, and folding will be
416 // disabled.
417 bool IsLiveOut = true;
418 int32_t NumUses = 0;
419 Type ComputationType;
420 };
421
422 // ComputationMap maps a Variable number to a payload identifying which
423 // instruction defined it.
424 using ComputationMap = CfgUnorderedMap<SizeT, ComputationEntry>;
425 ComputationMap KnownComputations;
426 };
427
428 ComputationTracker Computations;
352 }; 429 };
353 430
354 class TargetDataMIPS32 final : public TargetDataLowering { 431 class TargetDataMIPS32 final : public TargetDataLowering {
355 TargetDataMIPS32() = delete; 432 TargetDataMIPS32() = delete;
356 TargetDataMIPS32(const TargetDataMIPS32 &) = delete; 433 TargetDataMIPS32(const TargetDataMIPS32 &) = delete;
357 TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete; 434 TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete;
358 435
359 public: 436 public:
360 static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) { 437 static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) {
361 return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx)); 438 return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx));
(...skipping 28 matching lines...) Expand all
390 explicit TargetHeaderMIPS32(GlobalContext *Ctx); 467 explicit TargetHeaderMIPS32(GlobalContext *Ctx);
391 468
392 private: 469 private:
393 ~TargetHeaderMIPS32() = default; 470 ~TargetHeaderMIPS32() = default;
394 }; 471 };
395 472
396 } // end of namespace MIPS32 473 } // end of namespace MIPS32
397 } // end of namespace Ice 474 } // end of namespace Ice
398 475
399 #endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H 476 #endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698