27#define DEBUG_TYPE "dxil-prepare"
36 Attribute::AlwaysInline,
41 Attribute::Convergent,
42 Attribute::InlineHint,
51 Attribute::NoDuplicate,
52 Attribute::NoImplicitFloat,
54 Attribute::NonLazyBind,
56 Attribute::Dereferenceable,
57 Attribute::DereferenceableOrNull,
62 Attribute::OptimizeForSize,
63 Attribute::OptimizeNone,
67 Attribute::ReturnsTwice,
69 Attribute::StackAlignment,
70 Attribute::StackProtect,
71 Attribute::StackProtectReq,
72 Attribute::StackProtectStrong,
75 Attribute::SanitizeAddress,
76 Attribute::SanitizeThread,
77 Attribute::SanitizeMemory,
90 auto It = PointerTypes.
find(Operand);
91 if (It != PointerTypes.
end())
92 if (cast<TypedPointerType>(It->second)->getElementType() == Ty)
101 Builder.
getPtrTy(PtrTy->getAddressSpace())));
110 if (!isValidForDXIL(
I))
113 for (
auto &
F : M.functions()) {
114 F.removeFnAttrs(AttrMask);
115 F.removeRetAttrs(AttrMask);
117 F.removeParamAttrs(
Idx, AttrMask);
122 if (
I.getOpcode() == Instruction::FNeg) {
124 Value *In =
I.getOperand(0);
126 I.replaceAllUsesWith(Builder.
CreateFSub(Zero, In));
133 if (
auto LI = dyn_cast<LoadInst>(&
I)) {
134 if (
Value *NoOpBitcast = maybeGenerateBitcast(
135 Builder, PointerTypes,
I, LI->getPointerOperand(),
137 LI->replaceAllUsesWith(
138 Builder.
CreateLoad(LI->getType(), NoOpBitcast));
139 LI->eraseFromParent();
143 if (
auto SI = dyn_cast<StoreInst>(&
I)) {
144 if (
Value *NoOpBitcast = maybeGenerateBitcast(
145 Builder, PointerTypes,
I, SI->getPointerOperand(),
146 SI->getValueOperand()->getType())) {
148 SI->replaceAllUsesWith(
149 Builder.
CreateStore(SI->getValueOperand(), NoOpBitcast));
150 SI->eraseFromParent();
154 if (
auto GEP = dyn_cast<GetElementPtrInst>(&
I)) {
155 if (
Value *NoOpBitcast = maybeGenerateBitcast(
156 Builder, PointerTypes,
I,
GEP->getPointerOperand(),
157 GEP->getSourceElementType()))
158 GEP->setOperand(0, NoOpBitcast);
161 if (
auto *CB = dyn_cast<CallBase>(&
I)) {
162 CB->removeFnAttrs(AttrMask);
163 CB->removeRetAttrs(AttrMask);
165 CB->removeParamAttrs(
Idx, AttrMask);
178char DXILPrepareModule::ID = 0;
188 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)
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
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.