llvm.org GIT mirror llvm / 34ac6f6
[ARM][AsmParser] Don't dereference a dyn_cast result. NFCI. The static analyzer is warning about potential null dereferences of dyn_cast<> results - in these cases we can safely use cast<> directly as we know that these cases should all be the correct type, which is why its working atm and anyway cast<> will assert if they aren't. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372145 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 10 months ago
1 changed file(s) with 41 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
24862486
24872487 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
24882488 assert(N == 1 && "Invalid number of operands!");
2489 const MCConstantExpr *CE = dyn_cast(getImm());
2489 const MCConstantExpr *CE = cast(getImm());
24902490 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
24912491 Inst.addOperand(MCOperand::createImm(Enc));
24922492 }
24932493
24942494 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
24952495 assert(N == 1 && "Invalid number of operands!");
2496 const MCConstantExpr *CE = dyn_cast(getImm());
2496 const MCConstantExpr *CE = cast(getImm());
24972497 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
24982498 Inst.addOperand(MCOperand::createImm(Enc));
24992499 }
25002500
25012501 void addThumbModImmNeg8_255Operands(MCInst &Inst, unsigned N) const {
25022502 assert(N == 1 && "Invalid number of operands!");
2503 const MCConstantExpr *CE = dyn_cast(getImm());
2503 const MCConstantExpr *CE = cast(getImm());
25042504 uint32_t Val = -CE->getValue();
25052505 Inst.addOperand(MCOperand::createImm(Val));
25062506 }
25072507
25082508 void addThumbModImmNeg1_7Operands(MCInst &Inst, unsigned N) const {
25092509 assert(N == 1 && "Invalid number of operands!");
2510 const MCConstantExpr *CE = dyn_cast(getImm());
2510 const MCConstantExpr *CE = cast(getImm());
25112511 uint32_t Val = -CE->getValue();
25122512 Inst.addOperand(MCOperand::createImm(Val));
25132513 }
25302530
25312531 void addFBits16Operands(MCInst &Inst, unsigned N) const {
25322532 assert(N == 1 && "Invalid number of operands!");
2533 const MCConstantExpr *CE = dyn_cast(getImm());
2533 const MCConstantExpr *CE = cast(getImm());
25342534 Inst.addOperand(MCOperand::createImm(16 - CE->getValue()));
25352535 }
25362536
25372537 void addFBits32Operands(MCInst &Inst, unsigned N) const {
25382538 assert(N == 1 && "Invalid number of operands!");
2539 const MCConstantExpr *CE = dyn_cast(getImm());
2539 const MCConstantExpr *CE = cast(getImm());
25402540 Inst.addOperand(MCOperand::createImm(32 - CE->getValue()));
25412541 }
25422542
25432543 void addFPImmOperands(MCInst &Inst, unsigned N) const {
25442544 assert(N == 1 && "Invalid number of operands!");
2545 const MCConstantExpr *CE = dyn_cast(getImm());
2545 const MCConstantExpr *CE = cast(getImm());
25462546 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
25472547 Inst.addOperand(MCOperand::createImm(Val));
25482548 }
25512551 assert(N == 1 && "Invalid number of operands!");
25522552 // FIXME: We really want to scale the value here, but the LDRD/STRD
25532553 // instruction don't encode operands that way yet.
2554 const MCConstantExpr *CE = dyn_cast(getImm());
2554 const MCConstantExpr *CE = cast(getImm());
25552555 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25562556 }
25572557
25592559 assert(N == 1 && "Invalid number of operands!");
25602560 // FIXME: We really want to scale the value here, but the VSTR/VLDR_VSYSR
25612561 // instruction don't encode operands that way yet.
2562 const MCConstantExpr *CE = dyn_cast(getImm());
2562 const MCConstantExpr *CE = cast(getImm());
25632563 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25642564 }
25652565
25662566 void addImm7Shift0Operands(MCInst &Inst, unsigned N) const {
25672567 assert(N == 1 && "Invalid number of operands!");
2568 const MCConstantExpr *CE = dyn_cast(getImm());
2569 assert(CE != nullptr && "Invalid operand type!");
2568 const MCConstantExpr *CE = cast(getImm());
25702569 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25712570 }
25722571
25732572 void addImm7Shift1Operands(MCInst &Inst, unsigned N) const {
25742573 assert(N == 1 && "Invalid number of operands!");
2575 const MCConstantExpr *CE = dyn_cast(getImm());
2576 assert(CE != nullptr && "Invalid operand type!");
2574 const MCConstantExpr *CE = cast(getImm());
25772575 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25782576 }
25792577
25802578 void addImm7Shift2Operands(MCInst &Inst, unsigned N) const {
25812579 assert(N == 1 && "Invalid number of operands!");
2582 const MCConstantExpr *CE = dyn_cast(getImm());
2583 assert(CE != nullptr && "Invalid operand type!");
2580 const MCConstantExpr *CE = cast(getImm());
25842581 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25852582 }
25862583
25872584 void addImm7Operands(MCInst &Inst, unsigned N) const {
25882585 assert(N == 1 && "Invalid number of operands!");
2589 const MCConstantExpr *CE = dyn_cast(getImm());
2590 assert(CE != nullptr && "Invalid operand type!");
2586 const MCConstantExpr *CE = cast(getImm());
25912587 Inst.addOperand(MCOperand::createImm(CE->getValue()));
25922588 }
25932589
25952591 assert(N == 1 && "Invalid number of operands!");
25962592 // The immediate is scaled by four in the encoding and is stored
25972593 // in the MCInst as such. Lop off the low two bits here.
2598 const MCConstantExpr *CE = dyn_cast(getImm());
2594 const MCConstantExpr *CE = cast(getImm());
25992595 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
26002596 }
26012597
26032599 assert(N == 1 && "Invalid number of operands!");
26042600 // The immediate is scaled by four in the encoding and is stored
26052601 // in the MCInst as such. Lop off the low two bits here.
2606 const MCConstantExpr *CE = dyn_cast(getImm());
2602 const MCConstantExpr *CE = cast(getImm());
26072603 Inst.addOperand(MCOperand::createImm(-(CE->getValue() / 4)));
26082604 }
26092605
26112607 assert(N == 1 && "Invalid number of operands!");
26122608 // The immediate is scaled by four in the encoding and is stored
26132609 // in the MCInst as such. Lop off the low two bits here.
2614 const MCConstantExpr *CE = dyn_cast(getImm());
2610 const MCConstantExpr *CE = cast(getImm());
26152611 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
26162612 }
26172613
26192615 assert(N == 1 && "Invalid number of operands!");
26202616 // The constant encodes as the immediate-1, and we store in the instruction
26212617 // the bits as encoded, so subtract off one here.
2622 const MCConstantExpr *CE = dyn_cast(getImm());
2618 const MCConstantExpr *CE = cast(getImm());
26232619 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
26242620 }
26252621
26272623 assert(N == 1 && "Invalid number of operands!");
26282624 // The constant encodes as the immediate-1, and we store in the instruction
26292625 // the bits as encoded, so subtract off one here.
2630 const MCConstantExpr *CE = dyn_cast(getImm());
2626 const MCConstantExpr *CE = cast(getImm());
26312627 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
26322628 }
26332629
26352631 assert(N == 1 && "Invalid number of operands!");
26362632 // The constant encodes as the immediate, except for 32, which encodes as
26372633 // zero.
2638 const MCConstantExpr *CE = dyn_cast(getImm());
2634 const MCConstantExpr *CE = cast(getImm());
26392635 unsigned Imm = CE->getValue();
26402636 Inst.addOperand(MCOperand::createImm((Imm == 32 ? 0 : Imm)));
26412637 }
26442640 assert(N == 1 && "Invalid number of operands!");
26452641 // An ASR value of 32 encodes as 0, so that's how we want to add it to
26462642 // the instruction as well.
2647 const MCConstantExpr *CE = dyn_cast(getImm());
2643 const MCConstantExpr *CE = cast(getImm());
26482644 int Val = CE->getValue();
26492645 Inst.addOperand(MCOperand::createImm(Val == 32 ? 0 : Val));
26502646 }
26532649 assert(N == 1 && "Invalid number of operands!");
26542650 // The operand is actually a t2_so_imm, but we have its bitwise
26552651 // negation in the assembly source, so twiddle it here.
2656 const MCConstantExpr *CE = dyn_cast(getImm());
2652 const MCConstantExpr *CE = cast(getImm());
26572653 Inst.addOperand(MCOperand::createImm(~(uint32_t)CE->getValue()));
26582654 }
26592655
26612657 assert(N == 1 && "Invalid number of operands!");
26622658 // The operand is actually a t2_so_imm, but we have its
26632659 // negation in the assembly source, so twiddle it here.
2664 const MCConstantExpr *CE = dyn_cast(getImm());
2660 const MCConstantExpr *CE = cast(getImm());
26652661 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
26662662 }
26672663
26692665 assert(N == 1 && "Invalid number of operands!");
26702666 // The operand is actually an imm0_4095, but we have its
26712667 // negation in the assembly source, so twiddle it here.
2672 const MCConstantExpr *CE = dyn_cast(getImm());
2668 const MCConstantExpr *CE = cast(getImm());
26732669 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
26742670 }
26752671
26782674 Inst.addOperand(MCOperand::createImm(CE->getValue() >> 2));
26792675 return;
26802676 }
2681
2682 const MCSymbolRefExpr *SR = dyn_cast(Imm.Val);
2683 assert(SR && "Unknown value type!");
2677 const MCSymbolRefExpr *SR = cast(Imm.Val);
26842678 Inst.addOperand(MCOperand::createExpr(SR));
26852679 }
26862680
26922686 Inst.addOperand(MCOperand::createImm(CE->getValue()));
26932687 return;
26942688 }
2695
2696 const MCSymbolRefExpr *SR = dyn_cast(Imm.Val);
2697
2698 assert(SR && "Unknown value type!");
2689 const MCSymbolRefExpr *SR = cast(Imm.Val);
26992690 Inst.addOperand(MCOperand::createExpr(SR));
27002691 return;
27012692 }
27572748 return;
27582749 }
27592750
2760 const MCConstantExpr *CE = dyn_cast(getImm());
2751 const MCConstantExpr *CE = cast(getImm());
27612752 int Val = CE->getValue();
27622753 Inst.addOperand(MCOperand::createImm(Val));
27632754 }
31373128
31383129 void addPowerTwoOperands(MCInst &Inst, unsigned N) const {
31393130 assert(N == 1 && "Invalid number of operands!");
3140 const MCConstantExpr *CE = dyn_cast(getImm());
3131 const MCConstantExpr *CE = cast(getImm());
31413132 Inst.addOperand(MCOperand::createImm(CE->getValue()));
31423133 }
31433134
32323223 assert(N == 1 && "Invalid number of operands!");
32333224 // The immediate encodes the type of constant as well as the value.
32343225 // Mask in that this is an i8 splat.
3235 const MCConstantExpr *CE = dyn_cast(getImm());
3226 const MCConstantExpr *CE = cast(getImm());
32363227 Inst.addOperand(MCOperand::createImm(CE->getValue() | 0xe00));
32373228 }
32383229
32393230 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
32403231 assert(N == 1 && "Invalid number of operands!");
32413232 // The immediate encodes the type of constant as well as the value.
3242 const MCConstantExpr *CE = dyn_cast(getImm());
3233 const MCConstantExpr *CE = cast(getImm());
32433234 unsigned Value = CE->getValue();
32443235 Value = ARM_AM::encodeNEONi16splat(Value);
32453236 Inst.addOperand(MCOperand::createImm(Value));
32483239 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
32493240 assert(N == 1 && "Invalid number of operands!");
32503241 // The immediate encodes the type of constant as well as the value.
3251 const MCConstantExpr *CE = dyn_cast(getImm());
3242 const MCConstantExpr *CE = cast(getImm());
32523243 unsigned Value = CE->getValue();
32533244 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
32543245 Inst.addOperand(MCOperand::createImm(Value));
32573248 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
32583249 assert(N == 1 && "Invalid number of operands!");
32593250 // The immediate encodes the type of constant as well as the value.
3260 const MCConstantExpr *CE = dyn_cast(getImm());
3251 const MCConstantExpr *CE = cast(getImm());
32613252 unsigned Value = CE->getValue();
32623253 Value = ARM_AM::encodeNEONi32splat(Value);
32633254 Inst.addOperand(MCOperand::createImm(Value));
32663257 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
32673258 assert(N == 1 && "Invalid number of operands!");
32683259 // The immediate encodes the type of constant as well as the value.
3269 const MCConstantExpr *CE = dyn_cast(getImm());
3260 const MCConstantExpr *CE = cast(getImm());
32703261 unsigned Value = CE->getValue();
32713262 Value = ARM_AM::encodeNEONi32splat(~Value);
32723263 Inst.addOperand(MCOperand::createImm(Value));
32743265
32753266 void addNEONi8ReplicateOperands(MCInst &Inst, bool Inv) const {
32763267 // The immediate encodes the type of constant as well as the value.
3277 const MCConstantExpr *CE = dyn_cast(getImm());
3268 const MCConstantExpr *CE = cast(getImm());
32783269 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
32793270 Inst.getOpcode() == ARM::VMOVv16i8) &&
32803271 "All instructions that wants to replicate non-zero byte "
33053296 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
33063297 assert(N == 1 && "Invalid number of operands!");
33073298 // The immediate encodes the type of constant as well as the value.
3308 const MCConstantExpr *CE = dyn_cast(getImm());
3299 const MCConstantExpr *CE = cast(getImm());
33093300 unsigned Value = encodeNeonVMOVImmediate(CE->getValue());
33103301 Inst.addOperand(MCOperand::createImm(Value));
33113302 }
33173308
33183309 void addNEONvmovi16ReplicateOperands(MCInst &Inst, unsigned N) const {
33193310 assert(N == 1 && "Invalid number of operands!");
3320 const MCConstantExpr *CE = dyn_cast(getImm());
3311 const MCConstantExpr *CE = cast(getImm());
33213312 assert((Inst.getOpcode() == ARM::VMOVv4i16 ||
33223313 Inst.getOpcode() == ARM::VMOVv8i16 ||
33233314 Inst.getOpcode() == ARM::VMVNv4i16 ||
33343325 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
33353326 assert(N == 1 && "Invalid number of operands!");
33363327 // The immediate encodes the type of constant as well as the value.
3337 const MCConstantExpr *CE = dyn_cast(getImm());
3328 const MCConstantExpr *CE = cast(getImm());
33383329 unsigned Value = encodeNeonVMOVImmediate(~CE->getValue());
33393330 Inst.addOperand(MCOperand::createImm(Value));
33403331 }
33413332
33423333 void addNEONvmovi32ReplicateOperands(MCInst &Inst, unsigned N) const {
33433334 assert(N == 1 && "Invalid number of operands!");
3344 const MCConstantExpr *CE = dyn_cast(getImm());
3335 const MCConstantExpr *CE = cast(getImm());
33453336 assert((Inst.getOpcode() == ARM::VMOVv2i32 ||
33463337 Inst.getOpcode() == ARM::VMOVv4i32 ||
33473338 Inst.getOpcode() == ARM::VMVNv2i32 ||
33563347 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
33573348 assert(N == 1 && "Invalid number of operands!");
33583349 // The immediate encodes the type of constant as well as the value.
3359 const MCConstantExpr *CE = dyn_cast(getImm());
3350 const MCConstantExpr *CE = cast(getImm());
33603351 uint64_t Value = CE->getValue();
33613352 unsigned Imm = 0;
33623353 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
33673358
33683359 void addComplexRotationEvenOperands(MCInst &Inst, unsigned N) const {
33693360 assert(N == 1 && "Invalid number of operands!");
3370 const MCConstantExpr *CE = dyn_cast(getImm());
3361 const MCConstantExpr *CE = cast(getImm());
33713362 Inst.addOperand(MCOperand::createImm(CE->getValue() / 90));
33723363 }
33733364
33743365 void addComplexRotationOddOperands(MCInst &Inst, unsigned N) const {
33753366 assert(N == 1 && "Invalid number of operands!");
3376 const MCConstantExpr *CE = dyn_cast(getImm());
3367 const MCConstantExpr *CE = cast(getImm());
33773368 Inst.addOperand(MCOperand::createImm((CE->getValue() - 90) / 180));
33783369 }
33793370
33803371 void addMveSaturateOperands(MCInst &Inst, unsigned N) const {
33813372 assert(N == 1 && "Invalid number of operands!");
3382 const MCConstantExpr *CE = dyn_cast(getImm());
3373 const MCConstantExpr *CE = cast(getImm());
33833374 unsigned Imm = CE->getValue();
33843375 assert((Imm == 48 || Imm == 64) && "Invalid saturate operand");
33853376 Inst.addOperand(MCOperand::createImm(Imm == 48 ? 1 : 0));