|
@@ -34,6 +34,7 @@
|
|
|
#include "llvm/IR/PassManager.h"
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
+#include "llvm/ADT/DenseSet.h"
|
|
|
#include "llvm/Pass.h"
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
|
@@ -343,26 +344,18 @@ public:
|
|
|
|
|
|
StringRef getPassName() const override { return "HLSL DXIL Finalize Module"; }
|
|
|
|
|
|
- void patchValidation_1_1(Module &M) {
|
|
|
- for (iplist<Function>::iterator F : M.getFunctionList()) {
|
|
|
- for (Function::iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
|
|
|
- ++BBI) {
|
|
|
- BasicBlock *BB = BBI;
|
|
|
- for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;
|
|
|
- ++II) {
|
|
|
- Instruction *I = II;
|
|
|
- if (I->hasMetadataOtherThanDebugLoc()) {
|
|
|
- SmallVector<std::pair<unsigned, MDNode*>, 2> MDs;
|
|
|
- I->getAllMetadataOtherThanDebugLoc(MDs);
|
|
|
+ void patchInstructionMetadata(Module &M, DenseSet<unsigned> &IllegalMDSet) {
|
|
|
+ for (auto &F : M.getFunctionList()) {
|
|
|
+ for (auto &BB : F) {
|
|
|
+ for (auto &I : BB) {
|
|
|
+ if (I.hasMetadataOtherThanDebugLoc()) {
|
|
|
+ SmallVector<std::pair<unsigned, MDNode *>, 2> MDs;
|
|
|
+ I.getAllMetadataOtherThanDebugLoc(MDs);
|
|
|
for (auto &MD : MDs) {
|
|
|
unsigned kind = MD.first;
|
|
|
- // Remove Metadata which validation_1_0 not allowed.
|
|
|
- bool bNeedPatch = kind == LLVMContext::MD_tbaa ||
|
|
|
- kind == LLVMContext::MD_prof ||
|
|
|
- (kind > LLVMContext::MD_fpmath &&
|
|
|
- kind <= LLVMContext::MD_dereferenceable_or_null);
|
|
|
- if (bNeedPatch)
|
|
|
- I->setMetadata(kind, nullptr);
|
|
|
+ // Remove illegal metadata.
|
|
|
+ if (IllegalMDSet.count(kind))
|
|
|
+ I.setMetadata(kind, nullptr);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -774,8 +767,22 @@ public:
|
|
|
bool IsLib = DM.GetShaderModel()->IsLib();
|
|
|
// Skip validation patch for lib.
|
|
|
if (!IsLib) {
|
|
|
+ unsigned DxilTempMDKind =
|
|
|
+ M.getContext().getMDKindID(DxilMDHelper::kDxilTempAllocaMDName);
|
|
|
if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 1) <= 0) {
|
|
|
- patchValidation_1_1(M);
|
|
|
+ DenseSet<unsigned> IllegalMDSet;
|
|
|
+ IllegalMDSet.insert(LLVMContext::MD_tbaa);
|
|
|
+ IllegalMDSet.insert(LLVMContext::MD_prof);
|
|
|
+ for (unsigned I = LLVMContext::MD_fpmath + 1;
|
|
|
+ I <= LLVMContext::MD_dereferenceable_or_null; ++I) {
|
|
|
+ IllegalMDSet.insert(I);
|
|
|
+ }
|
|
|
+ IllegalMDSet.insert(DxilTempMDKind);
|
|
|
+ patchInstructionMetadata(M, IllegalMDSet);
|
|
|
+ } else {
|
|
|
+ DenseSet<unsigned> IllegalMDSet;
|
|
|
+ IllegalMDSet.insert(DxilTempMDKind);
|
|
|
+ patchInstructionMetadata(M, IllegalMDSet);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1713,3 +1720,33 @@ INITIALIZE_PASS_END(CleanupDxBreak, "hlsl-cleanup-dxbreak", "HLSL Remove unneces
|
|
|
FunctionPass *llvm::createCleanupDxBreakPass() {
|
|
|
return new CleanupDxBreak();
|
|
|
}
|
|
|
+
|
|
|
+///////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+namespace {
|
|
|
+
|
|
|
+class DxilModuleInit : public ModulePass {
|
|
|
+public:
|
|
|
+ static char ID; // Pass identification, replacement for typeid
|
|
|
+ explicit DxilModuleInit() : ModulePass(ID) {}
|
|
|
+
|
|
|
+ StringRef getPassName() const override {
|
|
|
+ return "Create DXIL Module for opt tests";
|
|
|
+ }
|
|
|
+
|
|
|
+ bool runOnModule(Module &M) override {
|
|
|
+ M.GetOrCreateDxilModule();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+} // namespace
|
|
|
+
|
|
|
+char DxilModuleInit::ID = 0;
|
|
|
+
|
|
|
+ModulePass *llvm::createDxilModuleInitPass() { return new DxilModuleInit(); }
|
|
|
+
|
|
|
+INITIALIZE_PASS(DxilModuleInit, "hlsl-dxil-module-init",
|
|
|
+ "Create DXIL Module for opt tests", false, false)
|
|
|
+
|
|
|
+///////////////////////////////////////////////////////////////////////////////
|