LLVM 18.0.0git
RISCVOptWInstrs.cpp
Go to the documentation of this file.
1//===- RISCVOptWInstrs.cpp - MI W instruction optimizations ---------------===//
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 does some optimizations for *W instructions at the MI level.
10//
11// First it removes unneeded sext.w instructions. Either because the sign
12// extended bits aren't consumed or because the input was already sign extended
13// by an earlier instruction.
14//
15// Then it removes the -w suffix from each addiw and slliw instructions
16// whenever all users are dependent only on the lower word of the result of the
17// instruction. We do this only for addiw, slliw, and mulw because the -w forms
18// are less compressible.
19//
20//===---------------------------------------------------------------------===//
21
22#include "RISCV.h"
24#include "RISCVSubtarget.h"
25#include "llvm/ADT/SmallSet.h"
26#include "llvm/ADT/Statistic.h"
29
30using namespace llvm;
31
32#define DEBUG_TYPE "riscv-opt-w-instrs"
33#define RISCV_OPT_W_INSTRS_NAME "RISC-V Optimize W Instructions"
34
35STATISTIC(NumRemovedSExtW, "Number of removed sign-extensions");
36STATISTIC(NumTransformedToWInstrs,
37 "Number of instructions transformed to W-ops");
38
39static cl::opt<bool> DisableSExtWRemoval("riscv-disable-sextw-removal",
40 cl::desc("Disable removal of sext.w"),
41 cl::init(false), cl::Hidden);
42static cl::opt<bool> DisableStripWSuffix("riscv-disable-strip-w-suffix",
43 cl::desc("Disable strip W suffix"),
44 cl::init(false), cl::Hidden);
45
46namespace {
47
48class RISCVOptWInstrs : public MachineFunctionPass {
49public:
50 static char ID;
51
52 RISCVOptWInstrs() : MachineFunctionPass(ID) {
54 }
55
56 bool runOnMachineFunction(MachineFunction &MF) override;
57 bool removeSExtWInstrs(MachineFunction &MF, const RISCVInstrInfo &TII,
59 bool stripWSuffixes(MachineFunction &MF, const RISCVInstrInfo &TII,
61
62 void getAnalysisUsage(AnalysisUsage &AU) const override {
63 AU.setPreservesCFG();
65 }
66
67 StringRef getPassName() const override { return RISCV_OPT_W_INSTRS_NAME; }
68};
69
70} // end anonymous namespace
71
72char RISCVOptWInstrs::ID = 0;
74 false)
75
77 return new RISCVOptWInstrs();
78}
79
80// Checks if all users only demand the lower \p OrigBits of the original
81// instruction's result.
82// TODO: handle multiple interdependent transformations
83static bool hasAllNBitUsers(const MachineInstr &OrigMI,
84 const RISCVSubtarget &ST,
85 const MachineRegisterInfo &MRI, unsigned OrigBits) {
86
89
90 Worklist.push_back(std::make_pair(&OrigMI, OrigBits));
91
92 while (!Worklist.empty()) {
93 auto P = Worklist.pop_back_val();
94 const MachineInstr *MI = P.first;
95 unsigned Bits = P.second;
96
97 if (!Visited.insert(P).second)
98 continue;
99
100 // Only handle instructions with one def.
101 if (MI->getNumExplicitDefs() != 1)
102 return false;
103
104 for (auto &UserOp : MRI.use_operands(MI->getOperand(0).getReg())) {
105 const MachineInstr *UserMI = UserOp.getParent();
106 unsigned OpIdx = UserOp.getOperandNo();
107
108 switch (UserMI->getOpcode()) {
109 default:
110 return false;
111
112 case RISCV::ADDIW:
113 case RISCV::ADDW:
114 case RISCV::DIVUW:
115 case RISCV::DIVW:
116 case RISCV::MULW:
117 case RISCV::REMUW:
118 case RISCV::REMW:
119 case RISCV::SLLIW:
120 case RISCV::SLLW:
121 case RISCV::SRAIW:
122 case RISCV::SRAW:
123 case RISCV::SRLIW:
124 case RISCV::SRLW:
125 case RISCV::SUBW:
126 case RISCV::ROLW:
127 case RISCV::RORW:
128 case RISCV::RORIW:
129 case RISCV::CLZW:
130 case RISCV::CTZW:
131 case RISCV::CPOPW:
132 case RISCV::SLLI_UW:
133 case RISCV::FMV_W_X:
134 case RISCV::FCVT_H_W:
135 case RISCV::FCVT_H_WU:
136 case RISCV::FCVT_S_W:
137 case RISCV::FCVT_S_WU:
138 case RISCV::FCVT_D_W:
139 case RISCV::FCVT_D_WU:
140 if (Bits >= 32)
141 break;
142 return false;
143 case RISCV::SEXT_B:
144 case RISCV::PACKH:
145 if (Bits >= 8)
146 break;
147 return false;
148 case RISCV::SEXT_H:
149 case RISCV::FMV_H_X:
150 case RISCV::ZEXT_H_RV32:
151 case RISCV::ZEXT_H_RV64:
152 case RISCV::PACKW:
153 if (Bits >= 16)
154 break;
155 return false;
156
157 case RISCV::PACK:
158 if (Bits >= (ST.getXLen() / 2))
159 break;
160 return false;
161
162 case RISCV::SRLI: {
163 // If we are shifting right by less than Bits, and users don't demand
164 // any bits that were shifted into [Bits-1:0], then we can consider this
165 // as an N-Bit user.
166 unsigned ShAmt = UserMI->getOperand(2).getImm();
167 if (Bits > ShAmt) {
168 Worklist.push_back(std::make_pair(UserMI, Bits - ShAmt));
169 break;
170 }
171 return false;
172 }
173
174 // these overwrite higher input bits, otherwise the lower word of output
175 // depends only on the lower word of input. So check their uses read W.
176 case RISCV::SLLI:
177 if (Bits >= (ST.getXLen() - UserMI->getOperand(2).getImm()))
178 break;
179 Worklist.push_back(std::make_pair(UserMI, Bits));
180 break;
181 case RISCV::ANDI: {
182 uint64_t Imm = UserMI->getOperand(2).getImm();
183 if (Bits >= (unsigned)llvm::bit_width(Imm))
184 break;
185 Worklist.push_back(std::make_pair(UserMI, Bits));
186 break;
187 }
188 case RISCV::ORI: {
189 uint64_t Imm = UserMI->getOperand(2).getImm();
190 if (Bits >= (unsigned)llvm::bit_width<uint64_t>(~Imm))
191 break;
192 Worklist.push_back(std::make_pair(UserMI, Bits));
193 break;
194 }
195
196 case RISCV::SLL:
197 case RISCV::BSET:
198 case RISCV::BCLR:
199 case RISCV::BINV:
200 // Operand 2 is the shift amount which uses log2(xlen) bits.
201 if (OpIdx == 2) {
202 if (Bits >= Log2_32(ST.getXLen()))
203 break;
204 return false;
205 }
206 Worklist.push_back(std::make_pair(UserMI, Bits));
207 break;
208
209 case RISCV::SRA:
210 case RISCV::SRL:
211 case RISCV::ROL:
212 case RISCV::ROR:
213 // Operand 2 is the shift amount which uses 6 bits.
214 if (OpIdx == 2 && Bits >= Log2_32(ST.getXLen()))
215 break;
216 return false;
217
218 case RISCV::ADD_UW:
219 case RISCV::SH1ADD_UW:
220 case RISCV::SH2ADD_UW:
221 case RISCV::SH3ADD_UW:
222 // Operand 1 is implicitly zero extended.
223 if (OpIdx == 1 && Bits >= 32)
224 break;
225 Worklist.push_back(std::make_pair(UserMI, Bits));
226 break;
227
228 case RISCV::BEXTI:
229 if (UserMI->getOperand(2).getImm() >= Bits)
230 return false;
231 break;
232
233 case RISCV::SB:
234 // The first argument is the value to store.
235 if (OpIdx == 0 && Bits >= 8)
236 break;
237 return false;
238 case RISCV::SH:
239 // The first argument is the value to store.
240 if (OpIdx == 0 && Bits >= 16)
241 break;
242 return false;
243 case RISCV::SW:
244 // The first argument is the value to store.
245 if (OpIdx == 0 && Bits >= 32)
246 break;
247 return false;
248
249 // For these, lower word of output in these operations, depends only on
250 // the lower word of input. So, we check all uses only read lower word.
251 case RISCV::COPY:
252 case RISCV::PHI:
253
254 case RISCV::ADD:
255 case RISCV::ADDI:
256 case RISCV::AND:
257 case RISCV::MUL:
258 case RISCV::OR:
259 case RISCV::SUB:
260 case RISCV::XOR:
261 case RISCV::XORI:
262
263 case RISCV::ANDN:
264 case RISCV::BREV8:
265 case RISCV::CLMUL:
266 case RISCV::ORC_B:
267 case RISCV::ORN:
268 case RISCV::SH1ADD:
269 case RISCV::SH2ADD:
270 case RISCV::SH3ADD:
271 case RISCV::XNOR:
272 case RISCV::BSETI:
273 case RISCV::BCLRI:
274 case RISCV::BINVI:
275 Worklist.push_back(std::make_pair(UserMI, Bits));
276 break;
277
278 case RISCV::PseudoCCMOVGPR:
279 // Either operand 4 or operand 5 is returned by this instruction. If
280 // only the lower word of the result is used, then only the lower word
281 // of operand 4 and 5 is used.
282 if (OpIdx != 4 && OpIdx != 5)
283 return false;
284 Worklist.push_back(std::make_pair(UserMI, Bits));
285 break;
286
287 case RISCV::CZERO_EQZ:
288 case RISCV::CZERO_NEZ:
289 case RISCV::VT_MASKC:
290 case RISCV::VT_MASKCN:
291 if (OpIdx != 1)
292 return false;
293 Worklist.push_back(std::make_pair(UserMI, Bits));
294 break;
295 }
296 }
297 }
298
299 return true;
300}
301
302static bool hasAllWUsers(const MachineInstr &OrigMI, const RISCVSubtarget &ST,
303 const MachineRegisterInfo &MRI) {
304 return hasAllNBitUsers(OrigMI, ST, MRI, 32);
305}
306
307// This function returns true if the machine instruction always outputs a value
308// where bits 63:32 match bit 31.
310 const MachineRegisterInfo &MRI) {
311 uint64_t TSFlags = MI.getDesc().TSFlags;
312
313 // Instructions that can be determined from opcode are marked in tablegen.
315 return true;
316
317 // Special cases that require checking operands.
318 switch (MI.getOpcode()) {
319 // shifting right sufficiently makes the value 32-bit sign-extended
320 case RISCV::SRAI:
321 return MI.getOperand(2).getImm() >= 32;
322 case RISCV::SRLI:
323 return MI.getOperand(2).getImm() > 32;
324 // The LI pattern ADDI rd, X0, imm is sign extended.
325 case RISCV::ADDI:
326 return MI.getOperand(1).isReg() && MI.getOperand(1).getReg() == RISCV::X0;
327 // An ANDI with an 11 bit immediate will zero bits 63:11.
328 case RISCV::ANDI:
329 return isUInt<11>(MI.getOperand(2).getImm());
330 // An ORI with an >11 bit immediate (negative 12-bit) will set bits 63:11.
331 case RISCV::ORI:
332 return !isUInt<11>(MI.getOperand(2).getImm());
333 // Copying from X0 produces zero.
334 case RISCV::COPY:
335 return MI.getOperand(1).getReg() == RISCV::X0;
336 }
337
338 return false;
339}
340
341static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
344
347
348 auto AddRegDefToWorkList = [&](Register SrcReg) {
349 if (!SrcReg.isVirtual())
350 return false;
351 MachineInstr *SrcMI = MRI.getVRegDef(SrcReg);
352 if (!SrcMI)
353 return false;
354 // Add SrcMI to the worklist.
355 Worklist.push_back(SrcMI);
356 return true;
357 };
358
359 if (!AddRegDefToWorkList(SrcReg))
360 return false;
361
362 while (!Worklist.empty()) {
363 MachineInstr *MI = Worklist.pop_back_val();
364
365 // If we already visited this instruction, we don't need to check it again.
366 if (!Visited.insert(MI).second)
367 continue;
368
369 // If this is a sign extending operation we don't need to look any further.
371 continue;
372
373 // Is this an instruction that propagates sign extend?
374 switch (MI->getOpcode()) {
375 default:
376 // Unknown opcode, give up.
377 return false;
378 case RISCV::COPY: {
379 const MachineFunction *MF = MI->getMF();
380 const RISCVMachineFunctionInfo *RVFI =
382
383 // If this is the entry block and the register is livein, see if we know
384 // it is sign extended.
385 if (MI->getParent() == &MF->front()) {
386 Register VReg = MI->getOperand(0).getReg();
387 if (MF->getRegInfo().isLiveIn(VReg) && RVFI->isSExt32Register(VReg))
388 continue;
389 }
390
391 Register CopySrcReg = MI->getOperand(1).getReg();
392 if (CopySrcReg == RISCV::X10) {
393 // For a method return value, we check the ZExt/SExt flags in attribute.
394 // We assume the following code sequence for method call.
395 // PseudoCALL @bar, ...
396 // ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
397 // %0:gpr = COPY $x10
398 //
399 // We use the PseudoCall to look up the IR function being called to find
400 // its return attributes.
401 const MachineBasicBlock *MBB = MI->getParent();
402 auto II = MI->getIterator();
403 if (II == MBB->instr_begin() ||
404 (--II)->getOpcode() != RISCV::ADJCALLSTACKUP)
405 return false;
406
407 const MachineInstr &CallMI = *(--II);
408 if (!CallMI.isCall() || !CallMI.getOperand(0).isGlobal())
409 return false;
410
411 auto *CalleeFn =
412 dyn_cast_if_present<Function>(CallMI.getOperand(0).getGlobal());
413 if (!CalleeFn)
414 return false;
415
416 auto *IntTy = dyn_cast<IntegerType>(CalleeFn->getReturnType());
417 if (!IntTy)
418 return false;
419
420 const AttributeSet &Attrs = CalleeFn->getAttributes().getRetAttrs();
421 unsigned BitWidth = IntTy->getBitWidth();
422 if ((BitWidth <= 32 && Attrs.hasAttribute(Attribute::SExt)) ||
423 (BitWidth < 32 && Attrs.hasAttribute(Attribute::ZExt)))
424 continue;
425 }
426
427 if (!AddRegDefToWorkList(CopySrcReg))
428 return false;
429
430 break;
431 }
432
433 // For these, we just need to check if the 1st operand is sign extended.
434 case RISCV::BCLRI:
435 case RISCV::BINVI:
436 case RISCV::BSETI:
437 if (MI->getOperand(2).getImm() >= 31)
438 return false;
439 [[fallthrough]];
440 case RISCV::REM:
441 case RISCV::ANDI:
442 case RISCV::ORI:
443 case RISCV::XORI:
444 // |Remainder| is always <= |Dividend|. If D is 32-bit, then so is R.
445 // DIV doesn't work because of the edge case 0xf..f 8000 0000 / (long)-1
446 // Logical operations use a sign extended 12-bit immediate.
447 if (!AddRegDefToWorkList(MI->getOperand(1).getReg()))
448 return false;
449
450 break;
451 case RISCV::PseudoCCADDW:
452 case RISCV::PseudoCCSUBW:
453 // Returns operand 4 or an ADDW/SUBW of operands 5 and 6. We only need to
454 // check if operand 4 is sign extended.
455 if (!AddRegDefToWorkList(MI->getOperand(4).getReg()))
456 return false;
457 break;
458 case RISCV::REMU:
459 case RISCV::AND:
460 case RISCV::OR:
461 case RISCV::XOR:
462 case RISCV::ANDN:
463 case RISCV::ORN:
464 case RISCV::XNOR:
465 case RISCV::MAX:
466 case RISCV::MAXU:
467 case RISCV::MIN:
468 case RISCV::MINU:
469 case RISCV::PseudoCCMOVGPR:
470 case RISCV::PseudoCCAND:
471 case RISCV::PseudoCCOR:
472 case RISCV::PseudoCCXOR:
473 case RISCV::PHI: {
474 // If all incoming values are sign-extended, the output of AND, OR, XOR,
475 // MIN, MAX, or PHI is also sign-extended.
476
477 // The input registers for PHI are operand 1, 3, ...
478 // The input registers for PseudoCCMOVGPR are 4 and 5.
479 // The input registers for PseudoCCAND/OR/XOR are 4, 5, and 6.
480 // The input registers for others are operand 1 and 2.
481 unsigned B = 1, E = 3, D = 1;
482 switch (MI->getOpcode()) {
483 case RISCV::PHI:
484 E = MI->getNumOperands();
485 D = 2;
486 break;
487 case RISCV::PseudoCCMOVGPR:
488 B = 4;
489 E = 6;
490 break;
491 case RISCV::PseudoCCAND:
492 case RISCV::PseudoCCOR:
493 case RISCV::PseudoCCXOR:
494 B = 4;
495 E = 7;
496 break;
497 }
498
499 for (unsigned I = B; I != E; I += D) {
500 if (!MI->getOperand(I).isReg())
501 return false;
502
503 if (!AddRegDefToWorkList(MI->getOperand(I).getReg()))
504 return false;
505 }
506
507 break;
508 }
509
510 case RISCV::CZERO_EQZ:
511 case RISCV::CZERO_NEZ:
512 case RISCV::VT_MASKC:
513 case RISCV::VT_MASKCN:
514 // Instructions return zero or operand 1. Result is sign extended if
515 // operand 1 is sign extended.
516 if (!AddRegDefToWorkList(MI->getOperand(1).getReg()))
517 return false;
518 break;
519
520 // With these opcode, we can "fix" them with the W-version
521 // if we know all users of the result only rely on bits 31:0
522 case RISCV::SLLI:
523 // SLLIW reads the lowest 5 bits, while SLLI reads lowest 6 bits
524 if (MI->getOperand(2).getImm() >= 32)
525 return false;
526 [[fallthrough]];
527 case RISCV::ADDI:
528 case RISCV::ADD:
529 case RISCV::LD:
530 case RISCV::LWU:
531 case RISCV::MUL:
532 case RISCV::SUB:
533 if (hasAllWUsers(*MI, ST, MRI)) {
534 FixableDef.insert(MI);
535 break;
536 }
537 return false;
538 }
539 }
540
541 // If we get here, then every node we visited produces a sign extended value
542 // or propagated sign extended values. So the result must be sign extended.
543 return true;
544}
545
546static unsigned getWOp(unsigned Opcode) {
547 switch (Opcode) {
548 case RISCV::ADDI:
549 return RISCV::ADDIW;
550 case RISCV::ADD:
551 return RISCV::ADDW;
552 case RISCV::LD:
553 case RISCV::LWU:
554 return RISCV::LW;
555 case RISCV::MUL:
556 return RISCV::MULW;
557 case RISCV::SLLI:
558 return RISCV::SLLIW;
559 case RISCV::SUB:
560 return RISCV::SUBW;
561 default:
562 llvm_unreachable("Unexpected opcode for replacement with W variant");
563 }
564}
565
566bool RISCVOptWInstrs::removeSExtWInstrs(MachineFunction &MF,
567 const RISCVInstrInfo &TII,
568 const RISCVSubtarget &ST,
571 return false;
572
573 bool MadeChange = false;
574 for (MachineBasicBlock &MBB : MF) {
575 for (auto I = MBB.begin(), IE = MBB.end(); I != IE;) {
576 MachineInstr *MI = &*I++;
577
578 // We're looking for the sext.w pattern ADDIW rd, rs1, 0.
579 if (!RISCV::isSEXT_W(*MI))
580 continue;
581
582 Register SrcReg = MI->getOperand(1).getReg();
583
585
586 // If all users only use the lower bits, this sext.w is redundant.
587 // Or if all definitions reaching MI sign-extend their output,
588 // then sext.w is redundant.
589 if (!hasAllWUsers(*MI, ST, MRI) &&
590 !isSignExtendedW(SrcReg, ST, MRI, FixableDefs))
591 continue;
592
593 Register DstReg = MI->getOperand(0).getReg();
594 if (!MRI.constrainRegClass(SrcReg, MRI.getRegClass(DstReg)))
595 continue;
596
597 // Convert Fixable instructions to their W versions.
598 for (MachineInstr *Fixable : FixableDefs) {
599 LLVM_DEBUG(dbgs() << "Replacing " << *Fixable);
600 Fixable->setDesc(TII.get(getWOp(Fixable->getOpcode())));
601 Fixable->clearFlag(MachineInstr::MIFlag::NoSWrap);
602 Fixable->clearFlag(MachineInstr::MIFlag::NoUWrap);
603 Fixable->clearFlag(MachineInstr::MIFlag::IsExact);
604 LLVM_DEBUG(dbgs() << " with " << *Fixable);
605 ++NumTransformedToWInstrs;
606 }
607
608 LLVM_DEBUG(dbgs() << "Removing redundant sign-extension\n");
609 MRI.replaceRegWith(DstReg, SrcReg);
610 MRI.clearKillFlags(SrcReg);
611 MI->eraseFromParent();
612 ++NumRemovedSExtW;
613 MadeChange = true;
614 }
615 }
616
617 return MadeChange;
618}
619
620bool RISCVOptWInstrs::stripWSuffixes(MachineFunction &MF,
621 const RISCVInstrInfo &TII,
622 const RISCVSubtarget &ST,
625 return false;
626
627 bool MadeChange = false;
628 for (MachineBasicBlock &MBB : MF) {
629 for (auto I = MBB.begin(), IE = MBB.end(); I != IE; ++I) {
630 MachineInstr &MI = *I;
631
632 unsigned Opc;
633 switch (MI.getOpcode()) {
634 default:
635 continue;
636 case RISCV::ADDW: Opc = RISCV::ADD; break;
637 case RISCV::MULW: Opc = RISCV::MUL; break;
638 case RISCV::SLLIW: Opc = RISCV::SLLI; break;
639 }
640
641 if (hasAllWUsers(MI, ST, MRI)) {
642 MI.setDesc(TII.get(Opc));
643 MadeChange = true;
644 }
645 }
646 }
647
648 return MadeChange;
649}
650
651bool RISCVOptWInstrs::runOnMachineFunction(MachineFunction &MF) {
652 if (skipFunction(MF.getFunction()))
653 return false;
654
657 const RISCVInstrInfo &TII = *ST.getInstrInfo();
658
659 if (!ST.is64Bit())
660 return false;
661
662 bool MadeChange = false;
663 MadeChange |= removeSExtWInstrs(MF, TII, ST, MRI);
664 MadeChange |= stripWSuffixes(MF, TII, ST, MRI);
665
666 return MadeChange;
667}
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DEBUG(X)
Definition: Debug.h:101
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
uint64_t TSFlags
static bool isSignExtendingOpW(const MachineInstr &MI, const MachineRegisterInfo &MRI)
static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST, const MachineRegisterInfo &MRI, SmallPtrSetImpl< MachineInstr * > &FixableDef)
static bool hasAllWUsers(const MachineInstr &OrigMI, const RISCVSubtarget &ST, const MachineRegisterInfo &MRI)
static cl::opt< bool > DisableStripWSuffix("riscv-disable-strip-w-suffix", cl::desc("Disable strip W suffix"), cl::init(false), cl::Hidden)
static bool hasAllNBitUsers(const MachineInstr &OrigMI, const RISCVSubtarget &ST, const MachineRegisterInfo &MRI, unsigned OrigBits)
#define RISCV_OPT_W_INSTRS_NAME
static cl::opt< bool > DisableSExtWRemoval("riscv-disable-sextw-removal", cl::desc("Disable removal of sext.w"), cl::init(false), cl::Hidden)
#define DEBUG_TYPE
static unsigned getWOp(unsigned Opcode)
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:191
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:269
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
instr_iterator instr_begin()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
Representation of each machine instruction.
Definition: MachineInstr.h:68
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:543
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:326
bool isCall(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:915
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:553
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool isLiveIn(Register Reg) const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
bool isSExt32Register(Register Reg) const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:91
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:345
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:366
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:451
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:179
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
#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
bool isSEXT_W(const MachineInstr &MI)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
Definition: bit.h:281
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:313
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
FunctionPass * createRISCVOptWInstrsPass()
void initializeRISCVOptWInstrsPass(PassRegistry &)
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:184