32#define DEBUG_TYPE "dxil-prepare"
41 bool AllowExperimental) {
42 for (
auto &Attr : AS) {
43 if (!Attr.isStringAttribute())
48 if (AllowExperimental &&
Key.starts_with(
"exp-"))
54static void removeStringFunctionAttributes(
Function &
F,
55 bool AllowExperimental) {
56 AttributeList Attrs =
F.getAttributes();
57 const StringSet<> LiveKeys = {
"waveops-include-helper-lanes",
61 collectDeadStringAttrs(DeadAttrs, Attrs.getFnAttrs(), LiveKeys,
63 collectDeadStringAttrs(DeadAttrs, Attrs.getRetAttrs(), LiveKeys,
66 F.removeFnAttrs(DeadAttrs);
67 F.removeRetAttrs(DeadAttrs);
77 auto It = PointerTypes.
find(Operand);
78 if (It != PointerTypes.
end()) {
87 ValTy = GlobalVar->getValueType();
90 ValTy = AI->getAllocatedType();
93 Type *ElTy = ArrTy->getElementType();
101 while (GEPInstr->getOpcode() == Instruction::GetElementPtr) {
102 Value *OpArg = GEPInstr->getOperand(0);
104 GEPInstr = NewGEPInstr;
109 ValTy = GlobalVar->getValueType();
111 ValTy = AI->getAllocatedType();
113 Type *ElTy = ArrTy->getElementType();
122 Builder.SetInsertPoint(&Inst);
126 return Builder.Insert(
128 Builder.getPtrTy(PtrTy->getAddressSpace())));
132 bool runOnModule(
Module &M)
override {
137 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
141 for (
auto &
F : M.functions()) {
142 F.removeFnAttrs(AttrMask);
143 F.removeRetAttrs(AttrMask);
147 removeStringFunctionAttributes(
F, AllowExperimental);
148 for (
size_t Idx = 0, End =
F.arg_size(); Idx < End; ++Idx)
149 F.removeParamAttrs(Idx, AttrMask);
156 CB->removeFnAttrs(AttrMask);
157 CB->removeRetAttrs(AttrMask);
158 for (
size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
159 CB->removeParamAttrs(Idx, AttrMask);
166 if (
Value *NoOpBitcast = maybeGenerateBitcast(
167 Builder, PointerTypes,
I, LI->getPointerOperand(),
169 LI->replaceAllUsesWith(
170 Builder.CreateLoad(LI->getType(), NoOpBitcast));
171 LI->eraseFromParent();
176 if (
Value *NoOpBitcast = maybeGenerateBitcast(
177 Builder, PointerTypes,
I,
SI->getPointerOperand(),
178 SI->getValueOperand()->getType())) {
180 SI->replaceAllUsesWith(
181 Builder.CreateStore(
SI->getValueOperand(), NoOpBitcast));
182 SI->eraseFromParent();
187 if (
Value *NoOpBitcast = maybeGenerateBitcast(
188 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
189 GEP->getSourceElementType()))
190 GEP->setOperand(0, NoOpBitcast);
211char DXILPrepareModule::ID = 0;
222 return new DXILPrepareModule();
Module.h This file contains the declarations for the Module class.
#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.
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.
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.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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...
ModulePass * createDXILPrepareModulePass()
Pass to convert modules into DXIL-compatable modules.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.