26#define DEBUG_TYPE "dxil-prepare"
35 Attribute::AlwaysInline,
40 Attribute::Convergent,
41 Attribute::InlineHint,
50 Attribute::NoDuplicate,
51 Attribute::NoImplicitFloat,
53 Attribute::NonLazyBind,
55 Attribute::Dereferenceable,
56 Attribute::DereferenceableOrNull,
61 Attribute::OptimizeForSize,
62 Attribute::OptimizeNone,
66 Attribute::ReturnsTwice,
68 Attribute::StackAlignment,
69 Attribute::StackProtect,
70 Attribute::StackProtectReq,
71 Attribute::StackProtectStrong,
74 Attribute::SanitizeAddress,
75 Attribute::SanitizeThread,
76 Attribute::SanitizeMemory,
89 auto It = PointerTypes.
find(Operand);
90 if (It != PointerTypes.
end())
91 if (cast<TypedPointerType>(It->second)->getElementType() == Ty)
100 Builder.getInt8PtrTy(PtrTy->getAddressSpace())));
109 if (!isValidForDXIL(
I))
112 for (
auto &
F : M.functions()) {
113 F.removeFnAttrs(AttrMask);
114 F.removeRetAttrs(AttrMask);
116 F.removeParamAttrs(
Idx, AttrMask);
121 if (
I.getOpcode() == Instruction::FNeg) {
123 Value *In =
I.getOperand(0);
125 I.replaceAllUsesWith(
Builder.CreateFSub(Zero, In));
130 if (M.getContext().supportsTypedPointers())
135 if (
auto LI = dyn_cast<LoadInst>(&
I)) {
136 if (
Value *NoOpBitcast = maybeGenerateBitcast(
137 Builder, PointerTypes,
I, LI->getPointerOperand(),
139 LI->replaceAllUsesWith(
140 Builder.CreateLoad(LI->getType(), NoOpBitcast));
141 LI->eraseFromParent();
145 if (
auto SI = dyn_cast<StoreInst>(&
I)) {
146 if (
Value *NoOpBitcast = maybeGenerateBitcast(
147 Builder, PointerTypes,
I,
SI->getPointerOperand(),
148 SI->getValueOperand()->getType())) {
150 SI->replaceAllUsesWith(
151 Builder.CreateStore(
SI->getValueOperand(), NoOpBitcast));
152 SI->eraseFromParent();
156 if (
auto GEP = dyn_cast<GetElementPtrInst>(&
I)) {
157 if (
Value *NoOpBitcast = maybeGenerateBitcast(
158 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
159 GEP->getResultElementType()))
160 GEP->setOperand(0, NoOpBitcast);
163 if (
auto *CB = dyn_cast<CallBase>(&
I)) {
164 CB->removeFnAttrs(AttrMask);
165 CB->removeRetAttrs(AttrMask);
167 CB->removeParamAttrs(
Idx, AttrMask);
180char DXILPrepareModule::ID = 0;
190 return new DXILPrepareModule();
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
@ EndAttrKinds
Sentinal value useful for loops.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
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...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
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.
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.
This is an optimization pass for GlobalISel generic memory operations.
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.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.