LLVM 20.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.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.getDataLayout();
141
143 DomTreeUpdater::UpdateStrategy::Lazy);
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
181static bool isLegalCrossLaneType(Type *Ty) {
182 switch (Ty->getTypeID()) {
183 case Type::FloatTyID:
184 case Type::DoubleTyID:
185 return true;
186 case Type::IntegerTyID: {
187 unsigned Size = Ty->getIntegerBitWidth();
188 return (Size == 32 || Size == 64);
189 }
190 default:
191 return false;
192 }
193}
194
195void AMDGPUAtomicOptimizerImpl::visitAtomicRMWInst(AtomicRMWInst &I) {
196 // Early exit for unhandled address space atomic instructions.
197 switch (I.getPointerAddressSpace()) {
198 default:
199 return;
202 break;
203 }
204
205 AtomicRMWInst::BinOp Op = I.getOperation();
206
207 switch (Op) {
208 default:
209 return;
223 break;
224 }
225
226 // Only 32 and 64 bit floating point atomic ops are supported.
228 !(I.getType()->isFloatTy() || I.getType()->isDoubleTy())) {
229 return;
230 }
231
232 const unsigned PtrIdx = 0;
233 const unsigned ValIdx = 1;
234
235 // If the pointer operand is divergent, then each lane is doing an atomic
236 // operation on a different address, and we cannot optimize that.
237 if (UA->isDivergentUse(I.getOperandUse(PtrIdx))) {
238 return;
239 }
240
241 bool ValDivergent = UA->isDivergentUse(I.getOperandUse(ValIdx));
242
243 // If the value operand is divergent, each lane is contributing a different
244 // value to the atomic calculation. We can only optimize divergent values if
245 // we have DPP available on our subtarget (for DPP strategy), and the atomic
246 // operation is 32 or 64 bits.
247 if (ValDivergent) {
248 if (ScanImpl == ScanOptions::DPP && !ST->hasDPP())
249 return;
250
251 if (!isLegalCrossLaneType(I.getType()))
252 return;
253 }
254
255 // If we get here, we can optimize the atomic using a single wavefront-wide
256 // atomic operation to do the calculation for the entire wavefront, so
257 // remember the instruction so we can come back to it.
258 const ReplacementInfo Info = {&I, Op, ValIdx, ValDivergent};
259
260 ToReplace.push_back(Info);
261}
262
263void AMDGPUAtomicOptimizerImpl::visitIntrinsicInst(IntrinsicInst &I) {
265
266 switch (I.getIntrinsicID()) {
267 default:
268 return;
269 case Intrinsic::amdgcn_struct_buffer_atomic_add:
270 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_add:
271 case Intrinsic::amdgcn_raw_buffer_atomic_add:
272 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_add:
274 break;
275 case Intrinsic::amdgcn_struct_buffer_atomic_sub:
276 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub:
277 case Intrinsic::amdgcn_raw_buffer_atomic_sub:
278 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub:
280 break;
281 case Intrinsic::amdgcn_struct_buffer_atomic_and:
282 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_and:
283 case Intrinsic::amdgcn_raw_buffer_atomic_and:
284 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_and:
286 break;
287 case Intrinsic::amdgcn_struct_buffer_atomic_or:
288 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_or:
289 case Intrinsic::amdgcn_raw_buffer_atomic_or:
290 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_or:
292 break;
293 case Intrinsic::amdgcn_struct_buffer_atomic_xor:
294 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_xor:
295 case Intrinsic::amdgcn_raw_buffer_atomic_xor:
296 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_xor:
298 break;
299 case Intrinsic::amdgcn_struct_buffer_atomic_smin:
300 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smin:
301 case Intrinsic::amdgcn_raw_buffer_atomic_smin:
302 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smin:
304 break;
305 case Intrinsic::amdgcn_struct_buffer_atomic_umin:
306 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umin:
307 case Intrinsic::amdgcn_raw_buffer_atomic_umin:
308 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umin:
310 break;
311 case Intrinsic::amdgcn_struct_buffer_atomic_smax:
312 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smax:
313 case Intrinsic::amdgcn_raw_buffer_atomic_smax:
314 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smax:
316 break;
317 case Intrinsic::amdgcn_struct_buffer_atomic_umax:
318 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umax:
319 case Intrinsic::amdgcn_raw_buffer_atomic_umax:
320 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umax:
322 break;
323 }
324
325 const unsigned ValIdx = 0;
326
327 const bool ValDivergent = UA->isDivergentUse(I.getOperandUse(ValIdx));
328
329 // If the value operand is divergent, each lane is contributing a different
330 // value to the atomic calculation. We can only optimize divergent values if
331 // we have DPP available on our subtarget (for DPP strategy), and the atomic
332 // operation is 32 or 64 bits.
333 if (ValDivergent) {
334 if (ScanImpl == ScanOptions::DPP && !ST->hasDPP())
335 return;
336
337 if (!isLegalCrossLaneType(I.getType()))
338 return;
339 }
340
341 // If any of the other arguments to the intrinsic are divergent, we can't
342 // optimize the operation.
343 for (unsigned Idx = 1; Idx < I.getNumOperands(); Idx++) {
344 if (UA->isDivergentUse(I.getOperandUse(Idx))) {
345 return;
346 }
347 }
348
349 // If we get here, we can optimize the atomic using a single wavefront-wide
350 // atomic operation to do the calculation for the entire wavefront, so
351 // remember the instruction so we can come back to it.
352 const ReplacementInfo Info = {&I, Op, ValIdx, ValDivergent};
353
354 ToReplace.push_back(Info);
355}
356
357// Use the builder to create the non-atomic counterpart of the specified
358// atomicrmw binary op.
360 Value *LHS, Value *RHS) {
362
363 switch (Op) {
364 default:
365 llvm_unreachable("Unhandled atomic op");
367 return B.CreateBinOp(Instruction::Add, LHS, RHS);
369 return B.CreateFAdd(LHS, RHS);
371 return B.CreateBinOp(Instruction::Sub, LHS, RHS);
373 return B.CreateFSub(LHS, RHS);
375 return B.CreateBinOp(Instruction::And, LHS, RHS);
377 return B.CreateBinOp(Instruction::Or, LHS, RHS);
379 return B.CreateBinOp(Instruction::Xor, LHS, RHS);
380
382 Pred = CmpInst::ICMP_SGT;
383 break;
385 Pred = CmpInst::ICMP_SLT;
386 break;
388 Pred = CmpInst::ICMP_UGT;
389 break;
391 Pred = CmpInst::ICMP_ULT;
392 break;
394 return B.CreateMaxNum(LHS, RHS);
396 return B.CreateMinNum(LHS, RHS);
397 }
398 Value *Cond = B.CreateICmp(Pred, LHS, RHS);
399 return B.CreateSelect(Cond, LHS, RHS);
400}
401
402// Use the builder to create a reduction of V across the wavefront, with all
403// lanes active, returning the same result in all lanes.
404Value *AMDGPUAtomicOptimizerImpl::buildReduction(IRBuilder<> &B,
406 Value *V,
407 Value *const Identity) const {
408 Type *AtomicTy = V->getType();
409 Module *M = B.GetInsertBlock()->getModule();
410 Function *UpdateDPP =
411 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
412
413 // Reduce within each row of 16 lanes.
414 for (unsigned Idx = 0; Idx < 4; Idx++) {
416 B, Op, V,
417 B.CreateCall(UpdateDPP,
418 {Identity, V, B.getInt32(DPP::ROW_XMASK0 | 1 << Idx),
419 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()}));
420 }
421
422 // Reduce within each pair of rows (i.e. 32 lanes).
423 assert(ST->hasPermLaneX16());
424 Value *Permlanex16Call = B.CreateIntrinsic(
425 V->getType(), Intrinsic::amdgcn_permlanex16,
426 {V, V, B.getInt32(-1), B.getInt32(-1), B.getFalse(), B.getFalse()});
427 V = buildNonAtomicBinOp(B, Op, V, Permlanex16Call);
428 if (ST->isWave32()) {
429 return V;
430 }
431
432 if (ST->hasPermLane64()) {
433 // Reduce across the upper and lower 32 lanes.
434 Value *Permlane64Call =
435 B.CreateIntrinsic(V->getType(), Intrinsic::amdgcn_permlane64, V);
436 return buildNonAtomicBinOp(B, Op, V, Permlane64Call);
437 }
438
439 // Pick an arbitrary lane from 0..31 and an arbitrary lane from 32..63 and
440 // combine them with a scalar operation.
441 Function *ReadLane =
442 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, AtomicTy);
443 Value *Lane0 = B.CreateCall(ReadLane, {V, B.getInt32(0)});
444 Value *Lane32 = B.CreateCall(ReadLane, {V, B.getInt32(32)});
445 return buildNonAtomicBinOp(B, Op, Lane0, Lane32);
446}
447
448// Use the builder to create an inclusive scan of V across the wavefront, with
449// all lanes active.
450Value *AMDGPUAtomicOptimizerImpl::buildScan(IRBuilder<> &B,
452 Value *Identity) const {
453 Type *AtomicTy = V->getType();
454 Module *M = B.GetInsertBlock()->getModule();
455 Function *UpdateDPP =
456 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
457
458 for (unsigned Idx = 0; Idx < 4; Idx++) {
460 B, Op, V,
461 B.CreateCall(UpdateDPP,
462 {Identity, V, B.getInt32(DPP::ROW_SHR0 | 1 << Idx),
463 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()}));
464 }
465 if (ST->hasDPPBroadcasts()) {
466 // GFX9 has DPP row broadcast operations.
468 B, Op, V,
469 B.CreateCall(UpdateDPP,
470 {Identity, V, B.getInt32(DPP::BCAST15), B.getInt32(0xa),
471 B.getInt32(0xf), B.getFalse()}));
473 B, Op, V,
474 B.CreateCall(UpdateDPP,
475 {Identity, V, B.getInt32(DPP::BCAST31), B.getInt32(0xc),
476 B.getInt32(0xf), B.getFalse()}));
477 } else {
478 // On GFX10 all DPP operations are confined to a single row. To get cross-
479 // row operations we have to use permlane or readlane.
480
481 // Combine lane 15 into lanes 16..31 (and, for wave 64, lane 47 into lanes
482 // 48..63).
483 assert(ST->hasPermLaneX16());
484 Value *PermX = B.CreateIntrinsic(
485 V->getType(), Intrinsic::amdgcn_permlanex16,
486 {V, V, B.getInt32(-1), B.getInt32(-1), B.getFalse(), B.getFalse()});
487
488 Value *UpdateDPPCall = B.CreateCall(
489 UpdateDPP, {Identity, PermX, B.getInt32(DPP::QUAD_PERM_ID),
490 B.getInt32(0xa), B.getInt32(0xf), B.getFalse()});
491 V = buildNonAtomicBinOp(B, Op, V, UpdateDPPCall);
492
493 if (!ST->isWave32()) {
494 // Combine lane 31 into lanes 32..63.
495 Value *const Lane31 = B.CreateIntrinsic(
496 V->getType(), Intrinsic::amdgcn_readlane, {V, B.getInt32(31)});
497
498 Value *UpdateDPPCall = B.CreateCall(
499 UpdateDPP, {Identity, Lane31, B.getInt32(DPP::QUAD_PERM_ID),
500 B.getInt32(0xc), B.getInt32(0xf), B.getFalse()});
501
502 V = buildNonAtomicBinOp(B, Op, V, UpdateDPPCall);
503 }
504 }
505 return V;
506}
507
508// Use the builder to create a shift right of V across the wavefront, with all
509// lanes active, to turn an inclusive scan into an exclusive scan.
510Value *AMDGPUAtomicOptimizerImpl::buildShiftRight(IRBuilder<> &B, Value *V,
511 Value *Identity) const {
512 Type *AtomicTy = V->getType();
513 Module *M = B.GetInsertBlock()->getModule();
514 Function *UpdateDPP =
515 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy);
516 if (ST->hasDPPWavefrontShifts()) {
517 // GFX9 has DPP wavefront shift operations.
518 V = B.CreateCall(UpdateDPP,
519 {Identity, V, B.getInt32(DPP::WAVE_SHR1), B.getInt32(0xf),
520 B.getInt32(0xf), B.getFalse()});
521 } else {
522 Function *ReadLane =
523 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, AtomicTy);
524 Function *WriteLane =
525 Intrinsic::getDeclaration(M, Intrinsic::amdgcn_writelane, AtomicTy);
526
527 // On GFX10 all DPP operations are confined to a single row. To get cross-
528 // row operations we have to use permlane or readlane.
529 Value *Old = V;
530 V = B.CreateCall(UpdateDPP,
531 {Identity, V, B.getInt32(DPP::ROW_SHR0 + 1),
532 B.getInt32(0xf), B.getInt32(0xf), B.getFalse()});
533
534 // Copy the old lane 15 to the new lane 16.
535 V = B.CreateCall(WriteLane, {B.CreateCall(ReadLane, {Old, B.getInt32(15)}),
536 B.getInt32(16), V});
537
538 if (!ST->isWave32()) {
539 // Copy the old lane 31 to the new lane 32.
540 V = B.CreateCall(
541 WriteLane,
542 {B.CreateCall(ReadLane, {Old, B.getInt32(31)}), B.getInt32(32), V});
543
544 // Copy the old lane 47 to the new lane 48.
545 V = B.CreateCall(
546 WriteLane,
547 {B.CreateCall(ReadLane, {Old, B.getInt32(47)}), B.getInt32(48), V});
548 }
549 }
550
551 return V;
552}
553
554// Use the builder to create an exclusive scan and compute the final reduced
555// value using an iterative approach. This provides an alternative
556// implementation to DPP which uses WMM for scan computations. This API iterate
557// over active lanes to read, compute and update the value using
558// readlane and writelane intrinsics.
559std::pair<Value *, Value *> AMDGPUAtomicOptimizerImpl::buildScanIteratively(
560 IRBuilder<> &B, AtomicRMWInst::BinOp Op, Value *const Identity, Value *V,
561 Instruction &I, BasicBlock *ComputeLoop, BasicBlock *ComputeEnd) const {
562 auto *Ty = I.getType();
563 auto *WaveTy = B.getIntNTy(ST->getWavefrontSize());
564 auto *EntryBB = I.getParent();
565 auto NeedResult = !I.use_empty();
566
567 auto *Ballot =
568 B.CreateIntrinsic(Intrinsic::amdgcn_ballot, WaveTy, B.getTrue());
569
570 // Start inserting instructions for ComputeLoop block
571 B.SetInsertPoint(ComputeLoop);
572 // Phi nodes for Accumulator, Scan results destination, and Active Lanes
573 auto *Accumulator = B.CreatePHI(Ty, 2, "Accumulator");
574 Accumulator->addIncoming(Identity, EntryBB);
575 PHINode *OldValuePhi = nullptr;
576 if (NeedResult) {
577 OldValuePhi = B.CreatePHI(Ty, 2, "OldValuePhi");
578 OldValuePhi->addIncoming(PoisonValue::get(Ty), EntryBB);
579 }
580 auto *ActiveBits = B.CreatePHI(WaveTy, 2, "ActiveBits");
581 ActiveBits->addIncoming(Ballot, EntryBB);
582
583 // Use llvm.cttz instrinsic to find the lowest remaining active lane.
584 auto *FF1 =
585 B.CreateIntrinsic(Intrinsic::cttz, WaveTy, {ActiveBits, B.getTrue()});
586
587 auto *LaneIdxInt = B.CreateTrunc(FF1, B.getInt32Ty());
588
589 // Get the value required for atomic operation
590 Value *LaneValue = B.CreateIntrinsic(V->getType(), Intrinsic::amdgcn_readlane,
591 {V, LaneIdxInt});
592
593 // Perform writelane if intermediate scan results are required later in the
594 // kernel computations
595 Value *OldValue = nullptr;
596 if (NeedResult) {
597 OldValue = B.CreateIntrinsic(V->getType(), Intrinsic::amdgcn_writelane,
598 {Accumulator, LaneIdxInt, OldValuePhi});
599 OldValuePhi->addIncoming(OldValue, ComputeLoop);
600 }
601
602 // Accumulate the results
603 auto *NewAccumulator = buildNonAtomicBinOp(B, Op, Accumulator, LaneValue);
604 Accumulator->addIncoming(NewAccumulator, ComputeLoop);
605
606 // Set bit to zero of current active lane so that for next iteration llvm.cttz
607 // return the next active lane
608 auto *Mask = B.CreateShl(ConstantInt::get(WaveTy, 1), FF1);
609
610 auto *InverseMask = B.CreateXor(Mask, ConstantInt::get(WaveTy, -1));
611 auto *NewActiveBits = B.CreateAnd(ActiveBits, InverseMask);
612 ActiveBits->addIncoming(NewActiveBits, ComputeLoop);
613
614 // Branch out of the loop when all lanes are processed.
615 auto *IsEnd = B.CreateICmpEQ(NewActiveBits, ConstantInt::get(WaveTy, 0));
616 B.CreateCondBr(IsEnd, ComputeEnd, ComputeLoop);
617
618 B.SetInsertPoint(ComputeEnd);
619
620 return {OldValue, NewAccumulator};
621}
622
625 LLVMContext &C = Ty->getContext();
626 const unsigned BitWidth = Ty->getPrimitiveSizeInBits();
627 switch (Op) {
628 default:
629 llvm_unreachable("Unhandled atomic op");
635 return ConstantInt::get(C, APInt::getMinValue(BitWidth));
638 return ConstantInt::get(C, APInt::getMaxValue(BitWidth));
640 return ConstantInt::get(C, APInt::getSignedMinValue(BitWidth));
642 return ConstantInt::get(C, APInt::getSignedMaxValue(BitWidth));
644 return ConstantFP::get(C, APFloat::getZero(Ty->getFltSemantics(), true));
646 return ConstantFP::get(C, APFloat::getZero(Ty->getFltSemantics(), false));
649 // FIXME: atomicrmw fmax/fmin behave like llvm.maxnum/minnum so NaN is the
650 // closest thing they have to an identity, but it still does not preserve
651 // the difference between quiet and signaling NaNs or NaNs with different
652 // payloads.
653 return ConstantFP::get(C, APFloat::getNaN(Ty->getFltSemantics()));
654 }
655}
656
657static Value *buildMul(IRBuilder<> &B, Value *LHS, Value *RHS) {
658 const ConstantInt *CI = dyn_cast<ConstantInt>(LHS);
659 return (CI && CI->isOne()) ? RHS : B.CreateMul(LHS, RHS);
660}
661
662void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
664 unsigned ValIdx,
665 bool ValDivergent) const {
666 // Start building just before the instruction.
667 IRBuilder<> B(&I);
668
670 B.setIsFPConstrained(I.getFunction()->hasFnAttribute(Attribute::StrictFP));
671 }
672
673 // If we are in a pixel shader, because of how we have to mask out helper
674 // lane invocations, we need to record the entry and exit BB's.
675 BasicBlock *PixelEntryBB = nullptr;
676 BasicBlock *PixelExitBB = nullptr;
677
678 // If we're optimizing an atomic within a pixel shader, we need to wrap the
679 // entire atomic operation in a helper-lane check. We do not want any helper
680 // lanes that are around only for the purposes of derivatives to take part
681 // in any cross-lane communication, and we use a branch on whether the lane is
682 // live to do this.
683 if (IsPixelShader) {
684 // Record I's original position as the entry block.
685 PixelEntryBB = I.getParent();
686
687 Value *const Cond = B.CreateIntrinsic(Intrinsic::amdgcn_ps_live, {}, {});
688 Instruction *const NonHelperTerminator =
689 SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr);
690
691 // Record I's new position as the exit block.
692 PixelExitBB = I.getParent();
693
694 I.moveBefore(NonHelperTerminator);
695 B.SetInsertPoint(&I);
696 }
697
698 Type *const Ty = I.getType();
699 Type *Int32Ty = B.getInt32Ty();
700 bool isAtomicFloatingPointTy = Ty->isFloatingPointTy();
701 [[maybe_unused]] const unsigned TyBitWidth = DL->getTypeSizeInBits(Ty);
702
703 // This is the value in the atomic operation we need to combine in order to
704 // reduce the number of atomic operations.
705 Value *V = I.getOperand(ValIdx);
706
707 // We need to know how many lanes are active within the wavefront, and we do
708 // this by doing a ballot of active lanes.
709 Type *const WaveTy = B.getIntNTy(ST->getWavefrontSize());
710 CallInst *const Ballot =
711 B.CreateIntrinsic(Intrinsic::amdgcn_ballot, WaveTy, B.getTrue());
712
713 // We need to know how many lanes are active within the wavefront that are
714 // below us. If we counted each lane linearly starting from 0, a lane is
715 // below us only if its associated index was less than ours. We do this by
716 // using the mbcnt intrinsic.
717 Value *Mbcnt;
718 if (ST->isWave32()) {
719 Mbcnt = B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_lo, {},
720 {Ballot, B.getInt32(0)});
721 } else {
722 Value *const ExtractLo = B.CreateTrunc(Ballot, Int32Ty);
723 Value *const ExtractHi = B.CreateTrunc(B.CreateLShr(Ballot, 32), Int32Ty);
724 Mbcnt = B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_lo, {},
725 {ExtractLo, B.getInt32(0)});
726 Mbcnt =
727 B.CreateIntrinsic(Intrinsic::amdgcn_mbcnt_hi, {}, {ExtractHi, Mbcnt});
728 }
729
730 Function *F = I.getFunction();
731 LLVMContext &C = F->getContext();
732
733 // For atomic sub, perform scan with add operation and allow one lane to
734 // subtract the reduced value later.
735 AtomicRMWInst::BinOp ScanOp = Op;
736 if (Op == AtomicRMWInst::Sub) {
737 ScanOp = AtomicRMWInst::Add;
738 } else if (Op == AtomicRMWInst::FSub) {
739 ScanOp = AtomicRMWInst::FAdd;
740 }
741 Value *Identity = getIdentityValueForAtomicOp(Ty, ScanOp);
742
743 Value *ExclScan = nullptr;
744 Value *NewV = nullptr;
745
746 const bool NeedResult = !I.use_empty();
747
748 BasicBlock *ComputeLoop = nullptr;
749 BasicBlock *ComputeEnd = nullptr;
750 // If we have a divergent value in each lane, we need to combine the value
751 // using DPP.
752 if (ValDivergent) {
753 if (ScanImpl == ScanOptions::DPP) {
754 // First we need to set all inactive invocations to the identity value, so
755 // that they can correctly contribute to the final result.
756 NewV =
757 B.CreateIntrinsic(Intrinsic::amdgcn_set_inactive, Ty, {V, Identity});
758 if (!NeedResult && ST->hasPermLaneX16()) {
759 // On GFX10 the permlanex16 instruction helps us build a reduction
760 // without too many readlanes and writelanes, which are generally bad
761 // for performance.
762 NewV = buildReduction(B, ScanOp, NewV, Identity);
763 } else {
764 NewV = buildScan(B, ScanOp, NewV, Identity);
765 if (NeedResult)
766 ExclScan = buildShiftRight(B, NewV, Identity);
767 // Read the value from the last lane, which has accumulated the values
768 // of each active lane in the wavefront. This will be our new value
769 // which we will provide to the atomic operation.
770 Value *const LastLaneIdx = B.getInt32(ST->getWavefrontSize() - 1);
771 NewV = B.CreateIntrinsic(Ty, Intrinsic::amdgcn_readlane,
772 {NewV, LastLaneIdx});
773 }
774 // Finally mark the readlanes in the WWM section.
775 NewV = B.CreateIntrinsic(Intrinsic::amdgcn_strict_wwm, Ty, NewV);
776 } else if (ScanImpl == ScanOptions::Iterative) {
777 // Alternative implementation for scan
778 ComputeLoop = BasicBlock::Create(C, "ComputeLoop", F);
779 ComputeEnd = BasicBlock::Create(C, "ComputeEnd", F);
780 std::tie(ExclScan, NewV) = buildScanIteratively(B, ScanOp, Identity, V, I,
781 ComputeLoop, ComputeEnd);
782 } else {
783 llvm_unreachable("Atomic Optimzer is disabled for None strategy");
784 }
785 } else {
786 switch (Op) {
787 default:
788 llvm_unreachable("Unhandled atomic op");
789
791 case AtomicRMWInst::Sub: {
792 // The new value we will be contributing to the atomic operation is the
793 // old value times the number of active lanes.
794 Value *const Ctpop = B.CreateIntCast(
795 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Ty, false);
796 NewV = buildMul(B, V, Ctpop);
797 break;
798 }
800 case AtomicRMWInst::FSub: {
801 Value *const Ctpop = B.CreateIntCast(
802 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Int32Ty, false);
803 Value *const CtpopFP = B.CreateUIToFP(Ctpop, Ty);
804 NewV = B.CreateFMul(V, CtpopFP);
805 break;
806 }
815 // These operations with a uniform value are idempotent: doing the atomic
816 // operation multiple times has the same effect as doing it once.
817 NewV = V;
818 break;
819
821 // The new value we will be contributing to the atomic operation is the
822 // old value times the parity of the number of active lanes.
823 Value *const Ctpop = B.CreateIntCast(
824 B.CreateUnaryIntrinsic(Intrinsic::ctpop, Ballot), Ty, false);
825 NewV = buildMul(B, V, B.CreateAnd(Ctpop, 1));
826 break;
827 }
828 }
829
830 // We only want a single lane to enter our new control flow, and we do this
831 // by checking if there are any active lanes below us. Only one lane will
832 // have 0 active lanes below us, so that will be the only one to progress.
833 Value *const Cond = B.CreateICmpEQ(Mbcnt, B.getInt32(0));
834
835 // Store I's original basic block before we split the block.
836 BasicBlock *const OriginalBB = I.getParent();
837
838 // We need to introduce some new control flow to force a single lane to be
839 // active. We do this by splitting I's basic block at I, and introducing the
840 // new block such that:
841 // entry --> single_lane -\
842 // \------------------> exit
843 Instruction *const SingleLaneTerminator =
844 SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr);
845
846 // At this point, we have split the I's block to allow one lane in wavefront
847 // to update the precomputed reduced value. Also, completed the codegen for
848 // new control flow i.e. iterative loop which perform reduction and scan using
849 // ComputeLoop and ComputeEnd.
850 // For the new control flow, we need to move branch instruction i.e.
851 // terminator created during SplitBlockAndInsertIfThen from I's block to
852 // ComputeEnd block. We also need to set up predecessor to next block when
853 // single lane done updating the final reduced value.
854 BasicBlock *Predecessor = nullptr;
855 if (ValDivergent && ScanImpl == ScanOptions::Iterative) {
856 // Move terminator from I's block to ComputeEnd block.
857 //
858 // OriginalBB is known to have a branch as terminator because
859 // SplitBlockAndInsertIfThen will have inserted one.
860 BranchInst *Terminator = cast<BranchInst>(OriginalBB->getTerminator());
861 B.SetInsertPoint(ComputeEnd);
862 Terminator->removeFromParent();
863 B.Insert(Terminator);
864
865 // Branch to ComputeLoop Block unconditionally from the I's block for
866 // iterative approach.
867 B.SetInsertPoint(OriginalBB);
868 B.CreateBr(ComputeLoop);
869
870 // Update the dominator tree for new control flow.
872 {{DominatorTree::Insert, OriginalBB, ComputeLoop},
873 {DominatorTree::Insert, ComputeLoop, ComputeEnd}});
874
875 // We're moving the terminator from EntryBB to ComputeEnd, make sure we move
876 // the DT edges as well.
877 for (auto *Succ : Terminator->successors()) {
878 DomTreeUpdates.push_back({DominatorTree::Insert, ComputeEnd, Succ});
879 DomTreeUpdates.push_back({DominatorTree::Delete, OriginalBB, Succ});
880 }
881
882 DTU.applyUpdates(DomTreeUpdates);
883
884 Predecessor = ComputeEnd;
885 } else {
886 Predecessor = OriginalBB;
887 }
888 // Move the IR builder into single_lane next.
889 B.SetInsertPoint(SingleLaneTerminator);
890
891 // Clone the original atomic operation into single lane, replacing the
892 // original value with our newly created one.
893 Instruction *const NewI = I.clone();
894 B.Insert(NewI);
895 NewI->setOperand(ValIdx, NewV);
896
897 // Move the IR builder into exit next, and start inserting just before the
898 // original instruction.
899 B.SetInsertPoint(&I);
900
901 if (NeedResult) {
902 // Create a PHI node to get our new atomic result into the exit block.
903 PHINode *const PHI = B.CreatePHI(Ty, 2);
904 PHI->addIncoming(PoisonValue::get(Ty), Predecessor);
905 PHI->addIncoming(NewI, SingleLaneTerminator->getParent());
906
907 // We need to broadcast the value who was the lowest active lane (the first
908 // lane) to all other lanes in the wavefront. We use an intrinsic for this,
909 // but have to handle 64-bit broadcasts with two calls to this intrinsic.
910 Value *BroadcastI = nullptr;
911 BroadcastI = B.CreateIntrinsic(Ty, Intrinsic::amdgcn_readfirstlane, PHI);
912
913 // Now that we have the result of our single atomic operation, we need to
914 // get our individual lane's slice into the result. We use the lane offset
915 // we previously calculated combined with the atomic result value we got
916 // from the first lane, to get our lane's index into the atomic result.
917 Value *LaneOffset = nullptr;
918 if (ValDivergent) {
919 if (ScanImpl == ScanOptions::DPP) {
920 LaneOffset =
921 B.CreateIntrinsic(Intrinsic::amdgcn_strict_wwm, Ty, ExclScan);
922 } else if (ScanImpl == ScanOptions::Iterative) {
923 LaneOffset = ExclScan;
924 } else {
925 llvm_unreachable("Atomic Optimzer is disabled for None strategy");
926 }
927 } else {
928 Mbcnt = isAtomicFloatingPointTy ? B.CreateUIToFP(Mbcnt, Ty)
929 : B.CreateIntCast(Mbcnt, Ty, false);
930 switch (Op) {
931 default:
932 llvm_unreachable("Unhandled atomic op");
935 LaneOffset = buildMul(B, V, Mbcnt);
936 break;
945 LaneOffset = B.CreateSelect(Cond, Identity, V);
946 break;
948 LaneOffset = buildMul(B, V, B.CreateAnd(Mbcnt, 1));
949 break;
951 case AtomicRMWInst::FSub: {
952 LaneOffset = B.CreateFMul(V, Mbcnt);
953 break;
954 }
955 }
956 }
957 Value *Result = buildNonAtomicBinOp(B, Op, BroadcastI, LaneOffset);
958 if (isAtomicFloatingPointTy) {
959 // For fadd/fsub the first active lane of LaneOffset should be the
960 // identity (-0.0 for fadd or +0.0 for fsub) but the value we calculated
961 // is V * +0.0 which might have the wrong sign or might be nan (if V is
962 // inf or nan).
963 //
964 // For all floating point ops if the in-memory value was a nan then the
965 // binop we just built might have quieted it or changed its payload.
966 //
967 // Correct all these problems by using BroadcastI as the result in the
968 // first active lane.
969 Result = B.CreateSelect(Cond, BroadcastI, Result);
970 }
971
972 if (IsPixelShader) {
973 // Need a final PHI to reconverge to above the helper lane branch mask.
974 B.SetInsertPoint(PixelExitBB, PixelExitBB->getFirstNonPHIIt());
975
976 PHINode *const PHI = B.CreatePHI(Ty, 2);
977 PHI->addIncoming(PoisonValue::get(Ty), PixelEntryBB);
978 PHI->addIncoming(Result, I.getParent());
979 I.replaceAllUsesWith(PHI);
980 } else {
981 // Replace the original atomic instruction with the new one.
982 I.replaceAllUsesWith(Result);
983 }
984 }
985
986 // And delete the original.
987 I.eraseFromParent();
988}
989
990INITIALIZE_PASS_BEGIN(AMDGPUAtomicOptimizer, DEBUG_TYPE,
991 "AMDGPU atomic optimizations", false, false)
994INITIALIZE_PASS_END(AMDGPUAtomicOptimizer, DEBUG_TYPE,
995 "AMDGPU atomic optimizations", false, false)
996
998 return new AMDGPUAtomicOptimizer(ScanStrategy);
999}
static Constant * getIdentityValueForAtomicOp(Type *const Ty, AtomicRMWInst::BinOp Op)
static bool isLegalCrossLaneType(Type *Ty)
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
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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
uint64_t Size
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
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#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 getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition: APFloat.h:1021
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:994
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:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
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:696
static bool isFPOperation(BinOp Op)
Definition: Instructions.h:791
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:708
@ Add
*p = old + v
Definition: Instructions.h:712
@ FAdd
*p = old + v
Definition: Instructions.h:733
@ Min
*p = old <signed v ? old : v
Definition: Instructions.h:726
@ Or
*p = old | v
Definition: Instructions.h:720
@ Sub
*p = old - v
Definition: Instructions.h:714
@ And
*p = old & v
Definition: Instructions.h:716
@ Xor
*p = old ^ v
Definition: Instructions.h:722
@ FSub
*p = old - v
Definition: Instructions.h:736
@ Max
*p = old >signed v ? old : v
Definition: Instructions.h:724
@ UMin
*p = old <unsigned v ? old : v
Definition: Instructions.h:730
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
Definition: Instructions.h:744
@ UMax
*p = old >unsigned v ? old : v
Definition: Instructions.h:728
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
Definition: Instructions.h:740
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
Definition: BasicBlock.cpp:374
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:212
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:239
Conditional or Unconditional Branch instruction.
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:757
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:786
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:780
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:784
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:782
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:212
This is an important base class in LLVM.
Definition: Constant.h:42
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:63
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
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
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:2686
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
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
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:1852
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
void preserve()
Mark an analysis as preserved.
Definition: Analysis.h:131
void push_back(const T &Elt)
Definition: SmallVector.h:426
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:77
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
unsigned getIntegerBitWidth() const
const fltSemantics & getFltSemantics() const
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:70
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:184
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
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
const ParentTy * getParent() const
Definition: ilist_node.h:32
#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:1539
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ScanOptions
Definition: AMDGPU.h:108
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)