[llvm] [DirectX] Infrastructure to collect shader flags for each function (PR #112967)
Chris B via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 13:39:23 PST 2024
================
@@ -13,36 +13,79 @@
#include "DXILShaderFlags.h"
#include "DirectX.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::dxil;
-static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I) {
- Type *Ty = I.getType();
- if (Ty->isDoubleTy()) {
- Flags.Doubles = true;
+namespace {
+/// A simple Wrapper DiagnosticInfo that generates Module-level diagnostic
+/// for Shader Flags Analysis pass
+class DiagnosticInfoShaderFlags : public DiagnosticInfo {
+private:
+ const Twine &Msg;
+ const Module &Mod;
+
+public:
+ /// \p M is the module for which the diagnostic is being emitted. \p Msg is
+ /// the message to show. Note that this class does not copy this message, so
+ /// this reference must be valid for the whole life time of the diagnostic.
+ DiagnosticInfoShaderFlags(const Module &M, const Twine &Msg,
+ DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfo(DK_Unsupported, Severity), Msg(Msg), Mod(M) {}
+
+ void print(DiagnosticPrinter &DP) const override {
+ DP << Mod.getName() << ": " << Msg << '\n';
+ }
+};
+} // namespace
+
+void DXILModuleShaderFlagsInfo::updateFunctionFlags(ComputedShaderFlags &CSF,
+ const Instruction &I) {
+ if (!CSF.Doubles) {
+ CSF.Doubles = I.getType()->isDoubleTy();
+ }
----------------
llvm-beanz wrote:
nit: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
```suggestion
if (!CSF.Doubles)
CSF.Doubles = I.getType()->isDoubleTy();
```
https://github.com/llvm/llvm-project/pull/112967
More information about the llvm-commits
mailing list