@@ -26,7 +26,7 @@ using namespace llvm;
26
26
27
27
static void legalizeFreeze (Instruction &I,
28
28
SmallVectorImpl<Instruction *> &ToRemove,
29
- DenseMap<Value *, Value *>) {
29
+ DenseMap<Value *, Value *>, bool & ) {
30
30
auto *FI = dyn_cast<FreezeInst>(&I);
31
31
if (!FI)
32
32
return ;
@@ -37,7 +37,7 @@ static void legalizeFreeze(Instruction &I,
37
37
38
38
static void fixI8UseChain (Instruction &I,
39
39
SmallVectorImpl<Instruction *> &ToRemove,
40
- DenseMap<Value *, Value *> &ReplacedValues) {
40
+ DenseMap<Value *, Value *> &ReplacedValues, bool & ) {
41
41
42
42
auto ProcessOperands = [&](SmallVector<Value *> &NewOperands) {
43
43
Type *InstrType = IntegerType::get (I.getContext (), 32 );
@@ -253,7 +253,8 @@ static void fixI8UseChain(Instruction &I,
253
253
254
254
static void upcastI8AllocasAndUses (Instruction &I,
255
255
SmallVectorImpl<Instruction *> &ToRemove,
256
- DenseMap<Value *, Value *> &ReplacedValues) {
256
+ DenseMap<Value *, Value *> &ReplacedValues,
257
+ bool &) {
257
258
auto *AI = dyn_cast<AllocaInst>(&I);
258
259
if (!AI || !AI->getAllocatedType ()->isIntegerTy (8 ))
259
260
return ;
@@ -303,7 +304,7 @@ static void upcastI8AllocasAndUses(Instruction &I,
303
304
static void
304
305
downcastI64toI32InsertExtractElements (Instruction &I,
305
306
SmallVectorImpl<Instruction *> &ToRemove,
306
- DenseMap<Value *, Value *> &) {
307
+ DenseMap<Value *, Value *> &, bool & ) {
307
308
308
309
if (auto *Extract = dyn_cast<ExtractElementInst>(&I)) {
309
310
Value *Idx = Extract->getIndexOperand ();
@@ -455,7 +456,7 @@ static void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val,
455
456
// vector. `ReplacedValues` is unused.
456
457
static void legalizeMemCpy (Instruction &I,
457
458
SmallVectorImpl<Instruction *> &ToRemove,
458
- DenseMap<Value *, Value *> &ReplacedValues) {
459
+ DenseMap<Value *, Value *> &ReplacedValues, bool & ) {
459
460
460
461
CallInst *CI = dyn_cast<CallInst>(&I);
461
462
if (!CI)
@@ -480,7 +481,7 @@ static void legalizeMemCpy(Instruction &I,
480
481
481
482
static void legalizeMemSet (Instruction &I,
482
483
SmallVectorImpl<Instruction *> &ToRemove,
483
- DenseMap<Value *, Value *> &ReplacedValues) {
484
+ DenseMap<Value *, Value *> &ReplacedValues, bool & ) {
484
485
485
486
CallInst *CI = dyn_cast<CallInst>(&I);
486
487
if (!CI)
@@ -501,7 +502,7 @@ static void legalizeMemSet(Instruction &I,
501
502
502
503
static void updateFnegToFsub (Instruction &I,
503
504
SmallVectorImpl<Instruction *> &ToRemove,
504
- DenseMap<Value *, Value *> &) {
505
+ DenseMap<Value *, Value *> &, bool & ) {
505
506
const Intrinsic::ID ID = I.getOpcode ();
506
507
if (ID != Instruction::FNeg)
507
508
return ;
@@ -516,7 +517,7 @@ static void updateFnegToFsub(Instruction &I,
516
517
static void
517
518
legalizeGetHighLowi64Bytes (Instruction &I,
518
519
SmallVectorImpl<Instruction *> &ToRemove,
519
- DenseMap<Value *, Value *> &ReplacedValues) {
520
+ DenseMap<Value *, Value *> &ReplacedValues, bool & ) {
520
521
if (auto *BitCast = dyn_cast<BitCastInst>(&I)) {
521
522
if (BitCast->getDestTy () ==
522
523
FixedVectorType::get (Type::getInt32Ty (I.getContext ()), 2 ) &&
@@ -562,10 +563,9 @@ legalizeGetHighLowi64Bytes(Instruction &I,
562
563
}
563
564
}
564
565
565
- static void
566
- legalizeScalarLoadStoreOnArrays (Instruction &I,
567
- SmallVectorImpl<Instruction *> &ToRemove,
568
- DenseMap<Value *, Value *> &) {
566
+ static void legalizeScalarLoadStoreOnArrays (
567
+ Instruction &I, SmallVectorImpl<Instruction *> &ToRemove,
568
+ DenseMap<Value *, Value *> &, bool &MadeChange) {
569
569
570
570
Value *PtrOp;
571
571
unsigned PtrOpIndex;
@@ -607,6 +607,7 @@ legalizeScalarLoadStoreOnArrays(Instruction &I,
607
607
Value *GEP = GetElementPtrInst::Create (
608
608
ArrayTy, PtrOp, {Zero, Zero}, GEPNoWrapFlags::all (), " " , I.getIterator ());
609
609
I.setOperand (PtrOpIndex, GEP);
610
+ MadeChange = true ;
610
611
}
611
612
612
613
namespace {
@@ -623,8 +624,11 @@ class DXILLegalizationPipeline {
623
624
ToRemove.clear ();
624
625
ReplacedValues.clear ();
625
626
for (auto &I : instructions (F)) {
626
- for (auto &LegalizationFn : LegalizationPipeline[Stage])
627
- LegalizationFn (I, ToRemove, ReplacedValues);
627
+ for (auto &LegalizationFn : LegalizationPipeline[Stage]) {
628
+ bool PerLegalizationChange = false ;
629
+ LegalizationFn (I, ToRemove, ReplacedValues, PerLegalizationChange);
630
+ MadeChange |= PerLegalizationChange;
631
+ }
628
632
}
629
633
630
634
for (auto *Inst : reverse (ToRemove))
@@ -640,7 +644,7 @@ class DXILLegalizationPipeline {
640
644
641
645
using LegalizationFnTy =
642
646
std::function<void (Instruction &, SmallVectorImpl<Instruction *> &,
643
- DenseMap<Value *, Value *> &)>;
647
+ DenseMap<Value *, Value *> &, bool & )>;
644
648
645
649
SmallVector<LegalizationFnTy> LegalizationPipeline[NumStages];
646
650
0 commit comments