llvm.org GIT mirror llvm / 586c004
MC: Clean up MCExpr naming. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238634 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 5 years ago
97 changed file(s) with 777 addition(s) and 777 deletion(s). Raw diff Collapse all Expand all
4545 MCExpr(const MCExpr&) = delete;
4646 void operator=(const MCExpr&) = delete;
4747
48 bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
48 bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
4949 const MCAsmLayout *Layout,
5050 const SectionAddrMap *Addrs) const;
5151
5656 protected:
5757 explicit MCExpr(ExprKind Kind) : Kind(Kind) {}
5858
59 bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
59 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
6060 const MCAsmLayout *Layout,
6161 const MCFixup *Fixup,
6262 const SectionAddrMap *Addrs, bool InSet) const;
8585 /// values. If not given, then only non-symbolic expressions will be
8686 /// evaluated.
8787 /// \return - True on success.
88 bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout,
88 bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout,
8989 const SectionAddrMap &Addrs) const;
90 bool EvaluateAsAbsolute(int64_t &Res) const;
91 bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
92 bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
90 bool evaluateAsAbsolute(int64_t &Res) const;
91 bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
92 bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
9393
9494 bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
9595
100100 /// \param Layout - The assembler layout object to use for evaluating values.
101101 /// \param Fixup - The Fixup object if available.
102102 /// \return - True on success.
103 bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout,
103 bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout,
104104 const MCFixup *Fixup) const;
105105
106106 /// \brief Try to evaluate the expression to the form (a - b + constant) where
107107 /// neither a nor b are variables.
108108 ///
109 /// This is a more aggressive variant of EvaluateAsRelocatable. The intended
109 /// This is a more aggressive variant of evaluateAsRelocatable. The intended
110110 /// use is for when relocations are not available, like the .size directive.
111111 bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const;
112112
114114 /// currently defined as the absolute section for constants, or
115115 /// otherwise the section associated with the first defined symbol in the
116116 /// expression.
117 MCSection *FindAssociatedSection() const;
117 MCSection *findAssociatedSection() const;
118118
119119 /// @}
120120 };
135135 /// \name Construction
136136 /// @{
137137
138 static const MCConstantExpr *Create(int64_t Value, MCContext &Ctx);
138 static const MCConstantExpr *create(int64_t Value, MCContext &Ctx);
139139
140140 /// @}
141141 /// \name Accessors
311311 /// \name Construction
312312 /// @{
313313
314 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, MCContext &Ctx) {
315 return MCSymbolRefExpr::Create(Symbol, VK_None, Ctx);
316 }
317
318 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, VariantKind Kind,
314 static const MCSymbolRefExpr *create(const MCSymbol *Symbol, MCContext &Ctx) {
315 return MCSymbolRefExpr::create(Symbol, VK_None, Ctx);
316 }
317
318 static const MCSymbolRefExpr *create(const MCSymbol *Symbol, VariantKind Kind,
319319 MCContext &Ctx);
320 static const MCSymbolRefExpr *Create(StringRef Name, VariantKind Kind,
320 static const MCSymbolRefExpr *create(StringRef Name, VariantKind Kind,
321321 MCContext &Ctx);
322322
323323 /// @}
368368 /// \name Construction
369369 /// @{
370370
371 static const MCUnaryExpr *Create(Opcode Op, const MCExpr *Expr,
371 static const MCUnaryExpr *create(Opcode Op, const MCExpr *Expr,
372372 MCContext &Ctx);
373 static const MCUnaryExpr *CreateLNot(const MCExpr *Expr, MCContext &Ctx) {
374 return Create(LNot, Expr, Ctx);
375 }
376 static const MCUnaryExpr *CreateMinus(const MCExpr *Expr, MCContext &Ctx) {
377 return Create(Minus, Expr, Ctx);
378 }
379 static const MCUnaryExpr *CreateNot(const MCExpr *Expr, MCContext &Ctx) {
380 return Create(Not, Expr, Ctx);
381 }
382 static const MCUnaryExpr *CreatePlus(const MCExpr *Expr, MCContext &Ctx) {
383 return Create(Plus, Expr, Ctx);
373 static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx) {
374 return create(LNot, Expr, Ctx);
375 }
376 static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx) {
377 return create(Minus, Expr, Ctx);
378 }
379 static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx) {
380 return create(Not, Expr, Ctx);
381 }
382 static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx) {
383 return create(Plus, Expr, Ctx);
384384 }
385385
386386 /// @}
440440 /// \name Construction
441441 /// @{
442442
443 static const MCBinaryExpr *Create(Opcode Op, const MCExpr *LHS,
443 static const MCBinaryExpr *create(Opcode Op, const MCExpr *LHS,
444444 const MCExpr *RHS, MCContext &Ctx);
445 static const MCBinaryExpr *CreateAdd(const MCExpr *LHS, const MCExpr *RHS,
446 MCContext &Ctx) {
447 return Create(Add, LHS, RHS, Ctx);
448 }
449 static const MCBinaryExpr *CreateAnd(const MCExpr *LHS, const MCExpr *RHS,
450 MCContext &Ctx) {
451 return Create(And, LHS, RHS, Ctx);
452 }
453 static const MCBinaryExpr *CreateDiv(const MCExpr *LHS, const MCExpr *RHS,
454 MCContext &Ctx) {
455 return Create(Div, LHS, RHS, Ctx);
456 }
457 static const MCBinaryExpr *CreateEQ(const MCExpr *LHS, const MCExpr *RHS,
445 static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS,
446 MCContext &Ctx) {
447 return create(Add, LHS, RHS, Ctx);
448 }
449 static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS,
450 MCContext &Ctx) {
451 return create(And, LHS, RHS, Ctx);
452 }
453 static const MCBinaryExpr *createDiv(const MCExpr *LHS, const MCExpr *RHS,
454 MCContext &Ctx) {
455 return create(Div, LHS, RHS, Ctx);
456 }
457 static const MCBinaryExpr *createEQ(const MCExpr *LHS, const MCExpr *RHS,
458458 MCContext &Ctx) {
459 return Create(EQ, LHS, RHS, Ctx);
460 }
461 static const MCBinaryExpr *CreateGT(const MCExpr *LHS, const MCExpr *RHS,
459 return create(EQ, LHS, RHS, Ctx);
460 }
461 static const MCBinaryExpr *createGT(const MCExpr *LHS, const MCExpr *RHS,
462462 MCContext &Ctx) {
463 return Create(GT, LHS, RHS, Ctx);
464 }
465 static const MCBinaryExpr *CreateGTE(const MCExpr *LHS, const MCExpr *RHS,
466 MCContext &Ctx) {
467 return Create(GTE, LHS, RHS, Ctx);
468 }
469 static const MCBinaryExpr *CreateLAnd(const MCExpr *LHS, const MCExpr *RHS,
463 return create(GT, LHS, RHS, Ctx);
464 }
465 static const MCBinaryExpr *createGTE(const MCExpr *LHS, const MCExpr *RHS,
466 MCContext &Ctx) {
467 return create(GTE, LHS, RHS, Ctx);
468 }
469 static const MCBinaryExpr *createLAnd(const MCExpr *LHS, const MCExpr *RHS,
470470 MCContext &Ctx) {
471 return Create(LAnd, LHS, RHS, Ctx);
472 }
473 static const MCBinaryExpr *CreateLOr(const MCExpr *LHS, const MCExpr *RHS,
474 MCContext &Ctx) {
475 return Create(LOr, LHS, RHS, Ctx);
476 }
477 static const MCBinaryExpr *CreateLT(const MCExpr *LHS, const MCExpr *RHS,
471 return create(LAnd, LHS, RHS, Ctx);
472 }
473 static const MCBinaryExpr *createLOr(const MCExpr *LHS, const MCExpr *RHS,
474 MCContext &Ctx) {
475 return create(LOr, LHS, RHS, Ctx);
476 }
477 static const MCBinaryExpr *createLT(const MCExpr *LHS, const MCExpr *RHS,
478478 MCContext &Ctx) {
479 return Create(LT, LHS, RHS, Ctx);
480 }
481 static const MCBinaryExpr *CreateLTE(const MCExpr *LHS, const MCExpr *RHS,
482 MCContext &Ctx) {
483 return Create(LTE, LHS, RHS, Ctx);
484 }
485 static const MCBinaryExpr *CreateMod(const MCExpr *LHS, const MCExpr *RHS,
486 MCContext &Ctx) {
487 return Create(Mod, LHS, RHS, Ctx);
488 }
489 static const MCBinaryExpr *CreateMul(const MCExpr *LHS, const MCExpr *RHS,
490 MCContext &Ctx) {
491 return Create(Mul, LHS, RHS, Ctx);
492 }
493 static const MCBinaryExpr *CreateNE(const MCExpr *LHS, const MCExpr *RHS,
479 return create(LT, LHS, RHS, Ctx);
480 }
481 static const MCBinaryExpr *createLTE(const MCExpr *LHS, const MCExpr *RHS,
482 MCContext &Ctx) {
483 return create(LTE, LHS, RHS, Ctx);
484 }
485 static const MCBinaryExpr *createMod(const MCExpr *LHS, const MCExpr *RHS,
486 MCContext &Ctx) {
487 return create(Mod, LHS, RHS, Ctx);
488 }
489 static const MCBinaryExpr *createMul(const MCExpr *LHS, const MCExpr *RHS,
490 MCContext &Ctx) {
491 return create(Mul, LHS, RHS, Ctx);
492 }
493 static const MCBinaryExpr *createNE(const MCExpr *LHS, const MCExpr *RHS,
494494 MCContext &Ctx) {
495 return Create(NE, LHS, RHS, Ctx);
496 }
497 static const MCBinaryExpr *CreateOr(const MCExpr *LHS, const MCExpr *RHS,
495 return create(NE, LHS, RHS, Ctx);
496 }
497 static const MCBinaryExpr *createOr(const MCExpr *LHS, const MCExpr *RHS,
498498 MCContext &Ctx) {
499 return Create(Or, LHS, RHS, Ctx);
500 }
501 static const MCBinaryExpr *CreateShl(const MCExpr *LHS, const MCExpr *RHS,
502 MCContext &Ctx) {
503 return Create(Shl, LHS, RHS, Ctx);
504 }
505 static const MCBinaryExpr *CreateAShr(const MCExpr *LHS, const MCExpr *RHS,
506 MCContext &Ctx) {
507 return Create(AShr, LHS, RHS, Ctx);
508 }
509 static const MCBinaryExpr *CreateLShr(const MCExpr *LHS, const MCExpr *RHS,
510 MCContext &Ctx) {
511 return Create(LShr, LHS, RHS, Ctx);
512 }
513 static const MCBinaryExpr *CreateSub(const MCExpr *LHS, const MCExpr *RHS,
514 MCContext &Ctx) {
515 return Create(Sub, LHS, RHS, Ctx);
516 }
517 static const MCBinaryExpr *CreateXor(const MCExpr *LHS, const MCExpr *RHS,
518 MCContext &Ctx) {
519 return Create(Xor, LHS, RHS, Ctx);
499 return create(Or, LHS, RHS, Ctx);
500 }
501 static const MCBinaryExpr *createShl(const MCExpr *LHS, const MCExpr *RHS,
502 MCContext &Ctx) {
503 return create(Shl, LHS, RHS, Ctx);
504 }
505 static const MCBinaryExpr *createAShr(const MCExpr *LHS, const MCExpr *RHS,
506 MCContext &Ctx) {
507 return create(AShr, LHS, RHS, Ctx);
508 }
509 static const MCBinaryExpr *createLShr(const MCExpr *LHS, const MCExpr *RHS,
510 MCContext &Ctx) {
511 return create(LShr, LHS, RHS, Ctx);
512 }
513 static const MCBinaryExpr *createSub(const MCExpr *LHS, const MCExpr *RHS,
514 MCContext &Ctx) {
515 return create(Sub, LHS, RHS, Ctx);
516 }
517 static const MCBinaryExpr *createXor(const MCExpr *LHS, const MCExpr *RHS,
518 MCContext &Ctx) {
519 return create(Xor, LHS, RHS, Ctx);
520520 }
521521
522522 /// @}
551551 virtual ~MCTargetExpr() {}
552552 public:
553553
554 virtual void PrintImpl(raw_ostream &OS) const = 0;
555 virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
554 virtual void printImpl(raw_ostream &OS) const = 0;
555 virtual bool evaluateAsRelocatableImpl(MCValue &Res,
556556 const MCAsmLayout *Layout,
557557 const MCFixup *Fixup) const = 0;
558558 virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
559 virtual MCSection *FindAssociatedSection() const = 0;
559 virtual MCSection *findAssociatedSection() const = 0;
560560
561561 virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;
562562
107107 MCSection *getSectionPtr() const {
108108 if (Section || !Value)
109109 return Section;
110 return Section = Value->FindAssociatedSection();
110 return Section = Value->findAssociatedSection();
111111 }
112112
113113 public:
3737 Entries[I.second.Number] =
3838 I.second.TLS
3939 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
40 : MCSymbolRefExpr::Create(I.first, Asm.OutContext);
40 : MCSymbolRefExpr::create(I.first, Asm.OutContext);
4141
4242 for (const MCExpr *Entry : Entries)
4343 Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
511511
512512 if (MAI->hasDotTypeDotSizeDirective())
513513 // .size foo, 42
514 OutStreamer->EmitELFSize(GVSym, MCConstantExpr::Create(Size, OutContext));
514 OutStreamer->EmitELFSize(GVSym, MCConstantExpr::create(Size, OutContext));
515515
516516 OutStreamer->AddBlankLine();
517517 }
565565 MCSymbol *CurPos = OutContext.createTempSymbol();
566566 OutStreamer->EmitLabel(CurPos);
567567 OutStreamer->EmitAssignment(CurrentFnBegin,
568 MCSymbolRefExpr::Create(CurPos, OutContext));
568 MCSymbolRefExpr::create(CurPos, OutContext));
569569 } else {
570570 OutStreamer->EmitLabel(CurrentFnBegin);
571571 }
775775
776776 // Emit a symbol assignment.
777777 OutStreamer->EmitAssignment(FrameAllocSym,
778 MCConstantExpr::Create(FrameOffset, OutContext));
778 MCConstantExpr::create(FrameOffset, OutContext));
779779 }
780780
781781 /// EmitFunctionBody - This method emits the body and trailer for a
899899 // We can get the size as difference between the function label and the
900900 // temp label.
901901 const MCExpr *SizeExp =
902 MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(CurrentFnEnd, OutContext),
903 MCSymbolRefExpr::Create(CurrentFnSymForSize,
902 MCBinaryExpr::createSub(MCSymbolRefExpr::create(CurrentFnEnd, OutContext),
903 MCSymbolRefExpr::create(CurrentFnSymForSize,
904904 OutContext),
905905 OutContext);
906906 OutStreamer->EmitELFSize(CurrentFnSym, SizeExp);
13251325
13261326 // .set LJTSet, LBB32-base
13271327 const MCExpr *LHS =
1328 MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
1328 MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
13291329 OutStreamer->EmitAssignment(GetJTSetSymbol(JTI, MBB->getNumber()),
1330 MCBinaryExpr::CreateSub(LHS, Base,
1330 MCBinaryExpr::createSub(LHS, Base,
13311331 OutContext));
13321332 }
13331333 }
13671367 case MachineJumpTableInfo::EK_BlockAddress:
13681368 // EK_BlockAddress - Each entry is a plain address of block, e.g.:
13691369 // .word LBB123
1370 Value = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
1370 Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
13711371 break;
13721372 case MachineJumpTableInfo::EK_GPRel32BlockAddress: {
13731373 // EK_GPRel32BlockAddress - Each entry is an address of block, encoded
13741374 // with a relocation as gp-relative, e.g.:
13751375 // .gprel32 LBB123
13761376 MCSymbol *MBBSym = MBB->getSymbol();
1377 OutStreamer->EmitGPRel32Value(MCSymbolRefExpr::Create(MBBSym, OutContext));
1377 OutStreamer->EmitGPRel32Value(MCSymbolRefExpr::create(MBBSym, OutContext));
13781378 return;
13791379 }
13801380
13831383 // with a relocation as gp-relative, e.g.:
13841384 // .gpdword LBB123
13851385 MCSymbol *MBBSym = MBB->getSymbol();
1386 OutStreamer->EmitGPRel64Value(MCSymbolRefExpr::Create(MBBSym, OutContext));
1386 OutStreamer->EmitGPRel64Value(MCSymbolRefExpr::create(MBBSym, OutContext));
13871387 return;
13881388 }
13891389
13961396 // .set L4_5_set_123, LBB123 - LJTI1_2
13971397 // .word L4_5_set_123
13981398 if (MAI->doesSetDirectiveSuppressesReloc()) {
1399 Value = MCSymbolRefExpr::Create(GetJTSetSymbol(UID, MBB->getNumber()),
1399 Value = MCSymbolRefExpr::create(GetJTSetSymbol(UID, MBB->getNumber()),
14001400 OutContext);
14011401 break;
14021402 }
1403 Value = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
1403 Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
14041404 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
14051405 const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext);
1406 Value = MCBinaryExpr::CreateSub(Value, Base, OutContext);
1406 Value = MCBinaryExpr::createSub(Value, Base, OutContext);
14071407 break;
14081408 }
14091409 }
15951595
15961596 // Get the Hi-Lo expression.
15971597 const MCExpr *Diff =
1598 MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(Hi, OutContext),
1599 MCSymbolRefExpr::Create(Lo, OutContext),
1598 MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, OutContext),
1599 MCSymbolRefExpr::create(Lo, OutContext),
16001600 OutContext);
16011601
16021602 if (!MAI->doesSetDirectiveSuppressesReloc()) {
16221622 }
16231623
16241624 // Emit Label+Offset (or just Label if Offset is zero)
1625 const MCExpr *Expr = MCSymbolRefExpr::Create(Label, OutContext);
1625 const MCExpr *Expr = MCSymbolRefExpr::create(Label, OutContext);
16261626 if (Offset)
1627 Expr = MCBinaryExpr::CreateAdd(
1628 Expr, MCConstantExpr::Create(Offset, OutContext), OutContext);
1627 Expr = MCBinaryExpr::createAdd(
1628 Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
16291629
16301630 OutStreamer->EmitValue(Expr, Size);
16311631 }
16621662 MCContext &Ctx = OutContext;
16631663
16641664 if (CV->isNullValue() || isa(CV))
1665 return MCConstantExpr::Create(0, Ctx);
1665 return MCConstantExpr::create(0, Ctx);
16661666
16671667 if (const ConstantInt *CI = dyn_cast(CV))
1668 return MCConstantExpr::Create(CI->getZExtValue(), Ctx);
1668 return MCConstantExpr::create(CI->getZExtValue(), Ctx);
16691669
16701670 if (const GlobalValue *GV = dyn_cast(CV))
1671 return MCSymbolRefExpr::Create(getSymbol(GV), Ctx);
1671 return MCSymbolRefExpr::create(getSymbol(GV), Ctx);
16721672
16731673 if (const BlockAddress *BA = dyn_cast(CV))
1674 return MCSymbolRefExpr::Create(GetBlockAddressSymbol(BA), Ctx);
1674 return MCSymbolRefExpr::create(GetBlockAddressSymbol(BA), Ctx);
16751675
16761676 const ConstantExpr *CE = dyn_cast(CV);
16771677 if (!CE) {
17121712 return Base;
17131713
17141714 int64_t Offset = OffsetAI.getSExtValue();
1715 return MCBinaryExpr::CreateAdd(Base, MCConstantExpr::Create(Offset, Ctx),
1715 return MCBinaryExpr::createAdd(Base, MCConstantExpr::create(Offset, Ctx),
17161716 Ctx);
17171717 }
17181718
17551755 // the high bits so we are sure to get a proper truncation if the input is
17561756 // a constant expr.
17571757 unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType());
1758 const MCExpr *MaskExpr = MCConstantExpr::Create(~0ULL >> (64-InBits), Ctx);
1759 return MCBinaryExpr::CreateAnd(OpExpr, MaskExpr, Ctx);
1758 const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx);
1759 return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx);
17601760 }
17611761
17621762 // The MC library also has a right-shift operator, but it isn't consistently
17741774 const MCExpr *RHS = lowerConstant(CE->getOperand(1));
17751775 switch (CE->getOpcode()) {
17761776 default: llvm_unreachable("Unknown binary operator constant cast expr");
1777 case Instruction::Add: return MCBinaryExpr::CreateAdd(LHS, RHS, Ctx);
1778 case Instruction::Sub: return MCBinaryExpr::CreateSub(LHS, RHS, Ctx);
1779 case Instruction::Mul: return MCBinaryExpr::CreateMul(LHS, RHS, Ctx);
1780 case Instruction::SDiv: return MCBinaryExpr::CreateDiv(LHS, RHS, Ctx);
1781 case Instruction::SRem: return MCBinaryExpr::CreateMod(LHS, RHS, Ctx);
1782 case Instruction::Shl: return MCBinaryExpr::CreateShl(LHS, RHS, Ctx);
1783 case Instruction::And: return MCBinaryExpr::CreateAnd(LHS, RHS, Ctx);
1784 case Instruction::Or: return MCBinaryExpr::CreateOr (LHS, RHS, Ctx);
1785 case Instruction::Xor: return MCBinaryExpr::CreateXor(LHS, RHS, Ctx);
1777 case Instruction::Add: return MCBinaryExpr::createAdd(LHS, RHS, Ctx);
1778 case Instruction::Sub: return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1779 case Instruction::Mul: return MCBinaryExpr::createMul(LHS, RHS, Ctx);
1780 case Instruction::SDiv: return MCBinaryExpr::createDiv(LHS, RHS, Ctx);
1781 case Instruction::SRem: return MCBinaryExpr::createMod(LHS, RHS, Ctx);
1782 case Instruction::Shl: return MCBinaryExpr::createShl(LHS, RHS, Ctx);
1783 case Instruction::And: return MCBinaryExpr::createAnd(LHS, RHS, Ctx);
1784 case Instruction::Or: return MCBinaryExpr::createOr (LHS, RHS, Ctx);
1785 case Instruction::Xor: return MCBinaryExpr::createXor(LHS, RHS, Ctx);
17861786 }
17871787 }
17881788 }
21062106 // cstexpr := - "." +
21072107 // cstexpr := - ( - ) +
21082108 //
2109 // After canonicalization by EvaluateAsRelocatable `ME` turns into:
2109 // After canonicalization by evaluateAsRelocatable `ME` turns into:
21102110 //
21112111 // cstexpr := - + gotpcrelcst, where
21122112 // gotpcrelcst := +
21132113 //
21142114 MCValue MV;
2115 if (!(*ME)->EvaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
2115 if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
21162116 return;
21172117
21182118 const MCSymbol *GOTEquivSym = &MV.getSymA()->getSymbol();
191191 PrevHash = HashValue;
192192 Asm->OutStreamer->AddComment("Offset in Bucket " + Twine(i));
193193 MCContext &Context = Asm->OutStreamer->getContext();
194 const MCExpr *Sub = MCBinaryExpr::CreateSub(
195 MCSymbolRefExpr::Create((*HI)->Sym, Context),
196 MCSymbolRefExpr::Create(SecBegin, Context), Context);
194 const MCExpr *Sub = MCBinaryExpr::createSub(
195 MCSymbolRefExpr::create((*HI)->Sym, Context),
196 MCSymbolRefExpr::create(SecBegin, Context), Context);
197197 Asm->OutStreamer->EmitValue(Sub, sizeof(uint32_t));
198198 }
199199 }
170170 unsigned int Size = 4) {
171171 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
172172 MCContext &Context = Streamer.getContext();
173 const MCExpr *FromRef = MCSymbolRefExpr::Create(From, Variant, Context),
174 *ToRef = MCSymbolRefExpr::Create(To, Variant, Context);
173 const MCExpr *FromRef = MCSymbolRefExpr::create(From, Variant, Context),
174 *ToRef = MCSymbolRefExpr::create(To, Variant, Context);
175175 const MCExpr *AddrDelta =
176 MCBinaryExpr::Create(MCBinaryExpr::Sub, ToRef, FromRef, Context);
176 MCBinaryExpr::create(MCBinaryExpr::Sub, ToRef, FromRef, Context);
177177 Streamer.EmitValue(AddrDelta, Size);
178178 }
179179
9595 // Emit a symbol assignment.
9696 Asm->OutStreamer->EmitAssignment(
9797 HandlerTypeParentFrameOffset,
98 MCConstantExpr::Create(I->second, Asm->OutContext));
98 MCConstantExpr::create(I->second, Asm->OutContext));
9999 }
100100 }
101101
158158
159159 const MCExpr *WinException::create32bitRef(const MCSymbol *Value) {
160160 if (!Value)
161 return MCConstantExpr::Create(0, Asm->OutContext);
162 return MCSymbolRefExpr::Create(Value, useImageRel32
161 return MCConstantExpr::create(0, Asm->OutContext);
162 return MCSymbolRefExpr::create(Value, useImageRel32
163163 ? MCSymbolRefExpr::VK_COFF_IMGREL32
164164 : MCSymbolRefExpr::VK_None,
165165 Asm->OutContext);
167167
168168 const MCExpr *WinException::create32bitRef(const GlobalValue *GV) {
169169 if (!GV)
170 return MCConstantExpr::Create(0, Asm->OutContext);
170 return MCConstantExpr::create(0, Asm->OutContext);
171171 return create32bitRef(Asm->getSymbol(GV));
172172 }
173173
254254 if (CSE.EndLabel) {
255255 // The interval is half-open, so we have to add one to include the return
256256 // address of the last invoke in the range.
257 End = MCBinaryExpr::CreateAdd(create32bitRef(CSE.EndLabel),
258 MCConstantExpr::Create(1, Asm->OutContext),
257 End = MCBinaryExpr::createAdd(create32bitRef(CSE.EndLabel),
258 MCConstantExpr::create(1, Asm->OutContext),
259259 Asm->OutContext);
260260 } else {
261261 End = create32bitRef(EHFuncEndSym);
427427 Asm->OutContext.getOrCreateFrameAllocSymbol(
428428 GlobalValue::getRealLinkageName(ParentF->getName()),
429429 HT.CatchObjRecoverIdx);
430 FrameAllocOffsetRef = MCSymbolRefExpr::Create(
430 FrameAllocOffsetRef = MCSymbolRefExpr::create(
431431 FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
432432 } else {
433 FrameAllocOffsetRef = MCConstantExpr::Create(0, Asm->OutContext);
433 FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext);
434434 }
435435
436436 OS.EmitIntValue(HT.Adjectives, 4); // Adjectives
442442 MCSymbol *ParentFrameOffset =
443443 Asm->OutContext.getOrCreateParentFrameOffsetSymbol(
444444 GlobalValue::getRealLinkageName(HT.Handler->getName()));
445 const MCSymbolRefExpr *ParentFrameOffsetRef = MCSymbolRefExpr::Create(
445 const MCSymbolRefExpr *ParentFrameOffsetRef = MCSymbolRefExpr::create(
446446 ParentFrameOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
447447 OS.EmitValue(ParentFrameOffsetRef, 4); // ParentFrameOffset
448448 }
253253 TargetLowering::getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
254254 unsigned JTI,MCContext &Ctx) const{
255255 // The normal PIC reloc base is the label at the start of the jump table.
256 return MCSymbolRefExpr::Create(MF->getJTISymbol(JTI, Ctx), Ctx);
256 return MCSymbolRefExpr::create(MF->getJTISymbol(JTI, Ctx), Ctx);
257257 }
258258
259259 bool
314314
315315 // Create an expression to calculate the offset of the callsite from function
316316 // entry.
317 const MCExpr *CSOffsetExpr = MCBinaryExpr::CreateSub(
318 MCSymbolRefExpr::Create(MILabel, OutContext),
319 MCSymbolRefExpr::Create(AP.CurrentFnSymForSize, OutContext),
317 const MCExpr *CSOffsetExpr = MCBinaryExpr::createSub(
318 MCSymbolRefExpr::create(MILabel, OutContext),
319 MCSymbolRefExpr::create(AP.CurrentFnSymForSize, OutContext),
320320 OutContext);
321321
322322 CSInfos.emplace_back(CSOffsetExpr, ID, std::move(Locations),
7474 Streamer.SwitchSection(Sec);
7575 Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment());
7676 Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject);
77 const MCExpr *E = MCConstantExpr::Create(Size, getContext());
77 const MCExpr *E = MCConstantExpr::create(Size, getContext());
7878 Streamer.EmitELFSize(Label, E);
7979 Streamer.EmitLabel(Label);
8080
100100 }
101101
102102 return TargetLoweringObjectFile::
103 getTTypeReference(MCSymbolRefExpr::Create(SSym, getContext()),
103 getTTypeReference(MCSymbolRefExpr::create(SSym, getContext()),
104104 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
105105 }
106106
683683 }
684684
685685 return TargetLoweringObjectFile::
686 getTTypeReference(MCSymbolRefExpr::Create(SSym, getContext()),
686 getTTypeReference(MCSymbolRefExpr::create(SSym, getContext()),
687687 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
688688 }
689689
759759 StubValueTy(const_cast(Sym), true /* access indirectly */);
760760
761761 const MCExpr *BSymExpr =
762 MCSymbolRefExpr::Create(BaseSym, MCSymbolRefExpr::VK_None, Ctx);
762 MCSymbolRefExpr::create(BaseSym, MCSymbolRefExpr::VK_None, Ctx);
763763 const MCExpr *LHS =
764 MCSymbolRefExpr::Create(Stub, MCSymbolRefExpr::VK_None, Ctx);
764 MCSymbolRefExpr::create(Stub, MCSymbolRefExpr::VK_None, Ctx);
765765
766766 if (!Offset)
767 return MCBinaryExpr::CreateSub(LHS, BSymExpr, Ctx);
767 return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
768768
769769 const MCExpr *RHS =
770 MCBinaryExpr::CreateAdd(BSymExpr, MCConstantExpr::Create(Offset, Ctx), Ctx);
771 return MCBinaryExpr::CreateSub(LHS, RHS, Ctx);
770 MCBinaryExpr::createAdd(BSymExpr, MCConstantExpr::create(Offset, Ctx), Ctx);
771 return MCBinaryExpr::createSub(LHS, RHS, Ctx);
772772 }
773773
774774 //===----------------------------------------------------------------------===//
3939 MCSymbol *CPEntryLabel = Context.createTempSymbol();
4040
4141 Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size));
42 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
42 return MCSymbolRefExpr::create(CPEntryLabel, Context);
4343 }
4444
4545 bool ConstantPool::empty() { return Entries.empty(); }
127127 unsigned Encoding,
128128 MCStreamer &Streamer) const {
129129 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
130 return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
130 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
131131
132132 MCContext &Context = Streamer.getContext();
133 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
133 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
134134 MCSymbol *PCSym = Context.createTempSymbol();
135135 Streamer.EmitLabel(PCSym);
136 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
137 return MCBinaryExpr::CreateSub(Res, PC, Context);
136 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
137 return MCBinaryExpr::createSub(Res, PC, Context);
138138 }
642642 }
643643
644644 void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
645 EmitValue(MCConstantExpr::Create(Value, getContext()), Size);
645 EmitValue(MCConstantExpr::create(Value, getContext()), Size);
646646 }
647647
648648 void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
661661
662662 if (!Directive) {
663663 int64_t IntValue;
664 if (!Value->EvaluateAsAbsolute(IntValue))
664 if (!Value->evaluateAsAbsolute(IntValue))
665665 report_fatal_error("Don't know how to emit this value.");
666666
667667 // We couldn't handle the requested integer size so we fallback by breaking
702702
703703 void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
704704 int64_t IntValue;
705 if (Value->EvaluateAsAbsolute(IntValue)) {
705 if (Value->evaluateAsAbsolute(IntValue)) {
706706 EmitULEB128IntValue(IntValue);
707707 return;
708708 }
712712
713713 void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
714714 int64_t IntValue;
715 if (Value->EvaluateAsAbsolute(IntValue)) {
715 if (Value->evaluateAsAbsolute(IntValue)) {
716716 EmitSLEB128IntValue(IntValue);
717717 return;
718718 }
136136
137137 // If SD is a variable, evaluate it.
138138 MCValue Target;
139 if (!S.getVariableValue()->EvaluateAsRelocatable(Target, &Layout, nullptr))
139 if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Layout, nullptr))
140140 report_fatal_error("unable to evaluate offset for variable '" +
141141 S.getName() + "'");
142142
397397 // probably merge the two into a single callback that tries to evaluate a
398398 // fixup and records a relocation if one is needed.
399399 const MCExpr *Expr = Fixup.getValue();
400 if (!Expr->EvaluateAsRelocatable(Target, &Layout, &Fixup))
400 if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup))
401401 getContext().reportFatalError(Fixup.getLoc(), "expected relocatable expression");
402402
403403 bool IsPCRel = Backend.getFixupKindInfo(
490490 case MCFragment::FT_Org: {
491491 const MCOrgFragment &OF = cast(F);
492492 int64_t TargetLocation;
493 if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, Layout))
493 if (!OF.getOffset().evaluateAsAbsolute(TargetLocation, Layout))
494494 report_fatal_error("expected assembly-time absolute expression");
495495
496496 // FIXME: We need a way to communicate this error.
8787 if (SymbolicOp.AddSymbol.Name) {
8888 StringRef Name(SymbolicOp.AddSymbol.Name);
8989 MCSymbol *Sym = Ctx.getOrCreateSymbol(Name);
90 Add = MCSymbolRefExpr::Create(Sym, Ctx);
90 Add = MCSymbolRefExpr::create(Sym, Ctx);
9191 } else {
92 Add = MCConstantExpr::Create((int)SymbolicOp.AddSymbol.Value, Ctx);
92 Add = MCConstantExpr::create((int)SymbolicOp.AddSymbol.Value, Ctx);
9393 }
9494 }
9595
9898 if (SymbolicOp.SubtractSymbol.Name) {
9999 StringRef Name(SymbolicOp.SubtractSymbol.Name);
100100 MCSymbol *Sym = Ctx.getOrCreateSymbol(Name);
101 Sub = MCSymbolRefExpr::Create(Sym, Ctx);
101 Sub = MCSymbolRefExpr::create(Sym, Ctx);
102102 } else {
103 Sub = MCConstantExpr::Create((int)SymbolicOp.SubtractSymbol.Value, Ctx);
103 Sub = MCConstantExpr::create((int)SymbolicOp.SubtractSymbol.Value, Ctx);
104104 }
105105 }
106106
107107 const MCExpr *Off = nullptr;
108108 if (SymbolicOp.Value != 0)
109 Off = MCConstantExpr::Create(SymbolicOp.Value, Ctx);
109 Off = MCConstantExpr::create(SymbolicOp.Value, Ctx);
110110
111111 const MCExpr *Expr;
112112 if (Sub) {
113113 const MCExpr *LHS;
114114 if (Add)
115 LHS = MCBinaryExpr::CreateSub(Add, Sub, Ctx);
115 LHS = MCBinaryExpr::createSub(Add, Sub, Ctx);
116116 else
117 LHS = MCUnaryExpr::CreateMinus(Sub, Ctx);
117 LHS = MCUnaryExpr::createMinus(Sub, Ctx);
118118 if (Off)
119 Expr = MCBinaryExpr::CreateAdd(LHS, Off, Ctx);
119 Expr = MCBinaryExpr::createAdd(LHS, Off, Ctx);
120120 else
121121 Expr = LHS;
122122 } else if (Add) {
123123 if (Off)
124 Expr = MCBinaryExpr::CreateAdd(Add, Off, Ctx);
124 Expr = MCBinaryExpr::createAdd(Add, Off, Ctx);
125125 else
126126 Expr = Add;
127127 } else {
128128 if (Off)
129129 Expr = Off;
130130 else
131 Expr = MCConstantExpr::Create(0, Ctx);
131 Expr = MCConstantExpr::create(0, Ctx);
132132 }
133133
134134 Expr = RelInfo->createExprForCAPIVariantKind(Expr, SymbolicOp.VariantKind);
9797 int IntVal) {
9898 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
9999 const MCExpr *Res =
100 MCSymbolRefExpr::Create(&End, Variant, MCOS.getContext());
100 MCSymbolRefExpr::create(&End, Variant, MCOS.getContext());
101101 const MCExpr *RHS =
102 MCSymbolRefExpr::Create(&Start, Variant, MCOS.getContext());
102 MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext());
103103 const MCExpr *Res1 =
104 MCBinaryExpr::Create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext());
104 MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext());
105105 const MCExpr *Res2 =
106 MCConstantExpr::Create(IntVal, MCOS.getContext());
106 MCConstantExpr::create(IntVal, MCOS.getContext());
107107 const MCExpr *Res3 =
108 MCBinaryExpr::Create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext());
108 MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext());
109109 return Res3;
110110 }
111111
246246
247247 MCSymbol *ABS = Context.createTempSymbol();
248248 OS.EmitAssignment(ABS, Expr);
249 return MCSymbolRefExpr::Create(ABS, Context);
249 return MCSymbolRefExpr::create(ABS, Context);
250250 }
251251
252252 static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
615615 assert(StartSymbol && "StartSymbol must not be NULL");
616616 assert(EndSymbol && "EndSymbol must not be NULL");
617617
618 const MCExpr *Addr = MCSymbolRefExpr::Create(
618 const MCExpr *Addr = MCSymbolRefExpr::create(
619619 StartSymbol, MCSymbolRefExpr::VK_None, context);
620620 const MCExpr *Size = MakeStartMinusEndExpr(*MCOS,
621621 *StartSymbol, *EndSymbol, 0);
704704 assert(EndSymbol && "EndSymbol must not be NULL");
705705
706706 // AT_low_pc, the first address of the default .text section.
707 const MCExpr *Start = MCSymbolRefExpr::Create(
707 const MCExpr *Start = MCSymbolRefExpr::create(
708708 StartSymbol, MCSymbolRefExpr::VK_None, context);
709709 MCOS->EmitValue(Start, AddrSize);
710710
711711 // AT_high_pc, the last address of the default .text section.
712 const MCExpr *End = MCSymbolRefExpr::Create(
712 const MCExpr *End = MCSymbolRefExpr::create(
713713 EndSymbol, MCSymbolRefExpr::VK_None, context);
714714 MCOS->EmitValue(End, AddrSize);
715715 }
771771 MCOS->EmitIntValue(Entry.getLineNumber(), 4);
772772
773773 // AT_low_pc, start address of the label.
774 const MCExpr *AT_low_pc = MCSymbolRefExpr::Create(Entry.getLabel(),
774 const MCExpr *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(),
775775 MCSymbolRefExpr::VK_None, context);
776776 MCOS->EmitValue(AT_low_pc, AddrSize);
777777
811811 assert(EndSymbol && "EndSymbol must not be NULL");
812812
813813 // Emit a base address selection entry for the start of this section
814 const MCExpr *SectionStartAddr = MCSymbolRefExpr::Create(
814 const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
815815 StartSymbol, MCSymbolRefExpr::VK_None, context);
816816 MCOS->EmitFill(AddrSize, 0xFF);
817817 MCOS->EmitValue(SectionStartAddr, AddrSize);
171171
172172 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
173173 getAssembler().registerSymbol(*Symbol);
174 const MCExpr *Value = MCSymbolRefExpr::Create(
174 const MCExpr *Value = MCSymbolRefExpr::create(
175175 Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
176176 Alias->setVariableValue(Value);
177177 }
332332 Symbol->setCommon(Size, ByteAlignment);
333333 }
334334
335 Symbol->setSize(MCConstantExpr::Create(Size, getContext()));
335 Symbol->setSize(MCConstantExpr::create(Size, getContext()));
336336 }
337337
338338 void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
3232 void MCExpr::print(raw_ostream &OS) const {
3333 switch (getKind()) {
3434 case MCExpr::Target:
35 return cast(this)->PrintImpl(OS);
35 return cast(this)->printImpl(OS);
3636 case MCExpr::Constant:
3737 OS << cast(*this).getValue();
3838 return;
130130
131131 /* *** */
132132
133 const MCBinaryExpr *MCBinaryExpr::Create(Opcode Opc, const MCExpr *LHS,
133 const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,
134134 const MCExpr *RHS, MCContext &Ctx) {
135135 return new (Ctx) MCBinaryExpr(Opc, LHS, RHS);
136136 }
137137
138 const MCUnaryExpr *MCUnaryExpr::Create(Opcode Opc, const MCExpr *Expr,
138 const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
139139 MCContext &Ctx) {
140140 return new (Ctx) MCUnaryExpr(Opc, Expr);
141141 }
142142
143 const MCConstantExpr *MCConstantExpr::Create(int64_t Value, MCContext &Ctx) {
143 const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {
144144 return new (Ctx) MCConstantExpr(Value);
145145 }
146146
155155 assert(Symbol);
156156 }
157157
158 const MCSymbolRefExpr *MCSymbolRefExpr::Create(const MCSymbol *Sym,
158 const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym,
159159 VariantKind Kind,
160160 MCContext &Ctx) {
161161 return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo());
162162 }
163163
164 const MCSymbolRefExpr *MCSymbolRefExpr::Create(StringRef Name, VariantKind Kind,
164 const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind,
165165 MCContext &Ctx) {
166 return Create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
166 return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
167167 }
168168
169169 StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
399399
400400 /* *** */
401401
402 bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
403 return EvaluateAsAbsolute(Res, nullptr, nullptr, nullptr);
404 }
405
406 bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
402 bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
403 return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr);
404 }
405
406 bool MCExpr::evaluateAsAbsolute(int64_t &Res,
407407 const MCAsmLayout &Layout) const {
408 return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr);
409 }
410
411 bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
408 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr);
409 }
410
411 bool MCExpr::evaluateAsAbsolute(int64_t &Res,
412412 const MCAsmLayout &Layout,
413413 const SectionAddrMap &Addrs) const {
414 return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
415 }
416
417 bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
418 return EvaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
414 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
415 }
416
417 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
418 return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
419419 }
420420
421421 bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
424424 true);
425425 }
426426
427 bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
427 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
428428 const MCAsmLayout *Layout,
429429 const SectionAddrMap *Addrs) const {
430430 // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
445445 }
446446
447447 bool IsRelocatable =
448 EvaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
448 evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
449449
450450 // Record the current value.
451451 Res = Value.getConstant();
585585 return true;
586586 }
587587
588 bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
588 bool MCExpr::evaluateAsRelocatable(MCValue &Res,
589589 const MCAsmLayout *Layout,
590590 const MCFixup *Fixup) const {
591591 MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
592 return EvaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
592 return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
593593 false);
594594 }
595595
596596 bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
597597 MCAssembler *Assembler = &Layout.getAssembler();
598 return EvaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
598 return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
599599 true);
600600 }
601601
607607 return !Asm->getWriter().isWeak(Sym);
608608 }
609609
610 bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
610 bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
611611 const MCAsmLayout *Layout,
612612 const MCFixup *Fixup,
613613 const SectionAddrMap *Addrs,
616616
617617 switch (getKind()) {
618618 case Target:
619 return cast(this)->EvaluateAsRelocatableImpl(Res, Layout,
619 return cast(this)->evaluateAsRelocatableImpl(Res, Layout,
620620 Fixup);
621621
622622 case Constant:
631631 if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
632632 canExpand(Sym, Asm, InSet)) {
633633 bool IsMachO = SRE->hasSubsectionsViaSymbols();
634 if (Sym.getVariableValue()->EvaluateAsRelocatableImpl(
634 if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
635635 Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
636636 if (!IsMachO)
637637 return true;
657657 const MCUnaryExpr *AUE = cast(this);
658658 MCValue Value;
659659
660 if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
660 if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
661661 Addrs, InSet))
662662 return false;
663663
691691 const MCBinaryExpr *ABE = cast(this);
692692 MCValue LHSValue, RHSValue;
693693
694 if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
694 if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
695695 Addrs, InSet) ||
696 !ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
696 !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
697697 Addrs, InSet))
698698 return false;
699699
751751 llvm_unreachable("Invalid assembly expression kind!");
752752 }
753753
754 MCSection *MCExpr::FindAssociatedSection() const {
754 MCSection *MCExpr::findAssociatedSection() const {
755755 switch (getKind()) {
756756 case Target:
757757 // We never look through target specific expressions.
758 return cast(this)->FindAssociatedSection();
758 return cast(this)->findAssociatedSection();
759759
760760 case Constant:
761761 return MCSymbol::AbsolutePseudoSection;
771771 }
772772
773773 case Unary:
774 return cast(this)->getSubExpr()->FindAssociatedSection();
774 return cast(this)->getSubExpr()->findAssociatedSection();
775775
776776 case Binary: {
777777 const MCBinaryExpr *BE = cast(this);
778 MCSection *LHS_S = BE->getLHS()->FindAssociatedSection();
779 MCSection *RHS_S = BE->getRHS()->FindAssociatedSection();
778 MCSection *LHS_S = BE->getLHS()->findAssociatedSection();
779 MCSection *RHS_S = BE->getRHS()->findAssociatedSection();
780780
781781 // If either section is absolute, return the other.
782782 if (LHS_S == MCSymbol::AbsolutePseudoSection)
135135
136136 // Avoid fixups when possible.
137137 int64_t AbsValue;
138 if (Value->EvaluateAsAbsolute(AbsValue, getAssembler())) {
138 if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
139139 EmitIntValue(AbsValue, Size);
140140 return;
141141 }
177177
178178 void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {
179179 int64_t IntValue;
180 if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
180 if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
181181 EmitULEB128IntValue(IntValue);
182182 return;
183183 }
186186
187187 void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value) {
188188 int64_t IntValue;
189 if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
189 if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
190190 EmitSLEB128IntValue(IntValue);
191191 return;
192192 }
212212
213213 int64_t IntSubsection = 0;
214214 if (Subsection &&
215 !Subsection->EvaluateAsAbsolute(IntSubsection, getAssembler()))
215 !Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
216216 report_fatal_error("Cannot evaluate subsection number");
217217 if (IntSubsection < 0 || IntSubsection > 8192)
218218 report_fatal_error("Subsection number out of range");
319319 const MCSymbol *B) {
320320 MCContext &Context = OS.getContext();
321321 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
322 const MCExpr *ARef = MCSymbolRefExpr::Create(A, Variant, Context);
323 const MCExpr *BRef = MCSymbolRefExpr::Create(B, Variant, Context);
322 const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
323 const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
324324 const MCExpr *AddrDelta =
325 MCBinaryExpr::Create(MCBinaryExpr::Sub, ARef, BRef, Context);
325 MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
326326 return AddrDelta;
327327 }
328328
348348 }
349349 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
350350 int64_t Res;
351 if (AddrDelta->EvaluateAsAbsolute(Res, getAssembler())) {
351 if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
352352 MCDwarfLineAddr::Emit(this, LineDelta, Res);
353353 return;
354354 }
359359 const MCSymbol *Label) {
360360 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
361361 int64_t Res;
362 if (AddrDelta->EvaluateAsAbsolute(Res, getAssembler())) {
362 if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
363363 MCDwarfFrameEmitter::EmitAdvanceLoc(*this, Res);
364364 return;
365365 }
394394 bool MCObjectStreamer::EmitValueToOffset(const MCExpr *Offset,
395395 unsigned char Value) {
396396 int64_t Res;
397 if (Offset->EvaluateAsAbsolute(Res, getAssembler())) {
397 if (Offset->evaluateAsAbsolute(Res, getAssembler())) {
398398 insert(new MCOrgFragment(*Offset, Value));
399399 return false;
400400 }
403403 EmitLabel(CurrentPos);
404404 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
405405 const MCExpr *Ref =
406 MCSymbolRefExpr::Create(CurrentPos, Variant, getContext());
406 MCSymbolRefExpr::create(CurrentPos, Variant, getContext());
407407 const MCExpr *Delta =
408 MCBinaryExpr::Create(MCBinaryExpr::Sub, Offset, Ref, getContext());
409
410 if (!Delta->EvaluateAsAbsolute(Res, getAssembler()))
408 MCBinaryExpr::create(MCBinaryExpr::Sub, Offset, Ref, getContext());
409
410 if (!Delta->evaluateAsAbsolute(Res, getAssembler()))
411411 return true;
412412 EmitFill(Res, Value);
413413 return false;
788788 Lex(); // Eat the operator.
789789 if (parsePrimaryExpr(Res, EndLoc))
790790 return true;
791 Res = MCUnaryExpr::CreateLNot(Res, getContext());
791 Res = MCUnaryExpr::createLNot(Res, getContext());
792792 return false;
793793 case AsmToken::Dollar:
794794 case AsmToken::At:
802802 // temporary label to the streamer and refer to it.
803803 MCSymbol *Sym = Ctx.createTempSymbol();
804804 Out.EmitLabel(Sym);
805 Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
805 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
806806 getContext());
807807 EndLoc = FirstTokenLoc;
808808 return false;
870870 }
871871
872872 // Otherwise create a symbol ref.
873 Res = MCSymbolRefExpr::Create(Sym, Variant, getContext());
873 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
874874 return false;
875875 }
876876 case AsmToken::BigNum:
878878 case AsmToken::Integer: {
879879 SMLoc Loc = getTok().getLoc();
880880 int64_t IntVal = getTok().getIntVal();
881 Res = MCConstantExpr::Create(IntVal, getContext());
881 Res = MCConstantExpr::create(IntVal, getContext());
882882 EndLoc = Lexer.getTok().getEndLoc();
883883 Lex(); // Eat token.
884884 // Look for 'b' or 'f' following an Integer as a directional label
896896 if (IDVal == "f" || IDVal == "b") {
897897 MCSymbol *Sym =
898898 Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b");
899 Res = MCSymbolRefExpr::Create(Sym, Variant, getContext());
899 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
900900 if (IDVal == "b" && Sym->isUndefined())
901901 return Error(Loc, "invalid reference to undefined symbol");
902902 EndLoc = Lexer.getTok().getEndLoc();
908908 case AsmToken::Real: {
909909 APFloat RealVal(APFloat::IEEEdouble, getTok().getString());
910910 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
911 Res = MCConstantExpr::Create(IntVal, getContext());
911 Res = MCConstantExpr::create(IntVal, getContext());
912912 EndLoc = Lexer.getTok().getEndLoc();
913913 Lex(); // Eat token.
914914 return false;
918918 // temporary label to the streamer and refer to it.
919919 MCSymbol *Sym = Ctx.createTempSymbol();
920920 Out.EmitLabel(Sym);
921 Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
921 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
922922 EndLoc = Lexer.getTok().getEndLoc();
923923 Lex(); // Eat identifier.
924924 return false;
935935 Lex(); // Eat the operator.
936936 if (parsePrimaryExpr(Res, EndLoc))
937937 return true;
938 Res = MCUnaryExpr::CreateMinus(Res, getContext());
938 Res = MCUnaryExpr::createMinus(Res, getContext());
939939 return false;
940940 case AsmToken::Plus:
941941 Lex(); // Eat the operator.
942942 if (parsePrimaryExpr(Res, EndLoc))
943943 return true;
944 Res = MCUnaryExpr::CreatePlus(Res, getContext());
944 Res = MCUnaryExpr::createPlus(Res, getContext());
945945 return false;
946946 case AsmToken::Tilde:
947947 Lex(); // Eat the operator.
948948 if (parsePrimaryExpr(Res, EndLoc))
949949 return true;
950 Res = MCUnaryExpr::CreateNot(Res, getContext());
950 Res = MCUnaryExpr::createNot(Res, getContext());
951951 return false;
952952 }
953953 }
980980 return E;
981981 }
982982
983 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
983 return MCSymbolRefExpr::create(&SRE->getSymbol(), Variant, getContext());
984984 }
985985
986986 case MCExpr::Unary: {
988988 const MCExpr *Sub = applyModifierToExpr(UE->getSubExpr(), Variant);
989989 if (!Sub)
990990 return nullptr;
991 return MCUnaryExpr::Create(UE->getOpcode(), Sub, getContext());
991 return MCUnaryExpr::create(UE->getOpcode(), Sub, getContext());
992992 }
993993
994994 case MCExpr::Binary: {
10041004 if (!RHS)
10051005 RHS = BE->getRHS();
10061006
1007 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1007 return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, getContext());
10081008 }
10091009 }
10101010
10531053
10541054 // Try to constant fold it up front, if possible.
10551055 int64_t Value;
1056 if (Res->EvaluateAsAbsolute(Value))
1057 Res = MCConstantExpr::Create(Value, getContext());
1056 if (Res->evaluateAsAbsolute(Value))
1057 Res = MCConstantExpr::create(Value, getContext());
10581058
10591059 return false;
10601060 }
10711071 if (parseExpression(Expr))
10721072 return true;
10731073
1074 if (!Expr->EvaluateAsAbsolute(Res))
1074 if (!Expr->evaluateAsAbsolute(Res))
10751075 return Error(StartLoc, "expected absolute expression");
10761076
10771077 return false;
11821182 return true;
11831183
11841184 // Merge LHS and RHS according to operator.
1185 Res = MCBinaryExpr::Create(Kind, Res, RHS, getContext());
1185 Res = MCBinaryExpr::create(Kind, Res, RHS, getContext());
11861186 }
11871187 }
11881188
43774377 return true;
43784378
43794379 int64_t Count;
4380 if (!CountExpr->EvaluateAsAbsolute(Count)) {
4380 if (!CountExpr->evaluateAsAbsolute(Count)) {
43814381 eatToEndOfStatement();
43824382 return Error(CountLoc, "unexpected token in '" + Dir + "' directive");
43834383 }
662662
663663 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
664664 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
665 const MCExpr *Value = MCSymbolRefExpr::Create(Sym, getContext());
665 const MCExpr *Value = MCSymbolRefExpr::create(Sym, getContext());
666666
667667 getStreamer().EmitAssignment(Alias, Value);
668668 return false;
116116 "SectionRelative value requires 4-bytes");
117117
118118 if (!IsSectionRelative)
119 EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size);
119 EmitValueImpl(MCSymbolRefExpr::create(Sym, getContext()), Size);
120120 else
121121 EmitCOFFSecRel32(Sym);
122122 }
132132 /// EmitFill - Emit NumBytes bytes worth of the value specified by
133133 /// FillValue. This implements directives such as '.space'.
134134 void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
135 const MCExpr *E = MCConstantExpr::Create(FillValue, getContext());
135 const MCExpr *E = MCConstantExpr::create(FillValue, getContext());
136136 for (uint64_t i = 0, e = NumBytes; i != e; ++i)
137137 EmitValue(E, 1);
138138 }
5050 const MCSymbol *RHS) {
5151 MCContext &Context = Streamer.getContext();
5252 const MCExpr *Diff =
53 MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(LHS, Context),
54 MCSymbolRefExpr::Create(RHS, Context), Context);
53 MCBinaryExpr::createSub(MCSymbolRefExpr::create(LHS, Context),
54 MCSymbolRefExpr::create(RHS, Context), Context);
5555 Streamer.EmitValue(Diff, 1);
5656 }
5757
125125 const MCSymbol *Base,
126126 const MCSymbol *Other) {
127127 MCContext &Context = streamer.getContext();
128 const MCSymbolRefExpr *BaseRef = MCSymbolRefExpr::Create(Base, Context);
129 const MCSymbolRefExpr *OtherRef = MCSymbolRefExpr::Create(Other, Context);
130 const MCExpr *Ofs = MCBinaryExpr::CreateSub(OtherRef, BaseRef, Context);
131 const MCSymbolRefExpr *BaseRefRel = MCSymbolRefExpr::Create(Base,
128 const MCSymbolRefExpr *BaseRef = MCSymbolRefExpr::create(Base, Context);
129 const MCSymbolRefExpr *OtherRef = MCSymbolRefExpr::create(Other, Context);
130 const MCExpr *Ofs = MCBinaryExpr::createSub(OtherRef, BaseRef, Context);
131 const MCSymbolRefExpr *BaseRefRel = MCSymbolRefExpr::create(Base,
132132 MCSymbolRefExpr::VK_COFF_IMGREL32,
133133 Context);
134 streamer.EmitValue(MCBinaryExpr::CreateAdd(BaseRefRel, Ofs, Context), 4);
134 streamer.EmitValue(MCBinaryExpr::createAdd(BaseRefRel, Ofs, Context), 4);
135135 }
136136
137137 static void EmitRuntimeFunction(MCStreamer &streamer,
141141 streamer.EmitValueToAlignment(4);
142142 EmitSymbolRefWithOfs(streamer, info->Function, info->Begin);
143143 EmitSymbolRefWithOfs(streamer, info->Function, info->End);
144 streamer.EmitValue(MCSymbolRefExpr::Create(info->Symbol,
144 streamer.EmitValue(MCSymbolRefExpr::create(info->Symbol,
145145 MCSymbolRefExpr::VK_COFF_IMGREL32,
146146 context), 4);
147147 }
206206 EmitRuntimeFunction(streamer, info->ChainedParent);
207207 else if (flags &
208208 ((Win64EH::UNW_TerminateHandler|Win64EH::UNW_ExceptionHandler) << 3))
209 streamer.EmitValue(MCSymbolRefExpr::Create(info->ExceptionHandler,
209 streamer.EmitValue(MCSymbolRefExpr::create(info->ExceptionHandler,
210210 MCSymbolRefExpr::VK_COFF_IMGREL32,
211211 context), 4);
212212 else if (numCodes == 0) {
8080
8181
8282 MCValue Target;
83 if (!S.getVariableValue()->EvaluateAsRelocatable(Target, &Layout, nullptr))
83 if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Layout, nullptr))
8484 report_fatal_error("unable to evaluate offset for variable '" +
8585 S.getName() + "'");
8686
159159
160160 void MCWinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
161161 MCDataFragment *DF = getOrCreateDataFragment();
162 const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol, getContext());
162 const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
163163 MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
164164 DF->getFixups().push_back(Fixup);
165165 DF->getContents().resize(DF->getContents().size() + 2, 0);
167167
168168 void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
169169 MCDataFragment *DF = getOrCreateDataFragment();
170 const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol, getContext());
170 const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
171171 MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_4);
172172 DF->getFixups().push_back(Fixup);
173173 DF->getContents().resize(DF->getContents().size() + 4, 0);
6868 AArch64II::MO_PAGEOFF)
6969 RefKind = MCSymbolRefExpr::VK_PAGEOFF;
7070 }
71 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, RefKind, Ctx);
71 const MCExpr *Expr = MCSymbolRefExpr::create(Sym, RefKind, Ctx);
7272 if (!MO.isJTI() && MO.getOffset())
73 Expr = MCBinaryExpr::CreateAdd(
74 Expr, MCConstantExpr::Create(MO.getOffset(), Ctx), Ctx);
73 Expr = MCBinaryExpr::createAdd(
74 Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
7575 return MCOperand::createExpr(Expr);
7676 }
7777
138138 RefFlags |= AArch64MCExpr::VK_NC;
139139
140140 const MCExpr *Expr =
141 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, Ctx);
141 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx);
142142 if (!MO.isJTI() && MO.getOffset())
143 Expr = MCBinaryExpr::CreateAdd(
144 Expr, MCConstantExpr::Create(MO.getOffset(), Ctx), Ctx);
143 Expr = MCBinaryExpr::createAdd(
144 Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
145145
146146 AArch64MCExpr::VariantKind RefKind;
147147 RefKind = static_cast(RefFlags);
148 Expr = AArch64MCExpr::Create(Expr, RefKind, Ctx);
148 Expr = AArch64MCExpr::create(Expr, RefKind, Ctx);
149149
150150 return MCOperand::createExpr(Expr);
151151 }
178178 break;
179179 case MachineOperand::MO_MachineBasicBlock:
180180 MCOp = MCOperand::createExpr(
181 MCSymbolRefExpr::Create(MO.getMBB()->getSymbol(), Ctx));
181 MCSymbolRefExpr::create(MO.getMBB()->getSymbol(), Ctx));
182182 break;
183183 case MachineOperand::MO_GlobalAddress:
184184 MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
3939 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
4040 const MCSymbol *Sym = TM.getSymbol(GV, Mang);
4141 const MCExpr *Res =
42 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
42 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
4343 MCSymbol *PCSym = getContext().createTempSymbol();
4444 Streamer.EmitLabel(PCSym);
45 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext());
46 return MCBinaryExpr::CreateSub(Res, PC, getContext());
45 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
46 return MCBinaryExpr::createSub(Res, PC, getContext());
4747 }
4848
4949 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
6464 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
6565 // is an indirect pc-relative reference.
6666 const MCExpr *Res =
67 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
67 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
6868 MCSymbol *PCSym = getContext().createTempSymbol();
6969 Streamer.EmitLabel(PCSym);
70 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext());
71 return MCBinaryExpr::CreateSub(Res, PC, getContext());
70 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
71 return MCBinaryExpr::createSub(Res, PC, getContext());
7272 }
20232023 // No modifier was specified at all; this is the syntax for an ELF basic
20242024 // ADRP relocation (unfortunately).
20252025 Expr =
2026 AArch64MCExpr::Create(Expr, AArch64MCExpr::VK_ABS_PAGE, getContext());
2026 AArch64MCExpr::create(Expr, AArch64MCExpr::VK_ABS_PAGE, getContext());
20272027 } else if ((DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGE ||
20282028 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGE) &&
20292029 Addend != 0) {
21562156 if (MCE) {
21572157 int64_t Val = MCE->getValue();
21582158 if (Val > 0xfff && (Val & 0xfff) == 0) {
2159 Imm = MCConstantExpr::Create(Val >> 12, getContext());
2159 Imm = MCConstantExpr::create(Val >> 12, getContext());
21602160 ShiftAmount = 12;
21612161 }
21622162 }
23462346
23472347 #define SYS_ALIAS(op1, Cn, Cm, op2) \
23482348 do { \
2349 Expr = MCConstantExpr::Create(op1, getContext()); \
2349 Expr = MCConstantExpr::create(op1, getContext()); \
23502350 Operands.push_back( \
23512351 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
23522352 Operands.push_back( \
23532353 AArch64Operand::CreateSysCR(Cn, S, getLoc(), getContext())); \
23542354 Operands.push_back( \
23552355 AArch64Operand::CreateSysCR(Cm, S, getLoc(), getContext())); \
2356 Expr = MCConstantExpr::Create(op2, getContext()); \
2356 Expr = MCConstantExpr::create(op2, getContext()); \
23572357 Operands.push_back( \
23582358 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
23592359 } while (0)
28342834 return true;
28352835
28362836 if (HasELFModifier)
2837 ImmVal = AArch64MCExpr::Create(ImmVal, RefKind, getContext());
2837 ImmVal = AArch64MCExpr::create(ImmVal, RefKind, getContext());
28382838
28392839 return false;
28402840 }
31273127 if (ShiftAmt <= MaxShiftAmt && Imm <= 0xFFFF) {
31283128 Operands[0] = AArch64Operand::CreateToken("movz", false, Loc, Ctx);
31293129 Operands.push_back(AArch64Operand::CreateImm(
3130 MCConstantExpr::Create(Imm, Ctx), S, E, Ctx));
3130 MCConstantExpr::create(Imm, Ctx), S, E, Ctx));
31313131 if (ShiftAmt)
31323132 Operands.push_back(AArch64Operand::CreateShiftExtend(AArch64_AM::LSL,
31333133 ShiftAmt, true, S, E, Ctx));
36333633 NewOp4Val = 63 - Op3Val;
36343634 }
36353635
3636 const MCExpr *NewOp3 = MCConstantExpr::Create(NewOp3Val, getContext());
3637 const MCExpr *NewOp4 = MCConstantExpr::Create(NewOp4Val, getContext());
3636 const MCExpr *NewOp3 = MCConstantExpr::create(NewOp3Val, getContext());
3637 const MCExpr *NewOp4 = MCConstantExpr::create(NewOp4Val, getContext());
36383638
36393639 Operands[0] = AArch64Operand::CreateToken(
36403640 "ubfm", false, Op.getStartLoc(), getContext());
36843684 return Error(WidthOp.getStartLoc(),
36853685 "requested insert overflows register");
36863686
3687 const MCExpr *ImmRExpr = MCConstantExpr::Create(ImmR, getContext());
3688 const MCExpr *ImmSExpr = MCConstantExpr::Create(ImmS, getContext());
3687 const MCExpr *ImmRExpr = MCConstantExpr::create(ImmR, getContext());
3688 const MCExpr *ImmSExpr = MCConstantExpr::create(ImmS, getContext());
36893689 Operands[0] = AArch64Operand::CreateToken(
36903690 "bfm", false, Op.getStartLoc(), getContext());
36913691 Operands[2] = AArch64Operand::CreateReg(
37413741 "requested insert overflows register");
37423742
37433743 const MCExpr *NewOp3 =
3744 MCConstantExpr::Create(NewOp3Val, getContext());
3744 MCConstantExpr::create(NewOp3Val, getContext());
37453745 const MCExpr *NewOp4 =
3746 MCConstantExpr::Create(NewOp4Val, getContext());
3746 MCConstantExpr::create(NewOp4Val, getContext());
37473747 Operands[3] = AArch64Operand::CreateImm(
37483748 NewOp3, Op3.getStartLoc(), Op3.getEndLoc(), getContext());
37493749 Operands[4] = AArch64Operand::CreateImm(
37993799 "requested extract overflows register");
38003800
38013801 const MCExpr *NewOp4 =
3802 MCConstantExpr::Create(NewOp4Val, getContext());
3802 MCConstantExpr::create(NewOp4Val, getContext());
38033803 Operands[4] = AArch64Operand::CreateImm(
38043804 NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
38053805 if (Tok == "bfxil")
41054105 return Error(L, "expected symbol after directive");
41064106
41074107 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4108 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, getContext());
4109 Expr = AArch64MCExpr::Create(Expr, AArch64MCExpr::VK_TLSDESC, getContext());
4108 const MCExpr *Expr = MCSymbolRefExpr::create(Sym, getContext());
4109 Expr = AArch64MCExpr::create(Expr, AArch64MCExpr::VK_TLSDESC, getContext());
41104110
41114111 MCInst Inst;
41124112 Inst.setOpcode(AArch64::TLSDESCCALL);
167167 MCSymbol *Sym = Ctx.getOrCreateSymbol(Name);
168168 MCSymbolRefExpr::VariantKind Variant = getVariant(SymbolicOp.VariantKind);
169169 if (Variant != MCSymbolRefExpr::VK_None)
170 Add = MCSymbolRefExpr::Create(Sym, Variant, Ctx);
170 Add = MCSymbolRefExpr::create(Sym, Variant, Ctx);
171171 else
172 Add = MCSymbolRefExpr::Create(Sym, Ctx);
172 Add = MCSymbolRefExpr::create(Sym, Ctx);
173173 } else {
174 Add = MCConstantExpr::Create(SymbolicOp.AddSymbol.Value, Ctx);
174 Add = MCConstantExpr::create(SymbolicOp.AddSymbol.Value, Ctx);
175175 }
176176 }
177177
180180 if (SymbolicOp.SubtractSymbol.Name) {
181181 StringRef Name(SymbolicOp.SubtractSymbol.Name);
182182 MCSymbol *Sym = Ctx.getOrCreateSymbol(Name);
183 Sub = MCSymbolRefExpr::Create(Sym, Ctx);
183 Sub = MCSymbolRefExpr::create(Sym, Ctx);
184184 } else {
185 Sub = MCConstantExpr::Create(SymbolicOp.SubtractSymbol.Value, Ctx);
185 Sub = MCConstantExpr::create(SymbolicOp.SubtractSymbol.Value, Ctx);
186186 }
187187 }
188188
189189 const MCExpr *Off = nullptr;
190190 if (SymbolicOp.Value != 0)
191 Off = MCConstantExpr::Create(SymbolicOp.Value, Ctx);
191 Off = MCConstantExpr::create(SymbolicOp.Value, Ctx);
192192
193193 const MCExpr *Expr;
194194 if (Sub) {
195195 const MCExpr *LHS;
196196 if (Add)
197 LHS = MCBinaryExpr::CreateSub(Add, Sub, Ctx);
198 else
199 LHS = MCUnaryExpr::CreateMinus(Sub, Ctx);
197 LHS = MCBinaryExpr::createSub(Add, Sub, Ctx);
198 else
199 LHS = MCUnaryExpr::createMinus(Sub, Ctx);
200200 if (Off)
201 Expr = MCBinaryExpr::CreateAdd(LHS, Off, Ctx);
201 Expr = MCBinaryExpr::createAdd(LHS, Off, Ctx);
202202 else
203203 Expr = LHS;
204204 } else if (Add) {
205205 if (Off)
206 Expr = MCBinaryExpr::CreateAdd(Add, Off, Ctx);
206 Expr = MCBinaryExpr::createAdd(Add, Off, Ctx);
207207 else
208208 Expr = Add;
209209 } else {
210210 if (Off)
211211 Expr = Off;
212212 else
213 Expr = MCConstantExpr::Create(0, Ctx);
213 Expr = MCConstantExpr::create(0, Ctx);
214214 }
215215
216216 MI.addOperand(MCOperand::createExpr(Expr));
12631263 const MCConstantExpr *BranchTarget =
12641264 dyn_cast(MI->getOperand(OpNum).getExpr());
12651265 int64_t Address;
1266 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
1266 if (BranchTarget && BranchTarget->evaluateAsAbsolute(Address)) {
12671267 O << "0x";
12681268 O.write_hex(Address);
12691269 } else {
495495 // FIXME: Should be replaced with something more principled.
496496 static bool isByteSwappedFixup(const MCExpr *E) {
497497 MCValue Val;
498 if (!E->EvaluateAsRelocatable(Val, nullptr, nullptr))
498 if (!E->evaluateAsRelocatable(Val, nullptr, nullptr))
499499 return false;
500500
501501 if (!Val.getSymA() || Val.getSymA()->getSymbol().isUndefined())
171171 assert(Sec && "need a section");
172172 Symbol->setSection(*Sec);
173173
174 const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
174 const MCExpr *Value = MCSymbolRefExpr::create(Start, getContext());
175175 Symbol->setVariableValue(Value);
176176 }
177177
6161 // version.
6262 MCContext &Context = Streamer.getContext();
6363 const MCExpr *Res =
64 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, Context);
64 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, Context);
6565 MCSymbol *PCSym = Context.createTempSymbol();
6666 Streamer.EmitLabel(PCSym);
67 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
68 return MCBinaryExpr::CreateSub(Res, PC, Context);
67 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
68 return MCBinaryExpr::createSub(Res, PC, Context);
6969 }
7070
7171 AArch64MCAsmInfoELF::AArch64MCAsmInfoELF(StringRef TT) {
2525
2626 #define DEBUG_TYPE "aarch64symbolrefexpr"
2727
28 const AArch64MCExpr *AArch64MCExpr::Create(const MCExpr *Expr, VariantKind Kind,
28 const AArch64MCExpr *AArch64MCExpr::create(const MCExpr *Expr, VariantKind Kind,
2929 MCContext &Ctx) {
3030 return new (Ctx) AArch64MCExpr(Expr, Kind);
3131 }
7575 }
7676 }
7777
78 void AArch64MCExpr::PrintImpl(raw_ostream &OS) const {
78 void AArch64MCExpr::printImpl(raw_ostream &OS) const {
7979 if (getKind() != VK_NONE)
8080 OS << getVariantKindName();
8181 OS << *Expr;
8585 Streamer.visitUsedExpr(*getSubExpr());
8686 }
8787
88 MCSection *AArch64MCExpr::FindAssociatedSection() const {
88 MCSection *AArch64MCExpr::findAssociatedSection() const {
8989 llvm_unreachable("FIXME: what goes here?");
9090 }
9191
92 bool AArch64MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
92 bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
9393 const MCAsmLayout *Layout,
9494 const MCFixup *Fixup) const {
95 if (!getSubExpr()->EvaluateAsRelocatable(Res, Layout, Fixup))
95 if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
9696 return false;
9797
9898 Res =
111111 /// @name Construction
112112 /// @{
113113
114 static const AArch64MCExpr *Create(const MCExpr *Expr, VariantKind Kind,
114 static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
115115 MCContext &Ctx);
116116
117117 /// @}
144144 /// (e.g. ":got:", ":lo12:").
145145 StringRef getVariantKindName() const;
146146
147 void PrintImpl(raw_ostream &OS) const override;
147 void printImpl(raw_ostream &OS) const override;
148148
149149 void visitUsedExpr(MCStreamer &Streamer) const override;
150150
151 MCSection *FindAssociatedSection() const override;
151 MCSection *findAssociatedSection() const override;
152152
153 bool EvaluateAsRelocatableImpl(MCValue &Res,
153 bool evaluateAsRelocatableImpl(MCValue &Res,
154154 const MCAsmLayout *Layout,
155155 const MCFixup *Fixup) const override;
156156
299299 // If the evaluation is an absolute value, just use that directly
300300 // to keep things easy.
301301 int64_t Res;
302 if (Symbol->getVariableValue()->EvaluateAsAbsolute(
302 if (Symbol->getVariableValue()->evaluateAsAbsolute(
303303 Res, Layout, Writer->getSectionAddressMap())) {
304304 FixedValue = Res;
305305 return;
308308 // FIXME: Will the Target we already have ever have any data in it
309309 // we need to preserve and merge with the new Target? How about
310310 // the FixedValue?
311 if (!Symbol->getVariableValue()->EvaluateAsRelocatable(Target, &Layout,
311 if (!Symbol->getVariableValue()->evaluateAsRelocatable(Target, &Layout,
312312 &Fixup))
313313 Asm.getContext().reportFatalError(Fixup.getLoc(),
314314 "unable to resolve variable '" +
355355 // Resolve constant variables.
356356 if (Symbol->isVariable()) {
357357 int64_t Res;
358 if (Symbol->getVariableValue()->EvaluateAsAbsolute(
358 if (Symbol->getVariableValue()->evaluateAsAbsolute(
359359 Res, Layout, Writer->getSectionAddressMap())) {
360360 FixedValue = Res;
361361 return;
8686 const GlobalValue *GV = dyn_cast(CV->stripPointerCasts());
8787 assert(GV && "C++ constructor pointer was not a GlobalValue!");
8888
89 const MCExpr *E = MCSymbolRefExpr::Create(GetARMGVSymbol(GV,
89 const MCExpr *E = MCSymbolRefExpr::create(GetARMGVSymbol(GV,
9090 ARMII::MO_NO_FLAG),
9191 (Subtarget->isTargetELF()
9292 ? MCSymbolRefExpr::VK_ARM_TARGET1
466466 // using NLPs; however, sometimes the types are local to the file.
467467 // We need to fill in the value for the NLP in those cases.
468468 OutStreamer.EmitValue(
469 MCSymbolRefExpr::Create(MCSym.getPointer(), OutStreamer.getContext()),
469 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
470470 4 /*size*/);
471471 }
472472
894894
895895 // Create an MCSymbol for the reference.
896896 const MCExpr *Expr =
897 MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()),
897 MCSymbolRefExpr::create(MCSym, getModifierVariantKind(ACPV->getModifier()),
898898 OutContext);
899899
900900 if (ACPV->getPCAdjustment()) {
902902 getFunctionNumber(),
903903 ACPV->getLabelId(),
904904 OutContext);
905 const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext);
905 const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);
906906 PCRelExpr =
907 MCBinaryExpr::CreateAdd(PCRelExpr,
908 MCConstantExpr::Create(ACPV->getPCAdjustment(),
907 MCBinaryExpr::createAdd(PCRelExpr,
908 MCConstantExpr::create(ACPV->getPCAdjustment(),
909909 OutContext),
910910 OutContext);
911911 if (ACPV->mustAddCurrentAddress()) {
913913 // label, so just emit a local label end reference that instead.
914914 MCSymbol *DotSym = OutContext.createTempSymbol();
915915 OutStreamer->EmitLabel(DotSym);
916 const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext);
917 PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext);
918 }
919 Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext);
916 const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
917 PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);
918 }
919 Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);
920920 }
921921 OutStreamer->EmitValue(Expr, Size);
922922 }
954954 // LJTI_0_0:
955955 // .word (LBB0 - LJTI_0_0)
956956 // .word (LBB1 - LJTI_0_0)
957 const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
957 const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
958958
959959 if (TM.getRelocationModel() == Reloc::PIC_)
960 Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol,
960 Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
961961 OutContext),
962962 OutContext);
963963 // If we're generating a table of Thumb addresses in static relocation
964964 // model, we need to add one to keep interworking correctly.
965965 else if (AFI->isThumbFunction())
966 Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(1,OutContext),
966 Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(1,OutContext),
967967 OutContext);
968968 OutStreamer->EmitValue(Expr, 4);
969969 }
997997
998998 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
999999 MachineBasicBlock *MBB = JTBBs[i];
1000 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(),
1000 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
10011001 OutContext);
10021002 // If this isn't a TBB or TBH, the entries are direct branch instructions.
10031003 if (OffsetWidth == 4) {
10171017 // .byte (LBB0 - LJTI_0_0) / 2
10181018 // .byte (LBB1 - LJTI_0_0) / 2
10191019 const MCExpr *Expr =
1020 MCBinaryExpr::CreateSub(MBBSymbolExpr,
1021 MCSymbolRefExpr::Create(JTISymbol, OutContext),
1020 MCBinaryExpr::createSub(MBBSymbolExpr,
1021 MCSymbolRefExpr::create(JTISymbol, OutContext),
10221022 OutContext);
1023 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext),
1023 Expr = MCBinaryExpr::createDiv(Expr, MCConstantExpr::create(2, OutContext),
10241024 OutContext);
10251025 OutStreamer->EmitValue(Expr, OffsetWidth);
10261026 }
12111211 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
12121212 : ARM::ADR))
12131213 .addReg(MI->getOperand(0).getReg())
1214 .addExpr(MCSymbolRefExpr::Create(CPISymbol, OutContext))
1214 .addExpr(MCSymbolRefExpr::create(CPISymbol, OutContext))
12151215 // Add predicate operands.
12161216 .addImm(MI->getOperand(2).getImm())
12171217 .addReg(MI->getOperand(3).getReg()));
12271227 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
12281228 : ARM::ADR))
12291229 .addReg(MI->getOperand(0).getReg())
1230 .addExpr(MCSymbolRefExpr::Create(JTIPICSymbol, OutContext))
1230 .addExpr(MCSymbolRefExpr::create(JTIPICSymbol, OutContext))
12311231 // Add predicate operands.
12321232 .addImm(MI->getOperand(2).getImm())
12331233 .addReg(MI->getOperand(3).getReg()));
12771277 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)
12781278 // Predicate comes first here.
12791279 .addImm(ARMCC::AL).addReg(0)
1280 .addExpr(MCSymbolRefExpr::Create(TRegSym, OutContext)));
1280 .addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));
12811281 return;
12821282 }
12831283 case ARM::BMOVPCRX_CALL: {
13141314 const GlobalValue *GV = Op.getGlobal();
13151315 const unsigned TF = Op.getTargetFlags();
13161316 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1317 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1317 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
13181318 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)
13191319 .addExpr(GVSymExpr)
13201320 // Add predicate operands.
13311331 unsigned TF = MI->getOperand(1).getTargetFlags();
13321332 const GlobalValue *GV = MI->getOperand(1).getGlobal();
13331333 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1334 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1334 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
13351335
13361336 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
13371337 getFunctionNumber(),
13381338 MI->getOperand(2).getImm(), OutContext);
1339 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1339 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
13401340 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
13411341 const MCExpr *PCRelExpr =
1342 ARMMCExpr::CreateLower16(MCBinaryExpr::CreateSub(GVSymExpr,
1343 MCBinaryExpr::CreateAdd(LabelSymExpr,
1344 MCConstantExpr::Create(PCAdj, OutContext),
1342 ARMMCExpr::createLower16(MCBinaryExpr::createSub(GVSymExpr,
1343 MCBinaryExpr::createAdd(LabelSymExpr,
1344 MCConstantExpr::create(PCAdj, OutContext),
13451345 OutContext), OutContext), OutContext);
13461346 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
13471347
13641364 unsigned TF = MI->getOperand(2).getTargetFlags();
13651365 const GlobalValue *GV = MI->getOperand(2).getGlobal();
13661366 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1367 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1367 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
13681368
13691369 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
13701370 getFunctionNumber(),
13711371 MI->getOperand(3).getImm(), OutContext);
1372 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1372 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
13731373 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
13741374 const MCExpr *PCRelExpr =
1375 ARMMCExpr::CreateUpper16(MCBinaryExpr::CreateSub(GVSymExpr,
1376 MCBinaryExpr::CreateAdd(LabelSymExpr,
1377 MCConstantExpr::Create(PCAdj, OutContext),
1375 ARMMCExpr::createUpper16(MCBinaryExpr::createSub(GVSymExpr,
1376 MCBinaryExpr::createAdd(LabelSymExpr,
1377 MCConstantExpr::create(PCAdj, OutContext),
13781378 OutContext), OutContext), OutContext);
13791379 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
13801380 // Add predicate operands.
16941694 .addImm(ARMCC::AL)
16951695 .addReg(0));
16961696
1697 const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext);
1697 const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);
16981698 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)
16991699 .addExpr(SymbolExpr)
17001700 .addImm(ARMCC::AL)
2929 unsigned Option = MO.getTargetFlags() & ARMII::MO_OPTION_MASK;
3030 switch (Option) {
3131 default: {
32 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,
32 Expr = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None,
3333 OutContext);
3434 switch (Option) {
3535 default: llvm_unreachable("Unknown target flag on symbol operand");
3636 case ARMII::MO_NO_FLAG:
3737 break;
3838 case ARMII::MO_LO16:
39 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,
39 Expr = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None,
4040 OutContext);
41 Expr = ARMMCExpr::CreateLower16(Expr, OutContext);
41 Expr = ARMMCExpr::createLower16(Expr, OutContext);
4242 break;
4343 case ARMII::MO_HI16:
44 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,
44 Expr = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None,
4545 OutContext);
46 Expr = ARMMCExpr::CreateUpper16(Expr, OutContext);
46 Expr = ARMMCExpr::createUpper16(Expr, OutContext);
4747 break;
4848 }
4949 break;
5050 }
5151
5252 case ARMII::MO_PLT:
53 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_PLT,
53 Expr = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_PLT,
5454 OutContext);
5555 break;
5656 }
5757
5858 if (!MO.isJTI() && MO.getOffset())
59 Expr = MCBinaryExpr::CreateAdd(Expr,
60 MCConstantExpr::Create(MO.getOffset(),
59 Expr = MCBinaryExpr::createAdd(Expr,
60 MCConstantExpr::create(MO.getOffset(),
6161 OutContext),
6262 OutContext);
6363 return MCOperand::createExpr(Expr);
7979 MCOp = MCOperand::createImm(MO.getImm());
8080 break;
8181 case MachineOperand::MO_MachineBasicBlock:
82 MCOp = MCOperand::createExpr(MCSymbolRefExpr::Create(
82 MCOp = MCOperand::createExpr(MCSymbolRefExpr::create(
8383 MO.getMBB()->getSymbol(), OutContext));
8484 break;
8585 case MachineOperand::MO_GlobalAddress: {
4949
5050 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
5151
52 return MCSymbolRefExpr::Create(TM.getSymbol(GV, Mang),
52 return MCSymbolRefExpr::create(TM.getSymbol(GV, Mang),
5353 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
5454 }
5555
5656 const MCExpr *ARMElfTargetObjectFile::
5757 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
58 return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
58 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
5959 getContext());
6060 }
42514251 Error(S, "'be' or 'le' operand expected");
42524252 return MatchOperand_ParseFail;
42534253 }
4254 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4254 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::create(Val,
42554255 getContext()),
42564256 S, Tok.getEndLoc()));
42574257 return MatchOperand_Success;
46554655 Val = INT32_MIN;
46564656
46574657 Operands.push_back(
4658 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4658 ARMOperand::CreateImm(MCConstantExpr::create(Val, getContext()), S, E));
46594659
46604660 return MatchOperand_Success;
46614661 }
48854885 // If the constant was #-0, represent it as INT32_MIN.
48864886 int32_t Val = CE->getValue();
48874887 if (isNegative && Val == 0)
4888 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4888 CE = MCConstantExpr::create(INT32_MIN, getContext());
48894889
48904890 // Now we should have the closing ']'
48914891 if (Parser.getTok().isNot(AsmToken::RBrac))
50725072 IntVal ^= (uint64_t)isNegative << 31;
50735073 Parser.Lex(); // Eat the token.
50745074 Operands.push_back(ARMOperand::CreateImm(
5075 MCConstantExpr::Create(IntVal, getContext()),
5075 MCConstantExpr::create(IntVal, getContext()),
50765076 S, Parser.getTok().getLoc()));
50775077 return MatchOperand_Success;
50785078 }
50895089 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
50905090
50915091 Operands.push_back(ARMOperand::CreateImm(
5092 MCConstantExpr::Create(Val, getContext()), S,
5092 MCConstantExpr::create(Val, getContext()), S,
50935093 Parser.getTok().getLoc()));
50945094 return MatchOperand_Success;
50955095 }
51785178 if (CE) {
51795179 int32_t Val = CE->getValue();
51805180 if (isNegative && Val == 0)
5181 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5181 ImmVal = MCConstantExpr::create(INT32_MIN, getContext());
51825182 }
51835183 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
51845184 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
52085208 if (getParser().parseExpression(SubExprVal))
52095209 return true;
52105210
5211 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
5211 const MCExpr *ExprVal = ARMMCExpr::create(RefKind, SubExprVal,
52125212 getContext());
52135213 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
52145214 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
57645764 // Add the processor imod operand, if necessary.
57655765 if (ProcessorIMod) {
57665766 Operands.push_back(ARMOperand::CreateImm(
5767 MCConstantExpr::Create(ProcessorIMod, getContext()),
5767 MCConstantExpr::create(ProcessorIMod, getContext()),
57685768 NameLoc, NameLoc));
57695769 } else if (Mnemonic == "cps" && isMClass()) {
57705770 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
67516751 MCSymbol *Dot = getContext().createTempSymbol();
67526752 Out.EmitLabel(Dot);
67536753 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6754 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6754 const MCExpr *InstPC = MCSymbolRefExpr::create(Dot,
67556755 MCSymbolRefExpr::VK_None,
67566756 getContext());
6757 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6758 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6757 const MCExpr *Const8 = MCConstantExpr::create(8, getContext());
6758 const MCExpr *ReadPC = MCBinaryExpr::createAdd(InstPC, Const8,
67596759 getContext());
6760 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6760 const MCExpr *FixupAddr = MCBinaryExpr::createAdd(ReadPC, OpExpr,
67616761 getContext());
67626762 TmpInst.addOperand(MCOperand::createExpr(FixupAddr));
67636763 }
98039803 }
98049804
98059805 const MCSymbolRefExpr *SRE =
9806 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9806 MCSymbolRefExpr::create(Parser.getTok().getIdentifier(),
98079807 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
98089808 Lex();
98099809
1007910079 if (Op.isImm()) {
1008010080 const MCExpr *SOExpr = Op.getImm();
1008110081 int64_t Value;
10082 if (!SOExpr->EvaluateAsAbsolute(Value))
10082 if (!SOExpr->evaluateAsAbsolute(Value))
1008310083 return Match_Success;
1008410084 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
1008510085 "expression value must be representable in 32 bits");
336336 // address.
337337 const MCConstantExpr *Constant = cast(Expr);
338338 int64_t TargetAddress;
339 if (!Constant->EvaluateAsAbsolute(TargetAddress)) {
339 if (!Constant->evaluateAsAbsolute(TargetAddress)) {
340340 O << '#' << *Expr;
341341 } else {
342342 O << "0x";
571571 Symbol->setExternal(false);
572572 AssignSection(Symbol, getCurrentSection().first);
573573
574 const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
574 const MCExpr *Value = MCSymbolRefExpr::create(Start, getContext());
575575 Symbol->setVariableValue(Value);
576576 }
577577
10941094 EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
10951095
10961096 const MCSymbolRefExpr *FnStartRef =
1097 MCSymbolRefExpr::Create(FnStart,
1097 MCSymbolRefExpr::create(FnStart,
10981098 MCSymbolRefExpr::VK_ARM_PREL31,
10991099 getContext());
11001100
11051105 } else if (ExTab) {
11061106 // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
11071107 const MCSymbolRefExpr *ExTabEntryRef =
1108 MCSymbolRefExpr::Create(ExTab,
1108 MCSymbolRefExpr::create(ExTab,
11091109 MCSymbolRefExpr::VK_ARM_PREL31,
11101110 getContext());
11111111 EmitValue(ExTabEntryRef, 4);
11371137 void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
11381138 const MCSymbol *PersonalitySym = getContext().getOrCreateSymbol(Name);
11391139
1140 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
1140 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::create(
11411141 PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
11421142
11431143 visitUsedExpr(*PersonalityRef);
11851185 // Emit personality
11861186 if (Personality) {
11871187 const MCSymbolRefExpr *PersonalityRef =
1188 MCSymbolRefExpr::Create(Personality,
1188 MCSymbolRefExpr::create(Personality,
11891189 MCSymbolRefExpr::VK_ARM_PREL31,
11901190 getContext());
11911191
1515 #define DEBUG_TYPE "armmcexpr"
1616
1717 const ARMMCExpr*
18 ARMMCExpr::Create(VariantKind Kind, const MCExpr *Expr,
18 ARMMCExpr::create(VariantKind Kind, const MCExpr *Expr,
1919 MCContext &Ctx) {
2020 return new (Ctx) ARMMCExpr(Kind, Expr);
2121 }
2222
23 void ARMMCExpr::PrintImpl(raw_ostream &OS) const {
23 void ARMMCExpr::printImpl(raw_ostream &OS) const {
2424 switch (Kind) {
2525 default: llvm_unreachable("Invalid kind!");
2626 case VK_ARM_HI16: OS << ":upper16:"; break;
3232 /// @name Construction
3333 /// @{
3434
35 static const ARMMCExpr *Create(VariantKind Kind, const MCExpr *Expr,
35 static const ARMMCExpr *create(VariantKind Kind, const MCExpr *Expr,
3636 MCContext &Ctx);
3737
38 static const ARMMCExpr *CreateUpper16(const MCExpr *Expr, MCContext &Ctx) {
39 return Create(VK_ARM_HI16, Expr, Ctx);
38 static const ARMMCExpr *createUpper16(const MCExpr *Expr, MCContext &Ctx) {
39 return create(VK_ARM_HI16, Expr, Ctx);
4040 }
4141
42 static const ARMMCExpr *CreateLower16(const MCExpr *Expr, MCContext &Ctx) {
43 return Create(VK_ARM_LO16, Expr, Ctx);
42 static const ARMMCExpr *createLower16(const MCExpr *Expr, MCContext &Ctx) {
43 return create(VK_ARM_LO16, Expr, Ctx);
4444 }
4545
4646 /// @}
5555
5656 /// @}
5757
58 void PrintImpl(raw_ostream &OS) const override;
59 bool EvaluateAsRelocatableImpl(MCValue &Res,
58 void printImpl(raw_ostream &OS) const override;
59 bool evaluateAsRelocatableImpl(MCValue &Res,
6060 const MCAsmLayout *Layout,
6161 const MCFixup *Fixup) const override {
6262 return false;
6363 }
6464 void visitUsedExpr(MCStreamer &Streamer) const override;
65 MCSection *FindAssociatedSection() const override {
66 return getSubExpr()->FindAssociatedSection();
65 MCSection *findAssociatedSection() const override {
66 return getSubExpr()->findAssociatedSection();
6767 }
6868
6969 // There are no TLS ARMMCExprs at the moment.
2525 unsigned VariantKind) override {
2626 switch(VariantKind) {
2727 case LLVMDisassembler_VariantKind_ARM_HI16:
28 return ARMMCExpr::CreateUpper16(SubExpr, Ctx);
28 return ARMMCExpr::createUpper16(SubExpr, Ctx);
2929 case LLVMDisassembler_VariantKind_ARM_LO16:
30 return ARMMCExpr::CreateLower16(SubExpr, Ctx);
30 return ARMMCExpr::createLower16(SubExpr, Ctx);
3131 default:
3232 return MCRelocationInfo::createExprForCAPIVariantKind(SubExpr,
3333 VariantKind);
400400 // Resolve constant variables.
401401 if (A->isVariable()) {
402402 int64_t Res;
403 if (A->getVariableValue()->EvaluateAsAbsolute(
403 if (A->getVariableValue()->evaluateAsAbsolute(
404404 Res, Layout, Writer->getSectionAddressMap())) {
405405 FixedValue = Res;
406406 return;
3030 MCContext &MC = Printer.OutContext;
3131 const MCExpr *ME;
3232
33 ME = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, MC);
33 ME = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None, MC);
3434
3535 if (!MO.isJTI() && MO.getOffset())
36 ME = MCBinaryExpr::CreateAdd(ME, MCConstantExpr::Create(MO.getOffset(), MC),
36 ME = MCBinaryExpr::createAdd(ME, MCConstantExpr::create(MO.getOffset(), MC),
3737 MC);
3838
3939 return (MCOperand::createExpr(ME));
8080 break;
8181 case MachineOperand::MO_MachineBasicBlock:
8282 MCO = MCOperand::createExpr
83 (MCSymbolRefExpr::Create(MO.getMBB()->getSymbol(),
83 (MCSymbolRefExpr::create(MO.getMBB()->getSymbol(),
8484 AP.OutContext));
8585 break;
8686 case MachineOperand::MO_GlobalAddress:
276276 {
277277 int64_t Res;
278278
279 if (ME->EvaluateAsAbsolute(Res))
279 if (ME->evaluateAsAbsolute(Res))
280280 return Res;
281281
282282 MCExpr::ExprKind MK = ME->getKind();
9595 LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const {
9696 // FIXME: We would like an efficient form for this, so we don't have to do a
9797 // lot of extra uniquing.
98 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, Ctx);
98 const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
9999
100100 switch (MO.getTargetFlags()) {
101101 default: llvm_unreachable("Unknown target flag on GV operand");
103103 }
104104
105105 if (!MO.isJTI() && MO.getOffset())
106 Expr = MCBinaryExpr::CreateAdd(Expr,
107 MCConstantExpr::Create(MO.getOffset(), Ctx),
106 Expr = MCBinaryExpr::createAdd(Expr,
107 MCConstantExpr::create(MO.getOffset(), Ctx),
108108 Ctx);
109109 return MCOperand::createExpr(Expr);
110110 }
129129 MCOp = MCOperand::createImm(MO.getImm());
130130 break;
131131 case MachineOperand::MO_MachineBasicBlock:
132 MCOp = MCOperand::createExpr(MCSymbolRefExpr::Create(
132 MCOp = MCOperand::createExpr(MCSymbolRefExpr::create(
133133 MO.getMBB()->getSymbol(), Ctx));
134134 break;
135135 case MachineOperand::MO_GlobalAddress:
19451945 unsigned RegNo = DstRegOp.getReg();
19461946 const MCSymbolRefExpr *Symbol = cast(SymOp.getExpr());
19471947 const MCSymbolRefExpr *HiExpr =
1948 MCSymbolRefExpr::Create(Symbol->getSymbol().getName(),
1948 MCSymbolRefExpr::create(Symbol->getSymbol().getName(),
19491949 MCSymbolRefExpr::VK_Mips_ABS_HI, getContext());
19501950 const MCSymbolRefExpr *LoExpr =
1951 MCSymbolRefExpr::Create(Symbol->getSymbol().getName(),
1951 MCSymbolRefExpr::create(Symbol->getSymbol().getName(),
19521952 MCSymbolRefExpr::VK_Mips_ABS_LO, getContext());
19531953 if (!Is32BitSym) {
19541954 // If it's a 64-bit architecture, expand to:
19591959 // dsll d,d,16
19601960 // ori d,d,lo16(sym)
19611961 const MCSymbolRefExpr *HighestExpr =
1962 MCSymbolRefExpr::Create(Symbol->getSymbol().getName(),
1962 MCSymbolRefExpr::create(Symbol->getSymbol().getName(),
19631963 MCSymbolRefExpr::VK_Mips_HIGHEST, getContext());
19641964 const MCSymbolRefExpr *HigherExpr =
1965 MCSymbolRefExpr::Create(Symbol->getSymbol().getName(),
1965 MCSymbolRefExpr::create(Symbol->getSymbol().getName(),
19661966 MCSymbolRefExpr::VK_Mips_HIGHER, getContext());
19671967
19681968 tmpInst.setOpcode(Mips::LUi);
21012101 else {
21022102 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
21032103 SR = static_cast(ExprOffset);
2104 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
2104 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
21052105 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_HI,
21062106 getContext());
21072107 TempInst.addOperand(MCOperand::createExpr(HiExpr));
21322132 TempInst.addOperand(MCOperand::createImm(LoOffset));
21332133 else {
21342134 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
2135 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
2135 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
21362136 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_LO,
21372137 getContext());
21382138 TempInst.addOperand(MCOperand::createExpr(LoExpr));
25042504 MCSymbol *Sym = getContext().getOrCreateSymbol("$" + Identifier);
25052505 // Otherwise create a symbol reference.
25062506 const MCExpr *Res =
2507 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
2507 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
25082508
25092509 Operands.push_back(MipsOperand::CreateImm(Res, S, E, *this));
25102510 return false;
25642564 default:
25652565 report_fatal_error("unsupported reloc value");
25662566 }
2567 return MCConstantExpr::Create(Val, getContext());
2567 return MCConstantExpr::create(Val, getContext());
25682568 }
25692569
25702570 if (const MCSymbolRefExpr *MSRE = dyn_cast(Expr)) {
25712571 // It's a symbol, create a symbolic expression from the symbol.
25722572 StringRef Symbol = MSRE->getSymbol().getName();
25732573 MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
2574 Res = MCSymbolRefExpr::Create(Symbol, VK, getContext());
2574 Res = MCSymbolRefExpr::create(Symbol, VK, getContext());
25752575 return Res;
25762576 }
25772577
25802580
25812581 // Try to create target expression.
25822582 if (MipsMCExpr::isSupportedBinaryExpr(VK, BE))
2583 return MipsMCExpr::Create(VK, Expr, getContext());
2583 return MipsMCExpr::create(VK, Expr, getContext());
25842584
25852585 const MCExpr *LExp = evaluateRelocExpr(BE->getLHS(), RelocStr);
25862586 const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
2587 Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
2587 Res = MCBinaryExpr::create(BE->getOpcode(), LExp, RExp, getContext());
25882588 return Res;
25892589 }
25902590
25912591 if (const MCUnaryExpr *UN = dyn_cast(Expr)) {
25922592 const MCExpr *UnExp = evaluateRelocExpr(UN->getSubExpr(), RelocStr);
2593 Res = MCUnaryExpr::Create(UN->getOpcode(), UnExp, getContext());
2593 Res = MCUnaryExpr::create(UN->getOpcode(), UnExp, getContext());
25942594 return Res;
25952595 }
25962596 // Just return the original expression.
27782778 Parser.Lex(); // Eat the ')' token.
27792779
27802780 if (!IdVal)
2781 IdVal = MCConstantExpr::Create(0, getContext());
2781 IdVal = MCConstantExpr::create(0, getContext());
27822782
27832783 // Replace the register operand with the memory operand.
27842784 std::unique_ptr op(
27892789 // Add the memory operand.
27902790 if (const MCBinaryExpr *BE = dyn_cast(IdVal)) {
27912791 int64_t Imm;
2792 if (IdVal->EvaluateAsAbsolute(Imm))
2793 IdVal = MCConstantExpr::Create(Imm, getContext());
2792 if (IdVal->evaluateAsAbsolute(Imm))
2793 IdVal = MCConstantExpr::create(Imm, getContext());
27942794 else if (BE->getLHS()->getKind() != MCExpr::SymbolRef)
2795 IdVal = MCBinaryExpr::Create(BE->getOpcode(), BE->getRHS(), BE->getLHS(),
2795 IdVal = MCBinaryExpr::create(BE->getOpcode(), BE->getRHS(), BE->getLHS(),
27962796 getContext());
27972797 }
27982798
30093009 int64_t Val = MCE->getValue();
30103010 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
30113011 Operands.push_back(MipsOperand::CreateImm(
3012 MCConstantExpr::Create(0 - Val, getContext()), S, E, *this));
3012 MCConstantExpr::create(0 - Val, getContext()), S, E, *this));
30133013 return MatchOperand_Success;
30143014 }
30153015
30333033 return MatchOperand_ParseFail;
30343034
30353035 int64_t Val;
3036 if (!Expr->EvaluateAsAbsolute(Val)) {
3036 if (!Expr->evaluateAsAbsolute(Val)) {
30373037 Error(S, "expected immediate value");
30383038 return MatchOperand_ParseFail;
30393039 }
42854285 reportParseError("expected number after comma");
42864286 return false;
42874287 }
4288 if (!DummyNumber->EvaluateAsAbsolute(DummyNumberVal)) {
4288 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
42894289 reportParseError("expected an absolute expression after comma");
42904290 return false;
42914291 }
43654365 return false;
43664366 }
43674367
4368 if (!FrameSize->EvaluateAsAbsolute(FrameSizeVal)) {
4368 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
43694369 reportParseError("frame size not an absolute expression");
43704370 return false;
43714371 }
44264426 return false;
44274427 }
44284428
4429 if (!BitMask->EvaluateAsAbsolute(BitMaskVal)) {
4429 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
44304430 reportParseError("bitmask not an absolute expression");
44314431 return false;
44324432 }
44474447 return false;
44484448 }
44494449
4450 if (!FrameOffset->EvaluateAsAbsolute(FrameOffsetVal)) {
4450 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
44514451 reportParseError("frame offset not an absolute expression");
44524452 return false;
44534453 }
466466 const MCSubtargetInfo &STI) const {
467467 int64_t Res;
468468
469 if (Expr->EvaluateAsAbsolute(Res))
469 if (Expr->evaluateAsAbsolute(Res))
470470 return Res;
471471
472472 MCExpr::ExprKind Kind = Expr->getKind();
4040 }
4141
4242 const MipsMCExpr*
43 MipsMCExpr::Create(MCSymbolRefExpr::VariantKind VK, const MCExpr *Expr,
43 MipsMCExpr::create(MCSymbolRefExpr::VariantKind VK, const MCExpr *Expr,
4444 MCContext &Ctx) {
4545 VariantKind Kind;
4646 switch (VK) {
6363 return new (Ctx) MipsMCExpr(Kind, Expr);
6464 }
6565
66 void MipsMCExpr::PrintImpl(raw_ostream &OS) const {
66 void MipsMCExpr::printImpl(raw_ostream &OS) const {
6767 switch (Kind) {
6868 default: llvm_unreachable("Invalid kind!");
6969 case VK_Mips_LO: OS << "%lo"; break;
7878 }
7979
8080 bool
81 MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
81 MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
8282 const MCAsmLayout *Layout,
8383 const MCFixup *Fixup) const {
84 return getSubExpr()->EvaluateAsRelocatable(Res, Layout, Fixup);
84 return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
8585 }
8686
8787 void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
3636 static bool isSupportedBinaryExpr(MCSymbolRefExpr::VariantKind VK,
3737 const MCBinaryExpr *BE);
3838
39 static const MipsMCExpr *Create(MCSymbolRefExpr::VariantKind VK,
39 static const MipsMCExpr *create(MCSymbolRefExpr::VariantKind VK,
4040 const MCExpr *Expr, MCContext &Ctx);
4141
4242 /// getOpcode - Get the kind of this expression.
4545 /// getSubExpr - Get the child of this expression.
4646 const MCExpr *getSubExpr() const { return Expr; }
4747
48 void PrintImpl(raw_ostream &OS) const override;
49 bool EvaluateAsRelocatableImpl(MCValue &Res,
48 void printImpl(raw_ostream &OS) const override;
49 bool evaluateAsRelocatableImpl(MCValue &Res,
5050 const MCAsmLayout *Layout,
5151 const MCFixup *Fixup) const override;
5252 void visitUsedExpr(MCStreamer &Streamer) const override;
53 MCSection *FindAssociatedSection() const override {
54 return getSubExpr()->FindAssociatedSection();
53 MCSection *findAssociatedSection() const override {
54 return getSubExpr()->findAssociatedSection();
5555 }
5656
5757 // There are no TLS MipsMCExprs at the moment.
563563 ELF::SHF_ALLOC | ELF::SHT_REL);
564564
565565 const MCSymbolRefExpr *ExprRef =
566 MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
566 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
567567
568568 MCA.registerSection(*Sec);
569569 Sec->setAlignment(4);
693693 MCInst TmpInst;
694694 TmpInst.setOpcode(Mips::LUi);
695695 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
696 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::Create(
696 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
697697 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
698698 TmpInst.addOperand(MCOperand::createExpr(HiSym));
699699 getStreamer().EmitInstruction(TmpInst, STI);
703703 TmpInst.setOpcode(Mips::ADDiu);
704704 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
705705 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
706 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::Create(
706 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
707707 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
708708 TmpInst.addOperand(MCOperand::createExpr(LoSym));
709709 getStreamer().EmitInstruction(TmpInst, STI);
747747 getStreamer().EmitInstruction(Inst, STI);
748748 Inst.clear();
749749
750 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
750 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
751751 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
752 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
752 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
753753 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
754754
755755 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
777777 MCInst I;
778778 I.setOpcode(Mips::JAL);
779779 I.addOperand(
780 MCOperand::createExpr(MCSymbolRefExpr::Create(Symbol, OutContext)));
780 MCOperand::createExpr(MCSymbolRefExpr::create(Symbol, OutContext)));
781781 OutStreamer->EmitInstruction(I, STI);
782782 }
783783
10271027
10281028 MCSymbol *Tmp = OutContext.createTempSymbol();
10291029 OutStreamer->EmitLabel(Tmp);
1030 const MCSymbolRefExpr *E = MCSymbolRefExpr::Create(Stub, OutContext);
1031 const MCSymbolRefExpr *T = MCSymbolRefExpr::Create(Tmp, OutContext);
1032 const MCExpr *T_min_E = MCBinaryExpr::CreateSub(T, E, OutContext);
1030 const MCSymbolRefExpr *E = MCSymbolRefExpr::create(Stub, OutContext);
1031 const MCSymbolRefExpr *T = MCSymbolRefExpr::create(Tmp, OutContext);
1032 const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
10331033 OutStreamer->EmitELFSize(Stub, T_min_E);
10341034 TS.emitDirectiveEnd(x);
10351035 OutStreamer->PopSection();
100100 llvm_unreachable("");
101101 }
102102
103 const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::Create(Symbol, Kind, *Ctx);
103 const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol, Kind, *Ctx);
104104
105105 if (!Offset)
106106 return MCOperand::createExpr(MCSym);
108108 // Assume offset is never negative.
109109 assert(Offset > 0);
110110
111 const MCConstantExpr *OffsetExpr = MCConstantExpr::Create(Offset, *Ctx);
112 const MCBinaryExpr *Add = MCBinaryExpr::CreateAdd(MCSym, OffsetExpr, *Ctx);
111 const MCConstantExpr *OffsetExpr = MCConstantExpr::create(Offset, *Ctx);
112 const MCBinaryExpr *Add = MCBinaryExpr::createAdd(MCSym, OffsetExpr, *Ctx);
113113 return MCOperand::createExpr(Add);
114114 }
115115
154154 MCOperand MipsMCInstLower::createSub(MachineBasicBlock *BB1,
155155 MachineBasicBlock *BB2,
156156 MCSymbolRefExpr::VariantKind Kind) const {
157 const MCSymbolRefExpr *Sym1 = MCSymbolRefExpr::Create(BB1->getSymbol(), *Ctx);
158 const MCSymbolRefExpr *Sym2 = MCSymbolRefExpr::Create(BB2->getSymbol(), *Ctx);
159 const MCBinaryExpr *Sub = MCBinaryExpr::CreateSub(Sym1, Sym2, *Ctx);
160
161 return MCOperand::createExpr(MipsMCExpr::Create(Kind, Sub, *Ctx));
157 const MCSymbolRefExpr *Sym1 = MCSymbolRefExpr::create(BB1->getSymbol(), *Ctx);
158 const MCSymbolRefExpr *Sym2 = MCSymbolRefExpr::create(BB2->getSymbol(), *Ctx);
159 const MCBinaryExpr *Sub = MCBinaryExpr::createSub(Sym1, Sym2, *Ctx);
160
161 return MCOperand::createExpr(MipsMCExpr::create(Kind, Sub, *Ctx));
162162 }
163163
164164 void MipsMCInstLower::
265265 MCOp = MCOperand::createImm(MO.getImm());
266266 break;
267267 case MachineOperand::MO_MachineBasicBlock:
268 MCOp = MCOperand::createExpr(MCSymbolRefExpr::Create(
268 MCOp = MCOperand::createExpr(MCSymbolRefExpr::create(
269269 MO.getMBB()->getSymbol(), OutContext));
270270 break;
271271 case MachineOperand::MO_ExternalSymbol:
282282 default: report_fatal_error("Unsupported FP type"); break;
283283 case Type::FloatTyID:
284284 MCOp = MCOperand::createExpr(
285 NVPTXFloatMCExpr::CreateConstantFPSingle(Val, OutContext));
285 NVPTXFloatMCExpr::createConstantFPSingle(Val, OutContext));
286286 break;
287287 case Type::DoubleTyID:
288288 MCOp = MCOperand::createExpr(
289 NVPTXFloatMCExpr::CreateConstantFPDouble(Val, OutContext));
289 NVPTXFloatMCExpr::createConstantFPDouble(Val, OutContext));
290290 break;
291291 }
292292 break;
333333
334334 MCOperand NVPTXAsmPrinter::GetSymbolRef(const MCSymbol *Symbol) {
335335 const MCExpr *Expr;
336 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,
336 Expr = MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None,
337337 OutContext);
338338 return MCOperand::createExpr(Expr);
339339 }
19901990 MCContext &Ctx = OutContext;
19911991
19921992 if (CV->isNullValue() || isa(CV))
1993 return MCConstantExpr::Create(0, Ctx);
1993 return MCConstantExpr::create(0, Ctx);
19941994
19951995 if (const ConstantInt *CI = dyn_cast(CV))
1996 return MCConstantExpr::Create(CI->getZExtValue(), Ctx);
1996 return MCConstantExpr::create(CI->getZExtValue(), Ctx);
19971997
19981998 if (const GlobalValue *GV = dyn_cast(CV)) {
19991999 const MCSymbolRefExpr *Expr =
2000 MCSymbolRefExpr::Create(getSymbol(GV), Ctx);
2000 MCSymbolRefExpr::create(getSymbol(GV), Ctx);
20012001 if (ProcessingGeneric) {
2002 return NVPTXGenericMCSymbolRefExpr::Create(Expr, Ctx);
2002 return NVPTXGenericMCSymbolRefExpr::create(Expr, Ctx);
20032003 } else {
20042004 return Expr;
20052005 }
20562056 return Base;
20572057
20582058 int64_t Offset = OffsetAI.getSExtValue();
2059 return MCBinaryExpr::CreateAdd(Base, MCConstantExpr::Create(Offset, Ctx),
2059 return MCBinaryExpr::createAdd(Base, MCConstantExpr::create(Offset, Ctx),
20602060 Ctx);
20612061 }
20622062
20992099 // the high bits so we are sure to get a proper truncation if the input is
21002100 // a constant expr.
21012101 unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType());
2102 const MCExpr *MaskExpr = MCConstantExpr::Create(~0ULL >> (64-InBits), Ctx);
2103 return MCBinaryExpr::CreateAnd(OpExpr, MaskExpr, Ctx);
2102 const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx);
2103 return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx);
21042104 }
21052105
21062106 // The MC library also has a right-shift operator, but it isn't consistently
21102110 const MCExpr *RHS = lowerConstantForGV(CE->getOperand(1), ProcessingGeneric);
21112111 switch (CE->getOpcode()) {
21122112 default: llvm_unreachable("Unknown binary operator constant cast expr");
2113 case Instruction::Add: return MCBinaryExpr::CreateAdd(LHS, RHS, Ctx);
2113 case Instruction::Add: return MCBinaryExpr::createAdd(LHS, RHS, Ctx);
21142114 }
21152115 }
21162116 }
21202120 void NVPTXAsmPrinter::printMCExpr(const MCExpr &Expr, raw_ostream &OS) {
21212121 switch (Expr.getKind()) {
21222122 case MCExpr::Target:
2123 return cast(&Expr)->PrintImpl(OS);
2123 return cast(&Expr)->printImpl(OS);
21242124 case MCExpr::Constant:
21252125 OS << cast(Expr).getValue();
21262126 return;
1515 #define DEBUG_TYPE "nvptx-mcexpr"
1616
1717 const NVPTXFloatMCExpr*
18 NVPTXFloatMCExpr::Create(VariantKind Kind, APFloat Flt, MCContext &Ctx) {
18 NVPTXFloatMCExpr::create(VariantKind Kind, APFloat Flt, MCContext &Ctx) {
1919 return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
2020 }
2121
22 void NVPTXFloatMCExpr::PrintImpl(raw_ostream &OS) const {
22 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS) const {
2323 bool Ignored;
2424 unsigned NumHex;
2525 APFloat APF = getAPFloat();
4646 }
4747
4848 const NVPTXGenericMCSymbolRefExpr*
49 NVPTXGenericMCSymbolRefExpr::Create(const MCSymbolRefExpr *SymExpr,
49 NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr *SymExpr,
5050 MCContext &Ctx) {
5151 return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
5252 }
5353
54 void NVPTXGenericMCSymbolRefExpr::PrintImpl(raw_ostream &OS) const {
54 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS) const {
5555 OS << "generic(" << *SymExpr << ")";
5656 }
3535 /// @name Construction
3636 /// @{
3737
38 static const NVPTXFloatMCExpr *Create(VariantKind Kind, APFloat Flt,
38 static const NVPTXFloatMCExpr *create(VariantKind Kind, APFloat Flt,
3939 MCContext &Ctx);
4040
41 static const NVPTXFloatMCExpr *CreateConstantFPSingle(APFloat Flt,
41 static const NVPTXFloatMCExpr *createConstantFPSingle(APFloat Flt,
4242 MCContext &Ctx) {
43 return Create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
43 return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
4444 }
4545
46 static const NVPTXFloatMCExpr *CreateConstantFPDouble(APFloat Flt,
46 static const NVPTXFloatMCExpr *createConstantFPDouble(APFloat Flt,
4747 MCContext &Ctx) {
48 return Create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
48 return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
4949 }
5050
5151 /// @}
6060
6161 /// @}
6262
63 void PrintImpl(raw_ostream &OS) const override;
64 bool EvaluateAsRelocatableImpl(MCValue &Res,
63 void printImpl(raw_ostream &OS) const override;
64 bool evaluateAsRelocatableImpl(MCValue &Res,
6565 const MCAsmLayout *Layout,
6666 const MCFixup *Fixup) const override {
6767 return false;
6868 }
6969 void visitUsedExpr(MCStreamer &Streamer) const override {};
70 MCSection *FindAssociatedSection() const override { return nullptr; }
70 MCSection *findAssociatedSection() const override { return nullptr; }
7171
7272 // There are no TLS NVPTXMCExprs at the moment.
7373 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
9191 /// @{
9292
9393 static const NVPTXGenericMCSymbolRefExpr
94 *Create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
94 *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
9595
9696 /// @}
9797 /// @name Accessors
102102
103103 /// @}
104104
105 void PrintImpl(raw_ostream &OS) const override;
106 bool EvaluateAsRelocatableImpl(MCValue &Res,
105 void printImpl(raw_ostream &OS) const override;
106 bool evaluateAsRelocatableImpl(MCValue &Res,
107107 const MCAsmLayout *Layout,
108108 const MCFixup *Fixup) const override {
109109 return false;
110110 }
111111 void visitUsedExpr(MCStreamer &Streamer) const override {};
112 MCSection *FindAssociatedSection() const override { return nullptr; }
112 MCSection *findAssociatedSection() const override { return nullptr; }
113113
114114 // There are no TLS NVPTXMCExprs at the moment.
115115 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
771771
772772 if (const PPCMCExpr *TE = dyn_cast(Val)) {
773773 int64_t Res;
774 if (TE->EvaluateAsConstant(Res))
774 if (TE->evaluateAsConstant(Res))
775775 return CreateContextImm(Res, S, E, IsPPC64);
776776 }
777777
813813 }
814814 } else if (const MCBinaryExpr *BinExpr = dyn_cast(Expr)) {
815815 if (BinExpr->getOpcode() == MCBinaryExpr::Sub) {
816 const MCExpr *NE = MCBinaryExpr::CreateSub(BinExpr->getRHS(),
816 const MCExpr *NE = MCBinaryExpr::createSub(BinExpr->getRHS(),
817817 BinExpr->getLHS(), Ctx);
818818 Inst.addOperand(MCOperand::createExpr(NE));
819819 return;
820820 }
821821 }
822 Inst.addOperand(MCOperand::createExpr(MCUnaryExpr::CreateMinus(Expr, Ctx)));
822 Inst.addOperand(MCOperand::createExpr(MCUnaryExpr::createMinus(Expr, Ctx)));
823823 }
824824
825825 void PPCAsmParser::ProcessInstruction(MCInst &Inst,
13291329 return nullptr;
13301330 }
13311331
1332 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Context);
1332 return MCSymbolRefExpr::create(&SRE->getSymbol(), Context);
13331333 }
13341334
13351335 case MCExpr::Unary: {
13371337 const MCExpr *Sub = ExtractModifierFromExpr(UE->getSubExpr(), Variant);
13381338 if (!Sub)
13391339 return nullptr;
1340 return MCUnaryExpr::Create(UE->getOpcode(), Sub, Context);
1340 return MCUnaryExpr::create(UE->getOpcode(), Sub, Context);
13411341 }
13421342
13431343 case MCExpr::Binary: {
13611361 else
13621362 return nullptr;
13631363
1364 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, Context);
1364 return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, Context);
13651365 }
13661366 }
13671367
13951395 default:
13961396 return E;
13971397 }
1398 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, Context);
1398 return MCSymbolRefExpr::create(&SRE->getSymbol(), Variant, Context);
13991399 }
14001400
14011401 case MCExpr::Unary: {
14031403 const MCExpr *Sub = FixupVariantKind(UE->getSubExpr());
14041404 if (Sub == UE->getSubExpr())
14051405 return E;
1406 return MCUnaryExpr::Create(UE->getOpcode(), Sub, Context);
1406 return MCUnaryExpr::create(UE->getOpcode(), Sub, Context);
14071407 }
14081408
14091409 case MCExpr::Binary: {
14121412 const MCExpr *RHS = FixupVariantKind(BE->getRHS());
14131413 if (LHS == BE->getLHS() && RHS == BE->getRHS())
14141414 return E;
1415 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, Context);
1415 return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, Context);
14161416 }
14171417 }
14181418
14371437 PPCMCExpr::VariantKind Variant;
14381438 const MCExpr *E = ExtractModifierFromExpr(EVal, Variant);
14391439 if (E)
1440 EVal = PPCMCExpr::Create(Variant, E, false, getParser().getContext());
1440 EVal = PPCMCExpr::create(Variant, E, false, getParser().getContext());
14411441
14421442 return false;
14431443 }
14841484 if (getLexer().isNot(AsmToken::RParen))
14851485 return Error(Parser.getTok().getLoc(), "expected ')'");
14861486 Parser.Lex(); // Eat the ')'
1487 EVal = PPCMCExpr::Create(Variant, EVal, false, getParser().getContext());
1487 EVal = PPCMCExpr::create(Variant, EVal, false, getParser().getContext());
14881488 }
14891489 return false;
14901490 }
19351935 MCContext &Ctx) {
19361936 switch (Variant) {
19371937 case MCSymbolRefExpr::VK_PPC_LO:
1938 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_LO, E, false, Ctx);
1938 return PPCMCExpr::create(PPCMCExpr::VK_PPC_LO, E, false, Ctx);
19391939 case MCSymbolRefExpr::VK_PPC_HI:
1940 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HI, E, false, Ctx);
1940 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HI, E, false, Ctx);
19411941 case MCSymbolRefExpr::VK_PPC_HA:
1942 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HA, E, false, Ctx);
1942 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HA, E, false, Ctx);
19431943 case MCSymbolRefExpr::VK_PPC_HIGHER:
1944 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHER, E, false, Ctx);
1944 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHER, E, false, Ctx);
19451945 case MCSymbolRefExpr::VK_PPC_HIGHERA:
1946 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHERA, E, false, Ctx);
1946 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHERA, E, false, Ctx);
19471947 case MCSymbolRefExpr::VK_PPC_HIGHEST:
1948 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHEST, E, false, Ctx);
1948 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHEST, E, false, Ctx);
19491949 case MCSymbolRefExpr::VK_PPC_HIGHESTA:
1950 return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHESTA, E, false, Ctx);
1950 return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHESTA, E, false, Ctx);
19511951 default:
19521952 return nullptr;
19531953 }
1818 #define DEBUG_TYPE "ppcmcexpr"
1919
2020 const PPCMCExpr*
21 PPCMCExpr::Create(VariantKind Kind, const MCExpr *Expr,
21 PPCMCExpr::create(VariantKind Kind, const MCExpr *Expr,
2222 bool isDarwin, MCContext &Ctx) {
2323 return new (Ctx) PPCMCExpr(Kind, Expr, isDarwin);
2424 }
2525
26 void PPCMCExpr::PrintImpl(raw_ostream &OS) const {
26 void PPCMCExpr::printImpl(raw_ostream &OS) const {
2727 if (isDarwinSyntax()) {
2828 switch (Kind) {
2929 default: llvm_unreachable("Invalid kind!");
5252 }
5353
5454 bool
55 PPCMCExpr::EvaluateAsConstant(int64_t &Res) const {
55 PPCMCExpr::evaluateAsConstant(int64_t &Res) const {
5656 MCValue Value;
5757
58 if (!getSubExpr()->EvaluateAsRelocatable(Value, nullptr, nullptr))
58 if (!getSubExpr()->evaluateAsRelocatable(Value, nullptr, nullptr))
5959 return false;
6060
6161 if (!Value.isAbsolute())
6262 return false;
6363
64 Res = EvaluateAsInt64(Value.getConstant());
64 Res = evaluateAsInt64(Value.getConstant());
6565 return true;
6666 }
6767
6868 int64_t
69 PPCMCExpr::EvaluateAsInt64(int64_t Value) const {
69 PPCMCExpr::evaluateAsInt64(int64_t Value) const {
7070 switch (Kind) {
7171 case VK_PPC_LO:
7272 return Value & 0xffff;
8989 }
9090
9191 bool
92 PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
92 PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
9393 const MCAsmLayout *Layout,
9494 const MCFixup *Fixup) const {
9595 MCValue Value;
9696
97 if (!getSubExpr()->EvaluateAsRelocatable(Value, Layout, Fixup))
97 if (!getSubExpr()->evaluateAsRelocatable(Value, Layout, Fixup))
9898 return false;
9999
100100 if (Value.isAbsolute()) {
101 int64_t Result = EvaluateAsInt64(Value.getConstant());
101 int64_t Result = evaluateAsInt64(Value.getConstant());
102102 if ((Fixup == nullptr || (unsigned)Fixup->getKind() != PPC::fixup_ppc_half16) &&
103103 (Result >= 0x8000))
104104 return false;
137137 Modifier = MCSymbolRefExpr::VK_PPC_HIGHESTA;
138138 break;
139139 }
140 Sym = MCSymbolRefExpr::Create(&Sym->getSymbol(), Modifier, Context);
140 Sym = MCSymbolRefExpr::create(&Sym->getSymbol(), Modifier, Context);
141141 Res = MCValue::get(Sym, Value.getSymB(), Value.getConstant());
142142 }
143143
3333 const MCExpr *Expr;
3434 bool IsDarwin;
3535
36 int64_t EvaluateAsInt64(int64_t Value) const;
36 int64_t evaluateAsInt64(int64_t Value) const;
3737
3838 explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, bool IsDarwin)
3939 : Kind(Kind), Expr(Expr), IsDarwin(IsDarwin) {}
4242 /// @name Construction
4343 /// @{
4444
45 static const PPCMCExpr *Create(VariantKind Kind, const MCExpr *Expr,
45 static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
4646 bool isDarwin, MCContext &Ctx);
4747
48 static const PPCMCExpr *CreateLo(const MCExpr *Expr,
48 static const PPCMCExpr *createLo(const MCExpr *Expr,
4949 bool isDarwin, MCContext &Ctx) {
50 return Create(VK_PPC_LO, Expr, isDarwin, Ctx);
50 return create(VK_PPC_LO, Expr, isDarwin, Ctx);
5151