[llvm] r306359 - [AVR] Migrate to new MCAsmBackend applyFixup and processFixupValue

Leslie Zhai via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 20:29:27 PDT 2017


Author: xiangzhai
Date: Mon Jun 26 20:29:27 2017
New Revision: 306359

URL: http://llvm.org/viewvc/llvm-project?rev=306359&view=rev
Log:
[AVR] Migrate to new MCAsmBackend applyFixup and processFixupValue

Reviewers: rafael, dylanmckay, jroelofs, meadori

Reviewed By: rafael, meadori

Subscribers: meadori, llvm-commits

Differential Revision: https://reviews.llvm.org/D34551

Modified:
    llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
    llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h

Modified: llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp?rev=306359&r1=306358&r2=306359&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp Mon Jun 26 20:29:27 2017
@@ -230,13 +230,25 @@ void ms8(unsigned Size, const MCFixup &F
 namespace llvm {
 
 // Prepare value for the target space for it
-void AVRAsmBackend::adjustFixupValue(const MCFixup &Fixup, uint64_t &Value,
+void AVRAsmBackend::adjustFixupValue(const MCFixup &Fixup,
+                                     const MCValue &Target,
+                                     uint64_t &Value,
                                      MCContext *Ctx) const {
   // The size of the fixup in bits.
   uint64_t Size = AVRAsmBackend::getFixupKindInfo(Fixup.getKind()).TargetSize;
 
   unsigned Kind = Fixup.getKind();
 
+  // Parsed LLVM-generated temporary labels are already
+  // adjusted for instruction size, but normal labels aren't.
+  //
+  // To handle both cases, we simply un-adjust the temporary label
+  // case so it acts like all other labels.
+  if (const MCSymbolRefExpr *A = Target.getSymA()) {
+    if (A->getSymbol().isTemporary())
+      Value += 2;
+  }
+
   switch (Kind) {
   default:
     llvm_unreachable("unhandled fixup");
@@ -333,9 +345,10 @@ MCObjectWriter *AVRAsmBackend::createObj
                                   MCELFObjectTargetWriter::getOSABI(OSType));
 }
 
-void AVRAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
-                               unsigned DataSize, uint64_t Value,
-                               bool IsPCRel, MCContext &Ctx) const {
+void AVRAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
+                               const MCValue &Target, MutableArrayRef<char> Data,
+                               uint64_t Value, bool IsPCRel) const {
+  adjustFixupValue(Fixup, Target, Value, &Asm.getContext());
   if (Value == 0)
     return; // Doesn't change encoding.
 
@@ -349,7 +362,7 @@ void AVRAsmBackend::applyFixup(const MCF
   Value <<= Info.TargetOffset;
 
   unsigned Offset = Fixup.getOffset();
-  assert(Offset + NumBytes <= DataSize && "Invalid fixup offset!");
+  assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
 
   // For each byte of the fragment that the fixup touches, mask in the
   // bits from the fixup value.
@@ -437,11 +450,8 @@ bool AVRAsmBackend::writeNopData(uint64_
 }
 
 void AVRAsmBackend::processFixupValue(const MCAssembler &Asm,
-                                      const MCAsmLayout &Layout,
                                       const MCFixup &Fixup,
-                                      const MCFragment *DF,
-                                      const MCValue &Target, uint64_t &Value,
-                                      bool &IsResolved) {
+                                      const MCValue &Target, bool &IsResolved) {
   switch ((unsigned) Fixup.getKind()) {
   // Fixups which should always be recorded as relocations.
   case AVR::fixup_7_pcrel:
@@ -449,17 +459,6 @@ void AVRAsmBackend::processFixupValue(co
   case AVR::fixup_call:
     IsResolved = false;
     break;
-  default:
-    // Parsed LLVM-generated temporary labels are already
-    // adjusted for instruction size, but normal labels aren't.
-    //
-    // To handle both cases, we simply un-adjust the temporary label
-    // case so it acts like all other labels.
-    if (Target.getSymA()->getSymbol().isTemporary())
-      Value += 2;
-
-    adjustFixupValue(Fixup, Value, &Asm.getContext());
-    break;
   }
 }
 

Modified: llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h?rev=306359&r1=306358&r2=306359&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h (original)
+++ llvm/trunk/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h Mon Jun 26 20:29:27 2017
@@ -35,13 +35,14 @@ public:
   AVRAsmBackend(Triple::OSType OSType)
       : MCAsmBackend(), OSType(OSType) {}
 
-  void adjustFixupValue(const MCFixup &Fixup, uint64_t &Value,
-                        MCContext *Ctx = nullptr) const;
+  void adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
+                        uint64_t &Value, MCContext *Ctx = nullptr) const;
 
   MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override;
 
-  void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
-                  uint64_t Value, bool IsPCRel, MCContext &Ctx) const override;
+  void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
+                  const MCValue &Target, MutableArrayRef<char> Data,
+                  uint64_t Value, bool IsPCRel) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 
@@ -63,10 +64,8 @@ public:
 
   bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
 
-  void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout,
-                         const MCFixup &Fixup, const MCFragment *DF,
-                         const MCValue &Target, uint64_t &Value,
-                         bool &IsResolved) override;
+  void processFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
+                         const MCValue &Target, bool &IsResolved) override;
 
 private:
   Triple::OSType OSType;




More information about the llvm-commits mailing list