|
9 | 9 | #include "llvm/Analysis/DXILResource.h"
|
10 | 10 | #include "llvm/ADT/APInt.h"
|
11 | 11 | #include "llvm/IR/DerivedTypes.h"
|
| 12 | +#include "llvm/IR/Instructions.h" |
12 | 13 | #include "llvm/IR/Metadata.h"
|
| 14 | +#include "llvm/InitializePasses.h" |
| 15 | + |
| 16 | +#define DEBUG_TYPE "dxil-resource" |
13 | 17 |
|
14 | 18 | using namespace llvm;
|
15 | 19 | using namespace dxil;
|
@@ -326,4 +330,73 @@ std::pair<uint32_t, uint32_t> ResourceInfo::getAnnotateProps() const {
|
326 | 330 | return {Word0, Word1};
|
327 | 331 | }
|
328 | 332 |
|
329 |
| -#define DEBUG_TYPE "dxil-resource" |
| 333 | +//===----------------------------------------------------------------------===// |
| 334 | +// DXILResourceAnalysis and DXILResourcePrinterPass |
| 335 | + |
| 336 | +// Provide an explicit template instantiation for the static ID. |
| 337 | +AnalysisKey DXILResourceAnalysis::Key; |
| 338 | + |
| 339 | +DXILResourceMap DXILResourceAnalysis::run(Module &M, |
| 340 | + ModuleAnalysisManager &AM) { |
| 341 | + DXILResourceMap Data; |
| 342 | + return Data; |
| 343 | +} |
| 344 | + |
| 345 | +PreservedAnalyses DXILResourcePrinterPass::run(Module &M, |
| 346 | + ModuleAnalysisManager &AM) { |
| 347 | + DXILResourceMap &Data = |
| 348 | + AM.getResult<DXILResourceAnalysis>(M); |
| 349 | + |
| 350 | + for (const auto &[Handle, Info] : Data) { |
| 351 | + OS << "Binding for "; |
| 352 | + Handle->print(OS); |
| 353 | + OS << "\n"; |
| 354 | + // TODO: Info.print(OS); |
| 355 | + OS << "\n"; |
| 356 | + } |
| 357 | + |
| 358 | + return PreservedAnalyses::all(); |
| 359 | +} |
| 360 | + |
| 361 | +//===----------------------------------------------------------------------===// |
| 362 | +// DXILResourceWrapperPass |
| 363 | + |
| 364 | +DXILResourceWrapperPass::DXILResourceWrapperPass() : ModulePass(ID) { |
| 365 | + initializeDXILResourceWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 366 | +} |
| 367 | + |
| 368 | +DXILResourceWrapperPass::~DXILResourceWrapperPass() = default; |
| 369 | + |
| 370 | +void DXILResourceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 371 | + AU.setPreservesAll(); |
| 372 | +} |
| 373 | + |
| 374 | +bool DXILResourceWrapperPass::runOnModule(Module &M) { |
| 375 | + ResourceMap.reset(new DXILResourceMap()); |
| 376 | + return false; |
| 377 | +} |
| 378 | + |
| 379 | +void DXILResourceWrapperPass::releaseMemory() { ResourceMap.reset(); } |
| 380 | + |
| 381 | +void DXILResourceWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 382 | + if (!ResourceMap) { |
| 383 | + OS << "No resource map has been built!\n"; |
| 384 | + return; |
| 385 | + } |
| 386 | + for (const auto &[Handle, Info] : *ResourceMap) { |
| 387 | + OS << "Binding for "; |
| 388 | + Handle->print(OS); |
| 389 | + OS << "\n"; |
| 390 | + // TODO: Info.print(OS); |
| 391 | + OS << "\n"; |
| 392 | + } |
| 393 | +} |
| 394 | + |
| 395 | +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 396 | +LLVM_DUMP_METHOD |
| 397 | +void DXILResourceWrapperPass::dump() const { print(dbgs(), nullptr); } |
| 398 | +#endif |
| 399 | + |
| 400 | +INITIALIZE_PASS(DXILResourceWrapperPass, DEBUG_TYPE, "DXIL Resource analysis", |
| 401 | + false, true) |
| 402 | +char DXILResourceWrapperPass::ID = 0; |
0 commit comments