|
13 | 13 | #include "llvm/IR/InstIterator.h"
|
14 | 14 | #include "llvm/IR/Instruction.h"
|
15 | 15 | #include "llvm/IR/Instructions.h"
|
16 |
| -#include "llvm/IR/Module.h" |
17 | 16 | #include "llvm/Pass.h"
|
18 | 17 | #include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
19 | 18 | #include <functional>
|
@@ -175,22 +174,16 @@ static void upcastI8AllocasAndUses(Instruction &I,
|
175 | 174 |
|
176 | 175 | Type *SmallestType = nullptr;
|
177 | 176 |
|
| 177 | + // Gather all cast targets |
178 | 178 | for (User *U : AI->users()) {
|
179 | 179 | auto *Load = dyn_cast<LoadInst>(U);
|
180 | 180 | if (!Load)
|
181 | 181 | continue;
|
182 | 182 | for (User *LU : Load->users()) {
|
183 |
| - Type *Ty = nullptr; |
184 |
| - if (auto *Cast = dyn_cast<CastInst>(LU)) |
185 |
| - Ty = Cast->getType(); |
186 |
| - if (CallInst *CI = dyn_cast<CallInst>(LU)) { |
187 |
| - if (CI->getIntrinsicID() == Intrinsic::memset) |
188 |
| - Ty = Type::getInt32Ty(CI->getContext()); |
189 |
| - } |
190 |
| - |
191 |
| - if (!Ty) |
| 183 | + auto *Cast = dyn_cast<CastInst>(LU); |
| 184 | + if (!Cast) |
192 | 185 | continue;
|
193 |
| - |
| 186 | + Type *Ty = Cast->getType(); |
194 | 187 | if (!SmallestType ||
|
195 | 188 | Ty->getPrimitiveSizeInBits() < SmallestType->getPrimitiveSizeInBits())
|
196 | 189 | SmallestType = Ty;
|
@@ -246,77 +239,6 @@ downcastI64toI32InsertExtractElements(Instruction &I,
|
246 | 239 | }
|
247 | 240 | }
|
248 | 241 |
|
249 |
| -static void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val, |
250 |
| - ConstantInt *SizeCI, |
251 |
| - DenseMap<Value *, Value *> &ReplacedValues) { |
252 |
| - LLVMContext &Ctx = Builder.getContext(); |
253 |
| - [[maybe_unused]] const DataLayout &DL = |
254 |
| - Builder.GetInsertBlock()->getModule()->getDataLayout(); |
255 |
| - [[maybe_unused]] uint64_t OrigSize = SizeCI->getZExtValue(); |
256 |
| - |
257 |
| - AllocaInst *Alloca = dyn_cast<AllocaInst>(Dst); |
258 |
| - |
259 |
| - assert(Alloca && "Expected memset on an Alloca"); |
260 |
| - assert(OrigSize == Alloca->getAllocationSize(DL)->getFixedValue() && |
261 |
| - "Expected for memset size to match DataLayout size"); |
262 |
| - |
263 |
| - Type *AllocatedTy = Alloca->getAllocatedType(); |
264 |
| - ArrayType *ArrTy = dyn_cast<ArrayType>(AllocatedTy); |
265 |
| - assert(ArrTy && "Expected Alloca for an Array Type"); |
266 |
| - |
267 |
| - Type *ElemTy = ArrTy->getElementType(); |
268 |
| - uint64_t Size = ArrTy->getArrayNumElements(); |
269 |
| - |
270 |
| - [[maybe_unused]] uint64_t ElemSize = DL.getTypeStoreSize(ElemTy); |
271 |
| - |
272 |
| - assert(ElemSize > 0 && "Size must be set"); |
273 |
| - assert(OrigSize == ElemSize * Size && "Size in bytes must match"); |
274 |
| - |
275 |
| - Value *TypedVal = Val; |
276 |
| - |
277 |
| - if (Val->getType() != ElemTy) { |
278 |
| - if (ReplacedValues[Val]) { |
279 |
| - // Note for i8 replacements if we know them we should use them. |
280 |
| - // Further if this is a constant ReplacedValues will return null |
281 |
| - // so we will stick to TypedVal = Val |
282 |
| - TypedVal = ReplacedValues[Val]; |
283 |
| - |
284 |
| - } else { |
285 |
| - // This case Val is a ConstantInt so the cast folds away. |
286 |
| - // However if we don't do the cast the store below ends up being |
287 |
| - // an i8. |
288 |
| - TypedVal = Builder.CreateIntCast(Val, ElemTy, false); |
289 |
| - } |
290 |
| - } |
291 |
| - |
292 |
| - for (uint64_t I = 0; I < Size; ++I) { |
293 |
| - Value *Offset = ConstantInt::get(Type::getInt32Ty(Ctx), I); |
294 |
| - Value *Ptr = Builder.CreateGEP(ElemTy, Dst, Offset, "gep"); |
295 |
| - Builder.CreateStore(TypedVal, Ptr); |
296 |
| - } |
297 |
| -} |
298 |
| - |
299 |
| -static void removeMemSet(Instruction &I, |
300 |
| - SmallVectorImpl<Instruction *> &ToRemove, |
301 |
| - DenseMap<Value *, Value *> &ReplacedValues) { |
302 |
| - |
303 |
| - CallInst *CI = dyn_cast<CallInst>(&I); |
304 |
| - if (!CI) |
305 |
| - return; |
306 |
| - |
307 |
| - Intrinsic::ID ID = CI->getIntrinsicID(); |
308 |
| - if (ID != Intrinsic::memset) |
309 |
| - return; |
310 |
| - |
311 |
| - IRBuilder<> Builder(&I); |
312 |
| - Value *Dst = CI->getArgOperand(0); |
313 |
| - Value *Val = CI->getArgOperand(1); |
314 |
| - ConstantInt *Size = dyn_cast<ConstantInt>(CI->getArgOperand(2)); |
315 |
| - assert(Size && "Expected Size to be a ConstantInt"); |
316 |
| - emitMemsetExpansion(Builder, Dst, Val, Size, ReplacedValues); |
317 |
| - ToRemove.push_back(CI); |
318 |
| -} |
319 |
| - |
320 | 242 | namespace {
|
321 | 243 | class DXILLegalizationPipeline {
|
322 | 244 |
|
@@ -348,7 +270,6 @@ class DXILLegalizationPipeline {
|
348 | 270 | LegalizationPipeline.push_back(fixI8UseChain);
|
349 | 271 | LegalizationPipeline.push_back(downcastI64toI32InsertExtractElements);
|
350 | 272 | LegalizationPipeline.push_back(legalizeFreeze);
|
351 |
| - LegalizationPipeline.push_back(removeMemSet); |
352 | 273 | }
|
353 | 274 | };
|
354 | 275 |
|
|
0 commit comments