31#define DEBUG_TYPE "dxil-prepare"
40 Attribute::AlwaysInline,
45 Attribute::Convergent,
46 Attribute::InlineHint,
54 Attribute::NoDuplicate,
55 Attribute::NoImplicitFloat,
57 Attribute::NonLazyBind,
59 Attribute::Dereferenceable,
60 Attribute::DereferenceableOrNull,
65 Attribute::OptimizeForSize,
66 Attribute::OptimizeNone,
70 Attribute::ReturnsTwice,
72 Attribute::StackAlignment,
73 Attribute::StackProtect,
74 Attribute::StackProtectReq,
75 Attribute::StackProtectStrong,
78 Attribute::SanitizeAddress,
79 Attribute::SanitizeThread,
80 Attribute::SanitizeMemory,
88 bool AllowExperimental) {
89 for (
auto &Attr : AS) {
90 if (!Attr.isStringAttribute())
95 if (AllowExperimental &&
Key.starts_with(
"exp-"))
101static void removeStringFunctionAttributes(
Function &
F,
102 bool AllowExperimental) {
103 AttributeList Attrs =
F.getAttributes();
104 const StringSet<> LiveKeys = {
"waveops-include-helper-lanes",
108 collectDeadStringAttrs(DeadAttrs, Attrs.getFnAttrs(), LiveKeys,
110 collectDeadStringAttrs(DeadAttrs, Attrs.getRetAttrs(), LiveKeys,
113 F.removeFnAttrs(DeadAttrs);
114 F.removeRetAttrs(DeadAttrs);
124 auto It = PointerTypes.
find(Operand);
125 if (It != PointerTypes.
end()) {
134 ValTy = GlobalVar->getValueType();
137 ValTy = AI->getAllocatedType();
140 Type *ElTy = ArrTy->getElementType();
148 while (GEPInstr->getOpcode() == Instruction::GetElementPtr) {
149 Value *OpArg = GEPInstr->getOperand(0);
151 GEPInstr = NewGEPInstr;
156 ValTy = GlobalVar->getValueType();
158 ValTy = AI->getAllocatedType();
160 Type *ElTy = ArrTy->getElementType();
169 Builder.SetInsertPoint(&Inst);
173 return Builder.Insert(
175 Builder.getPtrTy(PtrTy->getAddressSpace())));
179 bool runOnModule(
Module &M)
override {
184 if (!isValidForDXIL(
I))
189 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
193 for (
auto &
F : M.functions()) {
194 F.removeFnAttrs(AttrMask);
195 F.removeRetAttrs(AttrMask);
199 removeStringFunctionAttributes(
F, AllowExperimental);
200 for (
size_t Idx = 0, End =
F.arg_size(); Idx < End; ++Idx)
201 F.removeParamAttrs(Idx, AttrMask);
208 CB->removeFnAttrs(AttrMask);
209 CB->removeRetAttrs(AttrMask);
210 for (
size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
211 CB->removeParamAttrs(Idx, AttrMask);
218 if (
Value *NoOpBitcast = maybeGenerateBitcast(
219 Builder, PointerTypes,
I, LI->getPointerOperand(),
221 LI->replaceAllUsesWith(
222 Builder.CreateLoad(LI->getType(), NoOpBitcast));
223 LI->eraseFromParent();
228 if (
Value *NoOpBitcast = maybeGenerateBitcast(
229 Builder, PointerTypes,
I,
SI->getPointerOperand(),
230 SI->getValueOperand()->getType())) {
232 SI->replaceAllUsesWith(
233 Builder.CreateStore(
SI->getValueOperand(), NoOpBitcast));
234 SI->eraseFromParent();
239 if (
Value *NoOpBitcast = maybeGenerateBitcast(
240 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
241 GEP->getSourceElementType()))
242 GEP->setOperand(0, NoOpBitcast);
263char DXILPrepareModule::ID = 0;
274 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.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
@ EndAttrKinds
Sentinel value useful for loops.
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.
StringRef - 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
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.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.