|
17 | 17 | #include "llvm/ADT/SmallVector.h" |
18 | 18 | #include "llvm/Analysis/CallGraph.h" |
19 | 19 | #include "llvm/Analysis/DXILResource.h" |
| 20 | +#include "llvm/IR/Attributes.h" |
| 21 | +#include "llvm/IR/DiagnosticInfo.h" |
20 | 22 | #include "llvm/IR/Instruction.h" |
21 | 23 | #include "llvm/IR/Instructions.h" |
22 | 24 | #include "llvm/IR/IntrinsicInst.h" |
@@ -96,7 +98,8 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF, |
96 | 98 | } |
97 | 99 |
|
98 | 100 | /// Construct ModuleShaderFlags for module Module M |
99 | | -void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM) { |
| 101 | +void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, |
| 102 | + const ModuleMetadataInfo &MMDI) { |
100 | 103 | CallGraph CG(M); |
101 | 104 |
|
102 | 105 | // Compute Shader Flags Mask for all functions using post-order visit of SCC |
@@ -142,6 +145,20 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM) { |
142 | 145 | // Merge SCCSF with that of F |
143 | 146 | FunctionFlags[F].merge(SCCSF); |
144 | 147 | } |
| 148 | + |
| 149 | + // Set DisableOptimizations flag based on the presence of OptimizeNone |
| 150 | + // attribute of entry functions. |
| 151 | + if (MMDI.EntryPropertyVec.size() > 0) { |
| 152 | + CombinedSFMask.DisableOptimizations = |
| 153 | + MMDI.EntryPropertyVec[0].Entry->hasFnAttribute( |
| 154 | + llvm::Attribute::OptimizeNone); |
| 155 | + // Ensure all entry functions have the same optimization attribute |
| 156 | + for (const auto &EntryFunProps : MMDI.EntryPropertyVec) |
| 157 | + if (CombinedSFMask.DisableOptimizations != |
| 158 | + EntryFunProps.Entry->hasFnAttribute(llvm::Attribute::OptimizeNone)) |
| 159 | + EntryFunProps.Entry->getContext().diagnose(DiagnosticInfoUnsupported( |
| 160 | + *(EntryFunProps.Entry), "Inconsistent optnone attribute ")); |
| 161 | + } |
145 | 162 | } |
146 | 163 |
|
147 | 164 | void ComputedShaderFlags::print(raw_ostream &OS) const { |
@@ -180,9 +197,10 @@ AnalysisKey ShaderFlagsAnalysis::Key; |
180 | 197 | ModuleShaderFlags ShaderFlagsAnalysis::run(Module &M, |
181 | 198 | ModuleAnalysisManager &AM) { |
182 | 199 | DXILResourceTypeMap &DRTM = AM.getResult<DXILResourceTypeAnalysis>(M); |
| 200 | + const ModuleMetadataInfo MMDI = AM.getResult<DXILMetadataAnalysis>(M); |
183 | 201 |
|
184 | 202 | ModuleShaderFlags MSFI; |
185 | | - MSFI.initialize(M, DRTM); |
| 203 | + MSFI.initialize(M, DRTM, MMDI); |
186 | 204 |
|
187 | 205 | return MSFI; |
188 | 206 | } |
@@ -212,20 +230,24 @@ PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M, |
212 | 230 | bool ShaderFlagsAnalysisWrapper::runOnModule(Module &M) { |
213 | 231 | DXILResourceTypeMap &DRTM = |
214 | 232 | getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap(); |
| 233 | + const ModuleMetadataInfo MMDI = |
| 234 | + getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata(); |
215 | 235 |
|
216 | | - MSFI.initialize(M, DRTM); |
| 236 | + MSFI.initialize(M, DRTM, MMDI); |
217 | 237 | return false; |
218 | 238 | } |
219 | 239 |
|
220 | 240 | void ShaderFlagsAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const { |
221 | 241 | AU.setPreservesAll(); |
222 | 242 | AU.addRequiredTransitive<DXILResourceTypeWrapperPass>(); |
| 243 | + AU.addRequired<DXILMetadataAnalysisWrapperPass>(); |
223 | 244 | } |
224 | 245 |
|
225 | 246 | char ShaderFlagsAnalysisWrapper::ID = 0; |
226 | 247 |
|
227 | 248 | INITIALIZE_PASS_BEGIN(ShaderFlagsAnalysisWrapper, "dx-shader-flag-analysis", |
228 | 249 | "DXIL Shader Flag Analysis", true, true) |
229 | 250 | INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass) |
| 251 | +INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass) |
230 | 252 | INITIALIZE_PASS_END(ShaderFlagsAnalysisWrapper, "dx-shader-flag-analysis", |
231 | 253 | "DXIL Shader Flag Analysis", true, true) |
0 commit comments