Skip to content

Commit 3869dd3

Browse files
committed
fixup: adapt to changes in llvm#119773
1 parent 89db4cc commit 3869dd3

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

llvm/lib/Target/DirectX/DXILResourceAccess.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using namespace llvm;
2323

2424
static void replaceTypedBufferAccess(IntrinsicInst *II,
25-
dxil::ResourceInfo &RI) {
25+
dxil::ResourceTypeInfo &RTI) {
2626
const DataLayout &DL = II->getDataLayout();
2727

2828
auto *HandleType = cast<TargetExtType>(II->getOperand(0)->getType());
@@ -119,46 +119,43 @@ static void replaceTypedBufferAccess(IntrinsicInst *II,
119119
II->eraseFromParent();
120120
}
121121

122-
static bool transformResourcePointers(Function &F, DXILResourceMap &DRM) {
123-
// TODO: Should we have a more efficient way to find resources used in a
124-
// particular function?
125-
SmallVector<std::pair<IntrinsicInst *, dxil::ResourceInfo &>> Resources;
122+
static bool transformResourcePointers(Function &F, DXILResourceTypeMap &DRTM) {
123+
bool Changed = false;
124+
SmallVector<std::pair<IntrinsicInst *, dxil::ResourceTypeInfo>> Resources;
126125
for (BasicBlock &BB : F)
127126
for (Instruction &I : BB)
128-
if (auto *CI = dyn_cast<CallInst>(&I)) {
129-
auto It = DRM.find(CI);
130-
if (It == DRM.end())
131-
continue;
132-
for (User *U : CI->users())
133-
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U))
134-
if (II->getIntrinsicID() == Intrinsic::dx_resource_getpointer)
135-
Resources.emplace_back(II, *It);
136-
}
137-
138-
for (const auto &[II, RI] : Resources) {
139-
if (RI.isTyped())
127+
if (auto *II = dyn_cast<IntrinsicInst>(&I))
128+
if (II->getIntrinsicID() == Intrinsic::dx_resource_getpointer) {
129+
auto *HandleTy = cast<TargetExtType>(II->getArgOperand(0)->getType());
130+
Resources.emplace_back(II, DRTM[HandleTy]);
131+
}
132+
133+
for (auto &[II, RI] : Resources) {
134+
if (RI.isTyped()) {
135+
Changed = true;
140136
replaceTypedBufferAccess(II, RI);
137+
}
141138

142139
// TODO: handle other resource types. We should probably have an
143140
// `unreachable` here once we've added support for all of them.
144141
}
145142

146-
return false;
143+
return Changed;
147144
}
148145

149146
PreservedAnalyses DXILResourceAccess::run(Function &F,
150147
FunctionAnalysisManager &FAM) {
151148
auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
152-
DXILResourceMap *DRM =
153-
MAMProxy.getCachedResult<DXILResourceAnalysis>(*F.getParent());
154-
assert(DRM && "DXILResourceAnalysis must be available");
149+
DXILResourceTypeMap *DRTM =
150+
MAMProxy.getCachedResult<DXILResourceTypeAnalysis>(*F.getParent());
151+
assert(DRTM && "DXILResourceTypeAnalysis must be available");
155152

156-
bool MadeChanges = transformResourcePointers(F, *DRM);
153+
bool MadeChanges = transformResourcePointers(F, *DRTM);
157154
if (!MadeChanges)
158155
return PreservedAnalyses::all();
159156

160157
PreservedAnalyses PA;
161-
PA.preserve<DXILResourceAnalysis>();
158+
PA.preserve<DXILResourceTypeAnalysis>();
162159
PA.preserve<DominatorTreeAnalysis>();
163160
return PA;
164161
}
@@ -167,18 +164,17 @@ namespace {
167164
class DXILResourceAccessLegacy : public FunctionPass {
168165
public:
169166
bool runOnFunction(Function &F) override {
170-
DXILResourceMap &DRM =
171-
getAnalysis<DXILResourceWrapperPass>().getResourceMap();
167+
DXILResourceTypeMap &DRTM =
168+
getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
172169

173-
return transformResourcePointers(F, DRM);
170+
return transformResourcePointers(F, DRTM);
174171
}
175172
StringRef getPassName() const override { return "DXIL Resource Access"; }
176173
DXILResourceAccessLegacy() : FunctionPass(ID) {}
177174

178175
static char ID; // Pass identification.
179176
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
180-
AU.addRequired<DXILResourceWrapperPass>();
181-
AU.addPreserved<DXILResourceWrapperPass>();
177+
AU.addRequired<DXILResourceTypeWrapperPass>();
182178
AU.addPreserved<DominatorTreeWrapperPass>();
183179
}
184180
};
@@ -187,7 +183,7 @@ char DXILResourceAccessLegacy::ID = 0;
187183

188184
INITIALIZE_PASS_BEGIN(DXILResourceAccessLegacy, DEBUG_TYPE,
189185
"DXIL Resource Access", false, false)
190-
INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapperPass)
186+
INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
191187
INITIALIZE_PASS_END(DXILResourceAccessLegacy, DEBUG_TYPE,
192188
"DXIL Resource Access", false, false)
193189

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/PostOrderIterator.h"
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/Twine.h"
21-
#include "llvm/Analysis/DXILResource.h"
2221
#include "llvm/Analysis/TargetTransformInfo.h"
2322
#include "llvm/Analysis/VectorUtils.h"
2423
#include "llvm/IR/Argument.h"
@@ -352,7 +351,6 @@ void ScalarizerLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const {
352351
AU.addRequired<DominatorTreeWrapperPass>();
353352
AU.addRequired<TargetTransformInfoWrapperPass>();
354353
AU.addPreserved<DominatorTreeWrapperPass>();
355-
AU.addPreserved<DXILResourceWrapperPass>();
356354
}
357355

358356
char ScalarizerLegacyPass::ID = 0;
@@ -1350,6 +1348,5 @@ PreservedAnalyses ScalarizerPass::run(Function &F, FunctionAnalysisManager &AM)
13501348
bool Changed = Impl.visit(F);
13511349
PreservedAnalyses PA;
13521350
PA.preserve<DominatorTreeAnalysis>();
1353-
PA.preserve<DXILResourceAnalysis>();
13541351
return Changed ? PA : PreservedAnalyses::all();
13551352
}

llvm/test/CodeGen/DirectX/llc-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
; CHECK-LABEL: Pass Arguments:
77
; CHECK-NEXT: Target Library Information
8-
; CHECK-NEXT: Target Transform Information
98
; CHECK-NEXT: DXIL Resource Type Analysis
9+
; CHECK-NEXT: Target Transform Information
1010
; CHECK-NEXT: ModulePass Manager
1111
; CHECK-NEXT: DXIL Finalize Linkage
1212
; CHECK-NEXT: DXIL Intrinsic Expansion

0 commit comments

Comments
 (0)