================
@@ -0,0 +1,121 @@
+//===- SPIRVLowerResourceNames.cpp - Lower resource names to metadata
-----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SPIRV.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/IntrinsicsSPIRV.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Transforms/Utils/PromoteMemToReg.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "spirv-lower-resource-names"
+
+static void promoteNameAllocas(ArrayRef<CallInst *> Intrinsics) {
+ MapVector<Function *, SmallVector<AllocaInst *, 4>> Allocas;
+ SmallPtrSet<AllocaInst *, 8> Seen;
+ for (CallInst *CI : Intrinsics) {
+ auto *LI = dyn_cast<LoadInst>(CI->getArgOperand(4));
+ if (!LI)
+ continue;
+ auto *AI = cast<AllocaInst>(LI->getPointerOperand());
----------------
dnovillo wrote:
This will assert when the name is loaded from something other than an alloca.
HLSL cannot generate this, but it is valid IR, so we need to handle it here.
Something like this:
```llvm
@name.ptr = internal global ptr @.str
...
%name = load ptr, ptr @name.ptr
%h = call target("spirv.Image", ...)
@llvm.spv.resource.handlefrombinding(..., ptr %name)
```
Could you report the same error as the non-promotable case? A test would be
great too.
https://github.com/llvm/llvm-project/pull/243531
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits