@@ -39,13 +39,11 @@ class OpLowerer {
3939 DXILOpBuilder OpBuilder;
4040 DXILResourceMap &DRM;
4141 DXILResourceTypeMap &DRTM;
42- const ModuleMetadataInfo &MMDI;
4342 SmallVector<CallInst *> CleanupCasts;
4443
4544public:
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) {}
4947
5048 // / Replace every call to \c F using \c ReplaceCall, and then erase \c F. If
5149 // / there is an error replacing a call, we emit a diagnostic and return true.
@@ -318,7 +316,8 @@ class OpLowerer {
318316 // / model and taking into account binding information from
319317 // / DXILResourceAnalysis.
320318 bool lowerHandleFromBinding (Function &F) {
321- if (MMDI.DXILVersion < VersionTuple (1 , 6 ))
319+ const Triple &TT = M.getTargetTriple ();
320+ if (TT.getDXILVersion () < VersionTuple (1 , 6 ))
322321 return lowerToCreateHandle (F);
323322 return lowerToBindAndAnnotateHandle (F);
324323 }
@@ -487,6 +486,8 @@ class OpLowerer {
487486 }
488487
489488 [[nodiscard]] bool lowerRawBufferLoad (Function &F) {
489+ const Triple &TT = M.getTargetTriple ();
490+ VersionTuple DXILVersion = TT.getDXILVersion ();
490491 const DataLayout &DL = F.getDataLayout ();
491492 IRBuilder<> &IRB = OpBuilder.getIRB ();
492493 Type *Int8Ty = IRB.getInt8Ty ();
@@ -510,7 +511,7 @@ class OpLowerer {
510511 ConstantInt::get (Int32Ty, DL.getPrefTypeAlign (ScalarTy).value ());
511512
512513 Expected<CallInst *> OpCall =
513- MMDI. DXILVersion >= VersionTuple (1 , 2 )
514+ DXILVersion >= VersionTuple (1 , 2 )
514515 ? OpBuilder.tryCreateOp (OpCode::RawBufferLoad,
515516 {Handle, Index0, Index1, Mask, Align},
516517 CI->getName (), NewRetTy)
@@ -585,6 +586,8 @@ class OpLowerer {
585586 }
586587
587588 [[nodiscard]] bool lowerBufferStore (Function &F, bool IsRaw) {
589+ const Triple &TT = M.getTargetTriple ();
590+ VersionTuple DXILVersion = TT.getDXILVersion ();
588591 const DataLayout &DL = F.getDataLayout ();
589592 IRBuilder<> &IRB = OpBuilder.getIRB ();
590593 Type *Int8Ty = IRB.getInt8Ty ();
@@ -651,7 +654,7 @@ class OpLowerer {
651654 SmallVector<Value *, 9 > Args{
652655 Handle, Index0, Index1, DataElements[0 ],
653656 DataElements[1 ], DataElements[2 ], DataElements[3 ], Mask};
654- if (IsRaw && MMDI. DXILVersion >= VersionTuple (1 , 2 )) {
657+ if (IsRaw && DXILVersion >= VersionTuple (1 , 2 )) {
655658 Op = OpCode::RawBufferStore;
656659 // RawBufferStore requires the alignment
657660 Args.push_back (
@@ -742,37 +745,6 @@ class OpLowerer {
742745 });
743746 }
744747
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-
776748 [[nodiscard]] bool lowerIsFPClass (Function &F) {
777749 IRBuilder<> &IRB = OpBuilder.getIRB ();
778750 Type *RetTy = IRB.getInt1Ty ();
@@ -831,6 +803,8 @@ class OpLowerer {
831803 case Intrinsic::dx_resource_casthandle:
832804 // NOTE: llvm.dbg.value is supported as is in DXIL.
833805 case Intrinsic::dbg_value:
806+ case Intrinsic::lifetime_start:
807+ case Intrinsic::lifetime_end:
834808 case Intrinsic::not_intrinsic:
835809 if (F.use_empty ())
836810 F.eraseFromParent ();
@@ -881,17 +855,6 @@ class OpLowerer {
881855 case Intrinsic::ctpop:
882856 HasErrors |= lowerCtpopToCountBits (F);
883857 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 ;
895858 case Intrinsic::is_fpclass:
896859 HasErrors |= lowerIsFPClass (F);
897860 break ;
@@ -909,9 +872,8 @@ class OpLowerer {
909872PreservedAnalyses DXILOpLowering::run (Module &M, ModuleAnalysisManager &MAM) {
910873 DXILResourceMap &DRM = MAM.getResult <DXILResourceAnalysis>(M);
911874 DXILResourceTypeMap &DRTM = MAM.getResult <DXILResourceTypeAnalysis>(M);
912- const ModuleMetadataInfo MMDI = MAM.getResult <DXILMetadataAnalysis>(M);
913875
914- const bool MadeChanges = OpLowerer (M, DRM, DRTM, MMDI ).lowerIntrinsics ();
876+ bool MadeChanges = OpLowerer (M, DRM, DRTM).lowerIntrinsics ();
915877 if (!MadeChanges)
916878 return PreservedAnalyses::all ();
917879 PreservedAnalyses PA;
@@ -929,10 +891,8 @@ class DXILOpLoweringLegacy : public ModulePass {
929891 getAnalysis<DXILResourceWrapperPass>().getResourceMap ();
930892 DXILResourceTypeMap &DRTM =
931893 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
932- const ModuleMetadataInfo MMDI =
933- getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
934894
935- return OpLowerer (M, DRM, DRTM, MMDI ).lowerIntrinsics ();
895+ return OpLowerer (M, DRM, DRTM).lowerIntrinsics ();
936896 }
937897 StringRef getPassName () const override { return " DXIL Op Lowering" ; }
938898 DXILOpLoweringLegacy () : ModulePass(ID) {}
@@ -941,7 +901,6 @@ class DXILOpLoweringLegacy : public ModulePass {
941901 void getAnalysisUsage (llvm::AnalysisUsage &AU) const override {
942902 AU.addRequired <DXILResourceTypeWrapperPass>();
943903 AU.addRequired <DXILResourceWrapperPass>();
944- AU.addRequired <DXILMetadataAnalysisWrapperPass>();
945904 AU.addPreserved <DXILResourceWrapperPass>();
946905 AU.addPreserved <DXILMetadataAnalysisWrapperPass>();
947906 AU.addPreserved <ShaderFlagsAnalysisWrapper>();
0 commit comments