33#define DEBUG_TYPE "dxil-prepare"
42 bool AllowExperimental) {
43 for (
auto &Attr : AS) {
44 if (!Attr.isStringAttribute())
49 if (AllowExperimental &&
Key.starts_with(
"exp-"))
55static void removeStringFunctionAttributes(
Function &
F,
56 bool AllowExperimental) {
58 const StringSet<> LiveKeys = {
"waveops-include-helper-lanes",
62 collectDeadStringAttrs(DeadAttrs, Attrs.getFnAttrs(), LiveKeys,
64 collectDeadStringAttrs(DeadAttrs, Attrs.getRetAttrs(), LiveKeys,
67 F.removeFnAttrs(DeadAttrs);
68 F.removeRetAttrs(DeadAttrs);
78 auto It = PointerTypes.
find(Operand);
79 if (It != PointerTypes.
end()) {
88 ValTy = GlobalVar->getValueType();
91 ValTy = AI->getAllocatedType();
94 Type *ElTy = ArrTy->getElementType();
102 while (GEPInstr->getOpcode() == Instruction::GetElementPtr) {
103 Value *OpArg = GEPInstr->getOperand(0);
105 GEPInstr = NewGEPInstr;
110 ValTy = GlobalVar->getValueType();
112 ValTy = AI->getAllocatedType();
114 Type *ElTy = ArrTy->getElementType();
123 Builder.SetInsertPoint(&Inst);
127 return Builder.Insert(
129 Builder.getPtrTy(PtrTy->getAddressSpace())));
133 bool runOnModule(
Module &M)
override {
138 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
142 for (
auto &
F : M.functions()) {
143 F.removeFnAttrs(AttrMask);
144 F.removeRetAttrs(AttrMask);
148 removeStringFunctionAttributes(
F, AllowExperimental);
149 for (
size_t Idx = 0,
End =
F.arg_size(); Idx <
End; ++Idx)
150 F.removeParamAttrs(Idx, AttrMask);
157 CB->removeFnAttrs(AttrMask);
158 CB->removeRetAttrs(AttrMask);
159 for (
size_t Idx = 0,
End = CB->arg_size(); Idx <
End; ++Idx)
160 CB->removeParamAttrs(Idx, AttrMask);
167 if (
Value *NoOpBitcast = maybeGenerateBitcast(
168 Builder, PointerTypes,
I, LI->getPointerOperand(),
170 LI->replaceAllUsesWith(
171 Builder.CreateLoad(LI->getType(), NoOpBitcast));
172 LI->eraseFromParent();
177 if (
Value *NoOpBitcast = maybeGenerateBitcast(
178 Builder, PointerTypes,
I,
SI->getPointerOperand(),
179 SI->getValueOperand()->getType())) {
181 SI->replaceAllUsesWith(
182 Builder.CreateStore(
SI->getValueOperand(), NoOpBitcast));
183 SI->eraseFromParent();
188 if (
Value *NoOpBitcast = maybeGenerateBitcast(
189 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
190 GEP->getSourceElementType()))
191 GEP->setOperand(0, NoOpBitcast);
198 if (
Value *NoOpBitcast = maybeGenerateBitcast(
199 Builder, PointerTypes,
I, RMW->getPointerOperand(),
200 RMW->getValOperand()->getType()))
206 if (
Value *NoOpBitcast = maybeGenerateBitcast(
207 Builder, PointerTypes,
I, CmpXchg->getPointerOperand(),
208 CmpXchg->getNewValOperand()->getType()))
232char DXILPrepareModule::ID = 0;
243 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.
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.
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.
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.
@ End
Run the machine verifier once, at the end of the pipeline.