LLVM 23.0.0git
NVPTXLowerArgs.cpp
Go to the documentation of this file.
1//===-- NVPTXLowerArgs.cpp - Lower arguments ------------------------------===//
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//
10// Arguments to kernel and device functions are passed via param space,
11// which imposes certain restrictions:
12// http://docs.nvidia.com/cuda/parallel-thread-execution/#state-spaces
13//
14// Kernel parameters are read-only and accessible only via ld.param
15// instruction, directly or via a pointer.
16//
17// Device function parameters are directly accessible via
18// ld.param/st.param, but taking the address of one returns a pointer
19// to a copy created in local space which *can't* be used with
20// ld.param/st.param.
21//
22// Copying a byval struct into local memory in IR allows us to enforce
23// the param space restrictions, gives the rest of IR a pointer w/o
24// param space restrictions, and gives us an opportunity to eliminate
25// the copy.
26//
27// Pointer arguments to kernel functions need more work to be lowered:
28//
29// 1. Convert non-byval pointer arguments of CUDA kernels to pointers in the
30// global address space. This allows later optimizations to emit
31// ld.global.*/st.global.* for accessing these pointer arguments. For
32// example,
33//
34// define void @foo(float* %input) {
35// %v = load float, float* %input, align 4
36// ...
37// }
38//
39// becomes
40//
41// define void @foo(float* %input) {
42// %input2 = addrspacecast float* %input to float addrspace(1)*
43// %input3 = addrspacecast float addrspace(1)* %input2 to float*
44// %v = load float, float* %input3, align 4
45// ...
46// }
47//
48// Later, NVPTXInferAddressSpaces will optimize it to
49//
50// define void @foo(float* %input) {
51// %input2 = addrspacecast float* %input to float addrspace(1)*
52// %v = load float, float addrspace(1)* %input2, align 4
53// ...
54// }
55//
56// 2. Convert byval kernel parameters to pointers in the param address space
57// (so that NVPTX emits ld/st.param). Convert pointers *within* a byval
58// kernel parameter to pointers in the global address space. This allows
59// NVPTX to emit ld/st.global.
60//
61// struct S {
62// int *x;
63// int *y;
64// };
65// __global__ void foo(S s) {
66// int *b = s.y;
67// // use b
68// }
69//
70// "b" points to the global address space. In the IR level,
71//
72// define void @foo(ptr byval %input) {
73// %b_ptr = getelementptr {ptr, ptr}, ptr %input, i64 0, i32 1
74// %b = load ptr, ptr %b_ptr
75// ; use %b
76// }
77//
78// becomes
79//
80// define void @foo({i32*, i32*}* byval %input) {
81// %b_param = addrspacecat ptr %input to ptr addrspace(101)
82// %b_ptr = getelementptr {ptr, ptr}, ptr addrspace(101) %b_param, i64 0, i32 1
83// %b = load ptr, ptr addrspace(101) %b_ptr
84// %b_global = addrspacecast ptr %b to ptr addrspace(1)
85// ; use %b_generic
86// }
87//
88// Create a local copy of kernel byval parameters used in a way that *might* mutate
89// the parameter, by storing it in an alloca. Mutations to "grid_constant" parameters
90// are undefined behaviour, and don't require local copies.
91//
92// define void @foo(ptr byval(%struct.s) align 4 %input) {
93// store i32 42, ptr %input
94// ret void
95// }
96//
97// becomes
98//
99// define void @foo(ptr byval(%struct.s) align 4 %input) #1 {
100// %input1 = alloca %struct.s, align 4
101// %input2 = addrspacecast ptr %input to ptr addrspace(101)
102// %input3 = load %struct.s, ptr addrspace(101) %input2, align 4
103// store %struct.s %input3, ptr %input1, align 4
104// store i32 42, ptr %input1, align 4
105// ret void
106// }
107//
108// If %input were passed to a device function, or written to memory,
109// conservatively assume that %input gets mutated, and create a local copy.
110//
111// Convert param pointers to grid_constant byval kernel parameters that are
112// passed into calls (device functions, intrinsics, inline asm), or otherwise
113// "escape" (into stores/ptrtoints) to the generic address space, using the
114// `nvvm.ptr.param.to.gen` intrinsic, so that NVPTX emits cvta.param
115// (available for sm70+)
116//
117// define void @foo(ptr byval(%struct.s) %input) {
118// ; %input is a grid_constant
119// %call = call i32 @escape(ptr %input)
120// ret void
121// }
122//
123// becomes
124//
125// define void @foo(ptr byval(%struct.s) %input) {
126// %input1 = addrspacecast ptr %input to ptr addrspace(101)
127// ; the following intrinsic converts pointer to generic. We don't use an addrspacecast
128// ; to prevent generic -> param -> generic from getting cancelled out
129// %input1.gen = call ptr @llvm.nvvm.ptr.param.to.gen.p0.p101(ptr addrspace(101) %input1)
130// %call = call i32 @escape(ptr %input1.gen)
131// ret void
132// }
133//
134// TODO: merge this pass with NVPTXInferAddressSpaces so that other passes don't
135// cancel the addrspacecast pair this pass emits.
136//===----------------------------------------------------------------------===//
137
138#include "NVPTX.h"
139#include "NVPTXTargetMachine.h"
140#include "NVPTXUtilities.h"
141#include "NVVMProperties.h"
142#include "llvm/ADT/STLExtras.h"
146#include "llvm/IR/Attributes.h"
147#include "llvm/IR/Function.h"
148#include "llvm/IR/IRBuilder.h"
149#include "llvm/IR/Instructions.h"
151#include "llvm/IR/IntrinsicsNVPTX.h"
152#include "llvm/IR/Type.h"
154#include "llvm/Pass.h"
155#include "llvm/Support/Debug.h"
158#include <queue>
159
160#define DEBUG_TYPE "nvptx-lower-args"
161
162using namespace llvm;
163using namespace NVPTXAS;
164
165namespace {
166class NVPTXLowerArgsLegacyPass : public FunctionPass {
167 bool runOnFunction(Function &F) override;
168
169public:
170 static char ID; // Pass identification, replacement for typeid
171 NVPTXLowerArgsLegacyPass() : FunctionPass(ID) {}
172 StringRef getPassName() const override {
173 return "Lower pointer arguments of CUDA kernels";
174 }
175 void getAnalysisUsage(AnalysisUsage &AU) const override {
177 }
178};
179} // namespace
180
181char NVPTXLowerArgsLegacyPass::ID = 1;
182
183INITIALIZE_PASS_BEGIN(NVPTXLowerArgsLegacyPass, "nvptx-lower-args",
184 "Lower arguments (NVPTX)", false, false)
186INITIALIZE_PASS_END(NVPTXLowerArgsLegacyPass, "nvptx-lower-args",
187 "Lower arguments (NVPTX)", false, false)
188
189// =============================================================================
190// If the function had a byval struct ptr arg, say foo(ptr byval(%struct.x) %d),
191// and we can't guarantee that the only accesses are loads,
192// then add the following instructions to the first basic block:
193//
194// %temp = alloca %struct.x, align 8
195// %tempd = addrspacecast ptr %d to ptr addrspace(101)
196// %tv = load %struct.x, ptr addrspace(101) %tempd
197// store %struct.x %tv, ptr %temp, align 8
198//
199// The above code allocates some space in the stack and copies the incoming
200// struct from param space to local space.
201// Then replace all occurrences of %d by %temp.
202//
203// In case we know that all users are GEPs or Loads, replace them with the same
204// ones in parameter AS, so we can access them using ld.param.
205// =============================================================================
206
207/// Recursively convert the users of a param to the param address space.
208static void convertToParamAS(ArrayRef<Use *> OldUses, Value *Param) {
209 struct IP {
210 Use *OldUse;
211 Value *NewParam;
212 };
213
214 const auto CloneInstInParamAS = [](const IP &I) -> Value * {
215 auto *OldInst = cast<Instruction>(I.OldUse->getUser());
216 if (auto *LI = dyn_cast<LoadInst>(OldInst)) {
217 LI->setOperand(0, I.NewParam);
218 return LI;
219 }
220 if (auto *GEP = dyn_cast<GetElementPtrInst>(OldInst)) {
221 SmallVector<Value *, 4> Indices(GEP->indices());
222 auto *NewGEP = GetElementPtrInst::Create(
223 GEP->getSourceElementType(), I.NewParam, Indices, GEP->getName(),
224 GEP->getIterator());
225 NewGEP->setNoWrapFlags(GEP->getNoWrapFlags());
226 return NewGEP;
227 }
228 if (auto *BC = dyn_cast<BitCastInst>(OldInst)) {
229 auto *NewBCType =
231 return BitCastInst::Create(BC->getOpcode(), I.NewParam, NewBCType,
232 BC->getName(), BC->getIterator());
233 }
234 if (auto *ASC = dyn_cast<AddrSpaceCastInst>(OldInst)) {
235 assert(ASC->getDestAddressSpace() == ADDRESS_SPACE_ENTRY_PARAM);
236 (void)ASC;
237 // Just pass through the argument, the old ASC is no longer needed.
238 return I.NewParam;
239 }
240 if (auto *MI = dyn_cast<MemTransferInst>(OldInst)) {
241 if (MI->getRawSource() == I.OldUse->get()) {
242 // convert to memcpy/memmove from param space.
243 IRBuilder<> Builder(OldInst);
244 Intrinsic::ID ID = MI->getIntrinsicID();
245
246 CallInst *B = Builder.CreateMemTransferInst(
247 ID, MI->getRawDest(), MI->getDestAlign(), I.NewParam,
248 MI->getSourceAlign(), MI->getLength(), MI->isVolatile());
249 for (unsigned I : {0, 1})
250 if (uint64_t Bytes = MI->getParamDereferenceableBytes(I))
251 B->addDereferenceableParamAttr(I, Bytes);
252 return B;
253 }
254 }
255
256 llvm_unreachable("Unsupported instruction");
257 };
258
259 auto ItemsToConvert =
260 map_to_vector(OldUses, [=](Use *U) -> IP { return {U, Param}; });
261 SmallVector<Instruction *> InstructionsToDelete;
262
263 while (!ItemsToConvert.empty()) {
264 IP I = ItemsToConvert.pop_back_val();
265 Value *NewInst = CloneInstInParamAS(I);
266 Instruction *OldInst = cast<Instruction>(I.OldUse->getUser());
267
268 if (NewInst && NewInst != OldInst) {
269 // We've created a new instruction. Queue users of the old instruction to
270 // be converted and the instruction itself to be deleted. We can't delete
271 // the old instruction yet, because it's still in use by a load somewhere.
272 for (Use &U : OldInst->uses())
273 ItemsToConvert.push_back({&U, NewInst});
274
275 InstructionsToDelete.push_back(OldInst);
276 }
277 }
278
279 // Now we know that all argument loads are using addresses in parameter space
280 // and we can finally remove the old instructions in generic AS. Instructions
281 // scheduled for removal should be processed in reverse order so the ones
282 // closest to the load are deleted first. Otherwise they may still be in use.
283 // E.g if we have Value = Load(BitCast(GEP(arg))), InstructionsToDelete will
284 // have {GEP,BitCast}. GEP can't be deleted first, because it's still used by
285 // the BitCast.
286 for (Instruction *I : llvm::reverse(InstructionsToDelete))
287 I->eraseFromParent();
288}
289
291 Function *F = Arg->getParent();
292 Type *ByValType = Arg->getParamByValType();
293 const DataLayout &DL = F->getDataLayout();
294
295 const Align OptimizedAlign = getFunctionParamOptimizedAlign(F, ByValType, DL);
296 const Align CurrentAlign = Arg->getParamAlign().valueOrOne();
297
298 if (CurrentAlign >= OptimizedAlign)
299 return CurrentAlign;
300
301 LLVM_DEBUG(dbgs() << "Try to use alignment " << OptimizedAlign.value()
302 << " instead of " << CurrentAlign.value() << " for " << *Arg
303 << '\n');
304
305 Arg->removeAttr(Attribute::Alignment);
306 Arg->addAttr(Attribute::getWithAlignment(F->getContext(), OptimizedAlign));
307
308 return OptimizedAlign;
309}
310
311// Adjust alignment of arguments passed byval in .param address space. We can
312// increase alignment of such arguments in a way that ensures that we can
313// effectively vectorize their loads. We should also traverse all loads from
314// byval pointer and adjust their alignment, if those were using known offset.
315// Such alignment changes must be conformed with parameter store and load in
316// NVPTXTargetLowering::LowerCall.
317static void propagateAlignmentToLoads(Value *Val, Align NewAlign,
318 const DataLayout &DL) {
319 struct Load {
320 LoadInst *Inst;
322 };
323
324 struct LoadContext {
325 Value *InitialVal;
327 };
328
329 SmallVector<Load> Loads;
330 std::queue<LoadContext> Worklist;
331 Worklist.push({Val, 0});
332
333 while (!Worklist.empty()) {
334 LoadContext Ctx = Worklist.front();
335 Worklist.pop();
336
337 for (User *CurUser : Ctx.InitialVal->users()) {
338 if (auto *I = dyn_cast<LoadInst>(CurUser))
339 Loads.push_back({I, Ctx.Offset});
340 else if (isa<BitCastInst>(CurUser) || isa<AddrSpaceCastInst>(CurUser))
341 Worklist.push({cast<Instruction>(CurUser), Ctx.Offset});
342 else if (auto *I = dyn_cast<GetElementPtrInst>(CurUser)) {
343 APInt OffsetAccumulated =
344 APInt::getZero(DL.getIndexSizeInBits(ADDRESS_SPACE_ENTRY_PARAM));
345
346 if (!I->accumulateConstantOffset(DL, OffsetAccumulated))
347 continue;
348
349 uint64_t OffsetLimit = -1;
350 uint64_t Offset = OffsetAccumulated.getLimitedValue(OffsetLimit);
351 assert(Offset != OffsetLimit && "Expect Offset less than UINT64_MAX");
352
353 Worklist.push({I, Ctx.Offset + Offset});
354 }
355 }
356 }
357
358 for (Load &CurLoad : Loads) {
359 Align NewLoadAlign = commonAlignment(NewAlign, CurLoad.Offset);
360 Align CurLoadAlign = CurLoad.Inst->getAlign();
361 CurLoad.Inst->setAlignment(std::max(NewLoadAlign, CurLoadAlign));
362 }
363}
364
365// Create a call to the nvvm_internal_addrspace_wrap intrinsic and set the
366// alignment of the return value based on the alignment of the argument.
368 Argument &Arg) {
369 CallInst *ArgInParam = IRB.CreateIntrinsic(
370 Intrinsic::nvvm_internal_addrspace_wrap,
371 {IRB.getPtrTy(ADDRESS_SPACE_ENTRY_PARAM), Arg.getType()}, &Arg, {},
372 Arg.getName() + ".param");
373
374 if (MaybeAlign ParamAlign = Arg.getParamAlign())
375 ArgInParam->addRetAttr(
376 Attribute::getWithAlignment(ArgInParam->getContext(), *ParamAlign));
377
378 Arg.addAttr(Attribute::get(Arg.getContext(), "nvvm.grid_constant"));
379 Arg.addAttr(Attribute::ReadOnly);
380
381 return ArgInParam;
382}
383
384namespace {
385struct ArgUseChecker : PtrUseVisitor<ArgUseChecker> {
386 using Base = PtrUseVisitor<ArgUseChecker>;
387 // Set of phi/select instructions using the Arg
388 SmallPtrSet<Instruction *, 4> Conditionals;
389
390 ArgUseChecker(const DataLayout &DL) : PtrUseVisitor(DL) {}
391
392 PtrInfo visitArgPtr(Argument &A) {
393 assert(A.getType()->isPointerTy());
394 IntegerType *IntIdxTy = cast<IntegerType>(DL.getIndexType(A.getType()));
395 IsOffsetKnown = false;
396 Offset = APInt(IntIdxTy->getBitWidth(), 0);
397 PI.reset();
398
399 LLVM_DEBUG(dbgs() << "Checking Argument " << A << "\n");
400 // Enqueue the uses of this pointer.
401 enqueueUsers(A);
402
403 // Visit all the uses off the worklist until it is empty.
404 // Note that unlike PtrUseVisitor we intentionally do not track offsets.
405 // We're only interested in how we use the pointer.
406 while (!(Worklist.empty() || PI.isAborted())) {
407 UseToVisit ToVisit = Worklist.pop_back_val();
408 U = ToVisit.UseAndIsOffsetKnown.getPointer();
409 Instruction *I = cast<Instruction>(U->getUser());
410 LLVM_DEBUG(dbgs() << "Processing " << *I << "\n");
411 Base::visit(I);
412 }
413 if (PI.isEscaped())
414 LLVM_DEBUG(dbgs() << "Argument pointer escaped: " << *PI.getEscapingInst()
415 << "\n");
416 else if (PI.isAborted())
417 LLVM_DEBUG(dbgs() << "Pointer use needs a copy: " << *PI.getAbortingInst()
418 << "\n");
419 LLVM_DEBUG(dbgs() << "Traversed " << Conditionals.size()
420 << " conditionals\n");
421 return PI;
422 }
423
424 void visitStoreInst(StoreInst &SI) {
425 // Storing the pointer escapes it.
426 if (U->get() == SI.getValueOperand())
427 return PI.setEscapedAndAborted(&SI);
428
429 PI.setAborted(&SI);
430 }
431
432 void visitAddrSpaceCastInst(AddrSpaceCastInst &ASC) {
433 // ASC to param space are no-ops and do not need a copy
435 return PI.setEscapedAndAborted(&ASC);
437 }
438
439 void visitPtrToIntInst(PtrToIntInst &I) { Base::visitPtrToIntInst(I); }
440
441 void visitPHINodeOrSelectInst(Instruction &I) {
443 enqueueUsers(I);
444 Conditionals.insert(&I);
445 }
446 // PHI and select just pass through the pointers.
447 void visitPHINode(PHINode &PN) { visitPHINodeOrSelectInst(PN); }
448 void visitSelectInst(SelectInst &SI) { visitPHINodeOrSelectInst(SI); }
449
450 // memcpy/memmove are OK when the pointer is source. We can convert them to
451 // AS-specific memcpy.
452 void visitMemTransferInst(MemTransferInst &II) {
453 if (*U == II.getRawDest())
454 PI.setAborted(&II);
455 }
456
457 void visitMemSetInst(MemSetInst &II) { PI.setAborted(&II); }
458}; // struct ArgUseChecker
459
460void copyByValParam(Function &F, Argument &Arg) {
461 LLVM_DEBUG(dbgs() << "Creating a local copy of " << Arg << "\n");
462 Type *ByValType = Arg.getParamByValType();
463 const DataLayout &DL = F.getDataLayout();
464 IRBuilder<> IRB(&F.getEntryBlock().front());
465 AllocaInst *AllocA = IRB.CreateAlloca(ByValType, nullptr, Arg.getName());
466 // Set the alignment to alignment of the byval parameter. This is because,
467 // later load/stores assume that alignment, and we are going to replace
468 // the use of the byval parameter with this alloca instruction.
469 AllocA->setAlignment(
470 Arg.getParamAlign().value_or(DL.getPrefTypeAlign(ByValType)));
471 Arg.replaceAllUsesWith(AllocA);
472
473 Value *ArgInParamAS = createNVVMInternalAddrspaceWrap(IRB, Arg);
474
475 // Be sure to propagate alignment to this load; LLVM doesn't know that NVPTX
476 // addrspacecast preserves alignment. Since params are constant, this load
477 // is definitely not volatile.
478 const auto ArgSize = *AllocA->getAllocationSize(DL);
479 IRB.CreateMemCpy(AllocA, AllocA->getAlign(), ArgInParamAS, AllocA->getAlign(),
480 ArgSize);
481}
482} // namespace
483
484static bool argIsProcessed(Argument *Arg) {
485 if (Arg->use_empty())
486 return true;
487
488 // If the argument is already wrapped, it was processed by this pass before.
489 if (Arg->hasOneUse())
490 if (const auto *II = dyn_cast<IntrinsicInst>(*Arg->user_begin()))
491 if (II->getIntrinsicID() == Intrinsic::nvvm_internal_addrspace_wrap)
492 return true;
493
494 return false;
495}
496
498 const bool HasCvtaParam) {
500
501 const DataLayout &DL = F.getDataLayout();
502 IRBuilder<> IRB(&F.getEntryBlock().front());
503
504 if (argIsProcessed(Arg))
505 return;
506
507 const Align NewArgAlign = setByValParamAlign(Arg);
508
509 // (1) First check the easy case, if were able to trace through all the uses
510 // and we can convert them all to param AS, then we'll do this.
511 ArgUseChecker AUC(DL);
512 ArgUseChecker::PtrInfo PI = AUC.visitArgPtr(*Arg);
513 const bool ArgUseIsReadOnly = !(PI.isEscaped() || PI.isAborted());
514 if (ArgUseIsReadOnly && AUC.Conditionals.empty()) {
515 // Convert all loads and intermediate operations to use parameter AS and
516 // skip creation of a local copy of the argument.
518 Value *ArgInParamAS = createNVVMInternalAddrspaceWrap(IRB, *Arg);
519 for (Use *U : UsesToUpdate)
520 convertToParamAS(U, ArgInParamAS);
521
522 propagateAlignmentToLoads(ArgInParamAS, NewArgAlign, DL);
523 return;
524 }
525
526 // (2) If the argument is grid constant, we get to use the pointer directly.
527 if (HasCvtaParam && (ArgUseIsReadOnly || isParamGridConstant(*Arg))) {
528 LLVM_DEBUG(dbgs() << "Using non-copy pointer to " << *Arg << "\n");
529
530 // Cast argument to param address space. Because the backend will emit the
531 // argument already in the param address space, we need to use the noop
532 // intrinsic, this had the added benefit of preventing other optimizations
533 // from folding away this pair of addrspacecasts.
534 Instruction *ArgInParamAS = createNVVMInternalAddrspaceWrap(IRB, *Arg);
535
536 // Cast param address to generic address space.
537 Value *GenericArg = IRB.CreateAddrSpaceCast(
538 ArgInParamAS, IRB.getPtrTy(ADDRESS_SPACE_GENERIC),
539 Arg->getName() + ".gen");
540
541 Arg->replaceAllUsesWith(GenericArg);
542
543 // Do not replace Arg in the cast to param space
544 ArgInParamAS->setOperand(0, Arg);
545 return;
546 }
547
548 // (3) Otherwise we have to create a copy of the argument in local memory.
549 copyByValParam(F, *Arg);
550}
551
552// =============================================================================
553// Main function for this pass.
554// =============================================================================
556 const NVPTXSubtarget *ST = TM.getSubtargetImpl(F);
557 const bool HasCvtaParam = ST->hasCvtaParam();
558
559 LLVM_DEBUG(dbgs() << "Lowering kernel args of " << F.getName() << "\n");
560 bool Changed = false;
561 for (Argument &Arg : F.args())
562 if (Arg.hasByValAttr()) {
563 lowerKernelByValParam(&Arg, F, HasCvtaParam);
564 Changed = true;
565 }
566
567 return Changed;
568}
569
570// Device functions only need to copy byval args into local memory.
572 LLVM_DEBUG(dbgs() << "Lowering function args of " << F.getName() << "\n");
573
574 const DataLayout &DL = F.getDataLayout();
575
576 bool Changed = false;
577 for (Argument &Arg : F.args())
578 if (Arg.hasByValAttr()) {
579 const Align NewArgAlign = setByValParamAlign(&Arg);
580 propagateAlignmentToLoads(&Arg, NewArgAlign, DL);
581 Changed = true;
582 }
583
584 return Changed;
585}
586
591
592bool NVPTXLowerArgsLegacyPass::runOnFunction(Function &F) {
593 auto &TM = getAnalysis<TargetPassConfig>().getTM<NVPTXTargetMachine>();
594 return processFunction(F, TM);
595}
596
598 return new NVPTXLowerArgsLegacyPass();
599}
600
602 LLVM_DEBUG(dbgs() << "Creating a copy of byval args of " << F.getName()
603 << "\n");
604 bool Changed = false;
605 if (isKernelFunction(F)) {
606 for (Argument &Arg : F.args())
607 if (Arg.hasByValAttr() && !isParamGridConstant(Arg)) {
608 copyByValParam(F, Arg);
609 Changed = true;
610 }
611 }
612 return Changed;
613}
614
620
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
Hexagon Common GEP
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
NVPTX address space definition.
static bool runOnDeviceFunction(Function &F)
nvptx lower Lower static false void convertToParamAS(ArrayRef< Use * > OldUses, Value *Param)
Recursively convert the users of a param to the param address space.
static CallInst * createNVVMInternalAddrspaceWrap(IRBuilder<> &IRB, Argument &Arg)
static void lowerKernelByValParam(Argument *Arg, Function &F, const bool HasCvtaParam)
static bool copyFunctionByValArgs(Function &F)
static bool argIsProcessed(Argument *Arg)
static bool processFunction(Function &F, NVPTXTargetMachine &TM)
static Align setByValParamAlign(Argument *Arg)
static bool runOnKernelFunction(const NVPTXTargetMachine &TM, Function &F)
static void propagateAlignmentToLoads(Value *Val, Align NewAlign, const DataLayout &DL)
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This file provides a collection of visitors which walk the (instruction) uses of a pointer.
This file contains some templates that are useful if you are working with the STL at all.
This file defines less commonly used SmallVector utilities.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Target-Independent Code Generator Pass Configuration Options pass.
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:476
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:201
unsigned getDestAddressSpace() const
Returns the address space of the result.
an instruction to allocate memory on the stack
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
LLVM_ABI std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
void setAlignment(Align Align)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
LLVM_ABI void addAttr(Attribute::AttrKind Kind)
Definition Function.cpp:320
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition Function.cpp:128
LLVM_ABI void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition Function.cpp:328
const Function * getParent() const
Definition Argument.h:44
LLVM_ABI Type * getParamByValType() const
If this is a byval argument, return its type.
Definition Function.cpp:224
LLVM_ABI MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition Function.cpp:215
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:622
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2204
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2811
void visit(Iterator Start, Iterator End)
Definition InstVisitor.h:87
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
An instruction for reading from memory.
const NVPTXSubtarget * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
A base class for visitors over the uses of a pointer value.
void visitAddrSpaceCastInst(AddrSpaceCastInst &ASC)
void visitPtrToIntInst(PtrToIntInst &I)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Target-Independent Code Generator Pass Configuration Options.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
void setOperand(unsigned i, Value *Val)
Definition User.h:212
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
user_iterator user_begin()
Definition Value.h:403
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:440
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:259
iterator_range< user_iterator > users()
Definition Value.h:427
bool use_empty() const
Definition Value.h:347
iterator_range< use_iterator > uses()
Definition Value.h:381
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
FunctionPass * createNVPTXLowerArgsPass()
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
bool isParamGridConstant(const Argument &Arg)
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition iterator.h:368
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Align getFunctionParamOptimizedAlign(const Function *F, Type *ArgTy, const DataLayout &DL)
Since function arguments are passed via .param space, we may want to increase their alignment in a wa...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:130
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)