26 #define DEBUG_TYPE "dxil-prepare"
35 Attribute::AlwaysInline,
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)
104 bool runOnModule(
Module &
M)
override {
109 if (!isValidForDXIL(
I))
112 for (
auto &
F :
M.functions()) {
113 F.removeFnAttrs(AttrMask);
114 F.removeRetAttrs(AttrMask);
115 for (
size_t Idx = 0, End =
F.arg_size(); Idx < End; ++Idx)
116 F.removeParamAttrs(Idx, AttrMask);
121 if (
I.getOpcode() == Instruction::FNeg) {
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);
166 for (
size_t Idx = 0, End = CB->arg_size(); Idx < End; ++Idx)
167 CB->removeParamAttrs(Idx, AttrMask);
190 return new DXILPrepareModule();