35#define DEBUG_TYPE "dxil-prepare"
44 bool AllowExperimental) {
45 for (
auto &Attr : AS) {
46 if (!Attr.isStringAttribute())
51 if (AllowExperimental &&
Key.starts_with(
"exp-"))
57static void removeStringFunctionAttributes(
Function &
F,
58 bool AllowExperimental) {
60 const StringSet<> LiveKeys = {
"waveops-include-helper-lanes",
64 collectDeadStringAttrs(DeadAttrs, Attrs.getFnAttrs(), LiveKeys,
66 collectDeadStringAttrs(DeadAttrs, Attrs.getRetAttrs(), LiveKeys,
69 F.removeFnAttrs(DeadAttrs);
70 F.removeRetAttrs(DeadAttrs);
73class DXILPrepareModuleLegacy :
public ModulePass {
85 bool runOnModule(
Module &M)
override;
88char DXILPrepareModuleLegacy::ID = 0;
97 auto It = PointerTypes.
find(Operand);
98 if (It != PointerTypes.
end()) {
107 ValTy = GlobalVar->getValueType();
110 ValTy = AI->getAllocatedType();
113 Type *ElTy = ArrTy->getElementType();
121 while (GEPInstr->getOpcode() == Instruction::GetElementPtr) {
122 Value *OpArg = GEPInstr->getOperand(0);
124 GEPInstr = NewGEPInstr;
129 ValTy = GlobalVar->getValueType();
131 ValTy = AI->getAllocatedType();
133 Type *ElTy = ArrTy->getElementType();
142 Builder.SetInsertPoint(&Inst);
146 return Builder.Insert(
148 Builder.getPtrTy(PtrTy->getAddressSpace())));
161 for (
auto &
F : M.functions()) {
162 F.removeFnAttrs(AttrMask);
163 F.removeRetAttrs(AttrMask);
167 removeStringFunctionAttributes(
F, AllowExperimental);
168 for (
size_t Idx = 0,
End =
F.arg_size(); Idx <
End; ++Idx)
169 F.removeParamAttrs(Idx, AttrMask);
176 CB->removeFnAttrs(AttrMask);
177 CB->removeRetAttrs(AttrMask);
178 for (
size_t Idx = 0,
End = CB->arg_size(); Idx <
End; ++Idx)
179 CB->removeParamAttrs(Idx, AttrMask);
187 Builder, PointerTypes,
I, LI->getPointerOperand(),
189 LI->replaceAllUsesWith(
190 Builder.CreateLoad(LI->getType(), NoOpBitcast));
191 LI->eraseFromParent();
197 Builder, PointerTypes,
I,
SI->getPointerOperand(),
198 SI->getValueOperand()->getType())) {
200 SI->replaceAllUsesWith(
201 Builder.CreateStore(
SI->getValueOperand(), NoOpBitcast));
202 SI->eraseFromParent();
208 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
209 GEP->getSourceElementType()))
210 GEP->setOperand(0, NoOpBitcast);
218 Builder, PointerTypes,
I, RMW->getPointerOperand(),
219 RMW->getValOperand()->getType()))
226 Builder, PointerTypes,
I, CmpXchg->getPointerOperand(),
227 CmpXchg->getNewValOperand()->getType()))
239bool DXILPrepareModuleLegacy::runOnModule(
Module &M) {
240 return prepareModule(M, [&]() -> dxil::ModuleMetadataInfo & {
241 return getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
254 .preserve<DXILResourceAnalysis>()
256 .preserve<SignatureAnalysis>()
261 "DXIL Prepare Module",
false,
false)
267 return new DXILPrepareModuleLegacy();
static bool prepareModule(Module &M, function_ref< dxil::ModuleMetadataInfo &()> GetModuleMetadataInfo)
static Value * maybeGenerateBitcast(IRBuilder<> &Builder, PointerTypeMap &PointerTypes, Instruction &Inst, Value *Operand, Type *Ty)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
StringSet - A set-like wrapper for the StringMap.
Defines the llvm::VersionTuple class, which represents a version in the form major[....
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static unsigned getPointerOperandIndex()
static unsigned getPointerOperandIndex()
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
This class holds the attributes for a particular argument, parameter, function, or return value.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
A constant value that is initialized with an expression using other constant values.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
iterator find(const_arg_type_t< KeyT > Val)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Represent a constant reference to a string, i.e.
StringSet - A wrapper for StringMap that provides set-like functionality.
bool contains(StringRef key) const
Check if the set contains the given key.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Represents a version number in the form major[.minor[.subminor[.build]]].
unsigned getMajor() const
Retrieve the major version number.
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Wrapper pass for the legacy pass manager.
Wrapper pass for the legacy pass manager.
An efficient, type-erasing, non-owning reference to a callable.
Pass manager infrastructure for declaring and invalidating analyses.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
DenseMap< const Value *, Type * > PointerTypeMap
const AttributeMask & getNonDXILAttributeMask()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
ModulePass * createDXILPrepareModuleLegacyPass()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
@ End
Run the machine verifier once, at the end of the pipeline.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.