Skip to content

Commit 8f9ed78

Browse files
authored
Revert "[DirectX] Legalize lifetime intrinsics for DXIL" (#149883)
Reverts #148003 to fix a DirectX backend build breakage due to #149310
1 parent c4f3bc9 commit 8f9ed78

File tree

6 files changed

+5
-155
lines changed

6 files changed

+5
-155
lines changed

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/IR/AttributeMask.h"
2525
#include "llvm/IR/IRBuilder.h"
2626
#include "llvm/IR/Instruction.h"
27-
#include "llvm/IR/IntrinsicInst.h"
2827
#include "llvm/IR/Module.h"
2928
#include "llvm/InitializePasses.h"
3029
#include "llvm/Pass.h"
@@ -240,11 +239,6 @@ class DXILPrepareModule : public ModulePass {
240239
for (size_t Idx = 0, End = F.arg_size(); Idx < End; ++Idx)
241240
F.removeParamAttrs(Idx, AttrMask);
242241

243-
// Lifetime intrinsics in LLVM 3.7 do not have the memory FnAttr
244-
if (Intrinsic::ID IID = F.getIntrinsicID();
245-
IID == Intrinsic::lifetime_start || IID == Intrinsic::lifetime_end)
246-
F.removeFnAttr(Attribute::Memory);
247-
248242
for (auto &BB : F) {
249243
IRBuilder<> Builder(&BB);
250244
for (auto &I : make_early_inc_range(BB)) {
@@ -253,7 +247,7 @@ class DXILPrepareModule : public ModulePass {
253247

254248
// Emtting NoOp bitcast instructions allows the ValueEnumerator to be
255249
// unmodified as it reserves instruction IDs during contruction.
256-
if (auto *LI = dyn_cast<LoadInst>(&I)) {
250+
if (auto LI = dyn_cast<LoadInst>(&I)) {
257251
if (Value *NoOpBitcast = maybeGenerateBitcast(
258252
Builder, PointerTypes, I, LI->getPointerOperand(),
259253
LI->getType())) {
@@ -263,7 +257,7 @@ class DXILPrepareModule : public ModulePass {
263257
}
264258
continue;
265259
}
266-
if (auto *SI = dyn_cast<StoreInst>(&I)) {
260+
if (auto SI = dyn_cast<StoreInst>(&I)) {
267261
if (Value *NoOpBitcast = maybeGenerateBitcast(
268262
Builder, PointerTypes, I, SI->getPointerOperand(),
269263
SI->getValueOperand()->getType())) {
@@ -274,7 +268,7 @@ class DXILPrepareModule : public ModulePass {
274268
}
275269
continue;
276270
}
277-
if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
271+
if (auto GEP = dyn_cast<GetElementPtrInst>(&I)) {
278272
if (Value *NoOpBitcast = maybeGenerateBitcast(
279273
Builder, PointerTypes, I, GEP->getPointerOperand(),
280274
GEP->getSourceElementType()))
@@ -286,17 +280,6 @@ class DXILPrepareModule : public ModulePass {
286280
CB->removeRetAttrs(AttrMask);
287281
for (size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
288282
CB->removeParamAttrs(Idx, AttrMask);
289-
// LLVM 3.7 Lifetime intrinics require an i8* pointer operand, so we
290-
// insert a bitcast here to ensure that is the case
291-
if (isa<LifetimeIntrinsic>(CB)) {
292-
Value *PtrOperand = CB->getArgOperand(1);
293-
Builder.SetInsertPoint(CB);
294-
PointerType *PtrTy = cast<PointerType>(PtrOperand->getType());
295-
Value *NoOpBitcast = Builder.Insert(
296-
CastInst::Create(Instruction::BitCast, PtrOperand,
297-
Builder.getPtrTy(PtrTy->getAddressSpace())));
298-
CB->setArgOperand(1, NoOpBitcast);
299-
}
300283
continue;
301284
}
302285
}

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
152152
if (!CSF.Int64Ops)
153153
CSF.Int64Ops = I.getType()->isIntegerTy(64);
154154

155-
if (!CSF.Int64Ops && !isa<LifetimeIntrinsic>(&I)) {
155+
if (!CSF.Int64Ops) {
156156
for (const Value *Op : I.operands()) {
157157
if (Op->getType()->isIntegerTy(64)) {
158158
CSF.Int64Ops = true;

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,25 +2545,6 @@ void DXILBitcodeWriter::writeInstruction(const Instruction &I, unsigned InstID,
25452545
Vals.clear();
25462546
}
25472547

2548-
// HLSL Change
2549-
namespace {
2550-
struct ValueNameCreator {
2551-
MallocAllocator Allocator;
2552-
SmallVector<ValueName *, 2>
2553-
ValueNames; // SmallVector N = 2 because we currently only expect this
2554-
// to hold ValueNames for Lifetime intrinsics
2555-
~ValueNameCreator() {
2556-
for (auto *VN : ValueNames)
2557-
VN->Destroy(Allocator);
2558-
}
2559-
ValueName *create(StringRef Name, Value *V) {
2560-
ValueName *VN = ValueName::create(Name, Allocator, V);
2561-
ValueNames.push_back(VN);
2562-
return VN;
2563-
}
2564-
};
2565-
} // anonymous namespace
2566-
25672548
// Emit names for globals/functions etc.
25682549
void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
25692550
const ValueSymbolTable &VST) {
@@ -2578,24 +2559,9 @@ void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
25782559
// to ensure the binary is the same no matter what values ever existed.
25792560
SmallVector<const ValueName *, 16> SortedTable;
25802561

2581-
// HLSL Change
2582-
ValueNameCreator VNC;
25832562
for (auto &VI : VST) {
2584-
ValueName *VN = VI.second->getValueName();
2585-
// Clang mangles lifetime intrinsic names by appending '.p0' to the end,
2586-
// making them invalid lifetime intrinsics in LLVM 3.7. We can't
2587-
// demangle in dxil-prepare because it would result in invalid IR.
2588-
// Therefore we have to do this in the bitcode writer while writing its
2589-
// name to the symbol table.
2590-
if (const Function *Fn = dyn_cast<Function>(VI.getValue());
2591-
Fn && Fn->isIntrinsic()) {
2592-
Intrinsic::ID IID = Fn->getIntrinsicID();
2593-
if (IID == Intrinsic::lifetime_start || IID == Intrinsic::lifetime_end)
2594-
VN = VNC.create(Intrinsic::getBaseName(IID), VI.second);
2595-
}
2596-
SortedTable.push_back(VN);
2563+
SortedTable.push_back(VI.second->getValueName());
25972564
}
2598-
25992565
// The keys are unique, so there shouldn't be stability issues.
26002566
llvm::sort(SortedTable, [](const ValueName *A, const ValueName *B) {
26012567
return A->first() < B->first();

llvm/test/CodeGen/DirectX/ShaderFlags/lifetimes-noint64op.ll

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-SM63
22
; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.6-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-SM66
3-
; RUN: opt -S -dxil-op-lower -dxil-prepare -mtriple=dxil-pc-shadermodel6.6-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREPARE
43

54
; CHECK-LABEL: define void @test_legal_lifetime() {
65
;
@@ -16,14 +15,6 @@
1615
; CHECK-SM66-NEXT: store i32 0, ptr [[GEP]], align 4
1716
; CHECK-SM66-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[ACCUM_I_FLAT]])
1817
;
19-
; CHECK-PREPARE-NEXT: [[ACCUM_I_FLAT:%.*]] = alloca [1 x i32], align 4
20-
; CHECK-PREPARE-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[ACCUM_I_FLAT]], i32 0
21-
; CHECK-PREPARE-NEXT: [[BITCAST:%.*]] = bitcast ptr [[ACCUM_I_FLAT]] to ptr
22-
; CHECK-PREPARE-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[BITCAST]])
23-
; CHECK-PREPARE-NEXT: store i32 0, ptr [[GEP]], align 4
24-
; CHECK-PREPARE-NEXT: [[BITCAST:%.*]] = bitcast ptr [[ACCUM_I_FLAT]] to ptr
25-
; CHECK-PREPARE-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[BITCAST]])
26-
;
2718
; CHECK-NEXT: ret void
2819
;
2920
define void @test_legal_lifetime() {
@@ -35,22 +26,6 @@ define void @test_legal_lifetime() {
3526
ret void
3627
}
3728

38-
; CHECK-PREPARE-DAG: attributes [[LIFETIME_ATTRS:#.*]] = { nounwind }
39-
40-
; CHECK-PREPARE-DAG: ; Function Attrs: nounwind
41-
; CHECK-PREPARE-DAG: declare void @llvm.lifetime.start.p0(i64, ptr) [[LIFETIME_ATTRS]]
42-
43-
; CHECK-PREPARE-DAG: ; Function Attrs: nounwind
44-
; CHECK-PREPARE-DAG: declare void @llvm.lifetime.end.p0(i64, ptr) [[LIFETIME_ATTRS]]
45-
46-
; Function Attrs: nounwind memory(argmem: readwrite)
47-
declare void @llvm.lifetime.end.p0(i64, ptr) #0
48-
49-
; Function Attrs: nounwind memory(argmem: readwrite)
50-
declare void @llvm.lifetime.start.p0(i64, ptr) #0
51-
52-
attributes #0 = { nounwind memory(argmem: readwrite) }
53-
5429
; Set the validator version to 1.6
5530
!dx.valver = !{!0}
5631
!0 = !{i32 1, i32 6}

llvm/test/tools/dxil-dis/lifetimes.ll

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)