[llvm-branch-commits] [DXIL][Analysis] Replace #include with forward declaration. NFC (PR #100622)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100622

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make the DXILResource binding optional. NFC (PR #100623)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100623

This makes the binding structure in a DXILResource default to empty
and need a separate call to set up, and also moves the unique ID into
it since bindings are the only place where those are actually used.

This will put us in a better position when dealing with resource
handles in libraries.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Replace #include with forward declaration. NFC (PR #100622)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100622


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Replace #include with forward declaration. NFC (PR #100622)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100622


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make the DXILResource binding optional. NFC (PR #100623)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100623


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make the DXILResource binding optional. NFC (PR #100623)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100623


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100697

HLSL allows StructuredBuffer<> to be defined with scalar or
up-to-4-element vectors as well as with structs, but when doing so
`dxc` doesn't set the alignment. Emulate this behaviour.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Remove new-pm versions of DXILResource passes. NFC (PR #100698)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100698

This is a bit of a hack, but these aren't actually used at the moment
and they'll cause naming conflicts with DXIL resource passes that I'm
adding to llvm/Analysis for replacing all of this with the target
extension type based solution. I'd rather leave the existing stuff in
place until we're ready to replace it completely, and this is the
simplest way to get away with that.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100699

This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and
`dx.RawBuffer` types. This should be sufficient to lower
`dx.handle.fromBinding` for this set of types, but it leaves a number
of TODOs around for other resource types.

This also includes a straightforward `print` method in `ResourceInfo`
to make the analysis testable. This is deliberately different than the
printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to
print bindings in a format compatible with the comments `dxc` prints.
We will eventually want to make that functionality driven by this
analysis pass, but it isn't sufficient for testing so we need both.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass (PR #100700)

2024-07-25 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/100700

Broke this out into its own commit to make the next one easier to
review.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-27 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100697


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-27 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100697


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-27 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/100697
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-29 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100697


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-29 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100697


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-29 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();

bogner wrote:

No, `Type::getScalarType` cannot return nullptr.

https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-29 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();
+
+  if (Ty->isIntegerTy()) {
+switch (Ty->getIntegerBitWidth()) {
+case 16:
+  return IsSigned ? ElementType::I16 : ElementType::U16;
+case 32:
+  return IsSigned ? ElementType::I32 : ElementType::U32;
+case 64:
+  return IsSigned ? ElementType::I64 : ElementType::U64;
+case 1:
+default:
+  return ElementType::Invalid;
+}
+  } else if (Ty->isFloatTy()) {
+return ElementType::F32;
+  } else if (Ty->isDoubleTy()) {
+return ElementType::F64;
+  } else if (Ty->isHalfTy()) {
+return ElementType::F16;
+  }
+
+  return ElementType::Invalid;
+}
+
+namespace {
+
+class ResourceMapper {
+  Module &M;
+  LLVMContext &Context;
+  DXILResourceMap &Resources;
+
+  // Unique ID is per resource type to match DXC.
+  uint32_t NextUAV = 0;
+  uint32_t NextSRV = 0;
+  uint32_t NextCBuf = 0;
+  uint32_t NextSmp = 0;

bogner wrote:

This is the "Unique resource record ID" in the [DXIL resource 
metadata](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#metadata-resource-records).
 I'll go ahead and rename it to "RecordID" to make this a bit clearer.

https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-29 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();
+
+  if (Ty->isIntegerTy()) {
+switch (Ty->getIntegerBitWidth()) {
+case 16:
+  return IsSigned ? ElementType::I16 : ElementType::U16;
+case 32:
+  return IsSigned ? ElementType::I32 : ElementType::U32;
+case 64:
+  return IsSigned ? ElementType::I64 : ElementType::U64;
+case 1:
+default:
+  return ElementType::Invalid;
+}
+  } else if (Ty->isFloatTy()) {
+return ElementType::F32;
+  } else if (Ty->isDoubleTy()) {
+return ElementType::F64;
+  } else if (Ty->isHalfTy()) {
+return ElementType::F16;
+  }
+
+  return ElementType::Invalid;
+}
+
+namespace {
+
+class ResourceMapper {
+  Module &M;
+  LLVMContext &Context;
+  DXILResourceMap &Resources;
+
+  // Unique ID is per resource type to match DXC.
+  uint32_t NextUAV = 0;
+  uint32_t NextSRV = 0;
+  uint32_t NextCBuf = 0;
+  uint32_t NextSmp = 0;
+
+public:
+  ResourceMapper(Module &M,
+ MapVector &Resources)
+  : M(M), Context(M.getContext()), Resources(Resources) {}
+
+  void diagnoseHandle(CallInst *CI, const Twine &Msg,
+  DiagnosticSeverity Severity = DS_Error) {
+std::string S;
+raw_string_ostream SS(S);
+CI->printAsOperand(SS);
+DiagnosticInfoUnsupported Diag(*CI->getFunction(), Msg + ": " + SS.str(),
+   CI->getDebugLoc(), Severity);
+Context.diagnose(Diag);
+  }
+
+  ResourceInfo *mapBufferType(CallInst *CI, TargetExtType *HandleTy,
+  bool IsTyped) {
+if (HandleTy->getNumTypeParameters() != 1 ||
+HandleTy->getNumIntParameters() != (IsTyped ? 3 : 2)) {
+  diagnoseHandle(CI, Twine("Invalid buffer target type"));
+  return nullptr;
+}
+
+Type *ElTy = HandleTy->getTypeParameter(0);
+unsigned IsWriteable = HandleTy->getIntParameter(0);
+unsigned IsROV = HandleTy->getIntParameter(1);
+bool IsSigned = IsTyped && HandleTy->getIntParameter(2);
+
+ResourceClass RC = IsWriteable ? ResourceClass::UAV : ResourceClass::SRV;
+ResourceKind Kind;
+if (IsTyped)
+  Kind = ResourceKind::TypedBuffer;
+else if (ElTy->isIntegerTy(8))
+  Kind = ResourceKind::RawBuffer;
+else
+  Kind = ResourceKind::StructuredBuffer;
+
+// TODO: We need to lower to a typed pointer, can we smuggle the type
+// through?
+Value *Symbol = UndefValue::get(PointerType::getUnqual(Context));
+// TODO: We don't actually keep track of the name right now...
+StringRef Name = "";
+
+auto [It, Success] = Resources.try_emplace(CI, RC, Kind, Symbol, Name);
+assert(Success && "Mapping the same CallInst again?");
+(void)Success;
+// We grab a pointer into the map's storage, which isn't generally safe.
+// Since we're just using this to fill in the info the map won't mutate and
+// the pointer stays valid for as long as we need it to.
+ResourceInfo *RI = &(It->second);
+
+if (RI->isUAV())
+  // TODO: We need analysis for GloballyCoherent and HasCounter
+  RI->setUAV(false, false, IsROV);
+
+if (RI->isTyped()) {
+  dxil::ElementType ET = toDXILElementType(ElTy, IsSigned

[llvm-branch-commits] [DirectX] Simplify tablegen'd OpCode and OpClass enums (PR #101249)

2024-07-30 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/101249

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-30 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/101250

This adjusts the DXILOpBuilder API in a couple of ways:
1. Remove the need to call `getOverloadTy` before creating Ops
2. Introduce `tryCreateOp` to parallel `createOp` but propagate errors
3. Introduce specialized createOp methods for each DXIL Op

This will simplify usage of the builder in upcoming changes, and also allows us
to propagate errors via DiagnosticInfo rather than using fatal errors.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-30 Thread Justin Bogner via llvm-branch-commits


@@ -151,7 +151,11 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
 assert(knownType && "Specification of multiple differing overload "
 "parameter types not yet supported");
   } else {
-OverloadParamIndices.push_back(i);
+// Skip the return value - nothing is overloaded on only return, and it

bogner wrote:

That's a good point. This should still happen to work since we treat "not 
overloaded" and "overloaded on return type" the same for the purposes of 
overloadKind in tryCreateOp, and I've updated the comment to say so.

The right thing to do, which I think should be done in a follow up, is to 
generate a table of the function signatures per opcode, which can then be 
queried by a simple switch over those records. I think we'll need that soon any 
way so I'll do that shortly.

https://github.com/llvm/llvm-project/pull/101250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-30 Thread Justin Bogner via llvm-branch-commits


@@ -151,7 +151,11 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
 assert(knownType && "Specification of multiple differing overload "
 "parameter types not yet supported");
   } else {
-OverloadParamIndices.push_back(i);
+// Skip the return value - nothing is overloaded on only return, and it

bogner wrote:

Thinking about this some more I don't think we can get away with this - if an 
op is overloaded on return type we simply need to provide the one we want. I 
think I'll add a `Type *` argument that's defaulted to null for "infer it" and 
return an error if we can't do so.

https://github.com/llvm/llvm-project/pull/101250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-30 Thread Justin Bogner via llvm-branch-commits


@@ -151,7 +151,11 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
 assert(knownType && "Specification of multiple differing overload "
 "parameter types not yet supported");
   } else {
-OverloadParamIndices.push_back(i);
+// Skip the return value - nothing is overloaded on only return, and it

bogner wrote:

Fixed in latest.

https://github.com/llvm/llvm-project/pull/101250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-30 Thread Justin Bogner via llvm-branch-commits


@@ -289,24 +289,25 @@ static ShaderKind 
getShaderKindEnum(Triple::EnvironmentType EnvType) {
 ///   its specification in DXIL.td.
 /// \param OverloadTy Return type to be used to construct DXIL function type.

bogner wrote:

Removed the parameters from the comment

https://github.com/llvm/llvm-project/pull/101250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Simplify tablegen'd OpCode and OpClass enums (PR #101249)

2024-07-30 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/101249


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Simplify tablegen'd OpCode and OpClass enums (PR #101249)

2024-07-30 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/101249


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Make DXILOpBuilder's API more useable (PR #101250)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

> I do not see the invocation of any of the newly created functions in `class 
> DXILOpbuilder` specific to DXIL Ops `create##Name##Op(...)` or 
> `tryCreate##Name##Op(...)` (for example `createSinSin13()` or 
> `tryCreateSin13()` when lowering `llvm.sin.*`). Are these in preparation for 
> upcoming changes?

The intention is to make it a little bit cleaner when we do custom lowering, so 
that we can call `Builder->createCreateHandleFromBindingOp(...)` directly 
rather than having to do something like 
`Builder->createOp(DXILOp::CreateHandleFromBinding, ...)`.

> It appears that macro defs `DXIL_OPCODE` are generated in `DXILEmitter` with 
> its definition is in `DXILOpBuilder.h`. Would you consider generating the 
> `tryCreate(...)` and `create(...)` for each of DXIL 
> Ops in `DXILEmitter`, instead, to keep the entire function generation 
> functionality in a single place i.e., `DXILEmitter`?

I don't understand the suggestion. If you're saying we should emit the full 
text of the declarations from DXILEmitter rather than the table of simple 
macros then I disagree with that approach - generating full fledged C++ 
snippets from tablegen should be avoided when possible, as it's quite a bit 
harder to see what's happening when it's done that way.

https://github.com/llvm/llvm-project/pull/101250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";

bogner wrote:

I've done this in the latest. Note that I put the functions to translate to 
names as statics in this file rather than somewhere that would be accessible to 
others. There's an argument that we might want to move some or all of that into 
DXILABI.h or something, but given that this (and the old Resource analysis its 
replacing) are the only places that currently use the strings this seemed like 
the best choice for now.

https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass (PR #100700)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100700


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass (PR #100700)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100700


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Remove new-pm versions of DXILResource passes. NFC (PR #100698)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner closed 
https://github.com/llvm/llvm-project/pull/100698
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Remove new-pm versions of DXILResource passes. NFC (PR #100698)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Turns out I was wrong and this *does not* effectively avoid the naming 
collisions. Tried again here: #101393

https://github.com/llvm/llvm-project/pull/100698
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();
+
+  if (Ty->isIntegerTy()) {
+switch (Ty->getIntegerBitWidth()) {
+case 16:
+  return IsSigned ? ElementType::I16 : ElementType::U16;
+case 32:
+  return IsSigned ? ElementType::I32 : ElementType::U32;
+case 64:
+  return IsSigned ? ElementType::I64 : ElementType::U64;
+case 1:
+default:
+  return ElementType::Invalid;
+}
+  } else if (Ty->isFloatTy()) {
+return ElementType::F32;
+  } else if (Ty->isDoubleTy()) {
+return ElementType::F64;
+  } else if (Ty->isHalfTy()) {
+return ElementType::F16;
+  }
+
+  return ElementType::Invalid;
+}
+
+namespace {
+
+class ResourceMapper {
+  Module &M;
+  LLVMContext &Context;
+  DXILResourceMap &Resources;
+
+  // Unique ID is per resource type to match DXC.
+  uint32_t NextUAV = 0;
+  uint32_t NextSRV = 0;
+  uint32_t NextCBuf = 0;
+  uint32_t NextSmp = 0;
+
+public:
+  ResourceMapper(Module &M,
+ MapVector &Resources)
+  : M(M), Context(M.getContext()), Resources(Resources) {}
+
+  void diagnoseHandle(CallInst *CI, const Twine &Msg,
+  DiagnosticSeverity Severity = DS_Error) {
+std::string S;
+raw_string_ostream SS(S);
+CI->printAsOperand(SS);
+DiagnosticInfoUnsupported Diag(*CI->getFunction(), Msg + ": " + SS.str(),
+   CI->getDebugLoc(), Severity);
+Context.diagnose(Diag);
+  }
+
+  ResourceInfo *mapBufferType(CallInst *CI, TargetExtType *HandleTy,
+  bool IsTyped) {
+if (HandleTy->getNumTypeParameters() != 1 ||
+HandleTy->getNumIntParameters() != (IsTyped ? 3 : 2)) {
+  diagnoseHandle(CI, Twine("Invalid buffer target type"));
+  return nullptr;
+}
+
+Type *ElTy = HandleTy->getTypeParameter(0);
+unsigned IsWriteable = HandleTy->getIntParameter(0);
+unsigned IsROV = HandleTy->getIntParameter(1);
+bool IsSigned = IsTyped && HandleTy->getIntParameter(2);
+
+ResourceClass RC = IsWriteable ? ResourceClass::UAV : ResourceClass::SRV;
+ResourceKind Kind;
+if (IsTyped)
+  Kind = ResourceKind::TypedBuffer;
+else if (ElTy->isIntegerTy(8))
+  Kind = ResourceKind::RawBuffer;
+else
+  Kind = ResourceKind::StructuredBuffer;
+
+// TODO: We need to lower to a typed pointer, can we smuggle the type
+// through?
+Value *Symbol = UndefValue::get(PointerType::getUnqual(Context));
+// TODO: We don't actually keep track of the name right now...
+StringRef Name = "";
+
+auto [It, Success] = Resources.try_emplace(CI, RC, Kind, Symbol, Name);
+assert(Success && "Mapping the same CallInst again?");
+(void)Success;
+// We grab a pointer into the map's storage, which isn't generally safe.
+// Since we're just using this to fill in the info the map won't mutate and
+// the pointer stays valid for as long as we need it to.
+ResourceInfo *RI = &(It->second);
+
+if (RI->isUAV())
+  // TODO: We need analysis for GloballyCoherent and HasCounter
+  RI->setUAV(false, false, IsROV);
+
+if (RI->isTyped()) {
+  dxil::ElementType ET = toDXILElementType(ElTy, IsSigned

[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-31 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-01 Thread Justin Bogner via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();
+
+  if (Ty->isIntegerTy()) {
+switch (Ty->getIntegerBitWidth()) {
+case 16:
+  return IsSigned ? ElementType::I16 : ElementType::U16;
+case 32:
+  return IsSigned ? ElementType::I32 : ElementType::U32;
+case 64:
+  return IsSigned ? ElementType::I64 : ElementType::U64;
+case 1:
+default:
+  return ElementType::Invalid;
+}
+  } else if (Ty->isFloatTy()) {
+return ElementType::F32;
+  } else if (Ty->isDoubleTy()) {
+return ElementType::F64;
+  } else if (Ty->isHalfTy()) {
+return ElementType::F16;
+  }
+
+  return ElementType::Invalid;
+}
+
+namespace {
+
+class ResourceMapper {
+  Module &M;
+  LLVMContext &Context;
+  DXILResourceMap &Resources;
+
+  // Unique ID is per resource type to match DXC.
+  uint32_t NextUAV = 0;
+  uint32_t NextSRV = 0;
+  uint32_t NextCBuf = 0;
+  uint32_t NextSmp = 0;
+
+public:
+  ResourceMapper(Module &M,
+ MapVector &Resources)
+  : M(M), Context(M.getContext()), Resources(Resources) {}
+
+  void diagnoseHandle(CallInst *CI, const Twine &Msg,
+  DiagnosticSeverity Severity = DS_Error) {
+std::string S;
+raw_string_ostream SS(S);
+CI->printAsOperand(SS);
+DiagnosticInfoUnsupported Diag(*CI->getFunction(), Msg + ": " + SS.str(),
+   CI->getDebugLoc(), Severity);
+Context.diagnose(Diag);
+  }
+
+  ResourceInfo *mapBufferType(CallInst *CI, TargetExtType *HandleTy,
+  bool IsTyped) {
+if (HandleTy->getNumTypeParameters() != 1 ||
+HandleTy->getNumIntParameters() != (IsTyped ? 3 : 2)) {
+  diagnoseHandle(CI, Twine("Invalid buffer target type"));
+  return nullptr;
+}
+
+Type *ElTy = HandleTy->getTypeParameter(0);
+unsigned IsWriteable = HandleTy->getIntParameter(0);
+unsigned IsROV = HandleTy->getIntParameter(1);
+bool IsSigned = IsTyped && HandleTy->getIntParameter(2);
+
+ResourceClass RC = IsWriteable ? ResourceClass::UAV : ResourceClass::SRV;
+ResourceKind Kind;
+if (IsTyped)
+  Kind = ResourceKind::TypedBuffer;
+else if (ElTy->isIntegerTy(8))
+  Kind = ResourceKind::RawBuffer;
+else
+  Kind = ResourceKind::StructuredBuffer;
+
+// TODO: We need to lower to a typed pointer, can we smuggle the type
+// through?
+Value *Symbol = UndefValue::get(PointerType::getUnqual(Context));
+// TODO: We don't actually keep track of the name right now...
+StringRef Name = "";
+
+auto [It, Success] = Resources.try_emplace(CI, RC, Kind, Symbol, Name);
+assert(Success && "Mapping the same CallInst again?");
+(void)Success;
+// We grab a pointer into the map's storage, which isn't generally safe.
+// Since we're just using this to fill in the info the map won't mutate and
+// the pointer stays valid for as long as we need it to.
+ResourceInfo *RI = &(It->second);
+
+if (RI->isUAV())
+  // TODO: We need analysis for GloballyCoherent and HasCounter
+  RI->setUAV(false, false, IsROV);
+
+if (RI->isTyped()) {
+  dxil::ElementType ET = toDXILElementType(ElTy, IsSigned

[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-01 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-02 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-02 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass (PR #100700)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100700


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass (PR #100700)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100700


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/100699


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Revert specialized createOp methods part of #101250 (PR #104245)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104245

In 8cf85653b6f5 "[DirectX] Make DXILOpBuilder's API more useable" we introduced
specialized createOp methods for each DirectX op for convenience, but the API
is buggy and untested. It also isn't actually as useful as I imagined it would
be since we don't have argument names or const-ness represented in DXIL.td
currently. Remove these methods for now and we can reintroduce them if we
actually need them later.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104247

LLVMType is both too broad and too narrow for defining DXIL operations, in
different ways. It's too broad in the sense that we don't need the full set of
MVTs - the set of types DXIL operations work on is much smaller. It's too
narrow in the sense that it's difficult to use it for the various fixed
structure types in DXIL, like `%dx.types.Handle` or `%dx.Types.ResRet.f32`.

Replace the usage of LLVMType in DXIL.td with DXILOpParamType, a simple class
that we can define an enum of types from. Further, use this to replace the
"ParameterKind" enum in DXILABI.h that has nothing to do with DXIL's ABI.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Differentiate between 0/1 overloads in the OpBuilder. NFC (PR #104246)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104246

DXIL operations that only have one signature behave one of two ways - either
they are always suffixed with a type like `dx.op.ThreadId.i32` and hence have
exactly one overload, or they're never suffixed like `dx.op.CreateHandle` and
hence have zero overloads.

Update DXIL.td for operations that have one overload and remove the hack in the
builder that was adjusting names for unoverloaded ops.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Encapsulate DXILOpLowering's state into a class. NFC (PR #104248)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104248

This introduces an anonymous class "OpLowerer" to help with lowering DXIL ops,
and moves the DXILOpBuilder there instead of creating a new one for every
operation. DXILOpBuilder is also changed to own its IRBuilder, since that makes
it simpler to ensure that it isn't misused.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Use a more consistent pass name for DXILTranslateMetadata (PR #104249)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104249

This updates the "dxil-metadata-emit" pass flag to be spelled
"dxil-translate-metadata" to better match the pass name.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104250

This wires up dxil-op-lower, dxil-intrinsic-expansion, dxil-translate-metadata,
and dxil-pretty-printer to the new pass manager, both as a matter of future
proofing the backend and so that they can be used more flexibly in tests.

A few arbitrary tests are updated in order to test the new PM path, and we drop
the "print-dxil-resource-md" pass since it's redundant with the pretty printer.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104251

The `@llvm.dx.handle.fromBinding` intrinsic is lowered either to the
`CreateHandle` op or a pair of `CreateHandleFromBinding` and `AnnotateHandle`
ops, depending on the DXIL version. Regardless of the DXIL version we need to
emit metadata about the binding, but that's left to a separate change.

These DXIL ops all need to return the `%dx.types.Handle` type, but the llvm
intrinsic returns a target extension type. To facilitate changing the type of
the operation and all of its users, we introduce `%llvm.dx.cast.handle`, which
can cast between the two handle representations.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferLoad` to DXIL ops (PR #104252)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104252

The `@llvm.dx.typedBufferLoad` intrinsic is lowered to `@dx.op.bufferLoad`.
There's some complexity here due to translating from a vector return type to a
named struct and trying to avoid excessive IR coming out of that.

Note that this change includes a bit of a hack in how it deals with
`getOverloadKind` for the `dx.ResRet` types - we need to adjust how we deal
with operation overloads to generate a table directly rather than proxy through
the OverloadKind enum, but that's left for a later change here.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104253

The `@llvm.dx.typedBufferStore` intrinsic is lowered to `@dx.op.bufferStore`.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104248 

https://github.com/llvm/llvm-project/pull/104250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104246, #104247, and #104248

https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferLoad` to DXIL ops (PR #104252)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104251

https://github.com/llvm/llvm-project/pull/104252
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104252

https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104247
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferLoad` to DXIL ops (PR #104252)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104252
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-14 Thread Justin Bogner via llvm-branch-commits


@@ -23,7 +23,10 @@ MODULE_ANALYSIS("dxil-resource-md", DXILResourceMDAnalysis())
 #ifndef MODULE_PASS
 #define MODULE_PASS(NAME, CREATE_PASS)
 #endif
+MODULE_PASS("dxil-intrinsic-expansion", DXILIntrinsicExpansion())
+MODULE_PASS("dxil-op-lower", DXILOpLowering())
+MODULE_PASS("dxil-pretty-printer", DXILPrettyPrinterPass(dbgs()))
+MODULE_PASS("dxil-translate-metadata", DXILTranslateMetadata())
 // TODO: rename to print after NPM switch
 MODULE_PASS("print-dx-shader-flags", dxil::ShaderFlagsAnalysisPrinter(dbgs()))
-MODULE_PASS("print-dxil-resource-md", DXILResourceMDPrinterPass(dbgs()))

bogner wrote:

Yes we should. I currently have that as part of this change that isn't quite 
ready for review yet: 
https://github.com/bogner/llvm-project/commit/bed151261c5b26519f6e44c44631cc1f770dfd78

Maybe I should pull the deletion into this PR instead?

https://github.com/llvm/llvm-project/pull/104250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-14 Thread Justin Bogner via llvm-branch-commits


@@ -0,0 +1,63 @@
+; RUN: opt -S -dxil-op-lower %s | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+define void @test_bindings() {
+  ; RWBuffer Buf : register(u5, space3)
+  %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
+  @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0(
+  i32 3, i32 5, i32 1, i32 4, i1 false)
+  ; CHECK: [[BUF0:%[0-9]*]] = call %dx.types.Handle 
@dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 5, i32 5, i32 
3, i8 1 }, i32 4, i1 false)
+  ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, 
%dx.types.Handle [[BUF0]], %dx.types.ResourceProperties { i32 4106, i32 1033 })
+
+  ; RWBuffer Buf : register(u7, space2)
+  %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1)
+  @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0_0t(
+  i32 2, i32 7, i32 1, i32 6, i1 false)
+  ; CHECK: [[BUF1:%[0-9]*]] = call %dx.types.Handle 
@dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 7, i32 7, i32 
2, i8 1 }, i32 6, i1 false)
+  ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, 
%dx.types.Handle [[BUF1]], %dx.types.ResourceProperties { i32 4106, i32 260 })
+
+  ; Buffer Buf[24] : register(t3, space5)
+  %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)

bogner wrote:

You can see it in the `createHandleFromBinding` call below, though it looks 
more like math there:
```
%dx.types.ResBind { i32 7, i32 30, i32 2, i8 0 }
```
Here we have a resource binding with a lower bound of 7 and an upper bound of 
30 - ie, a size of 24.

https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-14 Thread Justin Bogner via llvm-branch-commits


@@ -23,7 +23,10 @@ MODULE_ANALYSIS("dxil-resource-md", DXILResourceMDAnalysis())
 #ifndef MODULE_PASS
 #define MODULE_PASS(NAME, CREATE_PASS)
 #endif
+MODULE_PASS("dxil-intrinsic-expansion", DXILIntrinsicExpansion())
+MODULE_PASS("dxil-op-lower", DXILOpLowering())
+MODULE_PASS("dxil-pretty-printer", DXILPrettyPrinterPass(dbgs()))
+MODULE_PASS("dxil-translate-metadata", DXILTranslateMetadata())
 // TODO: rename to print after NPM switch
 MODULE_PASS("print-dx-shader-flags", dxil::ShaderFlagsAnalysisPrinter(dbgs()))
-MODULE_PASS("print-dxil-resource-md", DXILResourceMDPrinterPass(dbgs()))

bogner wrote:

I've pulled the removal of the pass into this change.

https://github.com/llvm/llvm-project/pull/104250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-14 Thread Justin Bogner via llvm-branch-commits


@@ -289,6 +289,43 @@ class OpLowerer {
 });
   }
 
+  void lowerTypedBufferStore(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+Type *Int8Ty = IRB.getInt8Ty();
+Type *Int32Ty = IRB.getInt32Ty();
+
+replaceFunction(F, [&](CallInst *CI) -> Error {

bogner wrote:

It doesn't *need* to be - it just seemed more ergonomic than coming up with a 
name for it and spelling it elsewhere. Do you have a different suggestion?

https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104247


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104247
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104247


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

> Your description and the bug you are adressing make sense. One point of 
> confusion I see now is our mapping of intrinsics to DXIL Ops. The intrinsics 
> still all use `LLVMType`. Is that going to be problem?

I don't see why it would. LLVMType is perfectly reasonable for describing LLVM 
intrinsics. DXIL ops, on the other hand, use a number of specific `dx.types.*` 
struct types that aren't easy to describe with LLVMType and it wouldn't make 
sense to extend it to do so. Also, there are far fewer types that come up with 
DXIL ops, so the full flexibility of LLVMType isn't needed, hence this simpler 
approach.

https://github.com/llvm/llvm-project/pull/104247
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Use a more consistent pass name for DXILTranslateMetadata (PR #104249)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104249


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Use a more consistent pass name for DXILTranslateMetadata (PR #104249)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104249


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104251


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104251


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-15 Thread Justin Bogner via llvm-branch-commits


@@ -0,0 +1,63 @@
+; RUN: opt -S -dxil-op-lower %s | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+define void @test_bindings() {
+  ; RWBuffer Buf : register(u5, space3)
+  %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
+  @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0(
+  i32 3, i32 5, i32 1, i32 4, i1 false)
+  ; CHECK: [[BUF0:%[0-9]*]] = call %dx.types.Handle 
@dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 5, i32 5, i32 
3, i8 1 }, i32 4, i1 false)
+  ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, 
%dx.types.Handle [[BUF0]], %dx.types.ResourceProperties { i32 4106, i32 1033 })
+
+  ; RWBuffer Buf : register(u7, space2)
+  %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1)
+  @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0_0t(
+  i32 2, i32 7, i32 1, i32 6, i1 false)
+  ; CHECK: [[BUF1:%[0-9]*]] = call %dx.types.Handle 
@dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 7, i32 7, i32 
2, i8 1 }, i32 6, i1 false)
+  ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, 
%dx.types.Handle [[BUF1]], %dx.types.ResourceProperties { i32 4106, i32 260 })
+
+  ; Buffer Buf[24] : register(t3, space5)
+  %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)

bogner wrote:

It was technically `Buf[1]` as written, as the index is from the beginning of 
the binding space (matching DXC) and the test case didn't match the comment. 
I've updated the docs slightly to make that clearer and adjusted the test so 
the comment and test case agree.

https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104253


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104253


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-15 Thread Justin Bogner via llvm-branch-commits


@@ -289,6 +289,43 @@ class OpLowerer {
 });
   }
 
+  void lowerTypedBufferStore(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+Type *Int8Ty = IRB.getInt8Ty();
+Type *Int32Ty = IRB.getInt32Ty();
+
+replaceFunction(F, [&](CallInst *CI) -> Error {
+  IRB.SetInsertPoint(CI);
+
+  Value *Handle =
+  createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
+  Value *Index0 = CI->getArgOperand(1);
+  Value *Index1 = UndefValue::get(Int32Ty);
+  // For typed stores, the mask must always cover all four elements.
+  Constant *Mask = ConstantInt::get(Int8Ty, 0xF);
+
+  Value *Data = CI->getArgOperand(2);

bogner wrote:

The argument to `typedBufferStore` must be a vector of 4 elements, as we must 
store 16 bytes exactly. The only exception to this is a vector of 2 doubles, 
which isn't supported yet (I've filed #104423 for that).

That said, it'd probably be nice to get decent errors here if we get bad 
textual IR or a frontend other than clang messes up, so I've added better 
errors in the latest.

https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Implement metadata lowering for resources (PR #104447)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104447

Generate metadata from target extension type based resources.

Part of #91366



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Move resource logic into PrettyPrinter and TranslateMetadata (PR #104446)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104446

Move the module level logic for resources into the pretty printer and translate
metadata passes rather than embedding them in the DXILResource helper. This
will make it easier to migrate towards the target extension type based approach
to resources.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/104448

Handle target extension type resources when printing resources to textual IR.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Move resource logic into PrettyPrinter and TranslateMetadata. NFC (PR #104446)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner edited 
https://github.com/llvm/llvm-project/pull/104446
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Implement metadata lowering for resources (PR #104447)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104446

https://github.com/llvm/llvm-project/pull/104447
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

2024-08-15 Thread Justin Bogner via llvm-branch-commits

bogner wrote:

Depends on #104446

https://github.com/llvm/llvm-project/pull/104448
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Implement metadata lowering for resources (PR #104447)

2024-08-16 Thread Justin Bogner via llvm-branch-commits


@@ -13,27 +13,52 @@
 #include "DXILShaderFlags.h"
 #include "DirectX.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Analysis/DXILResource.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 #include "llvm/TargetParser/Triple.h"
 
 using namespace llvm;
 using namespace llvm::dxil;
 
-static void emitResourceMetadata(Module &M,
+static void emitResourceMetadata(Module &M, const DXILResourceMap &DRM,
  const dxil::Resources &MDResources) {
-  Metadata *SRVMD = nullptr, *UAVMD = nullptr, *CBufMD = nullptr,
-   *SmpMD = nullptr;
-  bool HasResources = false;
+  LLVMContext &Context = M.getContext();
+
+  SmallVector SRVs, UAVs, CBufs, Smps;
+  for (auto [_, RI] : DRM) {
+switch (RI.getResourceClass()) {
+case dxil::ResourceClass::SRV:
+  SRVs.push_back(RI.getAsMetadata(Context));
+  break;
+case dxil::ResourceClass::UAV:
+  UAVs.push_back(RI.getAsMetadata(Context));
+  break;
+case dxil::ResourceClass::CBuffer:
+  CBufs.push_back(RI.getAsMetadata(Context));
+  break;
+case dxil::ResourceClass::Sampler:
+  Smps.push_back(RI.getAsMetadata(Context));
+  break;
+}
+  }
+  Metadata *SRVMD = SRVs.empty() ? nullptr : MDNode::get(Context, SRVs);
+  Metadata *UAVMD = UAVs.empty() ? nullptr : MDNode::get(Context, UAVs);
+  Metadata *CBufMD = CBufs.empty() ? nullptr : MDNode::get(Context, CBufs);
+  Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps);
+  bool HasResources = !DRM.empty();
 
   if (MDResources.hasUAVs()) {
+assert(!UAVMD && "Old and new UAV representations can't coexist");

bogner wrote:

Yes. Once the frontend starts generating target extension types it will no 
longer generate the uav metadata node and we can remove all of that code. 
Similarly for the cbufs.

https://github.com/llvm/llvm-project/pull/104447
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-19 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104247


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-19 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104247


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Encapsulate DXILOpLowering's state into a class. NFC (PR #104248)

2024-08-20 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104248


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Encapsulate DXILOpLowering's state into a class. NFC (PR #104248)

2024-08-20 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104248


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-20 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104251


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-20 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/104251


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-20 Thread Justin Bogner via llvm-branch-commits


@@ -119,6 +123,119 @@ class OpLowerer {
 });
   }
 
+  Value *createTmpHandleCast(Value *V, Type *Ty) {
+Function *CastFn = Intrinsic::getDeclaration(&M, Intrinsic::dx_cast_handle,
+ {Ty, V->getType()});
+CallInst *Cast = OpBuilder.getIRB().CreateCall(CastFn, {V});
+CleanupCasts.push_back(Cast);
+return Cast;
+  }
+
+  void cleanupHandleCasts() {
+SmallVector ToRemove;
+SmallVector CastFns;
+
+for (CallInst *Cast : CleanupCasts) {
+  CastFns.push_back(Cast->getCalledFunction());
+  // All of the ops should be using `dx.types.Handle` at this point, so if
+  // we're not producing that we should be part of a pair. Track this so we
+  // can remove it at the end.
+  if (Cast->getType() != OpBuilder.getHandleType()) {
+ToRemove.push_back(Cast);
+continue;
+  }
+  // Otherwise, we're the second handle in a pair. Forward the arguments 
and
+  // remove the (second) cast.
+  CallInst *Def = cast(Cast->getOperand(0));
+  assert(Def->getIntrinsicID() == Intrinsic::dx_cast_handle &&
+ "Unbalanced pair of temporary handle casts");
+  Cast->replaceAllUsesWith(Def->getOperand(0));
+  Cast->eraseFromParent();
+}
+for (CallInst *Cast : ToRemove) {
+  assert(Cast->user_empty() && "Temporary handle cast still has users");
+  Cast->eraseFromParent();
+}
+llvm::sort(CastFns);
+CastFns.erase(llvm::unique(CastFns), CastFns.end());
+for (Function *F : CastFns)
+  F->eraseFromParent();

bogner wrote:

Above we add the cast function to the list every time we see a call to a cast - 
this means we could end up with duplicates if the same cast function is called 
multiple times. So, we need to deduplicate the list before we start erasing the 
functions from the module.

https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-20 Thread Justin Bogner via llvm-branch-commits


@@ -46,14 +46,14 @@ define void @test_typedbuffer() {
   ; Buffer Buf[24] : register(t3, space5)
   %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0t(
-  i32 2, i32 7, i32 24, i32 0, i1 false)
+  i32 5, i32 3, i32 24, i32 0, i1 false)

bogner wrote:

That was supposed to be included in #100699 in response to [a 
comment](https://github.com/llvm/llvm-project/pull/100699#discussion_r1715835841),
 but I guess I somehow put it in the wrong change. Committing that separately 
here: #105409

https://github.com/llvm/llvm-project/pull/104250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] cab6bcd - [𝘀𝗽𝗿] initial version

2023-11-03 Thread Justin Bogner via llvm-branch-commits

Author: Justin Bogner
Date: 2023-11-03T18:59:49-07:00
New Revision: cab6bcd73081fcbe9807adbf60b345f8d9e654e4

URL: 
https://github.com/llvm/llvm-project/commit/cab6bcd73081fcbe9807adbf60b345f8d9e654e4
DIFF: 
https://github.com/llvm/llvm-project/commit/cab6bcd73081fcbe9807adbf60b345f8d9e654e4.diff

LOG: [𝘀𝗽𝗿] initial version

Created using spr 1.3.5

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9b7..a86c428c9121abf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e453126..de5cc07f5d42865 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f9a..0952b065d56b58e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac76..603b7465323e237 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee354862212803f..1a6eaa196db09be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid())
+S.Diag(Template->getLocation(), diag::note_template_decl_here);
   SmallVector PartialAC, TemplateAC;
   Template->getAssociatedConstraints(Template

  1   2   3   >