aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/DirectX/DXILPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/DirectX/DXILPrepare.cpp')
-rw-r--r--llvm/lib/Target/DirectX/DXILPrepare.cpp89
1 files changed, 16 insertions, 73 deletions
diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp
index 42e90f0..d6fa65f 100644
--- a/llvm/lib/Target/DirectX/DXILPrepare.cpp
+++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
///
-/// \file This file contains pases and utilities to convert a modern LLVM
+/// \file This file contains passes and utilities to convert a modern LLVM
/// module into a module compatible with the LLVM 3.7-based DirectX Intermediate
/// Language (DXIL).
//===----------------------------------------------------------------------===//
@@ -16,7 +16,6 @@
#include "DirectX.h"
#include "DirectXIRPasses/PointerTypeAnalysis.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
#include "llvm/Analysis/DXILResource.h"
@@ -27,7 +26,6 @@
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
-#include "llvm/Support/Compiler.h"
#include "llvm/Support/VersionTuple.h"
#define DEBUG_TYPE "dxil-prepare"
@@ -116,31 +114,6 @@ static void removeStringFunctionAttributes(Function &F,
F.removeRetAttrs(DeadAttrs);
}
-static void cleanModuleFlags(Module &M) {
- NamedMDNode *MDFlags = M.getModuleFlagsMetadata();
- if (!MDFlags)
- return;
-
- SmallVector<llvm::Module::ModuleFlagEntry> FlagEntries;
- M.getModuleFlagsMetadata(FlagEntries);
- bool Updated = false;
- for (auto &Flag : FlagEntries) {
- // llvm 3.7 only supports behavior up to AppendUnique.
- if (Flag.Behavior <= Module::ModFlagBehavior::AppendUnique)
- continue;
- Flag.Behavior = Module::ModFlagBehavior::Warning;
- Updated = true;
- }
-
- if (!Updated)
- return;
-
- MDFlags->eraseFromParent();
-
- for (auto &Flag : FlagEntries)
- M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
-}
-
class DXILPrepareModule : public ModulePass {
static Value *maybeGenerateBitcast(IRBuilder<> &Builder,
@@ -202,15 +175,6 @@ class DXILPrepareModule : public ModulePass {
Builder.getPtrTy(PtrTy->getAddressSpace())));
}
- static std::array<unsigned, 6> getCompatibleInstructionMDs(llvm::Module &M) {
- return {M.getMDKindID("dx.nonuniform"),
- M.getMDKindID("dx.controlflow.hints"),
- M.getMDKindID("dx.precise"),
- llvm::LLVMContext::MD_range,
- llvm::LLVMContext::MD_alias_scope,
- llvm::LLVMContext::MD_noalias};
- }
-
public:
bool runOnModule(Module &M) override {
PointerTypeMap PointerTypes = PointerTypeAnalysis::run(M);
@@ -224,10 +188,7 @@ public:
const dxil::ModuleMetadataInfo MetadataInfo =
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
VersionTuple ValVer = MetadataInfo.ValidatorVersion;
- bool SkipValidation = ValVer.getMajor() == 0 && ValVer.getMinor() == 0;
-
- // construct allowlist of valid metadata node kinds
- std::array<unsigned, 6> DXILCompatibleMDs = getCompatibleInstructionMDs(M);
+ bool AllowExperimental = ValVer.getMajor() == 0 && ValVer.getMinor() == 0;
for (auto &F : M.functions()) {
F.removeFnAttrs(AttrMask);
@@ -235,7 +196,7 @@ public:
// Only remove string attributes if we are not skipping validation.
// This will reserve the experimental attributes when validation version
// is 0.0 for experiment mode.
- removeStringFunctionAttributes(F, SkipValidation);
+ removeStringFunctionAttributes(F, AllowExperimental);
for (size_t Idx = 0, End = F.arg_size(); Idx < End; ++Idx)
F.removeParamAttrs(Idx, AttrMask);
@@ -243,11 +204,17 @@ public:
IRBuilder<> Builder(&BB);
for (auto &I : make_early_inc_range(BB)) {
- I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
+ if (auto *CB = dyn_cast<CallBase>(&I)) {
+ CB->removeFnAttrs(AttrMask);
+ CB->removeRetAttrs(AttrMask);
+ for (size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
+ CB->removeParamAttrs(Idx, AttrMask);
+ continue;
+ }
// Emtting NoOp bitcast instructions allows the ValueEnumerator to be
// unmodified as it reserves instruction IDs during contruction.
- if (auto LI = dyn_cast<LoadInst>(&I)) {
+ if (auto *LI = dyn_cast<LoadInst>(&I)) {
if (Value *NoOpBitcast = maybeGenerateBitcast(
Builder, PointerTypes, I, LI->getPointerOperand(),
LI->getType())) {
@@ -257,7 +224,7 @@ public:
}
continue;
}
- if (auto SI = dyn_cast<StoreInst>(&I)) {
+ if (auto *SI = dyn_cast<StoreInst>(&I)) {
if (Value *NoOpBitcast = maybeGenerateBitcast(
Builder, PointerTypes, I, SI->getPointerOperand(),
SI->getValueOperand()->getType())) {
@@ -268,39 +235,16 @@ public:
}
continue;
}
- if (auto GEP = dyn_cast<GetElementPtrInst>(&I)) {
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
if (Value *NoOpBitcast = maybeGenerateBitcast(
Builder, PointerTypes, I, GEP->getPointerOperand(),
GEP->getSourceElementType()))
GEP->setOperand(0, NoOpBitcast);
continue;
}
- if (auto *CB = dyn_cast<CallBase>(&I)) {
- CB->removeFnAttrs(AttrMask);
- CB->removeRetAttrs(AttrMask);
- for (size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
- CB->removeParamAttrs(Idx, AttrMask);
- continue;
- }
}
}
}
- // Remove flags not for DXIL.
- cleanModuleFlags(M);
-
- // dx.rootsignatures will have been parsed from its metadata form as its
- // binary form as part of the RootSignatureAnalysisWrapper, so safely
- // remove it as it is not recognized in DXIL
- if (NamedMDNode *RootSignature = M.getNamedMetadata("dx.rootsignatures"))
- RootSignature->eraseFromParent();
-
- // llvm.errno.tbaa was recently added but is not supported in LLVM 3.7 and
- // causes all tests using the DXIL Validator to fail.
- //
- // This is a temporary fix and should be replaced with a whitelist once
- // we have determined all metadata that the DXIL Validator allows
- if (NamedMDNode *ErrNo = M.getNamedMetadata("llvm.errno.tbaa"))
- ErrNo->eraseFromParent();
return true;
}
@@ -308,11 +252,11 @@ public:
DXILPrepareModule() : ModulePass(ID) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
- AU.addRequired<RootSignatureAnalysisWrapper>();
- AU.addPreserved<RootSignatureAnalysisWrapper>();
- AU.addPreserved<ShaderFlagsAnalysisWrapper>();
+
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
AU.addPreserved<DXILResourceWrapperPass>();
+ AU.addPreserved<RootSignatureAnalysisWrapper>();
+ AU.addPreserved<ShaderFlagsAnalysisWrapper>();
}
static char ID; // Pass identification.
};
@@ -323,7 +267,6 @@ char DXILPrepareModule::ID = 0;
INITIALIZE_PASS_BEGIN(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module",
false, false)
INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(RootSignatureAnalysisWrapper)
INITIALIZE_PASS_END(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module", false,
false)