DirectXShaderCompiler/lib/Analysis/DxilValueCache.cpp

595 строки
17 KiB
C++
Исходник Обычный вид История

Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
//===---------- DxilValueCache.cpp - Dxil Constant Value Cache ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Utility to compute and cache constant values for instructions.
//
#include "llvm/Pass.h"
#include "dxc/DXIL/DxilConstants.h"
#include "llvm/Analysis/DxilSimplify.h"
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
#include "llvm/IR/Module.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/CFG.h"
#include "llvm/Support/Debug.h"
#include "llvm/IR/Dominators.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/ConstantFolding.h"
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/DxilValueCache.h"
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
#include <unordered_set>
#define DEBUG_TYPE "dxil-value-cache"
using namespace llvm;
static
bool IsConstantTrue(const Value *V) {
if (const ConstantInt *C = dyn_cast<ConstantInt>(V))
return C->getLimitedValue() != 0;
return false;
}
static
bool IsConstantFalse(const Value *V) {
if (const ConstantInt *C = dyn_cast<ConstantInt>(V))
return C->getLimitedValue() == 0;
return false;
}
static
bool IsEntryBlock(const BasicBlock *BB) {
return BB == &BB->getParent()->getEntryBlock();
}
void DxilValueCache::MarkAlwaysReachable(BasicBlock *BB) {
ValueMap.Set(BB, ConstantInt::get(Type::getInt1Ty(BB->getContext()), 1));
}
void DxilValueCache::MarkUnreachable(BasicBlock *BB) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
ValueMap.Set(BB, ConstantInt::get(Type::getInt1Ty(BB->getContext()), 0));
}
bool DxilValueCache::IsAlwaysReachable_(BasicBlock *BB) {
if (Value *V = ValueMap.Get(BB))
if (IsConstantTrue(V))
return true;
return false;
}
bool DxilValueCache::MayBranchTo(BasicBlock *A, BasicBlock *B) {
BranchInst *Br = dyn_cast<BranchInst>(A->getTerminator());
if (!Br) return false;
if (Br->isUnconditional() && Br->getSuccessor(0) == B)
return true;
if (ConstantInt *C = dyn_cast<ConstantInt>(TryGetCachedValue(Br->getCondition()))) {
unsigned SuccIndex = C->getLimitedValue() != 0 ? 0 : 1;
return Br->getSuccessor(SuccIndex) == B;
}
return true;
}
bool DxilValueCache::IsUnreachable_(BasicBlock *BB) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (Value *V = ValueMap.Get(BB))
if (IsConstantFalse(V))
return true;
return false;
}
Value *DxilValueCache::ProcessAndSimplify_PHI(Instruction *I, DominatorTree *DT) {
PHINode *PN = cast<PHINode>(I);
BasicBlock *SoleIncoming = nullptr;
bool Unreachable = true;
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
Value *Simplified = nullptr;
2021-10-05 13:28:21 +03:00
Value *SimplifiedNotDominating = nullptr;
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) {
BasicBlock *PredBB = PN->getIncomingBlock(i);
if (IsUnreachable_(PredBB))
continue;
Unreachable = false;
if (MayBranchTo(PredBB, PN->getParent())) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (SoleIncoming) {
SoleIncoming = nullptr;
break;
}
SoleIncoming = PredBB;
}
}
if (Unreachable) {
return UndefValue::get(I->getType());
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (SoleIncoming) {
Value *V = TryGetCachedValue(PN->getIncomingValueForBlock(SoleIncoming));
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (isa<Constant>(V))
Simplified = V;
else if (Instruction *I = dyn_cast<Instruction>(V)) {
// If this is an instruction, we have to make sure it
// dominates this PHI.
// There are several conditions that qualify:
// 1. There's only one predecessor
// 2. If the instruction is in the entry block, then it must dominate
// 3. If we are provided with a Dominator tree, and it decides that
// it dominates.
if (PN->getNumIncomingValues() == 1 ||
IsEntryBlock(I->getParent()) ||
(DT && DT->dominates(I, PN)))
{
Simplified = I;
}
2021-10-05 13:28:21 +03:00
else {
SimplifiedNotDominating = I;
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
}
2021-10-05 13:28:21 +03:00
// If we have a value but it's not dominating our PHI, see if it has a cached value
// that were computed previously.
if (!Simplified) {
if (SimplifiedNotDominating)
if (Value *CachedV = ValueMap.Get(SimplifiedNotDominating))
Simplified = CachedV;
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
// If we coulnd't deduce it, run the LLVM stock simplification to see
// if we could do anything.
if (!Simplified)
Simplified = llvm::SimplifyInstruction(I, I->getModule()->getDataLayout());
// One last step, to check if we have anything cached for whatever we
// simplified to.
if (Simplified)
Simplified = TryGetCachedValue(Simplified);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
return Simplified;
}
Value *DxilValueCache::ProcessAndSimplify_Br(Instruction *I, DominatorTree *DT) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
// The *only* reason we're paying special attention to the
// branch inst, is to mark certain Basic Blocks as always
// reachable or unreachable.
BranchInst *Br = cast<BranchInst>(I);
BasicBlock *BB = Br->getParent();
if (Br->isConditional()) {
BasicBlock *TrueSucc = Br->getSuccessor(0);
BasicBlock *FalseSucc = Br->getSuccessor(1);
Value *Cond = TryGetCachedValue(Br->getCondition());
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (IsUnreachable_(BB)) {
if (FalseSucc->getSinglePredecessor())
MarkUnreachable(FalseSucc);
if (TrueSucc->getSinglePredecessor())
MarkUnreachable(TrueSucc);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
else if (IsConstantTrue(Cond)) {
if (IsAlwaysReachable_(BB)) {
MarkAlwaysReachable(TrueSucc);
}
if (FalseSucc->getSinglePredecessor())
MarkUnreachable(FalseSucc);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
else if (IsConstantFalse(Cond)) {
if (IsAlwaysReachable_(BB)) {
MarkAlwaysReachable(FalseSucc);
}
if (TrueSucc->getSinglePredecessor())
MarkUnreachable(TrueSucc);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
}
else {
BasicBlock *Succ = Br->getSuccessor(0);
if (IsAlwaysReachable_(BB))
MarkAlwaysReachable(Succ);
else if (Succ->getSinglePredecessor() && IsUnreachable_(BB))
MarkUnreachable(Succ);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
return nullptr;
}
Value *DxilValueCache::ProcessAndSimplify_Load(Instruction *I, DominatorTree *DT) {
LoadInst *LI = cast<LoadInst>(I);
Value *V = TryGetCachedValue(LI->getPointerOperand());
if (Constant *ConstPtr = dyn_cast<Constant>(V)) {
const DataLayout &DL = I->getModule()->getDataLayout();
return llvm::ConstantFoldLoadFromConstPtr(ConstPtr, DL);
}
return nullptr;
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
Value *DxilValueCache::SimplifyAndCacheResult(Instruction *I, DominatorTree *DT) {
2021-10-05 13:28:21 +03:00
if (ShouldSkipCallback && ShouldSkipCallback(I))
return nullptr;
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
const DataLayout &DL = I->getModule()->getDataLayout();
Value *Simplified = nullptr;
if (Instruction::Br == I->getOpcode()) {
Simplified = ProcessAndSimplify_Br(I, DT);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
else if (Instruction::PHI == I->getOpcode()) {
Simplified = ProcessAndSimplify_PHI(I, DT);
}
else if (Instruction::Load == I->getOpcode()) {
Simplified = ProcessAndSimplify_Load(I, DT);
}
else if (Instruction::GetElementPtr == I->getOpcode()) {
SmallVector<Value *, 4> Ops;
for (unsigned i = 0; i < I->getNumOperands(); i++)
Ops.push_back(TryGetCachedValue(I->getOperand(i)));
Simplified = llvm::SimplifyGEPInst(Ops, DL, nullptr, DT);
}
else if (Instruction::Call == I->getOpcode()) {
Module *M = I->getModule();
CallInst *CI = cast<CallInst>(I);
Value *Callee = CI->getCalledValue();
Function *CalledFunction = dyn_cast<Function>(Callee);
if (CalledFunction && CalledFunction->getName() == hlsl::DXIL::kDxBreakFuncName) {
llvm::Type *i1Ty = llvm::Type::getInt1Ty(M->getContext());
Simplified = llvm::ConstantInt::get(i1Ty, 1);
}
else {
SmallVector<Value *,16> Args;
for (unsigned i = 0; i < CI->getNumArgOperands(); i++) {
Args.push_back(TryGetCachedValue(CI->getArgOperand(i)));
}
if (CalledFunction && hlsl::CanSimplify(CalledFunction)) {
Simplified = hlsl::SimplifyDxilCall(CalledFunction, Args, CI, /* MayInsert */ false);
}
else {
Simplified = llvm::SimplifyCall(Callee, Args, DL, nullptr, DT);
}
}
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
// The rest of the checks use LLVM stock simplifications
else if (I->isBinaryOp()) {
2021-10-05 13:28:21 +03:00
if (FPMathOperator *FPOp = dyn_cast<FPMathOperator>(I)) {
Simplified =
llvm::SimplifyFPBinOp(
I->getOpcode(),
TryGetCachedValue(I->getOperand(0)),
TryGetCachedValue(I->getOperand(1)),
FPOp->getFastMathFlags(),
DL);
}
else {
Simplified =
llvm::SimplifyBinOp(
I->getOpcode(),
TryGetCachedValue(I->getOperand(0)),
TryGetCachedValue(I->getOperand(1)),
DL);
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
else if (GetElementPtrInst *Gep = dyn_cast<GetElementPtrInst>(I)) {
SmallVector<Value *, 4> Values;
for (Value *V : Gep->operand_values()) {
Values.push_back(TryGetCachedValue(V));
}
Simplified =
llvm::SimplifyGEPInst(Values, DL, nullptr, DT, nullptr, nullptr);
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
else if (CmpInst *Cmp = dyn_cast<CmpInst>(I)) {
2021-10-05 13:28:21 +03:00
if (FPMathOperator *FPOp = dyn_cast<FPMathOperator>(I)) {
Simplified =
llvm::SimplifyFCmpInst(Cmp->getPredicate(),
TryGetCachedValue(I->getOperand(0)),
TryGetCachedValue(I->getOperand(1)),
FPOp->getFastMathFlags(),
DL);
}
else {
Simplified =
llvm::SimplifyCmpInst(Cmp->getPredicate(),
TryGetCachedValue(I->getOperand(0)),
TryGetCachedValue(I->getOperand(1)),
DL);
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
else if (SelectInst *Select = dyn_cast<SelectInst>(I)) {
Simplified =
llvm::SimplifySelectInst(
TryGetCachedValue(Select->getCondition()),
TryGetCachedValue(Select->getTrueValue()),
TryGetCachedValue(Select->getFalseValue()),
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
DL
);
}
else if (ExtractElementInst *IE = dyn_cast<ExtractElementInst>(I)) {
Simplified =
llvm::SimplifyExtractElementInst(
TryGetCachedValue(IE->getVectorOperand()),
TryGetCachedValue(IE->getIndexOperand()),
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
DL, nullptr, DT);
}
else if (CastInst *Cast = dyn_cast<CastInst>(I)) {
Simplified =
llvm::SimplifyCastInst(
Cast->getOpcode(),
TryGetCachedValue(Cast->getOperand(0)),
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
Cast->getType(), DL);
}
if (Simplified && isa<Constant>(Simplified))
ValueMap.Set(I, Simplified);
return Simplified;
}
bool DxilValueCache::WeakValueMap::Seen(Value *V) {
auto FindIt = Map.find(V);
if (FindIt == Map.end())
return false;
auto &Entry = FindIt->second;
if (Entry.IsStale())
return false;
return Entry.Value;
}
Value *DxilValueCache::WeakValueMap::Get(Value *V) {
auto FindIt = Map.find(V);
if (FindIt == Map.end())
return nullptr;
auto &Entry = FindIt->second;
if (Entry.IsStale())
return nullptr;
Value *Result = Entry.Value;
if (Result == GetSentinel(V->getContext()))
return nullptr;
return Result;
}
void DxilValueCache::WeakValueMap::SetSentinel(Value *Key) {
Map[Key].Set(Key, GetSentinel(Key->getContext()));
}
Value *DxilValueCache::WeakValueMap::GetSentinel(LLVMContext &Ctx) {
if (!Sentinel) {
Sentinel.reset( PHINode::Create(Type::getInt1Ty(Ctx), 0) );
}
return Sentinel.get();
}
2021-10-05 13:28:21 +03:00
void DxilValueCache::WeakValueMap::ResetAll() {
Map.clear();
}
void DxilValueCache::WeakValueMap::ResetUnknowns() {
if (!Sentinel)
return;
for (auto it = Map.begin(); it != Map.end(); it++) {
if (it->second.Value == Sentinel.get())
it->second.Value = nullptr;
}
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
LLVM_DUMP_METHOD
void DxilValueCache::WeakValueMap::dump() const {
for (auto It = Map.begin(), E = Map.end(); It != E; It++) {
const Value *Key = It->first;
if (It->second.IsStale())
continue;
const Value *V = It->second.Value;
bool IsSentinel = Sentinel && V == Sentinel.get();
if (const BasicBlock *BB = dyn_cast<BasicBlock>(Key)) {
dbgs() << "[BB]" << BB->getName() << " -> ";
if (IsSentinel)
dbgs() << "NO_VALUE";
else {
if (IsConstantTrue(V))
dbgs() << "Always Reachable!";
else if (IsConstantFalse(V))
dbgs() << "Never Reachable!";
}
}
else {
dbgs() << Key->getName() << " -> ";
if (IsSentinel)
dbgs() << "NO_VALUE";
else
dbgs() << *V;
}
dbgs() << "\n";
}
}
void DxilValueCache::WeakValueMap::Set(Value *Key, Value *V) {
Map[Key].Set(Key, V);
}
// If there's a cached value, return it. Otherwise, return
// the value itself.
Value *DxilValueCache::TryGetCachedValue(Value *V) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (Value *Simplified = ValueMap.Get(V))
return Simplified;
return V;
}
DxilValueCache::DxilValueCache() : ImmutablePass(ID) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
initializeDxilValueCachePass(*PassRegistry::getPassRegistry());
}
const char *DxilValueCache::getPassName() const {
return "Dxil Value Cache";
}
Value *DxilValueCache::GetValue(Value *V, DominatorTree *DT) {
if (dyn_cast<Constant>(V))
return V;
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
if (Value *NewV = ValueMap.Get(V))
return NewV;
2021-10-05 13:28:21 +03:00
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
return ProcessValue(V, DT);
}
Constant *DxilValueCache::GetConstValue(Value *V, DominatorTree *DT) {
if (Value *NewV = GetValue(V))
return dyn_cast<Constant>(NewV);
return nullptr;
}
ConstantInt *DxilValueCache::GetConstInt(Value *V, DominatorTree *DT) {
if (Value *NewV = GetValue(V))
return dyn_cast<ConstantInt>(NewV);
return nullptr;
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
bool DxilValueCache::IsAlwaysReachable(BasicBlock *BB, DominatorTree *DT) {
ProcessValue(BB, DT);
return IsAlwaysReachable_(BB);
}
bool DxilValueCache::IsUnreachable(BasicBlock *BB, DominatorTree *DT) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
ProcessValue(BB, DT);
return IsUnreachable_(BB);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
LLVM_DUMP_METHOD
void DxilValueCache::dump() const {
ValueMap.dump();
}
void DxilValueCache::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
Value *DxilValueCache::ProcessValue(Value *NewV, DominatorTree *DT) {
2021-10-05 13:28:21 +03:00
if (NewV->getType()->isVoidTy())
return nullptr;
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
Value *Result = nullptr;
SmallVector<Value *, 16> WorkList;
// Although we accept all values for convenience, we only process
// Instructions.
if (Instruction *I = dyn_cast<Instruction>(NewV)) {
WorkList.push_back(I);
}
else if (BasicBlock *BB = dyn_cast<BasicBlock>(NewV)) {
WorkList.push_back(BB->getTerminator());
WorkList.push_back(BB);
}
else {
return nullptr;
}
// Unconditionally process this one instruction, whether we've seen
// it or not. The simplification might be able to do something to
// simplify it even when we don't have its value cached.
// This is a basic DFS setup.
while (WorkList.size()) {
Value *V = WorkList.back();
// If we haven't seen this value, go in and push things it depends on
// into the worklist.
if (!ValueMap.Seen(V)) {
ValueMap.SetSentinel(V);
if (Instruction *I = dyn_cast<Instruction>(V)) {
for (Use &U : I->operands()) {
Instruction *UseI = dyn_cast<Instruction>(U.get());
if (!UseI)
continue;
if (!ValueMap.Seen(UseI))
WorkList.push_back(UseI);
}
if (PHINode *PN = dyn_cast<PHINode>(I)) {
for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) {
BasicBlock *BB = PN->getIncomingBlock(i);
TerminatorInst *Term = BB->getTerminator();
if (!ValueMap.Seen(Term))
WorkList.push_back(Term);
if (!ValueMap.Seen(BB))
WorkList.push_back(BB);
}
}
}
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
if (IsEntryBlock(BB)) {
MarkAlwaysReachable(BB);
}
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; PI++) {
BasicBlock *PredBB = *PI;
TerminatorInst *Term = PredBB->getTerminator();
if (!ValueMap.Seen(Term))
WorkList.push_back(Term);
if (!ValueMap.Seen(PredBB))
WorkList.push_back(PredBB);
}
}
}
// If we've seen this values, all its dependencies must have been processed
// as well.
else {
WorkList.pop_back();
if (Instruction *I = dyn_cast<Instruction>(V)) {
Value *SimplifiedValue = SimplifyAndCacheResult(I, DT);
// Set the result if this is the input inst.
// SimplifyInst may not have cached the value
// so we return it directly.
if (I == NewV)
Result = SimplifiedValue;
}
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
// Deduce the basic block's reachability based on
// other analysis.
if (!IsEntryBlock(BB)) {
bool AllNeverReachable = true;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; PI++) {
2021-10-05 13:28:21 +03:00
if (!IsUnreachable_(*PI)) {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
AllNeverReachable = false;
break;
}
}
if (AllNeverReachable)
MarkUnreachable(BB);
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
}
}
}
}
return Result;
}
char DxilValueCache::ID;
Pass *llvm::createDxilValueCachePass() {
Integrate dxcapi v2 and other changes from internal (#2575) * Integrate changes from internal. - dxcapi v2 - new dxc options - DxilValueCache - PDB and NoOpt improvements - noop / llvm::donothing() support * Update dxrfallbacklayer for dxcapi internal changes * Reorder diag block based on whether pDiag is set first. * llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well. * Fixes for spir-v, non-VC compiler and non-Windows builds - DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces - add SAL annotations - turn output argument validation for -P into warning - handle warnings without concatenating them to main output - update spirv preprocessing and compilation paths - return E_NOTIMPL from IDxcUtils::CreateReflection - cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment * Fix some warnings from clang/gcc. * Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4 Note this is an intermediate fix. On linux, what we are calling utf16 is actually a wide string that's probably utf32. This change fixes issues introduced by the new interface changes so things are consistent and pass tests. A future fix should correct the encodings so they are correctly labeled on platforms where wchar_t doesn't mean UTF16. * Return false for IsBufferNullTerminated when CP_ACP. One test for Disassembler was crashing because it created a pinned blob with a size of 1 << 31 + 1 without actual memory backing this. The IsBufferNullTerminated would attempt to see if this was null terminated, causing AV. This change also removes CP_UTF8 from this test when it was creating binary blobs, not UTF8 text blobs.
2019-11-14 03:16:46 +03:00
return new DxilValueCache();
}
INITIALIZE_PASS(DxilValueCache, DEBUG_TYPE, "Dxil Value Cache", false, false)