LLVM 20.0.0git
RISCVGatherScatterLowering.cpp
Go to the documentation of this file.
1//===- RISCVGatherScatterLowering.cpp - Gather/Scatter lowering -----------===//
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// This pass custom lowers llvm.gather and llvm.scatter instructions to
10// RISC-V intrinsics.
11//
12//===----------------------------------------------------------------------===//
13
14#include "RISCV.h"
15#include "RISCVTargetMachine.h"
22#include "llvm/IR/IRBuilder.h"
26#include <optional>
27
28using namespace llvm;
29using namespace PatternMatch;
30
31#define DEBUG_TYPE "riscv-gather-scatter-lowering"
32
33namespace {
34
35class RISCVGatherScatterLowering : public FunctionPass {
36 const RISCVSubtarget *ST = nullptr;
37 const RISCVTargetLowering *TLI = nullptr;
38 LoopInfo *LI = nullptr;
39 const DataLayout *DL = nullptr;
40
41 SmallVector<WeakTrackingVH> MaybeDeadPHIs;
42
43 // Cache of the BasePtr and Stride determined from this GEP. When a GEP is
44 // used by multiple gathers/scatters, this allow us to reuse the scalar
45 // instructions we created for the first gather/scatter for the others.
47
48public:
49 static char ID; // Pass identification, replacement for typeid
50
51 RISCVGatherScatterLowering() : FunctionPass(ID) {}
52
53 bool runOnFunction(Function &F) override;
54
55 void getAnalysisUsage(AnalysisUsage &AU) const override {
56 AU.setPreservesCFG();
59 }
60
61 StringRef getPassName() const override {
62 return "RISC-V gather/scatter lowering";
63 }
64
65private:
66 bool tryCreateStridedLoadStore(IntrinsicInst *II, Type *DataType, Value *Ptr,
67 Value *AlignOp);
68
69 std::pair<Value *, Value *> determineBaseAndStride(Instruction *Ptr,
70 IRBuilderBase &Builder);
71
72 bool matchStridedRecurrence(Value *Index, Loop *L, Value *&Stride,
73 PHINode *&BasePtr, BinaryOperator *&Inc,
74 IRBuilderBase &Builder);
75};
76
77} // end anonymous namespace
78
79char RISCVGatherScatterLowering::ID = 0;
80
81INITIALIZE_PASS(RISCVGatherScatterLowering, DEBUG_TYPE,
82 "RISC-V gather/scatter lowering pass", false, false)
83
85 return new RISCVGatherScatterLowering();
86}
87
88// TODO: Should we consider the mask when looking for a stride?
89static std::pair<Value *, Value *> matchStridedConstant(Constant *StartC) {
90 if (!isa<FixedVectorType>(StartC->getType()))
91 return std::make_pair(nullptr, nullptr);
92
93 unsigned NumElts = cast<FixedVectorType>(StartC->getType())->getNumElements();
94
95 // Check that the start value is a strided constant.
96 auto *StartVal =
97 dyn_cast_or_null<ConstantInt>(StartC->getAggregateElement((unsigned)0));
98 if (!StartVal)
99 return std::make_pair(nullptr, nullptr);
100 APInt StrideVal(StartVal->getValue().getBitWidth(), 0);
101 ConstantInt *Prev = StartVal;
102 for (unsigned i = 1; i != NumElts; ++i) {
103 auto *C = dyn_cast_or_null<ConstantInt>(StartC->getAggregateElement(i));
104 if (!C)
105 return std::make_pair(nullptr, nullptr);
106
107 APInt LocalStride = C->getValue() - Prev->getValue();
108 if (i == 1)
109 StrideVal = LocalStride;
110 else if (StrideVal != LocalStride)
111 return std::make_pair(nullptr, nullptr);
112
113 Prev = C;
114 }
115
116 Value *Stride = ConstantInt::get(StartVal->getType(), StrideVal);
117
118 return std::make_pair(StartVal, Stride);
119}
120
121static std::pair<Value *, Value *> matchStridedStart(Value *Start,
122 IRBuilderBase &Builder) {
123 // Base case, start is a strided constant.
124 auto *StartC = dyn_cast<Constant>(Start);
125 if (StartC)
126 return matchStridedConstant(StartC);
127
128 // Base case, start is a stepvector
129 if (match(Start, m_Intrinsic<Intrinsic::stepvector>())) {
130 auto *Ty = Start->getType()->getScalarType();
131 return std::make_pair(ConstantInt::get(Ty, 0), ConstantInt::get(Ty, 1));
132 }
133
134 // Not a constant, maybe it's a strided constant with a splat added or
135 // multipled.
136 auto *BO = dyn_cast<BinaryOperator>(Start);
137 if (!BO || (BO->getOpcode() != Instruction::Add &&
138 BO->getOpcode() != Instruction::Or &&
139 BO->getOpcode() != Instruction::Shl &&
140 BO->getOpcode() != Instruction::Mul))
141 return std::make_pair(nullptr, nullptr);
142
143 if (BO->getOpcode() == Instruction::Or &&
144 !cast<PossiblyDisjointInst>(BO)->isDisjoint())
145 return std::make_pair(nullptr, nullptr);
146
147 // Look for an operand that is splatted.
148 unsigned OtherIndex = 0;
149 Value *Splat = getSplatValue(BO->getOperand(1));
150 if (!Splat && Instruction::isCommutative(BO->getOpcode())) {
151 Splat = getSplatValue(BO->getOperand(0));
152 OtherIndex = 1;
153 }
154 if (!Splat)
155 return std::make_pair(nullptr, nullptr);
156
157 Value *Stride;
158 std::tie(Start, Stride) = matchStridedStart(BO->getOperand(OtherIndex),
159 Builder);
160 if (!Start)
161 return std::make_pair(nullptr, nullptr);
162
163 Builder.SetInsertPoint(BO);
165 // Add the splat value to the start or multiply the start and stride by the
166 // splat.
167 switch (BO->getOpcode()) {
168 default:
169 llvm_unreachable("Unexpected opcode");
170 case Instruction::Or:
171 // TODO: We'd be better off creating disjoint or here, but we don't yet
172 // have an IRBuilder API for that.
173 [[fallthrough]];
174 case Instruction::Add:
175 Start = Builder.CreateAdd(Start, Splat);
176 break;
177 case Instruction::Mul:
178 Start = Builder.CreateMul(Start, Splat);
179 Stride = Builder.CreateMul(Stride, Splat);
180 break;
181 case Instruction::Shl:
182 Start = Builder.CreateShl(Start, Splat);
183 Stride = Builder.CreateShl(Stride, Splat);
184 break;
185 }
186
187 return std::make_pair(Start, Stride);
188}
189
190// Recursively, walk about the use-def chain until we find a Phi with a strided
191// start value. Build and update a scalar recurrence as we unwind the recursion.
192// We also update the Stride as we unwind. Our goal is to move all of the
193// arithmetic out of the loop.
194bool RISCVGatherScatterLowering::matchStridedRecurrence(Value *Index, Loop *L,
195 Value *&Stride,
196 PHINode *&BasePtr,
197 BinaryOperator *&Inc,
198 IRBuilderBase &Builder) {
199 // Our base case is a Phi.
200 if (auto *Phi = dyn_cast<PHINode>(Index)) {
201 // A phi node we want to perform this function on should be from the
202 // loop header.
203 if (Phi->getParent() != L->getHeader())
204 return false;
205
206 Value *Step, *Start;
207 if (!matchSimpleRecurrence(Phi, Inc, Start, Step) ||
208 Inc->getOpcode() != Instruction::Add)
209 return false;
210 assert(Phi->getNumIncomingValues() == 2 && "Expected 2 operand phi.");
211 unsigned IncrementingBlock = Phi->getIncomingValue(0) == Inc ? 0 : 1;
212 assert(Phi->getIncomingValue(IncrementingBlock) == Inc &&
213 "Expected one operand of phi to be Inc");
214
215 // Only proceed if the step is loop invariant.
216 if (!L->isLoopInvariant(Step))
217 return false;
218
219 // Step should be a splat.
220 Step = getSplatValue(Step);
221 if (!Step)
222 return false;
223
224 std::tie(Start, Stride) = matchStridedStart(Start, Builder);
225 if (!Start)
226 return false;
227 assert(Stride != nullptr);
228
229 // Build scalar phi and increment.
230 BasePtr =
231 PHINode::Create(Start->getType(), 2, Phi->getName() + ".scalar", Phi->getIterator());
232 Inc = BinaryOperator::CreateAdd(BasePtr, Step, Inc->getName() + ".scalar",
233 Inc->getIterator());
234 BasePtr->addIncoming(Start, Phi->getIncomingBlock(1 - IncrementingBlock));
235 BasePtr->addIncoming(Inc, Phi->getIncomingBlock(IncrementingBlock));
236
237 // Note that this Phi might be eligible for removal.
238 MaybeDeadPHIs.push_back(Phi);
239 return true;
240 }
241
242 // Otherwise look for binary operator.
243 auto *BO = dyn_cast<BinaryOperator>(Index);
244 if (!BO)
245 return false;
246
247 switch (BO->getOpcode()) {
248 default:
249 return false;
250 case Instruction::Or:
251 // We need to be able to treat Or as Add.
252 if (!cast<PossiblyDisjointInst>(BO)->isDisjoint())
253 return false;
254 break;
255 case Instruction::Add:
256 break;
257 case Instruction::Shl:
258 break;
259 case Instruction::Mul:
260 break;
261 }
262
263 // We should have one operand in the loop and one splat.
264 Value *OtherOp;
265 if (isa<Instruction>(BO->getOperand(0)) &&
266 L->contains(cast<Instruction>(BO->getOperand(0)))) {
267 Index = cast<Instruction>(BO->getOperand(0));
268 OtherOp = BO->getOperand(1);
269 } else if (isa<Instruction>(BO->getOperand(1)) &&
270 L->contains(cast<Instruction>(BO->getOperand(1))) &&
271 Instruction::isCommutative(BO->getOpcode())) {
272 Index = cast<Instruction>(BO->getOperand(1));
273 OtherOp = BO->getOperand(0);
274 } else {
275 return false;
276 }
277
278 // Make sure other op is loop invariant.
279 if (!L->isLoopInvariant(OtherOp))
280 return false;
281
282 // Make sure we have a splat.
283 Value *SplatOp = getSplatValue(OtherOp);
284 if (!SplatOp)
285 return false;
286
287 // Recurse up the use-def chain.
288 if (!matchStridedRecurrence(Index, L, Stride, BasePtr, Inc, Builder))
289 return false;
290
291 // Locate the Step and Start values from the recurrence.
292 unsigned StepIndex = Inc->getOperand(0) == BasePtr ? 1 : 0;
293 unsigned StartBlock = BasePtr->getOperand(0) == Inc ? 1 : 0;
294 Value *Step = Inc->getOperand(StepIndex);
295 Value *Start = BasePtr->getOperand(StartBlock);
296
297 // We need to adjust the start value in the preheader.
298 Builder.SetInsertPoint(
299 BasePtr->getIncomingBlock(StartBlock)->getTerminator());
301
302 switch (BO->getOpcode()) {
303 default:
304 llvm_unreachable("Unexpected opcode!");
305 case Instruction::Add:
306 case Instruction::Or: {
307 // An add only affects the start value. It's ok to do this for Or because
308 // we already checked that there are no common set bits.
309 Start = Builder.CreateAdd(Start, SplatOp, "start");
310 break;
311 }
312 case Instruction::Mul: {
313 Start = Builder.CreateMul(Start, SplatOp, "start");
314 Step = Builder.CreateMul(Step, SplatOp, "step");
315 Stride = Builder.CreateMul(Stride, SplatOp, "stride");
316 break;
317 }
318 case Instruction::Shl: {
319 Start = Builder.CreateShl(Start, SplatOp, "start");
320 Step = Builder.CreateShl(Step, SplatOp, "step");
321 Stride = Builder.CreateShl(Stride, SplatOp, "stride");
322 break;
323 }
324 }
325
326 Inc->setOperand(StepIndex, Step);
327 BasePtr->setIncomingValue(StartBlock, Start);
328 return true;
329}
330
331std::pair<Value *, Value *>
332RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
333 IRBuilderBase &Builder) {
334
335 // A gather/scatter of a splat is a zero strided load/store.
336 if (auto *BasePtr = getSplatValue(Ptr)) {
337 Type *IntPtrTy = DL->getIntPtrType(BasePtr->getType());
338 return std::make_pair(BasePtr, ConstantInt::get(IntPtrTy, 0));
339 }
340
341 auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
342 if (!GEP)
343 return std::make_pair(nullptr, nullptr);
344
345 auto I = StridedAddrs.find(GEP);
346 if (I != StridedAddrs.end())
347 return I->second;
348
349 SmallVector<Value *, 2> Ops(GEP->operands());
350
351 // If the base pointer is a vector, check if it's strided.
352 Value *Base = GEP->getPointerOperand();
353 if (auto *BaseInst = dyn_cast<Instruction>(Base);
354 BaseInst && BaseInst->getType()->isVectorTy()) {
355 // If GEP's offset is scalar then we can add it to the base pointer's base.
356 auto IsScalar = [](Value *Idx) { return !Idx->getType()->isVectorTy(); };
357 if (all_of(GEP->indices(), IsScalar)) {
358 auto [BaseBase, Stride] = determineBaseAndStride(BaseInst, Builder);
359 if (BaseBase) {
360 Builder.SetInsertPoint(GEP);
361 SmallVector<Value *> Indices(GEP->indices());
362 Value *OffsetBase =
363 Builder.CreateGEP(GEP->getSourceElementType(), BaseBase, Indices,
364 GEP->getName() + "offset", GEP->isInBounds());
365 return {OffsetBase, Stride};
366 }
367 }
368 }
369
370 // Base pointer needs to be a scalar.
371 Value *ScalarBase = Base;
372 if (ScalarBase->getType()->isVectorTy()) {
373 ScalarBase = getSplatValue(ScalarBase);
374 if (!ScalarBase)
375 return std::make_pair(nullptr, nullptr);
376 }
377
378 std::optional<unsigned> VecOperand;
379 unsigned TypeScale = 0;
380
381 // Look for a vector operand and scale.
383 for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
384 if (!Ops[i]->getType()->isVectorTy())
385 continue;
386
387 if (VecOperand)
388 return std::make_pair(nullptr, nullptr);
389
390 VecOperand = i;
391
393 if (TS.isScalable())
394 return std::make_pair(nullptr, nullptr);
395
396 TypeScale = TS.getFixedValue();
397 }
398
399 // We need to find a vector index to simplify.
400 if (!VecOperand)
401 return std::make_pair(nullptr, nullptr);
402
403 // We can't extract the stride if the arithmetic is done at a different size
404 // than the pointer type. Adding the stride later may not wrap correctly.
405 // Technically we could handle wider indices, but I don't expect that in
406 // practice. Handle one special case here - constants. This simplifies
407 // writing test cases.
408 Value *VecIndex = Ops[*VecOperand];
409 Type *VecIntPtrTy = DL->getIntPtrType(GEP->getType());
410 if (VecIndex->getType() != VecIntPtrTy) {
411 auto *VecIndexC = dyn_cast<Constant>(VecIndex);
412 if (!VecIndexC)
413 return std::make_pair(nullptr, nullptr);
414 if (VecIndex->getType()->getScalarSizeInBits() > VecIntPtrTy->getScalarSizeInBits())
415 VecIndex = ConstantFoldCastInstruction(Instruction::Trunc, VecIndexC, VecIntPtrTy);
416 else
417 VecIndex = ConstantFoldCastInstruction(Instruction::SExt, VecIndexC, VecIntPtrTy);
418 }
419
420 // Handle the non-recursive case. This is what we see if the vectorizer
421 // decides to use a scalar IV + vid on demand instead of a vector IV.
422 auto [Start, Stride] = matchStridedStart(VecIndex, Builder);
423 if (Start) {
424 assert(Stride);
425 Builder.SetInsertPoint(GEP);
426
427 // Replace the vector index with the scalar start and build a scalar GEP.
428 Ops[*VecOperand] = Start;
429 Type *SourceTy = GEP->getSourceElementType();
430 Value *BasePtr =
431 Builder.CreateGEP(SourceTy, ScalarBase, ArrayRef(Ops).drop_front());
432
433 // Convert stride to pointer size if needed.
434 Type *IntPtrTy = DL->getIntPtrType(BasePtr->getType());
435 assert(Stride->getType() == IntPtrTy && "Unexpected type");
436
437 // Scale the stride by the size of the indexed type.
438 if (TypeScale != 1)
439 Stride = Builder.CreateMul(Stride, ConstantInt::get(IntPtrTy, TypeScale));
440
441 auto P = std::make_pair(BasePtr, Stride);
442 StridedAddrs[GEP] = P;
443 return P;
444 }
445
446 // Make sure we're in a loop and that has a pre-header and a single latch.
447 Loop *L = LI->getLoopFor(GEP->getParent());
448 if (!L || !L->getLoopPreheader() || !L->getLoopLatch())
449 return std::make_pair(nullptr, nullptr);
450
451 BinaryOperator *Inc;
452 PHINode *BasePhi;
453 if (!matchStridedRecurrence(VecIndex, L, Stride, BasePhi, Inc, Builder))
454 return std::make_pair(nullptr, nullptr);
455
456 assert(BasePhi->getNumIncomingValues() == 2 && "Expected 2 operand phi.");
457 unsigned IncrementingBlock = BasePhi->getOperand(0) == Inc ? 0 : 1;
458 assert(BasePhi->getIncomingValue(IncrementingBlock) == Inc &&
459 "Expected one operand of phi to be Inc");
460
461 Builder.SetInsertPoint(GEP);
462
463 // Replace the vector index with the scalar phi and build a scalar GEP.
464 Ops[*VecOperand] = BasePhi;
465 Type *SourceTy = GEP->getSourceElementType();
466 Value *BasePtr =
467 Builder.CreateGEP(SourceTy, ScalarBase, ArrayRef(Ops).drop_front());
468
469 // Final adjustments to stride should go in the start block.
470 Builder.SetInsertPoint(
471 BasePhi->getIncomingBlock(1 - IncrementingBlock)->getTerminator());
472
473 // Convert stride to pointer size if needed.
474 Type *IntPtrTy = DL->getIntPtrType(BasePtr->getType());
475 assert(Stride->getType() == IntPtrTy && "Unexpected type");
476
477 // Scale the stride by the size of the indexed type.
478 if (TypeScale != 1)
479 Stride = Builder.CreateMul(Stride, ConstantInt::get(IntPtrTy, TypeScale));
480
481 auto P = std::make_pair(BasePtr, Stride);
482 StridedAddrs[GEP] = P;
483 return P;
484}
485
486bool RISCVGatherScatterLowering::tryCreateStridedLoadStore(IntrinsicInst *II,
487 Type *DataType,
488 Value *Ptr,
489 Value *AlignOp) {
490 // Make sure the operation will be supported by the backend.
491 MaybeAlign MA = cast<ConstantInt>(AlignOp)->getMaybeAlignValue();
492 EVT DataTypeVT = TLI->getValueType(*DL, DataType);
493 if (!MA || !TLI->isLegalStridedLoadStore(DataTypeVT, *MA))
494 return false;
495
496 // FIXME: Let the backend type legalize by splitting/widening?
497 if (!TLI->isTypeLegal(DataTypeVT))
498 return false;
499
500 // Pointer should be an instruction.
501 auto *PtrI = dyn_cast<Instruction>(Ptr);
502 if (!PtrI)
503 return false;
504
505 LLVMContext &Ctx = PtrI->getContext();
506 IRBuilder Builder(Ctx, InstSimplifyFolder(*DL));
507 Builder.SetInsertPoint(PtrI);
508
509 Value *BasePtr, *Stride;
510 std::tie(BasePtr, Stride) = determineBaseAndStride(PtrI, Builder);
511 if (!BasePtr)
512 return false;
513 assert(Stride != nullptr);
514
515 Builder.SetInsertPoint(II);
516
517 Value *EVL = Builder.CreateElementCount(
518 IntegerType::get(Ctx, 32), cast<VectorType>(DataType)->getElementCount());
519
520 CallInst *Call;
521 if (II->getIntrinsicID() == Intrinsic::masked_gather) {
522 Call = Builder.CreateIntrinsic(
523 Intrinsic::experimental_vp_strided_load,
524 {DataType, BasePtr->getType(), Stride->getType()},
525 {BasePtr, Stride, II->getArgOperand(2), EVL});
526 Call = Builder.CreateIntrinsic(
527 Intrinsic::vp_select, {DataType},
528 {II->getOperand(2), Call, II->getArgOperand(3), EVL});
529 } else
530 Call = Builder.CreateIntrinsic(
531 Intrinsic::experimental_vp_strided_store,
532 {DataType, BasePtr->getType(), Stride->getType()},
533 {II->getArgOperand(0), BasePtr, Stride, II->getArgOperand(3), EVL});
534
535 Call->takeName(II);
536 II->replaceAllUsesWith(Call);
537 II->eraseFromParent();
538
539 if (PtrI->use_empty())
541
542 return true;
543}
544
545bool RISCVGatherScatterLowering::runOnFunction(Function &F) {
546 if (skipFunction(F))
547 return false;
548
549 auto &TPC = getAnalysis<TargetPassConfig>();
550 auto &TM = TPC.getTM<RISCVTargetMachine>();
551 ST = &TM.getSubtarget<RISCVSubtarget>(F);
552 if (!ST->hasVInstructions() || !ST->useRVVForFixedLengthVectors())
553 return false;
554
555 TLI = ST->getTargetLowering();
556 DL = &F.getDataLayout();
557 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
558
559 StridedAddrs.clear();
560
563
564 bool Changed = false;
565
566 for (BasicBlock &BB : F) {
567 for (Instruction &I : BB) {
568 IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
569 if (II && II->getIntrinsicID() == Intrinsic::masked_gather) {
570 Gathers.push_back(II);
571 } else if (II && II->getIntrinsicID() == Intrinsic::masked_scatter) {
572 Scatters.push_back(II);
573 }
574 }
575 }
576
577 // Rewrite gather/scatter to form strided load/store if possible.
578 for (auto *II : Gathers)
579 Changed |= tryCreateStridedLoadStore(
580 II, II->getType(), II->getArgOperand(0), II->getArgOperand(1));
581 for (auto *II : Scatters)
582 Changed |=
583 tryCreateStridedLoadStore(II, II->getArgOperand(0)->getType(),
584 II->getArgOperand(1), II->getArgOperand(2));
585
586 // Remove any dead phis.
587 while (!MaybeDeadPHIs.empty()) {
588 if (auto *Phi = dyn_cast_or_null<PHINode>(MaybeDeadPHIs.pop_back_val()))
590 }
591
592 return Changed;
593}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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
Hexagon Common GEP
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t IntrinsicInst * II
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
static std::pair< Value *, Value * > matchStridedStart(Value *Start, IRBuilderBase &Builder)
static std::pair< Value *, Value * > matchStridedConstant(Constant *StartC)
#define DEBUG_TYPE
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:39
Target-Independent Code Generator Pass Configuration Options pass.
Class for arbitrary precision integers.
Definition: APInt.h:78
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:256
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
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
BinaryOps getOpcode() const
Definition: InstrTypes.h:370
This class represents a function call, abstracting a target machine's calling convention.
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:148
This is an important base class in LLVM.
Definition: Constant.h:42
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition: Constants.cpp:435
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
A debug info location.
Definition: DebugLoc.h:33
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.
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Definition: IRBuilder.cpp:890
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:217
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition: IRBuilder.h:1889
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1439
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1350
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Definition: IRBuilder.cpp:98
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition: IRBuilder.h:177
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1384
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2697
InstSimplifyFolder - Use InstructionSimplify to fold operations to existing values.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
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
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:593
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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:45
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:270
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
void setOperand(unsigned i, Value *Val)
Definition: User.h:233
Value * getOperand(unsigned i) const
Definition: User.h:228
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:202
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
TypeSize getSequentialElementStride(const DataLayout &DL) const
self_iterator getIterator()
Definition: ilist_node.h:132
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
NodeAddr< PhiNode * > Phi
Definition: RDFGraph.h:390
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:546
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
FunctionPass * createRISCVGatherScatterLoweringPass()
bool matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO, Value *&Start, Value *&Step)
Attempt to match a simple first order recurrence cycle of the form: iv = phi Ty [Start,...
gep_type_iterator gep_type_begin(const User *GEP)
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition: Local.cpp:657
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Extended Value Type.
Definition: ValueTypes.h:35
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117