File: getCacheOpts.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 (214 lines) | stat: -rw-r--r-- 5,531 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*========================== begin_copyright_notice ============================

Copyright (C) 2021 Intel Corporation

SPDX-License-Identifier: MIT

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

/**
 * @file getCacheOpts.cpp
 *
 * @section DESCRIPTION
 *
 * This file contains definitions of utility functions which return the cache options
 * for a given load or store instruction.
 */

#include "visa_igc_common_header.h"                      // for LSC_L1_L3_CC
#include "common/igc_regkeys.hpp"                        // for IGC_IS_FLAG_ENABLED, IGC_GET_FLAG_VALUE
#include "Probe/Assertion.h"                             // for IGC_ASSERT_MESSAGE
#include "AdaptorCommon/RayTracing/MemRegionAnalysis.h"  // for getRTRegion(), RTMemRegion

#include "common/LLVMWarningsPush.hpp"                   // for suppressing LLVM warnings
#include "llvm/ADT/Optional.h"                           // for llvm::Optional
#include "llvm/IR/Instruction.h"                         // for llvm::Instruction
#include "llvm/IR/Instructions.h"                        // for llvm::StoreInst, llvm::LoadInst
#include "common/LLVMWarningsPop.hpp"                    // for suppressing LLVM warnings

#include "getCacheOpts.h"

using namespace llvm;

namespace IGC {

/**
 * @return the store cache policy for the RTStack
 */
LSC_L1_L3_CC RTStackStorePolicy()
{
    LSC_L1_L3_CC cacheOpts = LSC_L1IAR_WB_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceRTStackStoreCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(RTStackStoreCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

/**
 * @return the store cache policy for the SWHotZone
 */
LSC_L1_L3_CC SWHotZoneStorePolicy()
{
    LSC_L1_L3_CC cacheOpts = LSC_L1IAR_WB_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceSWHotZoneStoreCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(SWHotZoneStoreCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

/**
 * @return the store cache policy for the SWStack
 */
LSC_L1_L3_CC SWStackStorePolicy(const CodeGenContext &Ctx)
{
    LSC_L1_L3_CC cacheOpts = Ctx.platform.NeedsLSCFenceUGMBeforeEOT() ?
        LSC_L1S_L3C_WB :
        LSC_L1UC_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceSWStackStoreCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(SWStackStoreCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

/**
 * @return the load cache policy for the RTStack
 */
LSC_L1_L3_CC RTStackLoadPolicy()
{
    LSC_L1_L3_CC cacheOpts = LSC_L1C_WT_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceRTStackLoadCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(RTStackLoadCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

/**
 * @return the load cache policy for the SWHotZone
 */
LSC_L1_L3_CC SWHotZoneLoadPolicy()
{
    LSC_L1_L3_CC cacheOpts = LSC_L1C_WT_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceSWHotZoneLoadCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(SWHotZoneLoadCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

/**
 * @return the load cache policy for the SWStack
 */
LSC_L1_L3_CC SWStackLoadPolicy()
{
    LSC_L1_L3_CC cacheOpts = LSC_L1UC_L3C_WB;

    if (IGC_IS_FLAG_ENABLED(ForceSWStackLoadCacheCtrl))
    {
        cacheOpts = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(SWStackLoadCacheCtrl);

        IGC_ASSERT_MESSAGE(cacheOpts < LSC_CC_INVALID, "Invalid Custom LSC Cache Control Set");
    }

    return cacheOpts;
}

Optional<LSC_L1_L3_CC> getCacheOptsStorePolicy(
    const Value* Ptr,
    const CodeGenContext &Ctx)
{
    auto Region = getRTRegion(Ptr, *Ctx.getModuleMetaData());

    if (!Region)
        return None;

    Optional<LSC_L1_L3_CC> cacheOpts;

    switch (*Region)
    {
    case RTMemRegion::RTAsyncStack:
    case RTMemRegion::RTSyncStack:
        cacheOpts = RTStackStorePolicy();
        break;
    case RTMemRegion::SWStack:
        cacheOpts = SWStackStorePolicy(Ctx);
        break;
    case RTMemRegion::SWHotZone:
        cacheOpts = SWHotZoneStorePolicy();
        break;
    default:
        break;
    }

    return cacheOpts;
}

Optional<LSC_L1_L3_CC> getCacheOptsStorePolicy(
    const StoreInst& storeInst,
    const CodeGenContext &Ctx)
{
    return getCacheOptsStorePolicy(storeInst.getPointerOperand(), Ctx);
}

Optional<LSC_L1_L3_CC> getCacheOptsLoadPolicy(
    const Value* Ptr,
    const CodeGenContext &Ctx)
{
    auto Region = getRTRegion(Ptr, *Ctx.getModuleMetaData());

    if (!Region)
        return None;

    Optional<LSC_L1_L3_CC> cacheOpts;

    switch (*Region)
    {
    case RTMemRegion::RTAsyncStack:
    case RTMemRegion::RTSyncStack:
        cacheOpts = RTStackLoadPolicy();
        break;
    case RTMemRegion::SWStack:
        cacheOpts = SWStackLoadPolicy();
        break;
    case RTMemRegion::SWHotZone:
        cacheOpts = SWHotZoneLoadPolicy();
        break;
    default:
        break;
    }

    return cacheOpts;
}

Optional<LSC_L1_L3_CC> getCacheOptsLoadPolicy(
    const LoadInst& loadInst,
    const CodeGenContext &Ctx)
{
    return getCacheOptsLoadPolicy(loadInst.getPointerOperand(), Ctx);
}

} // namespace IGC