224
224
#include " SIDefines.h"
225
225
#include " llvm/ADT/SetOperations.h"
226
226
#include " llvm/ADT/SmallVector.h"
227
- #include " llvm/Analysis/ConstantFolding .h"
227
+ #include " llvm/Analysis/InstSimplifyFolder .h"
228
228
#include " llvm/Analysis/Utils/Local.h"
229
229
#include " llvm/CodeGen/TargetPassConfig.h"
230
230
#include " llvm/IR/AttributeMask.h"
@@ -445,7 +445,7 @@ class StoreFatPtrsAsIntsAndExpandMemcpyVisitor
445
445
446
446
ValueToValueMapTy ConvertedForStore;
447
447
448
- IRBuilder<> IRB;
448
+ IRBuilder<InstSimplifyFolder > IRB;
449
449
450
450
const TargetMachine *TM;
451
451
@@ -459,9 +459,10 @@ class StoreFatPtrsAsIntsAndExpandMemcpyVisitor
459
459
460
460
public:
461
461
StoreFatPtrsAsIntsAndExpandMemcpyVisitor (BufferFatPtrToIntTypeMap *TypeMap,
462
+ const DataLayout &DL,
462
463
LLVMContext &Ctx,
463
464
const TargetMachine *TM)
464
- : TypeMap(TypeMap), IRB(Ctx), TM(TM) {}
465
+ : TypeMap(TypeMap), IRB(Ctx, InstSimplifyFolder(DL) ), TM(TM) {}
465
466
bool processFunction (Function &F);
466
467
467
468
bool visitInstruction (Instruction &I) { return false ; }
@@ -683,7 +684,7 @@ class LegalizeBufferContentTypesVisitor
683
684
: public InstVisitor<LegalizeBufferContentTypesVisitor, bool > {
684
685
friend class InstVisitor <LegalizeBufferContentTypesVisitor, bool >;
685
686
686
- IRBuilder<> IRB;
687
+ IRBuilder<InstSimplifyFolder > IRB;
687
688
688
689
const DataLayout &DL;
689
690
@@ -743,7 +744,7 @@ class LegalizeBufferContentTypesVisitor
743
744
744
745
public:
745
746
LegalizeBufferContentTypesVisitor (const DataLayout &DL, LLVMContext &Ctx)
746
- : IRB(Ctx), DL(DL) {}
747
+ : IRB(Ctx, InstSimplifyFolder(DL) ), DL(DL) {}
747
748
bool processFunction (Function &F);
748
749
};
749
750
} // namespace
@@ -1326,7 +1327,7 @@ class SplitPtrStructs : public InstVisitor<SplitPtrStructs, PtrParts> {
1326
1327
const TargetMachine *TM;
1327
1328
const GCNSubtarget *ST = nullptr ;
1328
1329
1329
- IRBuilder<> IRB;
1330
+ IRBuilder<InstSimplifyFolder > IRB;
1330
1331
1331
1332
// Copy metadata between instructions if applicable.
1332
1333
void copyMetadata (Value *Dest, Value *Src);
@@ -1363,8 +1364,9 @@ class SplitPtrStructs : public InstVisitor<SplitPtrStructs, PtrParts> {
1363
1364
bool IsVolatile, SyncScope::ID SSID);
1364
1365
1365
1366
public:
1366
- SplitPtrStructs (LLVMContext &Ctx, const TargetMachine *TM)
1367
- : TM(TM), IRB(Ctx) {}
1367
+ SplitPtrStructs (const DataLayout &DL, LLVMContext &Ctx,
1368
+ const TargetMachine *TM)
1369
+ : TM(TM), IRB(Ctx, InstSimplifyFolder(DL)) {}
1368
1370
1369
1371
void processFunction (Function &F);
1370
1372
@@ -1415,7 +1417,7 @@ PtrParts SplitPtrStructs::getPtrParts(Value *V) {
1415
1417
return {*RsrcEntry = Rsrc, *OffEntry = Off};
1416
1418
}
1417
1419
1418
- IRBuilder<>::InsertPointGuard Guard (IRB);
1420
+ IRBuilder<InstSimplifyFolder >::InsertPointGuard Guard (IRB);
1419
1421
if (auto *I = dyn_cast<Instruction>(V)) {
1420
1422
LLVM_DEBUG (dbgs () << " Recursing to split parts of " << *I << " \n " );
1421
1423
auto [Rsrc, Off] = visit (*I);
@@ -1479,7 +1481,7 @@ void SplitPtrStructs::getPossibleRsrcRoots(Instruction *I,
1479
1481
}
1480
1482
1481
1483
void SplitPtrStructs::processConditionals () {
1482
- SmallDenseMap<Instruction *, Value *> FoundRsrcs;
1484
+ SmallDenseMap<Value *, Value *> FoundRsrcs;
1483
1485
SmallPtrSet<Value *, 4 > Roots;
1484
1486
SmallPtrSet<Value *, 4 > Seen;
1485
1487
for (Instruction *I : Conditionals) {
@@ -1493,7 +1495,7 @@ void SplitPtrStructs::processConditionals() {
1493
1495
if (MaybeFoundRsrc != FoundRsrcs.end ()) {
1494
1496
MaybeRsrc = MaybeFoundRsrc->second ;
1495
1497
} else {
1496
- IRBuilder<>::InsertPointGuard Guard (IRB);
1498
+ IRBuilder<InstSimplifyFolder >::InsertPointGuard Guard (IRB);
1497
1499
Roots.clear ();
1498
1500
Seen.clear ();
1499
1501
getPossibleRsrcRoots (I, Roots, Seen);
@@ -1558,21 +1560,29 @@ void SplitPtrStructs::processConditionals() {
1558
1560
// to put the corrections maps in an inconstent state. That'll be handed
1559
1561
// during the rest of the killing. Also, `ValueToValueMapTy` guarantees
1560
1562
// that references in that map will be updated as well.
1561
- ConditionalTemps.push_back (cast<Instruction>(Rsrc));
1562
- ConditionalTemps.push_back (cast<Instruction>(Off));
1563
- Rsrc->replaceAllUsesWith (NewRsrc);
1564
- Off->replaceAllUsesWith (NewOff);
1563
+ // Note that if the temporary instruction got `InstSimplify`'d away, it
1564
+ // might be something like a block argument.
1565
+ if (auto *RsrcInst = dyn_cast<Instruction>(Rsrc)) {
1566
+ ConditionalTemps.push_back (RsrcInst);
1567
+ RsrcInst->replaceAllUsesWith (NewRsrc);
1568
+ }
1569
+ if (auto *OffInst = dyn_cast<Instruction>(Off)) {
1570
+ ConditionalTemps.push_back (OffInst);
1571
+ OffInst->replaceAllUsesWith (NewOff);
1572
+ }
1565
1573
1566
1574
// Save on recomputing the cycle traversals in known-root cases.
1567
1575
if (MaybeRsrc)
1568
1576
for (Value *V : Seen)
1569
- FoundRsrcs[cast<Instruction>(V) ] = NewRsrc;
1577
+ FoundRsrcs[V ] = NewRsrc;
1570
1578
} else if (isa<SelectInst>(I)) {
1571
1579
if (MaybeRsrc) {
1572
- ConditionalTemps.push_back (cast<Instruction>(Rsrc));
1573
- Rsrc->replaceAllUsesWith (*MaybeRsrc);
1580
+ if (auto *RsrcInst = dyn_cast<Instruction>(Rsrc)) {
1581
+ ConditionalTemps.push_back (RsrcInst);
1582
+ RsrcInst->replaceAllUsesWith (*MaybeRsrc);
1583
+ }
1574
1584
for (Value *V : Seen)
1575
- FoundRsrcs[cast<Instruction>(V) ] = *MaybeRsrc;
1585
+ FoundRsrcs[V ] = *MaybeRsrc;
1576
1586
}
1577
1587
} else {
1578
1588
llvm_unreachable (" Only PHIs and selects go in the conditionals list" );
@@ -2426,8 +2436,8 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
2426
2436
/* RemoveDeadConstants=*/ false , /* IncludeSelf=*/ true );
2427
2437
}
2428
2438
2429
- StoreFatPtrsAsIntsAndExpandMemcpyVisitor MemOpsRewrite (&IntTM, M. getContext () ,
2430
- &TM);
2439
+ StoreFatPtrsAsIntsAndExpandMemcpyVisitor MemOpsRewrite (&IntTM, DL ,
2440
+ M. getContext (), &TM);
2431
2441
LegalizeBufferContentTypesVisitor BufferContentsTypeRewrite (DL,
2432
2442
M.getContext ());
2433
2443
for (Function &F : M.functions ()) {
@@ -2472,7 +2482,7 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
2472
2482
IntTM.clear ();
2473
2483
CloneMap.clear ();
2474
2484
2475
- SplitPtrStructs Splitter (M.getContext (), &TM);
2485
+ SplitPtrStructs Splitter (DL, M.getContext (), &TM);
2476
2486
for (Function *F : NeedsPostProcess)
2477
2487
Splitter.processFunction (*F);
2478
2488
for (Function *F : Intrinsics) {
0 commit comments