@@ -39,13 +39,11 @@ class OpLowerer {
39
39
DXILOpBuilder OpBuilder;
40
40
DXILResourceMap &DRM;
41
41
DXILResourceTypeMap &DRTM;
42
- const ModuleMetadataInfo &MMDI;
43
42
SmallVector<CallInst *> CleanupCasts;
44
43
45
44
public:
46
- OpLowerer (Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM,
47
- const ModuleMetadataInfo &MMDI)
48
- : M(M), OpBuilder(M), DRM(DRM), DRTM(DRTM), MMDI(MMDI) {}
45
+ OpLowerer (Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
46
+ : M(M), OpBuilder(M), DRM(DRM), DRTM(DRTM) {}
49
47
50
48
// / Replace every call to \c F using \c ReplaceCall, and then erase \c F. If
51
49
// / there is an error replacing a call, we emit a diagnostic and return true.
@@ -318,7 +316,8 @@ class OpLowerer {
318
316
// / model and taking into account binding information from
319
317
// / DXILResourceAnalysis.
320
318
bool lowerHandleFromBinding (Function &F) {
321
- if (MMDI.DXILVersion < VersionTuple (1 , 6 ))
319
+ const Triple &TT = M.getTargetTriple ();
320
+ if (TT.getDXILVersion () < VersionTuple (1 , 6 ))
322
321
return lowerToCreateHandle (F);
323
322
return lowerToBindAndAnnotateHandle (F);
324
323
}
@@ -487,6 +486,8 @@ class OpLowerer {
487
486
}
488
487
489
488
[[nodiscard]] bool lowerRawBufferLoad (Function &F) {
489
+ const Triple &TT = M.getTargetTriple ();
490
+ VersionTuple DXILVersion = TT.getDXILVersion ();
490
491
const DataLayout &DL = F.getDataLayout ();
491
492
IRBuilder<> &IRB = OpBuilder.getIRB ();
492
493
Type *Int8Ty = IRB.getInt8Ty ();
@@ -510,7 +511,7 @@ class OpLowerer {
510
511
ConstantInt::get (Int32Ty, DL.getPrefTypeAlign (ScalarTy).value ());
511
512
512
513
Expected<CallInst *> OpCall =
513
- MMDI. DXILVersion >= VersionTuple (1 , 2 )
514
+ DXILVersion >= VersionTuple (1 , 2 )
514
515
? OpBuilder.tryCreateOp (OpCode::RawBufferLoad,
515
516
{Handle, Index0, Index1, Mask, Align},
516
517
CI->getName (), NewRetTy)
@@ -585,6 +586,8 @@ class OpLowerer {
585
586
}
586
587
587
588
[[nodiscard]] bool lowerBufferStore (Function &F, bool IsRaw) {
589
+ const Triple &TT = M.getTargetTriple ();
590
+ VersionTuple DXILVersion = TT.getDXILVersion ();
588
591
const DataLayout &DL = F.getDataLayout ();
589
592
IRBuilder<> &IRB = OpBuilder.getIRB ();
590
593
Type *Int8Ty = IRB.getInt8Ty ();
@@ -651,7 +654,7 @@ class OpLowerer {
651
654
SmallVector<Value *, 9 > Args{
652
655
Handle, Index0, Index1, DataElements[0 ],
653
656
DataElements[1 ], DataElements[2 ], DataElements[3 ], Mask};
654
- if (IsRaw && MMDI. DXILVersion >= VersionTuple (1 , 2 )) {
657
+ if (IsRaw && DXILVersion >= VersionTuple (1 , 2 )) {
655
658
Op = OpCode::RawBufferStore;
656
659
// RawBufferStore requires the alignment
657
660
Args.push_back (
@@ -742,37 +745,6 @@ class OpLowerer {
742
745
});
743
746
}
744
747
745
- [[nodiscard]] bool lowerLifetimeIntrinsic (Function &F) {
746
- IRBuilder<> &IRB = OpBuilder.getIRB ();
747
- return replaceFunction (F, [&](CallInst *CI) -> Error {
748
- IRB.SetInsertPoint (CI);
749
- Value *Ptr = CI->getArgOperand (1 );
750
- assert (Ptr->getType ()->isPointerTy () &&
751
- " Expected operand of lifetime intrinsic to be a pointer" );
752
-
753
- auto ZeroOrUndef = [&](Type *Ty) {
754
- return MMDI.ValidatorVersion < VersionTuple (1 , 6 )
755
- ? Constant::getNullValue (Ty)
756
- : UndefValue::get (Ty);
757
- };
758
-
759
- Value *Val = nullptr ;
760
- if (auto *GV = dyn_cast<GlobalVariable>(Ptr)) {
761
- if (GV->hasInitializer () || GV->isExternallyInitialized ())
762
- return Error::success ();
763
- Val = ZeroOrUndef (GV->getValueType ());
764
- } else if (auto *AI = dyn_cast<AllocaInst>(Ptr))
765
- Val = ZeroOrUndef (AI->getAllocatedType ());
766
-
767
- assert (Val && " Expected operand of lifetime intrinsic to be a global "
768
- " variable or alloca instruction" );
769
- IRB.CreateStore (Val, Ptr, false );
770
-
771
- CI->eraseFromParent ();
772
- return Error::success ();
773
- });
774
- }
775
-
776
748
[[nodiscard]] bool lowerIsFPClass (Function &F) {
777
749
IRBuilder<> &IRB = OpBuilder.getIRB ();
778
750
Type *RetTy = IRB.getInt1Ty ();
@@ -831,6 +803,8 @@ class OpLowerer {
831
803
case Intrinsic::dx_resource_casthandle:
832
804
// NOTE: llvm.dbg.value is supported as is in DXIL.
833
805
case Intrinsic::dbg_value:
806
+ case Intrinsic::lifetime_start:
807
+ case Intrinsic::lifetime_end:
834
808
case Intrinsic::not_intrinsic:
835
809
if (F.use_empty ())
836
810
F.eraseFromParent ();
@@ -881,17 +855,6 @@ class OpLowerer {
881
855
case Intrinsic::ctpop:
882
856
HasErrors |= lowerCtpopToCountBits (F);
883
857
break ;
884
- case Intrinsic::lifetime_start:
885
- case Intrinsic::lifetime_end:
886
- if (F.use_empty ())
887
- F.eraseFromParent ();
888
- else {
889
- if (MMDI.DXILVersion < VersionTuple (1 , 6 ))
890
- HasErrors |= lowerLifetimeIntrinsic (F);
891
- else
892
- continue ;
893
- }
894
- break ;
895
858
case Intrinsic::is_fpclass:
896
859
HasErrors |= lowerIsFPClass (F);
897
860
break ;
@@ -909,9 +872,8 @@ class OpLowerer {
909
872
PreservedAnalyses DXILOpLowering::run (Module &M, ModuleAnalysisManager &MAM) {
910
873
DXILResourceMap &DRM = MAM.getResult <DXILResourceAnalysis>(M);
911
874
DXILResourceTypeMap &DRTM = MAM.getResult <DXILResourceTypeAnalysis>(M);
912
- const ModuleMetadataInfo MMDI = MAM.getResult <DXILMetadataAnalysis>(M);
913
875
914
- const bool MadeChanges = OpLowerer (M, DRM, DRTM, MMDI ).lowerIntrinsics ();
876
+ bool MadeChanges = OpLowerer (M, DRM, DRTM).lowerIntrinsics ();
915
877
if (!MadeChanges)
916
878
return PreservedAnalyses::all ();
917
879
PreservedAnalyses PA;
@@ -929,10 +891,8 @@ class DXILOpLoweringLegacy : public ModulePass {
929
891
getAnalysis<DXILResourceWrapperPass>().getResourceMap ();
930
892
DXILResourceTypeMap &DRTM =
931
893
getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
932
- const ModuleMetadataInfo MMDI =
933
- getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
934
894
935
- return OpLowerer (M, DRM, DRTM, MMDI ).lowerIntrinsics ();
895
+ return OpLowerer (M, DRM, DRTM).lowerIntrinsics ();
936
896
}
937
897
StringRef getPassName () const override { return " DXIL Op Lowering" ; }
938
898
DXILOpLoweringLegacy () : ModulePass(ID) {}
@@ -941,7 +901,6 @@ class DXILOpLoweringLegacy : public ModulePass {
941
901
void getAnalysisUsage (llvm::AnalysisUsage &AU) const override {
942
902
AU.addRequired <DXILResourceTypeWrapperPass>();
943
903
AU.addRequired <DXILResourceWrapperPass>();
944
- AU.addRequired <DXILMetadataAnalysisWrapperPass>();
945
904
AU.addPreserved <DXILResourceWrapperPass>();
946
905
AU.addPreserved <DXILMetadataAnalysisWrapperPass>();
947
906
AU.addPreserved <ShaderFlagsAnalysisWrapper>();
0 commit comments