@@ -2545,6 +2545,25 @@ 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+
25482567// Emit names for globals/functions etc.
25492568void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable (
25502569 const ValueSymbolTable &VST) {
@@ -2559,8 +2578,8 @@ void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
25592578 // to ensure the binary is the same no matter what values ever existed.
25602579 SmallVector<const ValueName *, 16 > SortedTable;
25612580
2562- MallocAllocator Allocator;
2563- SmallVector<ValueName *, 2 > LifetimeValueNames ;
2581+ // HLSL Change
2582+ ValueNameCreator VNC ;
25642583 for (auto &VI : VST) {
25652584 ValueName *VN = VI.second ->getValueName ();
25662585 // Clang mangles lifetime intrinsic names by appending '.p0' to the end,
@@ -2571,14 +2590,12 @@ void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
25712590 if (const Function *Fn = dyn_cast<Function>(VI.getValue ());
25722591 Fn && Fn->isIntrinsic ()) {
25732592 Intrinsic::ID IID = Fn->getIntrinsicID ();
2574- if (IID == Intrinsic::lifetime_start || IID == Intrinsic::lifetime_end) {
2575- VN = ValueName::create (Intrinsic::getBaseName (IID), Allocator,
2576- VI.second );
2577- LifetimeValueNames.push_back (VN);
2578- }
2593+ if (IID == Intrinsic::lifetime_start || IID == Intrinsic::lifetime_end)
2594+ VN = VNC.create (Intrinsic::getBaseName (IID), VI.second );
25792595 }
25802596 SortedTable.push_back (VN);
25812597 }
2598+
25822599 // The keys are unique, so there shouldn't be stability issues.
25832600 llvm::sort (SortedTable, [](const ValueName *A, const ValueName *B) {
25842601 return A->first () < B->first ();
@@ -2628,8 +2645,6 @@ void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
26282645 NameVals.clear ();
26292646 }
26302647 Stream.ExitBlock ();
2631- for (auto *VN : LifetimeValueNames)
2632- VN->Destroy (Allocator);
26332648}
26342649
26352650// / Emit a function body to the module stream.
0 commit comments