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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 void TargetLowering::genTargetHelperCalls() { | 334 void TargetLowering::genTargetHelperCalls() { |
335 TimerMarker T(TimerStack::TT_genHelpers, Func); | 335 TimerMarker T(TimerStack::TT_genHelpers, Func); |
336 Utils::BoolFlagSaver _(GeneratingTargetHelpers, true); | 336 Utils::BoolFlagSaver _(GeneratingTargetHelpers, true); |
337 for (CfgNode *Node : Func->getNodes()) { | 337 for (CfgNode *Node : Func->getNodes()) { |
338 Context.init(Node); | 338 Context.init(Node); |
339 while (!Context.atEnd()) { | 339 while (!Context.atEnd()) { |
340 PostIncrLoweringContext _(Context); | 340 PostIncrLoweringContext _(Context); |
341 genTargetHelperCallFor(Context.getCur()); | 341 genTargetHelperCallFor(iteratorToInst(Context.getCur())); |
342 } | 342 } |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
346 void TargetLowering::doAddressOpt() { | 346 void TargetLowering::doAddressOpt() { |
347 if (llvm::isa<InstLoad>(*Context.getCur())) | 347 if (llvm::isa<InstLoad>(*Context.getCur())) |
348 doAddressOptLoad(); | 348 doAddressOptLoad(); |
349 else if (llvm::isa<InstStore>(*Context.getCur())) | 349 else if (llvm::isa<InstStore>(*Context.getCur())) |
350 doAddressOptStore(); | 350 doAddressOptStore(); |
351 Context.advanceCur(); | 351 Context.advanceCur(); |
352 Context.advanceNext(); | 352 Context.advanceNext(); |
353 } | 353 } |
354 | 354 |
355 void TargetLowering::doNopInsertion(RandomNumberGenerator &RNG) { | 355 void TargetLowering::doNopInsertion(RandomNumberGenerator &RNG) { |
356 Inst *I = Context.getCur(); | 356 Inst *I = iteratorToInst(Context.getCur()); |
357 bool ShouldSkip = llvm::isa<InstFakeUse>(I) || llvm::isa<InstFakeDef>(I) || | 357 bool ShouldSkip = llvm::isa<InstFakeUse>(I) || llvm::isa<InstFakeDef>(I) || |
358 llvm::isa<InstFakeKill>(I) || I->isRedundantAssign() || | 358 llvm::isa<InstFakeKill>(I) || I->isRedundantAssign() || |
359 I->isDeleted(); | 359 I->isDeleted(); |
360 if (!ShouldSkip) { | 360 if (!ShouldSkip) { |
361 int Probability = getFlags().getNopProbabilityAsPercentage(); | 361 int Probability = getFlags().getNopProbabilityAsPercentage(); |
362 for (int I = 0; I < getFlags().getMaxNopsPerInstruction(); ++I) { | 362 for (int I = 0; I < getFlags().getMaxNopsPerInstruction(); ++I) { |
363 randomlyInsertNop(Probability / 100.0, RNG); | 363 randomlyInsertNop(Probability / 100.0, RNG); |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 // Lowers a single instruction according to the information in Context, by | 368 // Lowers a single instruction according to the information in Context, by |
369 // checking the Context.Cur instruction kind and calling the appropriate | 369 // checking the Context.Cur instruction kind and calling the appropriate |
370 // lowering method. The lowering method should insert target instructions at | 370 // lowering method. The lowering method should insert target instructions at |
371 // the Cur.Next insertion point, and should not delete the Context.Cur | 371 // the Cur.Next insertion point, and should not delete the Context.Cur |
372 // instruction or advance Context.Cur. | 372 // instruction or advance Context.Cur. |
373 // | 373 // |
374 // The lowering method may look ahead in the instruction stream as desired, and | 374 // The lowering method may look ahead in the instruction stream as desired, and |
375 // lower additional instructions in conjunction with the current one, for | 375 // lower additional instructions in conjunction with the current one, for |
376 // example fusing a compare and branch. If it does, it should advance | 376 // example fusing a compare and branch. If it does, it should advance |
377 // Context.Cur to point to the next non-deleted instruction to process, and it | 377 // Context.Cur to point to the next non-deleted instruction to process, and it |
378 // should delete any additional instructions it consumes. | 378 // should delete any additional instructions it consumes. |
379 void TargetLowering::lower() { | 379 void TargetLowering::lower() { |
380 assert(!Context.atEnd()); | 380 assert(!Context.atEnd()); |
381 Inst *Instr = Context.getCur(); | 381 Inst *Instr = iteratorToInst(Context.getCur()); |
382 Instr->deleteIfDead(); | 382 Instr->deleteIfDead(); |
383 if (!Instr->isDeleted() && !llvm::isa<InstFakeDef>(Instr) && | 383 if (!Instr->isDeleted() && !llvm::isa<InstFakeDef>(Instr) && |
384 !llvm::isa<InstFakeUse>(Instr)) { | 384 !llvm::isa<InstFakeUse>(Instr)) { |
385 // Mark the current instruction as deleted before lowering, otherwise the | 385 // Mark the current instruction as deleted before lowering, otherwise the |
386 // Dest variable will likely get marked as non-SSA. See | 386 // Dest variable will likely get marked as non-SSA. See |
387 // Variable::setDefinition(). However, just pass-through FakeDef and | 387 // Variable::setDefinition(). However, just pass-through FakeDef and |
388 // FakeUse instructions that might have been inserted prior to lowering. | 388 // FakeUse instructions that might have been inserted prior to lowering. |
389 Instr->setDeleted(); | 389 Instr->setDeleted(); |
390 switch (Instr->getKind()) { | 390 switch (Instr->getKind()) { |
391 case Inst::Alloca: | 391 case Inst::Alloca: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 void TargetLowering::lowerInst(CfgNode *Node, InstList::iterator Next, | 467 void TargetLowering::lowerInst(CfgNode *Node, InstList::iterator Next, |
468 InstHighLevel *Instr) { | 468 InstHighLevel *Instr) { |
469 // TODO(stichnot): Consider modifying the design/implementation to avoid | 469 // TODO(stichnot): Consider modifying the design/implementation to avoid |
470 // multiple init() calls when using lowerInst() to lower several instructions | 470 // multiple init() calls when using lowerInst() to lower several instructions |
471 // in the same node. | 471 // in the same node. |
472 Context.init(Node); | 472 Context.init(Node); |
473 Context.setNext(Next); | 473 Context.setNext(Next); |
474 Context.insert(Instr); | 474 Context.insert(Instr); |
475 --Next; | 475 --Next; |
476 assert(&*Next == Instr); | 476 assert(iteratorToInst(Next) == Instr); |
477 Context.setCur(Next); | 477 Context.setCur(Next); |
478 lower(); | 478 lower(); |
479 } | 479 } |
480 | 480 |
481 void TargetLowering::lowerOther(const Inst *Instr) { | 481 void TargetLowering::lowerOther(const Inst *Instr) { |
482 (void)Instr; | 482 (void)Instr; |
483 Func->setError("Can't lower unsupported instruction type"); | 483 Func->setError("Can't lower unsupported instruction type"); |
484 } | 484 } |
485 | 485 |
486 // Drives register allocation, allowing all physical registers (except perhaps | 486 // Drives register allocation, allowing all physical registers (except perhaps |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 case TARGET_LOWERING_CLASS_FOR(X): \ | 903 case TARGET_LOWERING_CLASS_FOR(X): \ |
904 return ::X::createTargetHeaderLowering(Ctx); | 904 return ::X::createTargetHeaderLowering(Ctx); |
905 #include "SZTargets.def" | 905 #include "SZTargets.def" |
906 #undef SUBZERO_TARGET | 906 #undef SUBZERO_TARGET |
907 } | 907 } |
908 } | 908 } |
909 | 909 |
910 TargetHeaderLowering::~TargetHeaderLowering() = default; | 910 TargetHeaderLowering::~TargetHeaderLowering() = default; |
911 | 911 |
912 } // end of namespace Ice | 912 } // end of namespace Ice |
OLD | NEW |