[llvm] [DirectX] Infrastructure to collect shader flags for each function (PR #112967)
Damyan Pepper via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 09:18:10 PDT 2024
================
@@ -13,43 +13,114 @@
#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/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::dxil;
-static void updateFlags(DXILModuleShaderFlagsInfo &MSFI, const Instruction &I) {
- ComputedShaderFlags &FSF = MSFI.FuncShaderFlagsMap[I.getFunction()];
+namespace {
+/// A simple Wrapper DiagnosticInfo that generates Module-level diagnostic
+/// for ShaderFlagsAnalysis 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
+
+static void updateFlags(ComputedShaderFlags &CSF, const Instruction &I) {
Type *Ty = I.getType();
- if (Ty->isDoubleTy()) {
- FSF.Doubles = true;
+ bool DoubleTyInUse = Ty->isDoubleTy();
+ for (Value *Op : I.operands()) {
+ DoubleTyInUse |= Op->getType()->isDoubleTy();
+ }
+
+ if (DoubleTyInUse) {
+ CSF.Doubles = true;
switch (I.getOpcode()) {
case Instruction::FDiv:
case Instruction::UIToFP:
case Instruction::SIToFP:
case Instruction::FPToUI:
case Instruction::FPToSI:
- FSF.DX11_1_DoubleExtensions = true;
+ // TODO: To be set if I is a call to DXIL intrinsic DXIL::Opcode::Fma
+ CSF.DX11_1_DoubleExtensions = true;
break;
}
}
}
+static bool compareFuncSFPairs(const FuncShaderFlagsMask &First,
+ const FuncShaderFlagsMask &Second) {
+ // Construct string representation of the functions in each pair
+ // as "retTypefunctionNamearg1Typearg2Ty..." where the function signature is
+ // retType functionName(arg1Type, arg2Ty,...). Spaces, braces and commas are
+ // omitted in the string representation of the signature. This allows
+ // determining a consistent lexicographical order of all functions by their
+ // signatures.
+ std::string FirstFunSig;
+ std::string SecondFunSig;
----------------
damyanp wrote:
Constructing strings in the comparison function like rings all sorts of alarm bells to me. I'd expect the overhead of doing this would far outweigh any potential savings of keeping the container sorted. Am I missing something that means this isn't as inefficient as it looks to be at first glance?
https://github.com/llvm/llvm-project/pull/112967
More information about the llvm-commits
mailing list