LLVM 19.0.0git
AMDGPUAtomicOptimizer.cpp
Go to the documentation of this file.
1//===-- AMDGPUAtomicOptimizer.cpp -----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This pass optimizes atomic operations by using a single lane of a wavefront
11/// to perform the atomic operation, thus reducing contention on that memory
12/// location.
13/// Atomic optimizer uses following strategies to compute scan and reduced
14/// values
15/// 1. DPP -
16/// This is the most efficient implementation for scan. DPP uses Whole Wave
17/// Mode (WWM)
18/// 2. Iterative -
19// An alternative implementation iterates over all active lanes
20/// of Wavefront using llvm.cttz and performs scan using readlane & writelane
21/// intrinsics
22//===----------------------------------------------------------------------===//
23
24#include "AMDGPU.h"
25#include "GCNSubtarget.h"
29#include "llvm/IR/IRBuilder.h"
30#include "llvm/IR/InstVisitor.h"
31#include "llvm/IR/IntrinsicsAMDGPU.h"
35
36#define DEBUG_TYPE "amdgpu-atomic-optimizer"
37
38using namespace llvm;
39using namespace llvm::AMDGPU;
40
41namespace {
42
43struct ReplacementInfo {
46 unsigned ValIdx;
47 bool ValDivergent;
48};
49
50class AMDGPUAtomicOptimizer : public FunctionPass {
51public:
52 static char ID;
53 ScanOptions ScanImpl;
54 AMDGPUAtomicOptimizer(ScanOptions ScanImpl)
55 : FunctionPass(ID), ScanImpl(ScanImpl) {}
56
57 bool runOnFunction(Function &F) override;
58
59 void getAnalysisUsage(AnalysisUsage &AU) const override {
63 }
64};
65
66class AMDGPUAtomicOptimizerImpl
67 : public InstVisitor<AMDGPUAtomicOptimizerImpl> {
68private:
70 const UniformityInfo *UA;
71 const DataLayout *DL;
72 DomTreeUpdater &DTU;
73 const GCNSubtarget *ST;
74 bool IsPixelShader;
75 ScanOptions ScanImpl;
76
77 Value *buildReduction(IRBuilder<> &B, AtomicRMWInst::BinOp Op, Value *V,
78 Value *const Identity) const;
80 Value *const Identity) const;
81 Value *buildShiftRight(IRBuilder<> &B, Value *V, Value *const Identity) const;
82
83 std::pair<Value *, Value *>
84 buildScanIteratively(IRBuilder<> &B, AtomicRMWInst::BinOp Op,
85 Value *const Identity, Value *V, Instruction &I,
86 BasicBlock *ComputeLoop, BasicBlock *ComputeEnd) const;
87
88 void optimizeAtomic(Instruction &I, AtomicRMWInst::BinOp Op, unsigned ValIdx,
89 bool ValDivergent) const;
90
91public:
92 AMDGPUAtomicOptimizerImpl() = delete;
93
94 AMDGPUAtomicOptimizerImpl(const UniformityInfo *UA, const DataLayout *DL,
95 DomTreeUpdater &DTU, const GCNSubtarget *ST,
96 bool IsPixelShader, ScanOptions ScanImpl)
97 : UA(UA), DL(DL), DTU(DTU), ST(ST), IsPixelShader(IsPixelShader),
98 ScanImpl(ScanImpl) {}
99
100 bool run(Function &F);
101
104};
105
106} // namespace
107
108char AMDGPUAtomicOptimizer::ID = 0;
109
110char &llvm::AMDGPUAtomicOptimizerID = AMDGPUAtomicOptimizer::ID;
111
112bool AMDGPUAtomicOptimizer::runOnFunction(Function &F) {
113 if (skipFunction(F)) {
114 return false;
115 }
116
117 const UniformityInfo *UA =
118 &getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
119 const DataLayout *DL = &F.getParent()->getDataLayout();
120
121 DominatorTreeWrapperPass *const DTW =
122 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
123 DomTreeUpdater DTU(DTW ? &DTW->getDomTree() : nullptr,
124 DomTreeUpdater::UpdateStrategy::Lazy);
125
126 const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
127 const TargetMachine &TM = TPC.getTM<TargetMachine>();
128 const GCNSubtarget *ST = &TM.getSubtarget<GCNSubtarget>(F);
129
130 bool IsPixelShader = F.getCallingConv() == CallingConv::AMDGPU_PS;
131
132 return AMDGPUAtomicOptimizerImpl(UA, DL, DTU, ST, IsPixelShader, ScanImpl)
133 .run(F);
134}
135
138
139 const auto *UA = &AM.getResult<UniformityInfoAnalysis>(F);
140 const DataLayout *DL = &F.getParent()->getDataLayout();
141
144 const GCNSubtarget *ST = &TM.getSubtarget<GCNSubtarget>(F);
145
146 bool IsPixelShader = F.getCallingConv() == CallingConv::AMDGPU_PS;
147
148 bool IsChanged =
149 AMDGPUAtomicOptimizerImpl(UA, DL, DTU, ST, IsPixelShader, ScanImpl)
150 .run(F);
151
152 if (!IsChanged) {
153 return PreservedAnalyses::all();
154 }
155
158 return PA;
159}
160
161bool AMDGPUAtomicOptimizerImpl::run(Function &F) {
162
163 // Scan option None disables the Pass
164 if (ScanImpl == ScanOptions::None) {
165 return false;
166 }
167
168 visit(F);
169
170 const bool Changed = !ToReplace.empty();
171
172 for (ReplacementInfo &Info : ToReplace) {
173 optimizeAtomic(*Info.I, Info.Op, Info.ValIdx, Info.ValDivergent);
174 }
175
176 ToReplace.clear();
177
178 return Changed;
179}
180
181void AMDGPUAtomicOptimizerImpl::visitAtomicRMWInst(AtomicRMWInst &I) {
182 // Early exit for unhandled address space atomic instructions.
183 switch (I.getPointerAddressSpace()) {
184 default:
185 return;
188 break;
189 }
190
191 AtomicRMWInst::BinOp Op = I.getOperation();
192
193 switch (Op) {
194 default:
195 return;
209 break;
210 }
211
212 // Only 32 and 64 bit floating point atomic ops are supported.
214 !(I.getType()->isFloatTy() || I.getType()->isDoubleTy())) {
215 return;
216 }
217
218 const unsigned PtrIdx = 0;
219 const unsigned ValIdx = 1;
220
221 // If the pointer operand is divergent, then each lane is doing an atomic
222 // operation on a different address, and we cannot optimize that.
223 if (UA->isDivergentUse(I.getOperandUse(PtrIdx))) {
224 return;
225 }
226
227 const bool ValDivergent = UA->isDivergentUse(I.getOperandUse(ValIdx));
228
229 // If the value operand is divergent, each lane is contributing a different
230 // value to the atomic calculation. We can only optimize divergent values if
231 // we have DPP available on our subtarget, and the atomic operation is 32
232 // bits.
233 if (ValDivergent &&
234 (!ST->hasDPP() || DL->getTypeSizeInBits(I.getType()) != 32)) {
235 return;
236 }
237
238 // If we get here, we can optimize the atomic using a single wavefront-wide
239 // atomic operation to do the calculation for the entire wavefront, so
240 // remember the instruction so we can come back to it.
241 const ReplacementInfo Info = {&I, Op, ValIdx, ValDivergent};
242
243 ToReplace.push_back(Info);
244}
245
246void AMDGPUAtomicOptimizerImpl::visitIntrinsicInst(IntrinsicInst &I) {
248
249 switch (I.getIntrinsicID()) {
250 default:
251 return;
252 case Intrinsic::amdgcn_buffer_atomic_add:
253 case Intrinsic::amdgcn_struct_buffer_atomic_add:
254 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_add:
255 case Intrinsic::amdgcn_raw_buffer_atomic_add:
256 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_add:
258 break;
259 case Intrinsic::amdgcn_buffer_atomic_sub:
260 case Intrinsic::amdgcn_struct_buffer_atomic_sub:
261 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub:
262 case Intrinsic::amdgcn_raw_buffer_atomic_sub:
263 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub:
265 break;
266 case Intrinsic::amdgcn_buffer_atomic_and:
267 case Intrinsic::amdgcn_struct_buffer_atomic_and:
268 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_and:
269 case Intrinsic::amdgcn_raw_buffer_atomic_and:
270 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_and:
272 break;
273 case Intrinsic::amdgcn_buffer_atomic_or:
274 case Intrinsic::amdgcn_struct_buffer_atomic_or:
275 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_or:
276 case Intrinsic::amdgcn_raw_buffer_atomic_or:
277 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_or:
279 break;
280 case Intrinsic::amdgcn_buffer_atomic_xor:
281 case Intrinsic::amdgcn_struct_buffer_atomic_xor:
282 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_xor:
283 case Intrinsic::amdgcn_raw_buffer_atomic_xor:
284 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_xor:
286 break;
287 case Intrinsic::amdgcn_buffer_atomic_smin:
288 case Intrinsic::amdgcn_struct_buffer_atomic_smin:
289 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smin:
290 case Intrinsic::amdgcn_raw_buffer_atomic_smin:
291 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smin:
293 break;
294 case Intrinsic::amdgcn_buffer_atomic_umin:
295 case Intrinsic::amdgcn_struct_buffer_atomic_umin:
296 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umin:
297 case Intrinsic::amdgcn_raw_buffer_atomic_umin:
298 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umin:
300 break;
301 case Intrinsic::amdgcn_buffer_atomic_smax:
302 case Intrinsic::amdgcn_struct_buffer_atomic_smax:
303 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smax:
304 case Intrinsic::amdgcn_raw_buffer_atomic_smax:
305 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smax:
307 break;
308 case Intrinsic::amdgcn_buffer_atomic_umax:
309 case Intrinsic::amdgcn_struct_buffer_atomic_umax:
310 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umax:
311 case Intrinsic::amdgcn_raw_buffer_atomic_umax:
312 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umax:
314 break;
315 }
316
317 const unsigned ValIdx = 0;
318
319 const bool ValDivergent = UA->isDivergentUse(I.getOperandUse(ValIdx));
320
321 // If the value operand is divergent, each lane is contributing a different
322 // value to the atomic calculation. We can only optimize divergent values if
323 // we have DPP available on our subtarget, and the atomic operation is 32
324 // bits.
325 if (ValDivergent &&
326 (!ST->hasDPP() || DL->getTypeSizeInBits(I.getType()) != 32)) {
327 return;
328 }
329
330 // If any of the other arguments to the intrinsic are divergent, we can't
331 // optimize the operation.
332 for (unsigned Idx = 1; Idx < I.getNumOperands(); Idx++) {
333 if (UA->isDivergentUse(I.getOperandUse(Idx))) {
334 return;
335 }
336 }
337
338 // If we get here, we can optimize the atomic using a single wavefront-wide
339 // atomic operation to do the calculation for the entire wavefront, so
340 // remember the instruction so we can come back to it.
341 const ReplacementInfo Info = {&I, Op, ValIdx, ValDivergent};
342
343 ToReplace.push_back(Info);
344}
345
346// Use the builder to create the non-atomic counterpart of the specified
347// atomicrmw binary op.
349 Value *LHS, Value *RHS) {
351
352 switch (Op) {
353 default:
354 llvm_unreachable("Unhandled atomic op");
356 return B.CreateBinOp(Instruction::Add, LHS, RHS);
358 return B.CreateFAdd(LHS, RHS);
360 return B.CreateBinOp(Instruction::Sub, LHS, RHS);
362 return B.CreateFSub(LHS, RHS);
364 return B.CreateBinOp(Instruction::And, LHS, RHS);
366 return B.CreateBinOp(Instruction::Or, LHS, RHS);
368 return B.CreateBinOp(Instruction::Xor, LHS, RHS);
369
371 Pred = CmpInst::ICMP_SGT;
372 break;
374 Pred = CmpInst::ICMP_SLT;
375 break;
377 Pred = CmpInst::ICMP_UGT;
378 break;
380 Pred = CmpInst::ICMP_ULT;
381 break;
383 return B.CreateMaxNum(LHS, RHS);
385 return B.CreateMinNum(LHS, RHS);
386 }
387 Value *Cond = B.CreateICmp(Pred, LHS, RHS);
388 return B.CreateSelect(Cond, LHS, RHS);
389}
390
391// Use the builder to create a reduction of V across the wavefront, with all
392// lanes active, returning the same result in all lanes.
393Value *AMDGPUAtomicOptimizerImpl::buildReduction(IRBuilder<> &B,
395 Value *V,
396 Value *const Identity) const {
397 Type *AtomicTy = V->getType();
398 Type *IntNTy = B.getIntNTy(AtomicTy->getPrimitiveSizeInBits());
399 Module *M = B.GetInsertBlock()->getModule();
400 Function *UpdateDPP =
401 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
402
403 // Reduce within each row of 16 lanes.
404 for (unsigned Idx = 0; Idx < 4; Idx++) {
406 B, Op, V,
407 B.CreateCall(UpdateDPP,
408 {Identity, V, B.getInt32(DPP::ROW_XMASK0 | 1 << Idx),
409 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()}));
410 }
411
412 // Reduce within each pair of rows (i.e. 32 lanes).
413 assert(ST->hasPermLaneX16());
414 V = B.CreateBitCast(V, IntNTy);
415 Value *Permlanex16Call = B.CreateIntrinsic(
416 Intrinsic::amdgcn_permlanex16, {},
417 {V, V, B.getInt32(-1), B.getInt32(-1), B.getFalse(), B.getFalse()});
418 V = buildNonAtomicBinOp(B, Op, B.CreateBitCast(V, AtomicTy),
419 B.CreateBitCast(Permlanex16Call, AtomicTy));
420 if (ST->isWave32()) {
421 return V;
422 }
423
424 if (ST->hasPermLane64()) {
425 // Reduce across the upper and lower 32 lanes.
426 V = B.CreateBitCast(V, IntNTy);
427 Value *Permlane64Call =
428 B.CreateIntrinsic(Intrinsic::amdgcn_permlane64, {}, V);
429 return buildNonAtomicBinOp(B, Op, B.CreateBitCast(V, AtomicTy),
430 B.CreateBitCast(Permlane64Call, AtomicTy));
431 }
432
433 // Pick an arbitrary lane from 0..31 and an arbitrary lane from 32..63 and
434 // combine them with a scalar operation.
435 Function *ReadLane =
436 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, {});
437 V = B.CreateBitCast(V, IntNTy);
438 Value *Lane0 = B.CreateCall(ReadLane, {V, B.getInt32(0)});
439 Value *Lane32 = B.CreateCall(ReadLane, {V, B.getInt32(32)});
440 return buildNonAtomicBinOp(B, Op, B.CreateBitCast(Lane0, AtomicTy),
441 B.CreateBitCast(Lane32, AtomicTy));
442}
443
444// Use the builder to create an inclusive scan of V across the wavefront, with
445// all lanes active.
446Value *AMDGPUAtomicOptimizerImpl::buildScan(IRBuilder<> &B,
448 Value *Identity) const {
449 Type *AtomicTy = V->getType();
450 Type *IntNTy = B.getIntNTy(AtomicTy->getPrimitiveSizeInBits());
451
452 Module *M = B.GetInsertBlock()->getModule();
453 Function *UpdateDPP =
454 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
455
456 for (unsigned Idx = 0; Idx < 4; Idx++) {
458 B, Op, V,
459 B.CreateCall(UpdateDPP,
460 {Identity, V, B.getInt32(DPP::ROW_SHR0 | 1 << Idx),
461 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()}));
462 }
463 if (ST->hasDPPBroadcasts()) {
464 // GFX9 has DPP row broadcast operations.
466 B, Op, V,
467 B.CreateCall(UpdateDPP,
468 {Identity, V, B.getInt32(DPP::BCAST15), B.getInt32(0xa),
469 B.getInt32(0xf), B.getFalse()}));
471 B, Op, V,
472 B.CreateCall(UpdateDPP,
473 {Identity, V, B.getInt32(DPP::BCAST31), B.getInt32(0xc),
474 B.getInt32(0xf), B.getFalse()}));
475 } else {
476 // On GFX10 all DPP operations are confined to a single row. To get cross-
477 // row operations we have to use permlane or readlane.
478
479 // Combine lane 15 into lanes 16..31 (and, for wave 64, lane 47 into lanes
480 // 48..63).
481 assert(ST->hasPermLaneX16());
482 V = B.CreateBitCast(V, IntNTy);
483 Value *PermX = B.CreateIntrinsic(
484 Intrinsic::amdgcn_permlanex16, {},
485 {V, V, B.getInt32(-1), B.getInt32(-1), B.getFalse(), B.getFalse()});
486
487 Value *UpdateDPPCall =
488 B.CreateCall(UpdateDPP, {Identity, B.CreateBitCast(PermX, AtomicTy),
489 B.getInt32(DPP::QUAD_PERM_ID), B.getInt32(0xa),
490 B.getInt32(0xf), B.getFalse()});
491 V = buildNonAtomicBinOp(B, Op, B.CreateBitCast(V, AtomicTy), UpdateDPPCall);
492
493 if (!ST->isWave32()) {
494 // Combine lane 31 into lanes 32..63.
495 V = B.CreateBitCast(V, IntNTy);
496 Value *const Lane31 = B.CreateIntrinsic(Intrinsic::amdgcn_readlane, {},
497 {V, B.getInt32(31)});
498
499 Value *UpdateDPPCall = B.CreateCall(
500 UpdateDPP, {Identity, Lane31, B.getInt32(DPP::QUAD_PERM_ID),
501 B.getInt32(0xc), B.getInt32(0xf), B.getFalse()});
502
503 V = buildNonAtomicBinOp(B, Op, B.CreateBitCast(V, AtomicTy),
504 UpdateDPPCall);
505 }
506 }
507 return V;
508}
509
510// Use the builder to create a shift right of V across the wavefront, with all
511// lanes active, to turn an inclusive scan into an exclusive scan.
512Value *AMDGPUAtomicOptimizerImpl::buildShiftRight(IRBuilder<> &B, Value *V,
513 Value *Identity) const {
514 Type *AtomicTy = V->getType();
515 Type *IntNTy = B.getIntNTy(AtomicTy->getPrimitiveSizeInBits());
516
517 Module *M = B.GetInsertBlock()->getModule();
518 Function *UpdateDPP =
519 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
520 if (ST->hasDPPWavefrontShifts()) {
521 // GFX9 has DPP wavefront shift operations.
522 V = B.CreateCall(UpdateDPP,
523 {Identity, V, B.getInt32(DPP::WAVE_SHR1), B.getInt32(0xf),
524 B.getInt32(0xf), B.getFalse()});
525 } else {
526 Function *ReadLane =
527 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, {});
528 Function *WriteLane =
529 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_writelane, {});
530
531 // On GFX10 all DPP operations are confined to a single row. To get cross-
532 // row operations we have to use permlane or readlane.
533 Value *Old = V;
534 V = B.CreateCall(UpdateDPP,
535 {Identity, V, B.getInt32(DPP::ROW_SHR0 + 1),
536 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()});
537
538 // Copy the old lane 15 to the new lane 16.
539 V = B.CreateCall(
540 WriteLane,
541 {B.CreateCall(ReadLane, {B.CreateBitCast(Old, IntNTy), B.getInt32(15)}),
542 B.getInt32(16), B.CreateBitCast(V, IntNTy)});
543 V = B.CreateBitCast(V, AtomicTy);
544 if (!ST->isWave32()) {
545 // Copy the old lane 31 to the new lane 32.
546 V = B.CreateBitCast(V, IntNTy);
547 V = B.CreateCall(WriteLane,
548 {B.CreateCall(ReadLane, {B.CreateBitCast(Old, IntNTy),
549 B.getInt32(31)}),
550 B.getInt32(32), V});
551
552 // Copy the old lane 47 to the new lane 48.
553 V = B.CreateCall(
554 WriteLane,
555 {B.CreateCall(ReadLane, {Old, B.getInt32(47)}), B.getInt32(48), V});
556 V = B.CreateBitCast(V, AtomicTy);
557 }
558 }
559
560 return V;
561}
562
563// Use the builder to create an exclusive scan and compute the final reduced
564// value using an iterative approach. This provides an alternative
565// implementation to DPP which uses WMM for scan computations. This API iterate
566// over active lanes to read, compute and update the value using
567// readlane and writelane intrinsics.
568std::pair<Value *, Value *> AMDGPUAtomicOptimizerImpl::buildScanIteratively(
569 IRBuilder<> &B, AtomicRMWInst::BinOp Op, Value *const Identity, Value *V,
570 Instruction &I, BasicBlock *ComputeLoop, BasicBlock *ComputeEnd) const {
571 auto *Ty = I.getType();
572 auto *WaveTy = B.getIntNTy(ST->getWavefrontSize());
573 auto *EntryBB = I.getParent();
574 auto NeedResult = !I.use_empty();
575
576 auto *Ballot =
577 B.CreateIntrinsic(Intrinsic::amdgcn_ballot, WaveTy, B.getTrue());
578
579 // Start inserting instructions for ComputeLoop block
580 B.SetInsertPoint(ComputeLoop);
581 // Phi nodes for Accumulator, Scan results destination, and Active Lanes
582 auto *Accumulator = B.CreatePHI(Ty, 2, "Accumulator");
583 Accumulator->addIncoming(Identity, EntryBB);
584 PHINode *OldValuePhi = nullptr;
585 if (NeedResult) {
586 OldValuePhi = B.CreatePHI(Ty, 2, "OldValuePhi");
587 OldValuePhi->addIncoming(PoisonValue::get(Ty), EntryBB);
588 }
589 auto *ActiveBits = B.CreatePHI(WaveTy, 2, "ActiveBits");
590 ActiveBits->addIncoming(Ballot, EntryBB);
591
592 // Use llvm.cttz instrinsic to find the lowest remaining active lane.
593 auto *FF1 =
594 B.CreateIntrinsic(Intrinsic::cttz, WaveTy, {ActiveBits, B.getTrue()});
595
596 Type *IntNTy = B.getIntNTy(Ty->getPrimitiveSizeInBits());
597 auto *LaneIdxInt = B.CreateTrunc(FF1, IntNTy);
598
599 // Get the value required for atomic operation
600 V = B.CreateBitCast(V, IntNTy);
601 Value *LaneValue =
602 B.CreateIntrinsic(Intrinsic::amdgcn_readlane, {}, {V, LaneIdxInt});
603 LaneValue = B.CreateBitCast(LaneValue, Ty);
604
605 // Perform writelane if intermediate scan results are required later in the
606 // kernel computations
607 Value *OldValue = nullptr;
608 if (NeedResult) {
609 OldValue =
610 B.CreateIntrinsic(Intrinsic::amdgcn_writelane, {},
611 {B.CreateBitCast(Accumulator, IntNTy), LaneIdxInt,
612 B.CreateBitCast(OldValuePhi, IntNTy)});
613 OldValue = B.CreateBitCast(OldValue, Ty);
614 OldValuePhi->addIncoming(OldValue, ComputeLoop);
615 }
616
617 // Accumulate the results
618 auto *NewAccumulator = buildNonAtomicBinOp(B, Op, Accumulator, LaneValue);
619 Accumulator->addIncoming(NewAccumulator, ComputeLoop);
620
621 // Set bit to zero of current active lane so that for next iteration llvm.cttz
622 // return the next active lane
623 auto *Mask = B.CreateShl(ConstantInt::get(WaveTy, 1), FF1);
624
625 auto *InverseMask = B.CreateXor(Mask, ConstantInt::get(WaveTy, -1));
626 auto *NewActiveBits = B.CreateAnd(ActiveBits, InverseMask);
627 ActiveBits->addIncoming(NewActiveBits, ComputeLoop);
628
629 // Branch out of the loop when all lanes are processed.
630 auto *IsEnd = B.CreateICmpEQ(NewActiveBits, ConstantInt::get(WaveTy, 0));
631 B.CreateCondBr(IsEnd, ComputeEnd, ComputeLoop);
632
633 B.SetInsertPoint(ComputeEnd);
634
635 return {OldValue, NewAccumulator};
636}
637
640 LLVMContext &C = Ty->getContext();
641 const unsigned BitWidth = Ty->getPrimitiveSizeInBits();
642 switch (Op) {
643 default:
644 llvm_unreachable("Unhandled atomic op");
650 return ConstantInt::get(C, APInt::getMinValue(BitWidth));
653 return ConstantInt::get(C, APInt::getMaxValue(BitWidth));
655 return ConstantInt::get(C, APInt::getSignedMinValue(BitWidth));
657 return ConstantInt::get(C, APInt::getSignedMaxValue(BitWidth));
659 return ConstantFP::get(C, APFloat::getZero(Ty->getFltSemantics(), true));
661 return ConstantFP::get(C, APFloat::getZero(Ty->getFltSemantics(), false));
663 return ConstantFP::get(C, APFloat::getInf(Ty->getFltSemantics(), false));
665 return ConstantFP::get(C, APFloat::getInf(Ty->getFltSemantics(), true));
666 }
667}
668
669static Value *buildMul(IRBuilder<> &B, Value *LHS, Value *RHS) {
670 const ConstantInt *CI = dyn_cast<ConstantInt>(LHS);
671 return (CI && CI->isOne()) ? RHS : B.CreateMul(LHS, RHS);
672}
673
674void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
676 unsigned ValIdx,
677 bool ValDivergent) const {
678 // Start building just before the instruction.
679 IRBuilder<> B(&I);
680
682 B.setIsFPConstrained(I.getFunction()->hasFnAttribute(Attribute::StrictFP));
683 }
684
685 // If we are in a pixel shader, because of how we have to mask out helper
686 // lane invocations, we need to record the entry and exit BB's.
687 BasicBlock *PixelEntryBB = nullptr;
688 BasicBlock *PixelExitBB = nullptr;
689
690 // If we're optimizing an atomic within a pixel shader, we need to wrap the
691 // entire atomic operation in a helper-lane check. We do not want any helper
692 // lanes that are around only for the purposes of derivatives to take part
693 // in any cross-lane communication, and we use a branch on whether the lane is
694 // live to do this.
695 if (IsPixelShader) {
696 // Record I's original position as the entry block.
697 PixelEntryBB = I.getParent();
698
699 Value *const Cond = B.CreateIntrinsic(Intrinsic::amdgcn_ps_live, {}, {});
700 Instruction *const NonHelperTerminator =
701 SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr);
702
703 // Record I's new position as the exit block.
704 PixelExitBB = I.getParent();
705
706 I.moveBefore(NonHelperTerminator);
707 B.SetInsertPoint(&I);
708 }
709
710 Type *const Ty = I.getType();
711 Type *Int32Ty = B.getInt32Ty();
712 Type *IntNTy = B.getIntNTy(Ty->getPrimitiveSizeInBits());
713 bool isAtomicFloatingPointTy = Ty->isFloatingPointTy();
714 const unsigned TyBitWidth = DL->getTypeSizeInBits(Ty);
715 auto *const VecTy = FixedVectorType::get(Int32Ty, 2);
716
717 // This is the value in the atomic operation we need to combine in order to
718 // reduce the number of atomic operations.
719 Value *V = I.getOperand(ValIdx);
720
721 // We need to know how many lanes are active within the wavefront, and we do
722 // this by doing a ballot of active lanes.
723 Type *const WaveTy = B.getIntNTy(ST->getWavefrontSize());
724 CallInst *const Ballot =
725 B.CreateIntrinsic(Intrinsic::amdgcn_ballot, WaveTy, B.getTrue());
726
727 // We need to know how many lanes are active within the wavefront that are
728 // below us. If we counted each lane linearly starting from 0, a lane is
729 // below us only if its associated index was less than ours. We do this by
730 // using the mbcnt intrinsic.
731 Value *Mbcnt;
732 if (ST->isWave32()) {
733 Mbcnt = B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_lo, {},
734 {Ballot, B.getInt32(0)});
735 } else {
736 Value *const ExtractLo = B.CreateTrunc(Ballot, Int32Ty);
737 Value *const ExtractHi = B.CreateTrunc(B.CreateLShr(Ballot, 32), Int32Ty);
738 Mbcnt = B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_lo, {},
739 {ExtractLo, B.getInt32(0)});
740 Mbcnt =
741 B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_hi, {}, {ExtractHi, Mbcnt});
742 }
743
744 Function *F = I.getFunction();
745 LLVMContext &C = F->getContext();
746
747 // For atomic sub, perform scan with add operation and allow one lane to
748 // subtract the reduced value later.
749 AtomicRMWInst::BinOp ScanOp = Op;
750 if (Op == AtomicRMWInst::Sub) {
751 ScanOp = AtomicRMWInst::Add;
752 } else if (Op == AtomicRMWInst::FSub) {
753 ScanOp = AtomicRMWInst::FAdd;
754 }
755 Value *Identity = getIdentityValueForAtomicOp(Ty, ScanOp);
756
757 Value *ExclScan = nullptr;
758 Value *NewV = nullptr;
759
760 const bool NeedResult = !I.use_empty();
761
762 BasicBlock *ComputeLoop = nullptr;
763 BasicBlock *ComputeEnd = nullptr;
764 // If we have a divergent value in each lane, we need to combine the value
765 // using DPP.
766 if (ValDivergent) {
767 if (ScanImpl == ScanOptions::DPP) {
768 // First we need to set all inactive invocations to the identity value, so
769 // that they can correctly contribute to the final result.
770 V = B.CreateBitCast(V, IntNTy);
771 Identity = B.CreateBitCast(Identity, IntNTy);
772 NewV = B.CreateIntrinsic(Intrinsic::amdgcn_set_inactive, IntNTy,
773 {V, Identity});
774 NewV = B.CreateBitCast(NewV, Ty);
775 V = B.CreateBitCast(V, Ty);
776 Identity = B.CreateBitCast(Identity, Ty);
777 if (!NeedResult && ST->hasPermLaneX16()) {
778 // On GFX10 the permlanex16 instruction helps us build a reduction
779 // without too many readlanes and writelanes, which are generally bad
780 // for performance.
781 NewV = buildReduction(B, ScanOp, NewV, Identity);
782 } else {
783 NewV = buildScan(B, ScanOp, NewV, Identity);
784 if (NeedResult)
785 ExclScan = buildShiftRight(B, NewV, Identity);
786 // Read the value from the last lane, which has accumulated the values
787 // of each active lane in the wavefront. This will be our new value
788 // which we will provide to the atomic operation.
789 Value *const LastLaneIdx = B.getInt32(ST->getWavefrontSize() - 1);
790 assert(TyBitWidth == 32);
791 NewV = B.CreateBitCast(NewV, IntNTy);
792 NewV = B.CreateIntrinsic(Intrinsic::amdgcn_readlane, {},
793 {NewV, LastLaneIdx});
794 NewV = B.CreateBitCast(NewV, Ty);
795 }
796 // Finally mark the readlanes in the WWM section.
797 NewV = B.CreateIntrinsic(Intrinsic::amdgcn_strict_wwm, Ty, NewV);
798 } else if (ScanImpl == ScanOptions::Iterative) {
799 // Alternative implementation for scan
800 ComputeLoop = BasicBlock::Create(C, "ComputeLoop", F);
801 ComputeEnd = BasicBlock::Create(C, "ComputeEnd", F);
802 std::tie(ExclScan, NewV) = buildScanIteratively(B, ScanOp, Identity, V, I,
803 ComputeLoop, ComputeEnd);
804 } else {
805 llvm_unreachable("Atomic Optimzer is disabled for None strategy");
806 }
807 } else {
808 switch (Op) {
809 default:
810 llvm_unreachable("Unhandled atomic op");
811
813 case AtomicRMWInst::Sub: {
814 // The new value we will be contributing to the atomic operation is the
815 // old value times the number of active lanes.
816 Value *const Ctpop = B.CreateIntCast(
817 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Ty, false);
818 NewV = buildMul(B, V, Ctpop);
819 break;
820 }
822 case AtomicRMWInst::FSub: {
823 Value *const Ctpop = B.CreateIntCast(
824 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Int32Ty, false);
825 Value *const CtpopFP = B.CreateUIToFP(Ctpop, Ty);
826 NewV = B.CreateFMul(V, CtpopFP);
827 break;
828 }
837 // These operations with a uniform value are idempotent: doing the atomic
838 // operation multiple times has the same effect as doing it once.
839 NewV = V;
840 break;
841
843 // The new value we will be contributing to the atomic operation is the
844 // old value times the parity of the number of active lanes.
845 Value *const Ctpop = B.CreateIntCast(
846 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Ty, false);
847 NewV = buildMul(B, V, B.CreateAnd(Ctpop, 1));
848 break;
849 }
850 }
851
852 // We only want a single lane to enter our new control flow, and we do this
853 // by checking if there are any active lanes below us. Only one lane will
854 // have 0 active lanes below us, so that will be the only one to progress.
855 Value *const Cond = B.CreateICmpEQ(Mbcnt, B.getInt32(0));
856
857 // Store I's original basic block before we split the block.
858 BasicBlock *const EntryBB = I.getParent();
859
860 // We need to introduce some new control flow to force a single lane to be
861 // active. We do this by splitting I's basic block at I, and introducing the
862 // new block such that:
863 // entry --> single_lane -\
864 // \------------------> exit
865 Instruction *const SingleLaneTerminator =
866 SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr);
867
868 // At this point, we have split the I's block to allow one lane in wavefront
869 // to update the precomputed reduced value. Also, completed the codegen for
870 // new control flow i.e. iterative loop which perform reduction and scan using
871 // ComputeLoop and ComputeEnd.
872 // For the new control flow, we need to move branch instruction i.e.
873 // terminator created during SplitBlockAndInsertIfThen from I's block to
874 // ComputeEnd block. We also need to set up predecessor to next block when
875 // single lane done updating the final reduced value.
876 BasicBlock *Predecessor = nullptr;
877 if (ValDivergent && ScanImpl == ScanOptions::Iterative) {
878 // Move terminator from I's block to ComputeEnd block.
880 B.SetInsertPoint(ComputeEnd);
881 Terminator->removeFromParent();
882 B.Insert(Terminator);
883
884 // Branch to ComputeLoop Block unconditionally from the I's block for
885 // iterative approach.
886 B.SetInsertPoint(EntryBB);
887 B.CreateBr(ComputeLoop);
888
889 // Update the dominator tree for new control flow.
890 DTU.applyUpdates(
891 {{DominatorTree::Insert, EntryBB, ComputeLoop},
892 {DominatorTree::Insert, ComputeLoop, ComputeEnd},
893 {DominatorTree::Delete, EntryBB, SingleLaneTerminator->getParent()}});
894
895 Predecessor = ComputeEnd;
896 } else {
897 Predecessor = EntryBB;
898 }
899 // Move the IR builder into single_lane next.
900 B.SetInsertPoint(SingleLaneTerminator);
901
902 // Clone the original atomic operation into single lane, replacing the
903 // original value with our newly created one.
904 Instruction *const NewI = I.clone();
905 B.Insert(NewI);
906 NewI->setOperand(ValIdx, NewV);
907
908 // Move the IR builder into exit next, and start inserting just before the
909 // original instruction.
910 B.SetInsertPoint(&I);
911
912 if (NeedResult) {
913 // Create a PHI node to get our new atomic result into the exit block.
914 PHINode *const PHI = B.CreatePHI(Ty, 2);
915 PHI->addIncoming(PoisonValue::get(Ty), Predecessor);
916 PHI->addIncoming(NewI, SingleLaneTerminator->getParent());
917
918 // We need to broadcast the value who was the lowest active lane (the first
919 // lane) to all other lanes in the wavefront. We use an intrinsic for this,
920 // but have to handle 64-bit broadcasts with two calls to this intrinsic.
921 Value *BroadcastI = nullptr;
922
923 if (TyBitWidth == 64) {
924 Value *CastedPhi = B.CreateBitCast(PHI, IntNTy);
925 Value *const ExtractLo = B.CreateTrunc(CastedPhi, Int32Ty);
926 Value *const ExtractHi =
927 B.CreateTrunc(B.CreateLShr(CastedPhi, 32), Int32Ty);
928 CallInst *const ReadFirstLaneLo =
929 B.CreateIntrinsic(Intrinsic::amdgcn_readfirstlane, {}, ExtractLo);
930 CallInst *const ReadFirstLaneHi =
931 B.CreateIntrinsic(Intrinsic::amdgcn_readfirstlane, {}, ExtractHi);
932 Value *const PartialInsert = B.CreateInsertElement(
933 PoisonValue::get(VecTy), ReadFirstLaneLo, B.getInt32(0));
934 Value *const Insert =
935 B.CreateInsertElement(PartialInsert, ReadFirstLaneHi, B.getInt32(1));
936 BroadcastI = B.CreateBitCast(Insert, Ty);
937 } else if (TyBitWidth == 32) {
938 Value *CastedPhi = B.CreateBitCast(PHI, IntNTy);
939 BroadcastI =
940 B.CreateIntrinsic(Intrinsic::amdgcn_readfirstlane, {}, CastedPhi);
941 BroadcastI = B.CreateBitCast(BroadcastI, Ty);
942
943 } else {
944 llvm_unreachable("Unhandled atomic bit width");
945 }
946
947 // Now that we have the result of our single atomic operation, we need to
948 // get our individual lane's slice into the result. We use the lane offset
949 // we previously calculated combined with the atomic result value we got
950 // from the first lane, to get our lane's index into the atomic result.
951 Value *LaneOffset = nullptr;
952 if (ValDivergent) {
953 if (ScanImpl == ScanOptions::DPP) {
954 LaneOffset =
955 B.CreateIntrinsic(Intrinsic::amdgcn_strict_wwm, Ty, ExclScan);
956 } else if (ScanImpl == ScanOptions::Iterative) {
957 LaneOffset = ExclScan;
958 } else {
959 llvm_unreachable("Atomic Optimzer is disabled for None strategy");
960 }
961 } else {
962 Mbcnt = isAtomicFloatingPointTy ? B.CreateUIToFP(Mbcnt, Ty)
963 : B.CreateIntCast(Mbcnt, Ty, false);
964 switch (Op) {
965 default:
966 llvm_unreachable("Unhandled atomic op");
969 LaneOffset = buildMul(B, V, Mbcnt);
970 break;
979 LaneOffset = B.CreateSelect(Cond, Identity, V);
980 break;
982 LaneOffset = buildMul(B, V, B.CreateAnd(Mbcnt, 1));
983 break;
985 case AtomicRMWInst::FSub: {
986 LaneOffset = B.CreateFMul(V, Mbcnt);
987 break;
988 }
989 }
990 }
991 Value *const Result = buildNonAtomicBinOp(B, Op, BroadcastI, LaneOffset);
992
993 if (IsPixelShader) {
994 // Need a final PHI to reconverge to above the helper lane branch mask.
995 B.SetInsertPoint(PixelExitBB, PixelExitBB->getFirstNonPHIIt());
996
997 PHINode *const PHI = B.CreatePHI(Ty, 2);
998 PHI->addIncoming(PoisonValue::get(Ty), PixelEntryBB);
999 PHI->addIncoming(Result, I.getParent());
1000 I.replaceAllUsesWith(PHI);
1001 } else {
1002 // Replace the original atomic instruction with the new one.
1003 I.replaceAllUsesWith(Result);
1004 }
1005 }
1006
1007 // And delete the original.
1008 I.eraseFromParent();
1009}
1010
1011INITIALIZE_PASS_BEGIN(AMDGPUAtomicOptimizer, DEBUG_TYPE,
1012 "AMDGPU atomic optimizations", false, false)
1015INITIALIZE_PASS_END(AMDGPUAtomicOptimizer, DEBUG_TYPE,
1016 "AMDGPU atomic optimizations", false, false)
1017
1019 return new AMDGPUAtomicOptimizer(ScanStrategy);
1020}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static Constant * getIdentityValueForAtomicOp(Type *const Ty, AtomicRMWInst::BinOp Op)
static Value * buildMul(IRBuilder<> &B, Value *LHS, Value *RHS)
static Value * buildNonAtomicBinOp(IRBuilder<> &B, AtomicRMWInst::BinOp Op, Value *LHS, Value *RHS)
Rewrite undef for PHI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
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
AMD GCN specific subclass of TargetSubtarget.
#define DEBUG_TYPE
Generic memory optimizations
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
IntegerType * Int32Ty
const char LLVMTargetMachineRef TM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Target-Independent Code Generator Pass Configuration Options pass.
LLVM IR instance of the generic uniformity analysis.
Value * RHS
Value * LHS
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition: APFloat.h:966
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:957
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:184
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:187
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:194
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:197
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:473
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.
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:748
static bool isFPOperation(BinOp Op)
Definition: Instructions.h:849
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:760
@ Add
*p = old + v
Definition: Instructions.h:764
@ FAdd
*p = old + v
Definition: Instructions.h:785
@ Min
*p = old <signed v ? old : v
Definition: Instructions.h:778
@ Or
*p = old | v
Definition: Instructions.h:772
@ Sub
*p = old - v
Definition: Instructions.h:766
@ And
*p = old & v
Definition: Instructions.h:768
@ Xor
*p = old ^ v
Definition: Instructions.h:774
@ FSub
*p = old - v
Definition: Instructions.h:788
@ Max
*p = old >signed v ? old : v
Definition: Instructions.h:776
@ UMin
*p = old <unsigned v ? old : v
Definition: Instructions.h:782
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
Definition: Instructions.h:796
@ UMax
*p = old >unsigned v ? old : v
Definition: Instructions.h:780
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
Definition: Instructions.h:792
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
Definition: BasicBlock.cpp:367
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:199
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:221
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:993
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:1022
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:1016
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:1020
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:1018
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:211
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:279
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:317
DominatorTree & getDomTree()
Definition: Dominators.h:325
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:692
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2666
Base class for instruction visitors.
Definition: InstVisitor.h:78
RetTy visitIntrinsicInst(IntrinsicInst &I)
Definition: InstVisitor.h:219
RetTy visitAtomicRMWInst(AtomicRMWInst &I)
Definition: InstVisitor.h:172
const BasicBlock * getParent() const
Definition: Instruction.h:152
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1827
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
void preserve()
Mark an analysis as preserved.
Definition: Analysis.h:129
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
Target-Independent Code Generator Pass Configuration Options.
TMC & getTM() const
Get the right type of TargetMachine for this target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
const fltSemantics & getFltSemantics() const
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:185
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Analysis pass which computes UniformityInfo.
Legacy analysis pass which computes a CycleInfo.
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ LOCAL_ADDRESS
Address space for local memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:121
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1461
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ScanOptions
Definition: AMDGPU.h:99
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
DWARFExpression::Operation Op
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
char & AMDGPUAtomicOptimizerID
Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)