File: RayTracingAddressSpaceAliasAnalysis.cpp

package info (click to toggle)
intel-graphics-compiler 1.0.12504.6-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 83,912 kB
  • sloc: cpp: 910,147; lisp: 202,655; ansic: 15,197; python: 4,025; yacc: 2,241; lex: 1,570; pascal: 244; sh: 104; makefile: 25
file content (176 lines) | stat: -rw-r--r-- 5,532 bytes parent folder | download
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*========================== begin_copyright_notice ============================

Copyright (C) 2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

//===----------------------------------------------------------------------===//
///
/// This pass adds custom AddrSpace AA for RT.
///
//===----------------------------------------------------------------------===//

#include "RayTracingAddressSpaceAliasAnalysis.h"
#include "Compiler/CodeGenPublic.h"
#include "Compiler/IGCPassSupport.h"
#include "Probe/Assertion.h"

#include "common/LLVMWarningsPush.hpp"
#include "llvm/Config/llvm-config.h"
#include "common/LLVMWarningsPop.hpp"

using namespace llvm;
using namespace IGC;

namespace IGC {

bool RayTracingAddressSpaceAAResult::checkStateful(const CodeGenContext &Ctx)
{
    // Determine if all RT memory regions are enabled stateful. This will
    // determine what we can say about aliasing in some cases.
    auto& rtInfo = Ctx.getModuleMetaData()->rtInfo;
    return rtInfo.RTAsyncStackAddrspace != UINT_MAX &&
           rtInfo.SWHotZoneAddrspace    != UINT_MAX &&
           rtInfo.SWStackAddrspace      != UINT_MAX &&
           (!Ctx.hasSyncRTCalls() || rtInfo.RTSyncStackAddrspace != UINT_MAX);
}

bool RayTracingAddressSpaceAAResult::isRTAS(unsigned AS, const CodeGenContext& Ctx)
{
    auto& rtInfo = Ctx.getModuleMetaData()->rtInfo;
    return isStatefulAddrSpace(AS) &&
        (AS == rtInfo.RTAsyncStackAddrspace ||
         AS == rtInfo.SWHotZoneAddrspace    ||
         AS == rtInfo.SWStackAddrspace      ||
         AS == rtInfo.RTSyncStackAddrspace);
}

bool RayTracingAddressSpaceAAResult::isRTAS(unsigned AS) const
{
    return isRTAS(AS, CGC);
}

bool RayTracingAddressSpaceAAResult::noRTASAlias(unsigned AS1, unsigned AS2) const
{
    return ((isRTAS(AS1) || isRTAS(AS2)) && AS1 != AS2);
}

IGCLLVM::AliasResultEnum RayTracingAddressSpaceAAResult::alias(
    const MemoryLocation& LocA, const MemoryLocation& LocB
#if LLVM_VERSION_MAJOR >= 9
    , AAQueryInfo & AAQI
#endif
)
{
    PointerType* PtrTy1 = dyn_cast<PointerType>(LocA.Ptr->getType());
    PointerType* PtrTy2 = dyn_cast<PointerType>(LocB.Ptr->getType());

    if (!PtrTy1 || !PtrTy2)
        return IGCLLVM::AliasResultEnum::NoAlias;

    unsigned AS1 = PtrTy1->getAddressSpace();
    unsigned AS2 = PtrTy2->getAddressSpace();
    if (noRTASAlias(AS1, AS2))
    {
        return IGCLLVM::AliasResultEnum::NoAlias;
    }

    // Forward the query to the next analysis.
    return AAResultBase::alias(LocA, LocB
#if LLVM_VERSION_MAJOR >= 9
        , AAQI
#endif
    );
}

ModRefInfo RayTracingAddressSpaceAAResult::getModRefInfo(
    const CallBase* Call, const MemoryLocation& Loc,
    AAQueryInfo& AAQI)
{
    auto* PtrTy = dyn_cast<PointerType>(Loc.Ptr->getType());
    if (!PtrTy)
        return ModRefInfo::NoModRef;

    if (auto* SRI = dyn_cast<StackIDReleaseIntrinsic>(Call))
    {
        if (allStateful)
        {
            uint32_t Addrspace = PtrTy->getPointerAddressSpace();
            return isRTAS(Addrspace) ? ModRefInfo::Mod : ModRefInfo::NoModRef;
        }
    }
    return AAResultBase::getModRefInfo(Call, Loc, AAQI);
}

ModRefInfo RayTracingAddressSpaceAAResult::getModRefInfo(
    const CallBase* Call1, const CallBase* Call2,
    AAQueryInfo& AAQI)
{
    return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
}

void RayTracingAddressSpaceAAWrapperPass::getAnalysisUsage(AnalysisUsage& AU) const
{
    AU.setPreservesAll();
    AU.addRequired<TargetLibraryInfoWrapperPass>();
    AU.addRequired<CodeGenContextWrapper>();
}

bool RayTracingAddressSpaceAAWrapperPass::doInitialization(Module& M)
{
    if(M.size() > 0)
    {
        Result.reset(new RayTracingAddressSpaceAAResult(
        getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
#if LLVM_VERSION_MAJOR >= 10
            *M.begin()
#endif
            ),
            *getAnalysis<CodeGenContextWrapper>().getCodeGenContext()));
    }
    return false;
}

bool RayTracingAddressSpaceAAWrapperPass::doFinalization(Module& M)
{
    Result.reset();
    return false;
}

RayTracingAddressSpaceAAResult& RayTracingAddressSpaceAAWrapperPass::getResult()
{
    return *Result;
}
const RayTracingAddressSpaceAAResult& RayTracingAddressSpaceAAWrapperPass::getResult() const
{
    return *Result;
}

} // End anonymous namespace

#define PASS_FLAG     "igc-raytracing-address-space-alias-analysis"
#define PASS_DESC     "RayTracing Address space alias analysis"
#define PASS_CFG_ONLY false
#define PASS_ANALYSIS true
IGC_INITIALIZE_PASS_BEGIN(RayTracingAddressSpaceAAWrapperPass, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS)
IGC_INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenContextWrapper)
IGC_INITIALIZE_PASS_END(RayTracingAddressSpaceAAWrapperPass, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS)

char IGC::RayTracingAddressSpaceAAWrapperPass::ID = 0;

IGC::RayTracingAddressSpaceAAWrapperPass::RayTracingAddressSpaceAAWrapperPass() : ImmutablePass(ID) {
    initializeRayTracingAddressSpaceAAWrapperPassPass(*PassRegistry::getPassRegistry());
    Result = nullptr;
}

ImmutablePass* IGC::createRayTracingAddressSpaceAAWrapperPass() {
    return new RayTracingAddressSpaceAAWrapperPass();
}

void IGC::addRayTracingAddressSpaceAAResult(Pass& P, Function&, AAResults& AAR) {
    if (auto* WrapperPass = P.getAnalysisIfAvailable<RayTracingAddressSpaceAAWrapperPass>())
        AAR.addAAResult(WrapperPass->getResult());
}