1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
//===----------------------------------------------------------------------===//
///
/// This pass prepares downstream RayQuery passes by lowering some specific intrinsics first.
/// Right now, it lowers Proceed only.
//===----------------------------------------------------------------------===//
#include "IGC/common/StringMacros.hpp"
#include "RTBuilder.h"
#include "Compiler/IGCPassSupport.h"
#include "Compiler/CodeGenPublicEnums.h"
#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/InstIterator.h>
#include "common/LLVMWarningsPop.hpp"
using namespace std;
using namespace llvm;
using namespace IGC;
using namespace RTStackFormat;
class TraceRayInlinePrepPass : public FunctionPass
{
public:
TraceRayInlinePrepPass(): FunctionPass(ID)
{
initializeTraceRayInlinePrepPassPass(*PassRegistry::getPassRegistry());
}
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override
{
AU.addRequired<CodeGenContextWrapper>();
}
bool runOnFunction(Function &F) override;
StringRef getPassName() const override
{
return "TraceRayInlinePrepPass";
}
static char ID;
private:
void lowerPI(Function& F);
};
char TraceRayInlinePrepPass::ID = 0;
#define PASS_FLAG2 "tracerayinline-prep-pass"
#define PASS_DESCRIPTION2 "prepare tracerayinline"
#define PASS_CFG_ONLY2 false
#define PASS_ANALYSIS2 false
IGC_INITIALIZE_PASS_BEGIN(TraceRayInlinePrepPass, PASS_FLAG2, PASS_DESCRIPTION2, PASS_CFG_ONLY2, PASS_ANALYSIS2)
IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenContextWrapper)
IGC_INITIALIZE_PASS_END(TraceRayInlinePrepPass, PASS_FLAG2, PASS_DESCRIPTION2, PASS_CFG_ONLY2, PASS_ANALYSIS2)
/// Lower TraceRaySyncProceedHLIntrinsic to 2 intrinsics which will be scheduled by downstream schedulers.
/// bool status = TraceRaySyncProceedHLIntrinsic();
/// if(status)
/// ...
/// =========>
/// int retPI = TraceRaySyncProceedIntrinsic();
/// bool status = RayQuerySyncStackToShadowMemory(retPI);
/// if(status)
/// ...
/// TODO: Right now, we don't use a separate GenISA_ShadowMemoryToSyncStack here, but we might want to do it later if necessary.
void TraceRayInlinePrepPass::lowerPI(Function& F)
{
SmallVector<TraceRaySyncProceedHLIntrinsic*, 4> ProceedHLs;
for (auto& I : instructions(F))
{
if (auto* PI = dyn_cast<TraceRaySyncProceedHLIntrinsic>(&I))
ProceedHLs.push_back(PI);
}
if (ProceedHLs.empty())
return;
RTBuilder IRB(F.getContext(), *getAnalysis<CodeGenContextWrapper>().getCodeGenContext());
for (auto* PIHL : ProceedHLs)
{
IRB.SetInsertPoint(PIHL->getNextNode());
Function* proceedFunc = GenISAIntrinsic::getDeclaration(
PIHL->getModule(), GenISAIntrinsic::GenISA_TraceRaySyncProceed);
CallInst* PI = IRB.CreateCall(proceedFunc, PIHL->getQueryObjIndex());
Function* stk2SMFunc = GenISAIntrinsic::getDeclaration(
PIHL->getModule(),
GenISAIntrinsic::GenISA_SyncStackToShadowMemory);
Value* args[] = {
PIHL->getQueryObjIndex(),
PI
};
CallInst* stk2SM = IRB.CreateCall(stk2SMFunc, args);
PIHL->replaceAllUsesWith(stk2SM);
PIHL->eraseFromParent();
}
return;
}
bool TraceRayInlinePrepPass::runOnFunction(Function &F)
{
SmallVector<RayQuerySyncStackToShadowMemory*, 4> Stk2SMs;
lowerPI(F);
return true;
}
namespace IGC
{
Pass* createTraceRayInlinePrepPass(void)
{
return new TraceRayInlinePrepPass();
}
} // namespace IGC
|