[llvm] 5d5f162 - Move PowerPC-specific MCSymbolRefExpr::VariantKind to PPCMCExpr

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 12 23:00:09 PDT 2025


Author: Fangrui Song
Date: 2025-03-12T23:00:03-07:00
New Revision: 5d5f16204f17eae903d5cead75f31a41e7e960d4

URL: https://github.com/llvm/llvm-project/commit/5d5f16204f17eae903d5cead75f31a41e7e960d4
DIFF: https://github.com/llvm/llvm-project/commit/5d5f16204f17eae903d5cead75f31a41e7e960d4.diff

LOG: Move PowerPC-specific MCSymbolRefExpr::VariantKind to PPCMCExpr

Most changes are mechanic, except:

* ELFObjectWriter::shouldRelocateWithSymbol: .TOC. at tocbase does not
  register the undefined symbol.  Move the handling into the
  Sym->isUndefined() code path.
* ELFObjectWriter::fixSymbolsInTLSFixups's VK_PPC* cases are moved to
  PPCELFObjectWriter::getRelocType. We should do similar refactoring
  for other targets and eventually remove fixSymbolsInTLSFixups.

In the future, we should classify PPCMCExpr similar to AArch64MCExpr.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCExpr.h
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCTargetStreamer.h
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp
    llvm/lib/Target/PowerPC/PPC.h
    llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
    llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
    llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index a302a81ac468a..76fb1133b1b3e 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -256,67 +256,6 @@ class MCSymbolRefExpr : public MCExpr {
     VK_AVR_DIFF32,
     VK_AVR_PM,
 
-    VK_PPC_GOT_LO,          // symbol at got@l
-    VK_PPC_GOT_HI,          // symbol at got@h
-    VK_PPC_GOT_HA,          // symbol at got@ha
-    VK_PPC_TOCBASE,         // symbol at tocbase
-    VK_PPC_TOC,             // symbol at toc
-    VK_PPC_TOC_LO,          // symbol at toc@l
-    VK_PPC_TOC_HI,          // symbol at toc@h
-    VK_PPC_TOC_HA,          // symbol at toc@ha
-    VK_PPC_U,               // symbol at u
-    VK_PPC_L,               // symbol at l
-    VK_PPC_DTPMOD,          // symbol at dtpmod
-    VK_PPC_TPREL_LO,        // symbol at tprel@l
-    VK_PPC_TPREL_HI,        // symbol at tprel@h
-    VK_PPC_TPREL_HA,        // symbol at tprel@ha
-    VK_PPC_TPREL_HIGH,      // symbol at tprel@high
-    VK_PPC_TPREL_HIGHA,     // symbol at tprel@higha
-    VK_PPC_TPREL_HIGHER,    // symbol at tprel@higher
-    VK_PPC_TPREL_HIGHERA,   // symbol at tprel@highera
-    VK_PPC_TPREL_HIGHEST,   // symbol at tprel@highest
-    VK_PPC_TPREL_HIGHESTA,  // symbol at tprel@highesta
-    VK_PPC_DTPREL_LO,       // symbol at dtprel@l
-    VK_PPC_DTPREL_HI,       // symbol at dtprel@h
-    VK_PPC_DTPREL_HA,       // symbol at dtprel@ha
-    VK_PPC_DTPREL_HIGH,     // symbol at dtprel@high
-    VK_PPC_DTPREL_HIGHA,    // symbol at dtprel@higha
-    VK_PPC_DTPREL_HIGHER,   // symbol at dtprel@higher
-    VK_PPC_DTPREL_HIGHERA,  // symbol at dtprel@highera
-    VK_PPC_DTPREL_HIGHEST,  // symbol at dtprel@highest
-    VK_PPC_DTPREL_HIGHESTA, // symbol at dtprel@highesta
-    VK_PPC_GOT_TPREL,       // symbol at got@tprel
-    VK_PPC_GOT_TPREL_LO,    // symbol at got@tprel at l
-    VK_PPC_GOT_TPREL_HI,    // symbol at got@tprel at h
-    VK_PPC_GOT_TPREL_HA,    // symbol at got@tprel at ha
-    VK_PPC_GOT_DTPREL,      // symbol at got@dtprel
-    VK_PPC_GOT_DTPREL_LO,   // symbol at got@dtprel at l
-    VK_PPC_GOT_DTPREL_HI,   // symbol at got@dtprel at h
-    VK_PPC_GOT_DTPREL_HA,   // symbol at got@dtprel at ha
-    VK_PPC_TLS,             // symbol at tls
-    VK_PPC_GOT_TLSGD,       // symbol at got@tlsgd
-    VK_PPC_GOT_TLSGD_LO,    // symbol at got@tlsgd at l
-    VK_PPC_GOT_TLSGD_HI,    // symbol at got@tlsgd at h
-    VK_PPC_GOT_TLSGD_HA,    // symbol at got@tlsgd at ha
-    VK_PPC_AIX_TLSGD,       // symbol at gd
-    VK_PPC_AIX_TLSGDM,      // symbol at m
-    VK_PPC_AIX_TLSIE,       // symbol at ie
-    VK_PPC_AIX_TLSLE,       // symbol at le
-    VK_PPC_AIX_TLSLD,       // symbol at ld
-    VK_PPC_AIX_TLSML,       // symbol at ml
-    VK_PPC_GOT_TLSLD,       // symbol at got@tlsld
-    VK_PPC_GOT_TLSLD_LO,    // symbol at got@tlsld at l
-    VK_PPC_GOT_TLSLD_HI,    // symbol at got@tlsld at h
-    VK_PPC_GOT_TLSLD_HA,    // symbol at got@tlsld at ha
-    VK_PPC_GOT_PCREL,       // symbol at got@pcrel
-    VK_PPC_GOT_TLSGD_PCREL, // symbol at got@tlsgd at pcrel
-    VK_PPC_GOT_TLSLD_PCREL, // symbol at got@tlsld at pcrel
-    VK_PPC_GOT_TPREL_PCREL, // symbol at got@tprel at pcrel
-    VK_PPC_TLS_PCREL,       // symbol at tls@pcrel
-    VK_PPC_LOCAL,           // symbol at local
-    VK_PPC_NOTOC,           // symbol at notoc
-    VK_PPC_PCREL_OPT,       // .reloc expr, R_PPC64_PCREL_OPT, expr
-
     VK_COFF_IMGREL32, // symbol at imgrel (image-relative)
 
     VK_Hexagon_LO16,

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index d0e56162f6162..dbef2875c6777 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1261,14 +1261,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
   switch (Kind) {
   default:
     break;
-  // The .odp creation emits a relocation against the symbol ".TOC." which
-  // create a R_PPC64_TOC relocation. However the relocation symbol name
-  // in final object creation should be NULL, since the symbol does not
-  // really exist, it is just the reference to TOC base for the current
-  // object file. Since the symbol is undefined, returning false results
-  // in a relocation with a null section which is the desired result.
-  case MCSymbolRefExpr::VK_PPC_TOCBASE:
-    return false;
 
   // These VariantKind cause the relocation to refer to something other than
   // the symbol itself, like a linker generated table. Since the address of
@@ -1278,17 +1270,22 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
   case MCSymbolRefExpr::VK_PLT:
   case MCSymbolRefExpr::VK_GOTPCREL:
   case MCSymbolRefExpr::VK_GOTPCREL_NORELAX:
-  case MCSymbolRefExpr::VK_PPC_GOT_LO:
-  case MCSymbolRefExpr::VK_PPC_GOT_HI:
-  case MCSymbolRefExpr::VK_PPC_GOT_HA:
     return true;
   }
 
   // An undefined symbol is not in any section, so the relocation has to point
   // to the symbol itself.
   assert(Sym && "Expected a symbol");
-  if (Sym->isUndefined())
-    return true;
+  if (Sym->isUndefined()) {
+    // The .odp creation emits a relocation against the symbol ".TOC." which
+    // create a R_PPC64_TOC relocation. However the relocation symbol name
+    // in final object creation should be NULL, since the symbol does not
+    // really exist, it is just the reference to TOC base for the current
+    // object file. Since the symbol is undefined, returning false results
+    // in a relocation with a null section which is the desired result.
+    return !(Type == ELF::R_PPC64_TOC &&
+             TargetObjectWriter->getEMachine() == ELF::EM_PPC64);
+  }
 
   // For memory-tagged symbols, ensure that the relocation uses the symbol. For
   // tagged symbols, we emit an empty relocation (R_AARCH64_NONE) in a special
@@ -1539,45 +1536,6 @@ void ELFObjectWriter::fixSymbolsInTLSFixups(MCAssembler &Asm,
     case MCSymbolRefExpr::VK_TPREL:
     case MCSymbolRefExpr::VK_DTPOFF:
     case MCSymbolRefExpr::VK_DTPREL:
-    case MCSymbolRefExpr::VK_PPC_DTPMOD:
-    case MCSymbolRefExpr::VK_PPC_TPREL_LO:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HI:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HA:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGH:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGHA:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
-    case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGH:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHA:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
-    case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
-    case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
-    case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
-    case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
-    case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
-    case MCSymbolRefExpr::VK_PPC_GOT_TPREL_PCREL:
-    case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
-    case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
-    case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
-    case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
-    case MCSymbolRefExpr::VK_PPC_TLS:
-    case MCSymbolRefExpr::VK_PPC_TLS_PCREL:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_PCREL:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
-    case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
       break;
     }
     Asm.registerSymbol(symRef.getSymbol());

diff  --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index b2c99b6013e92..e623b6c5100b6 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -745,8 +745,8 @@ struct PPCOperand : public MCParsedAsmOperand {
       return CreateImm(CE->getValue(), S, E, IsPPC64);
 
     if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Val))
-      if (SRE->getKind() == MCSymbolRefExpr::VK_PPC_TLS ||
-          SRE->getKind() == MCSymbolRefExpr::VK_PPC_TLS_PCREL)
+      if (getVariantKind(SRE) == PPCMCExpr::VK_TLS ||
+          getVariantKind(SRE) == PPCMCExpr::VK_TLS_PCREL)
         return CreateTLSReg(SRE, S, E, IsPPC64);
 
     if (const PPCMCExpr *TE = dyn_cast<PPCMCExpr>(Val)) {
@@ -1374,7 +1374,7 @@ const MCExpr *
 PPCAsmParser::extractModifierFromExpr(const MCExpr *E,
                                       PPCMCExpr::VariantKind &Variant) {
   MCContext &Context = getParser().getContext();
-  Variant = PPCMCExpr::VK_PPC_None;
+  Variant = PPCMCExpr::VK_None;
 
   switch (E->getKind()) {
   case MCExpr::Target:
@@ -1383,16 +1383,16 @@ PPCAsmParser::extractModifierFromExpr(const MCExpr *E,
 
   case MCExpr::SymbolRef: {
     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
-
-    switch ((PPCMCExpr::VariantKind)SRE->getKind()) {
+    Variant = (PPCMCExpr::VariantKind)SRE->getKind();
+    switch (Variant) {
     case PPCMCExpr::VK_LO:
       Variant = PPCMCExpr::VK_LO;
       break;
     case PPCMCExpr::VK_HI:
       Variant = PPCMCExpr::VK_HI;
       break;
-    case PPCMCExpr::VK_PPC_HA:
-      Variant = PPCMCExpr::VK_PPC_HA;
+    case PPCMCExpr::VK_HA:
+      Variant = PPCMCExpr::VK_HA;
       break;
     case PPCMCExpr::VK_HIGH:
       Variant = PPCMCExpr::VK_HIGH;
@@ -1439,9 +1439,9 @@ PPCAsmParser::extractModifierFromExpr(const MCExpr *E,
     if (!LHS) LHS = BE->getLHS();
     if (!RHS) RHS = BE->getRHS();
 
-    if (LHSVariant == PPCMCExpr::VK_PPC_None)
+    if (LHSVariant == PPCMCExpr::VK_None)
       Variant = RHSVariant;
-    else if (RHSVariant == PPCMCExpr::VK_PPC_None)
+    else if (RHSVariant == PPCMCExpr::VK_None)
       Variant = LHSVariant;
     else if (LHSVariant == RHSVariant)
       Variant = LHSVariant;
@@ -1539,8 +1539,9 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
       if (!(parseOptionalToken(AsmToken::Identifier) &&
             Tok.getString().compare_insensitive("plt") == 0))
         return Error(Tok.getLoc(), "expected 'plt'");
-      EVal = MCSymbolRefExpr::create(getContext().getOrCreateSymbol(TlsGetAddr),
-                                     MCSymbolRefExpr::VK_PLT, getContext());
+      EVal = MCSymbolRefExpr::create(
+          getContext().getOrCreateSymbol(TlsGetAddr),
+          MCSymbolRefExpr::VariantKind(PPCMCExpr::VK_PLT), getContext());
       if (parseOptionalToken(AsmToken::Plus)) {
         const MCExpr *Addend = nullptr;
         SMLoc EndLoc;
@@ -1856,7 +1857,7 @@ PPCAsmParser::applyModifierToExpr(const MCExpr *E,
     switch (PPCMCExpr::VariantKind(Variant)) {
     case PPCMCExpr::VariantKind::VK_LO:
     case PPCMCExpr::VariantKind::VK_HI:
-    case PPCMCExpr::VariantKind::VK_PPC_HA:
+    case PPCMCExpr::VariantKind::VK_HA:
     case PPCMCExpr::VariantKind::VK_HIGH:
     case PPCMCExpr::VariantKind::VK_HIGHA:
     case PPCMCExpr::VariantKind::VK_HIGHER:

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
index 7157dc4e275f5..80cf4a5bc7fd7 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
@@ -38,13 +38,13 @@ PPCELFObjectWriter::PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
                             Is64Bit ?  ELF::EM_PPC64 : ELF::EM_PPC,
                             /*HasRelocationAddend*/ true) {}
 
-static MCSymbolRefExpr::VariantKind getAccessVariant(const MCValue &Target,
-                                                     const MCFixup &Fixup) {
+static PPCMCExpr::VariantKind getAccessVariant(const MCValue &Target,
+                                               const MCFixup &Fixup) {
   const MCExpr *Expr = Fixup.getValue();
 
   if (Expr->getKind() != MCExpr::Target)
-    return Target.getAccessVariant();
-  return MCSymbolRefExpr::VariantKind(cast<PPCMCExpr>(Expr)->getKind());
+    return PPCMCExpr::VariantKind(Target.getAccessVariant());
+  return cast<PPCMCExpr>(Expr)->getKind();
 }
 
 unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
@@ -54,7 +54,58 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
   if (Kind >= FirstLiteralRelocationKind)
     return Kind - FirstLiteralRelocationKind;
   auto RefKind = static_cast<PPCMCExpr::VariantKind>(Target.getRefKind());
-  MCSymbolRefExpr::VariantKind Modifier = getAccessVariant(Target, Fixup);
+  auto Modifier = getAccessVariant(Target, Fixup);
+
+  switch (PPCMCExpr::VariantKind(Modifier)) {
+  case PPCMCExpr::VK_DTPMOD:
+  case PPCMCExpr::VK_DTPREL:
+  case PPCMCExpr::VK_DTPREL_HA:
+  case PPCMCExpr::VK_DTPREL_HI:
+  case PPCMCExpr::VK_DTPREL_HIGH:
+  case PPCMCExpr::VK_DTPREL_HIGHA:
+  case PPCMCExpr::VK_DTPREL_HIGHER:
+  case PPCMCExpr::VK_DTPREL_HIGHERA:
+  case PPCMCExpr::VK_DTPREL_HIGHEST:
+  case PPCMCExpr::VK_DTPREL_HIGHESTA:
+  case PPCMCExpr::VK_DTPREL_LO:
+  case PPCMCExpr::VK_GOT_DTPREL:
+  case PPCMCExpr::VK_GOT_DTPREL_HA:
+  case PPCMCExpr::VK_GOT_DTPREL_HI:
+  case PPCMCExpr::VK_GOT_DTPREL_LO:
+  case PPCMCExpr::VK_GOT_TLSGD:
+  case PPCMCExpr::VK_GOT_TLSGD_HA:
+  case PPCMCExpr::VK_GOT_TLSGD_HI:
+  case PPCMCExpr::VK_GOT_TLSGD_LO:
+  case PPCMCExpr::VK_GOT_TLSGD_PCREL:
+  case PPCMCExpr::VK_GOT_TLSLD:
+  case PPCMCExpr::VK_GOT_TLSLD_HA:
+  case PPCMCExpr::VK_GOT_TLSLD_HI:
+  case PPCMCExpr::VK_GOT_TLSLD_LO:
+  case PPCMCExpr::VK_GOT_TPREL:
+  case PPCMCExpr::VK_GOT_TPREL_HA:
+  case PPCMCExpr::VK_GOT_TPREL_HI:
+  case PPCMCExpr::VK_GOT_TPREL_LO:
+  case PPCMCExpr::VK_GOT_TPREL_PCREL:
+  case PPCMCExpr::VK_TLS:
+  case PPCMCExpr::VK_TLSGD:
+  case PPCMCExpr::VK_TLSLD:
+  case PPCMCExpr::VK_TLS_PCREL:
+  case PPCMCExpr::VK_TPREL:
+  case PPCMCExpr::VK_TPREL_HA:
+  case PPCMCExpr::VK_TPREL_HI:
+  case PPCMCExpr::VK_TPREL_HIGH:
+  case PPCMCExpr::VK_TPREL_HIGHA:
+  case PPCMCExpr::VK_TPREL_HIGHER:
+  case PPCMCExpr::VK_TPREL_HIGHERA:
+  case PPCMCExpr::VK_TPREL_HIGHEST:
+  case PPCMCExpr::VK_TPREL_HIGHESTA:
+  case PPCMCExpr::VK_TPREL_LO:
+    if (auto *S = Target.getSymA())
+      cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
+    break;
+  default:
+    break;
+  }
 
   // determine the type of the relocation
   unsigned Type;
@@ -67,16 +118,16 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
     case PPC::fixup_ppc_br24_notoc:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
-      case MCSymbolRefExpr::VK_None:
+      case PPCMCExpr::VK_None:
         Type = ELF::R_PPC_REL24;
         break;
-      case MCSymbolRefExpr::VK_PLT:
+      case PPCMCExpr::VK_PLT:
         Type = ELF::R_PPC_PLTREL24;
         break;
-      case MCSymbolRefExpr::VK_PPC_LOCAL:
+      case PPCMCExpr::VK_LOCAL:
         Type = ELF::R_PPC_LOCAL24PC;
         break;
-      case MCSymbolRefExpr::VK_PPC_NOTOC:
+      case PPCMCExpr::VK_NOTOC:
         Type = ELF::R_PPC64_REL24_NOTOC;
         break;
       }
@@ -90,13 +141,13 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       default:
         Ctx.reportError(Fixup.getLoc(), "invalid VariantKind");
         return ELF::R_PPC_NONE;
-      case PPCMCExpr::VK_PPC_None:
+      case PPCMCExpr::VK_None:
         return ELF::R_PPC_REL16;
       case PPCMCExpr::VK_LO:
         return ELF::R_PPC_REL16_LO;
       case PPCMCExpr::VK_HI:
         return ELF::R_PPC_REL16_HI;
-      case PPCMCExpr::VK_PPC_HA:
+      case PPCMCExpr::VK_HA:
         return ELF::R_PPC_REL16_HA;
       }
       break;
@@ -109,19 +160,19 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       switch (Modifier) {
       default:
         llvm_unreachable("Unsupported Modifier for fixup_ppc_pcrel34");
-      case MCSymbolRefExpr::VK_PCREL:
+      case PPCMCExpr::VK_PCREL:
         Type = ELF::R_PPC64_PCREL34;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_PCREL:
+      case PPCMCExpr::VK_GOT_PCREL:
         Type = ELF::R_PPC64_GOT_PCREL34;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_PCREL:
+      case PPCMCExpr::VK_GOT_TLSGD_PCREL:
         Type = ELF::R_PPC64_GOT_TLSGD_PCREL34;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_PCREL:
+      case PPCMCExpr::VK_GOT_TLSLD_PCREL:
         Type = ELF::R_PPC64_GOT_TLSLD_PCREL34;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL_PCREL:
+      case PPCMCExpr::VK_GOT_TPREL_PCREL:
         Type = ELF::R_PPC64_GOT_TPREL_PCREL34;
         break;
       }
@@ -146,13 +197,13 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       break;
     case PPC::fixup_ppc_half16:
       switch (RefKind) {
-      case PPCMCExpr::VK_PPC_None:
+      default:
         break;
       case PPCMCExpr::VK_LO:
         return ELF::R_PPC_ADDR16_LO;
       case PPCMCExpr::VK_HI:
         return ELF::R_PPC_ADDR16_HI;
-      case PPCMCExpr::VK_PPC_HA:
+      case PPCMCExpr::VK_HA:
         return ELF::R_PPC_ADDR16_HA;
       case PPCMCExpr::VK_HIGH:
         return ELF::R_PPC64_ADDR16_HIGH;
@@ -169,153 +220,153 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       }
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
-      case MCSymbolRefExpr::VK_None:
+      case PPCMCExpr::VK_None:
         Type = ELF::R_PPC_ADDR16;
         break;
-      case MCSymbolRefExpr::VK_GOT:
+      case PPCMCExpr::VK_GOT:
         Type = ELF::R_PPC_GOT16;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_LO:
+      case PPCMCExpr::VK_GOT_LO:
         Type = ELF::R_PPC_GOT16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_HI:
+      case PPCMCExpr::VK_GOT_HI:
         Type = ELF::R_PPC_GOT16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_HA:
+      case PPCMCExpr::VK_GOT_HA:
         Type = ELF::R_PPC_GOT16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC:
+      case PPCMCExpr::VK_TOC:
         Type = ELF::R_PPC64_TOC16;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC_LO:
+      case PPCMCExpr::VK_TOC_LO:
         Type = ELF::R_PPC64_TOC16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC_HI:
+      case PPCMCExpr::VK_TOC_HI:
         Type = ELF::R_PPC64_TOC16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC_HA:
+      case PPCMCExpr::VK_TOC_HA:
         Type = ELF::R_PPC64_TOC16_HA;
         break;
-      case MCSymbolRefExpr::VK_TPREL:
+      case PPCMCExpr::VK_TPREL:
         Type = ELF::R_PPC_TPREL16;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_LO:
+      case PPCMCExpr::VK_TPREL_LO:
         Type = ELF::R_PPC_TPREL16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HI:
+      case PPCMCExpr::VK_TPREL_HI:
         Type = ELF::R_PPC_TPREL16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HA:
+      case PPCMCExpr::VK_TPREL_HA:
         Type = ELF::R_PPC_TPREL16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGH:
+      case PPCMCExpr::VK_TPREL_HIGH:
         Type = ELF::R_PPC64_TPREL16_HIGH;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGHA:
+      case PPCMCExpr::VK_TPREL_HIGHA:
         Type = ELF::R_PPC64_TPREL16_HIGHA;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
+      case PPCMCExpr::VK_TPREL_HIGHER:
         Type = ELF::R_PPC64_TPREL16_HIGHER;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
+      case PPCMCExpr::VK_TPREL_HIGHERA:
         Type = ELF::R_PPC64_TPREL16_HIGHERA;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
+      case PPCMCExpr::VK_TPREL_HIGHEST:
         Type = ELF::R_PPC64_TPREL16_HIGHEST;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
+      case PPCMCExpr::VK_TPREL_HIGHESTA:
         Type = ELF::R_PPC64_TPREL16_HIGHESTA;
         break;
-      case MCSymbolRefExpr::VK_DTPREL:
+      case PPCMCExpr::VK_DTPREL:
         Type = ELF::R_PPC64_DTPREL16;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
+      case PPCMCExpr::VK_DTPREL_LO:
         Type = ELF::R_PPC64_DTPREL16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
+      case PPCMCExpr::VK_DTPREL_HI:
         Type = ELF::R_PPC64_DTPREL16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
+      case PPCMCExpr::VK_DTPREL_HA:
         Type = ELF::R_PPC64_DTPREL16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGH:
+      case PPCMCExpr::VK_DTPREL_HIGH:
         Type = ELF::R_PPC64_DTPREL16_HIGH;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHA:
+      case PPCMCExpr::VK_DTPREL_HIGHA:
         Type = ELF::R_PPC64_DTPREL16_HIGHA;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
+      case PPCMCExpr::VK_DTPREL_HIGHER:
         Type = ELF::R_PPC64_DTPREL16_HIGHER;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
+      case PPCMCExpr::VK_DTPREL_HIGHERA:
         Type = ELF::R_PPC64_DTPREL16_HIGHERA;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
+      case PPCMCExpr::VK_DTPREL_HIGHEST:
         Type = ELF::R_PPC64_DTPREL16_HIGHEST;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
+      case PPCMCExpr::VK_DTPREL_HIGHESTA:
         Type = ELF::R_PPC64_DTPREL16_HIGHESTA;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
+      case PPCMCExpr::VK_GOT_TLSGD:
         if (is64Bit())
           Type = ELF::R_PPC64_GOT_TLSGD16;
         else
           Type = ELF::R_PPC_GOT_TLSGD16;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
+      case PPCMCExpr::VK_GOT_TLSGD_LO:
         Type = ELF::R_PPC64_GOT_TLSGD16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
+      case PPCMCExpr::VK_GOT_TLSGD_HI:
         Type = ELF::R_PPC64_GOT_TLSGD16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
+      case PPCMCExpr::VK_GOT_TLSGD_HA:
         Type = ELF::R_PPC64_GOT_TLSGD16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
+      case PPCMCExpr::VK_GOT_TLSLD:
         if (is64Bit())
           Type = ELF::R_PPC64_GOT_TLSLD16;
         else
           Type = ELF::R_PPC_GOT_TLSLD16;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
+      case PPCMCExpr::VK_GOT_TLSLD_LO:
         Type = ELF::R_PPC64_GOT_TLSLD16_LO;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
+      case PPCMCExpr::VK_GOT_TLSLD_HI:
         Type = ELF::R_PPC64_GOT_TLSLD16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
+      case PPCMCExpr::VK_GOT_TLSLD_HA:
         Type = ELF::R_PPC64_GOT_TLSLD16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
+      case PPCMCExpr::VK_GOT_TPREL:
         /* We don't have R_PPC64_GOT_TPREL16, but since GOT offsets
            are always 4-aligned, we can use R_PPC64_GOT_TPREL16_DS.  */
         Type = ELF::R_PPC64_GOT_TPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
+      case PPCMCExpr::VK_GOT_TPREL_LO:
         /* We don't have R_PPC64_GOT_TPREL16_LO, but since GOT offsets
            are always 4-aligned, we can use R_PPC64_GOT_TPREL16_LO_DS.  */
         Type = ELF::R_PPC64_GOT_TPREL16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
+      case PPCMCExpr::VK_GOT_TPREL_HI:
         Type = ELF::R_PPC64_GOT_TPREL16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
+      case PPCMCExpr::VK_GOT_DTPREL:
         /* We don't have R_PPC64_GOT_DTPREL16, but since GOT offsets
            are always 4-aligned, we can use R_PPC64_GOT_DTPREL16_DS.  */
         Type = ELF::R_PPC64_GOT_DTPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
+      case PPCMCExpr::VK_GOT_DTPREL_LO:
         /* We don't have R_PPC64_GOT_DTPREL16_LO, but since GOT offsets
            are always 4-aligned, we can use R_PPC64_GOT_DTPREL16_LO_DS.  */
         Type = ELF::R_PPC64_GOT_DTPREL16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
+      case PPCMCExpr::VK_GOT_TPREL_HA:
         Type = ELF::R_PPC64_GOT_TPREL16_HA;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
+      case PPCMCExpr::VK_GOT_DTPREL_HI:
         Type = ELF::R_PPC64_GOT_DTPREL16_HI;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
+      case PPCMCExpr::VK_GOT_DTPREL_HA:
         Type = ELF::R_PPC64_GOT_DTPREL16_HA;
         break;
       }
@@ -326,50 +377,50 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       default:
         Ctx.reportError(Fixup.getLoc(), "invalid VariantKind");
         return ELF::R_PPC64_NONE;
-      case PPCMCExpr::VK_PPC_None:
+      case PPCMCExpr::VK_None:
         break;
       case PPCMCExpr::VK_LO:
         return ELF::R_PPC64_ADDR16_LO_DS;
       }
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
-      case MCSymbolRefExpr::VK_None:
+      case PPCMCExpr::VK_None:
         Type = ELF::R_PPC64_ADDR16_DS;
         break;
-      case MCSymbolRefExpr::VK_GOT:
+      case PPCMCExpr::VK_GOT:
         Type = ELF::R_PPC64_GOT16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_LO:
+      case PPCMCExpr::VK_GOT_LO:
         Type = ELF::R_PPC64_GOT16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC:
+      case PPCMCExpr::VK_TOC:
         Type = ELF::R_PPC64_TOC16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_TOC_LO:
+      case PPCMCExpr::VK_TOC_LO:
         Type = ELF::R_PPC64_TOC16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_TPREL:
+      case PPCMCExpr::VK_TPREL:
         Type = ELF::R_PPC64_TPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_TPREL_LO:
+      case PPCMCExpr::VK_TPREL_LO:
         Type = ELF::R_PPC64_TPREL16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_DTPREL:
+      case PPCMCExpr::VK_DTPREL:
         Type = ELF::R_PPC64_DTPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
+      case PPCMCExpr::VK_DTPREL_LO:
         Type = ELF::R_PPC64_DTPREL16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
+      case PPCMCExpr::VK_GOT_TPREL:
         Type = ELF::R_PPC64_GOT_TPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
+      case PPCMCExpr::VK_GOT_TPREL_LO:
         Type = ELF::R_PPC64_GOT_TPREL16_LO_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
+      case PPCMCExpr::VK_GOT_DTPREL:
         Type = ELF::R_PPC64_GOT_DTPREL16_DS;
         break;
-      case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
+      case PPCMCExpr::VK_GOT_DTPREL_LO:
         Type = ELF::R_PPC64_GOT_DTPREL16_LO_DS;
         break;
       }
@@ -377,25 +428,25 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
     case PPC::fixup_ppc_nofixup:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
-      case MCSymbolRefExpr::VK_TLSGD:
+      case PPCMCExpr::VK_TLSGD:
         if (is64Bit())
           Type = ELF::R_PPC64_TLSGD;
         else
           Type = ELF::R_PPC_TLSGD;
         break;
-      case MCSymbolRefExpr::VK_TLSLD:
+      case PPCMCExpr::VK_TLSLD:
         if (is64Bit())
           Type = ELF::R_PPC64_TLSLD;
         else
           Type = ELF::R_PPC_TLSLD;
         break;
-      case MCSymbolRefExpr::VK_PPC_TLS:
+      case PPCMCExpr::VK_TLS:
         if (is64Bit())
           Type = ELF::R_PPC64_TLS;
         else
           Type = ELF::R_PPC_TLS;
         break;
-      case MCSymbolRefExpr::VK_PPC_TLS_PCREL:
+      case PPCMCExpr::VK_TLS_PCREL:
         Type = ELF::R_PPC64_TLS;
         break;
       }
@@ -404,10 +455,10 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
       switch (Modifier) {
       default:
         report_fatal_error("Unsupported Modifier for fixup_ppc_imm34.");
-      case MCSymbolRefExpr::VK_DTPREL:
+      case PPCMCExpr::VK_DTPREL:
         Type = ELF::R_PPC64_DTPREL34;
         break;
-      case MCSymbolRefExpr::VK_TPREL:
+      case PPCMCExpr::VK_TPREL:
         Type = ELF::R_PPC64_TPREL34;
         break;
       }
@@ -415,26 +466,26 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
     case FK_Data_8:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
-      case MCSymbolRefExpr::VK_PPC_TOCBASE:
+      case PPCMCExpr::VK_TOCBASE:
         Type = ELF::R_PPC64_TOC;
         break;
-      case MCSymbolRefExpr::VK_None:
+      case PPCMCExpr::VK_None:
         Type = ELF::R_PPC64_ADDR64;
         break;
-      case MCSymbolRefExpr::VK_PPC_DTPMOD:
+      case PPCMCExpr::VK_DTPMOD:
         Type = ELF::R_PPC64_DTPMOD64;
         break;
-      case MCSymbolRefExpr::VK_TPREL:
+      case PPCMCExpr::VK_TPREL:
         Type = ELF::R_PPC64_TPREL64;
         break;
-      case MCSymbolRefExpr::VK_DTPREL:
+      case PPCMCExpr::VK_DTPREL:
         Type = ELF::R_PPC64_DTPREL64;
         break;
       }
       break;
     case FK_Data_4:
       switch (Modifier) {
-      case MCSymbolRefExpr::VK_DTPREL:
+      case PPCMCExpr::VK_DTPREL:
         Type = ELF::R_PPC_DTPREL32;
         break;
       default:
@@ -457,7 +508,7 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
       return false;
 
     case ELF::R_PPC_REL24:
-    case ELF::R_PPC64_REL24_NOTOC:
+    case ELF::R_PPC64_REL24_NOTOC: {
       // If the target symbol has a local entry point, we must keep the
       // target symbol to preserve that information for the linker.
       // The "other" values are stored in the last 6 bits of the second byte.
@@ -465,7 +516,16 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
       // the shift to pack it.
       unsigned Other = cast<MCSymbolELF>(Sym).getOther() << 2;
       return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0;
-  }
+    }
+
+    case ELF::R_PPC64_GOT16:
+    case ELF::R_PPC64_GOT16_DS:
+    case ELF::R_PPC64_GOT16_LO:
+    case ELF::R_PPC64_GOT16_LO_DS:
+    case ELF::R_PPC64_GOT16_HI:
+    case ELF::R_PPC64_GOT16_HA:
+      return true;
+    }
 }
 
 std::unique_ptr<MCObjectTargetWriter>

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
index addac6f41a715..39f509c75e0b8 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
@@ -19,6 +19,7 @@
 
 #include "PPCELFStreamer.h"
 #include "PPCMCCodeEmitter.h"
+#include "PPCMCExpr.h"
 #include "PPCMCTargetDesc.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/MC/MCAsmBackend.h"
@@ -138,8 +139,8 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
   // Cast the last operand to MCSymbolRefExpr to get the symbol.
   const MCExpr *Expr = Operand.getExpr();
   const MCSymbolRefExpr *SymExpr = static_cast<const MCSymbolRefExpr *>(Expr);
-  assert(SymExpr->getKind() == MCSymbolRefExpr::VK_PPC_PCREL_OPT &&
-         "Expecting a symbol of type VK_PPC_PCREL_OPT");
+  assert(getVariantKind(SymExpr) == PPCMCExpr::VK_PCREL_OPT &&
+         "Expecting a symbol of type VK_PCREL_OPT");
   MCSymbol *LabelSym =
       getContext().getOrCreateSymbol(SymExpr->getSymbol().getName());
   const MCExpr *LabelExpr = MCSymbolRefExpr::create(LabelSym, getContext());
@@ -173,8 +174,8 @@ void PPCELFStreamer::emitGOTToPCRelLabel(const MCInst &Inst) {
   // Cast the last operand to MCSymbolRefExpr to get the symbol.
   const MCExpr *Expr = Operand.getExpr();
   const MCSymbolRefExpr *SymExpr = static_cast<const MCSymbolRefExpr *>(Expr);
-  assert(SymExpr->getKind() == MCSymbolRefExpr::VK_PPC_PCREL_OPT &&
-         "Expecting a symbol of type VK_PPC_PCREL_OPT");
+  assert(getVariantKind(SymExpr) == PPCMCExpr::VK_PCREL_OPT &&
+         "Expecting a symbol of type VK_PCREL_OPT");
   MCSymbol *LabelSym =
       getContext().getOrCreateSymbol(SymExpr->getSymbol().getName());
   emitLabel(LabelSym, Inst.getLoc());
@@ -189,7 +190,7 @@ void PPCELFStreamer::emitGOTToPCRelLabel(const MCInst &Inst) {
 // The above is a pair of such instructions and this function will not return
 // std::nullopt for either one of them. In both cases we are looking for the
 // last operand <MCOperand Expr:(.Lpcrel@<<invalid>>)> which needs to be an
-// MCExpr and has the flag MCSymbolRefExpr::VK_PPC_PCREL_OPT. After that we just
+// MCExpr and has the flag PPCMCExpr::VK_PCREL_OPT. After that we just
 // look at the opcode and in the case of PLDpc we will return true. For the load
 // (or store) this function will return false indicating it has found the second
 // instruciton in the pair.
@@ -201,17 +202,17 @@ std::optional<bool> llvm::isPartOfGOTToPCRelPair(const MCInst &Inst,
 
   unsigned LastOp = Inst.getNumOperands() - 1;
   // The last operand needs to be an MCExpr and it needs to have a variant kind
-  // of VK_PPC_PCREL_OPT. If it does not satisfy these conditions it is not a
+  // of VK_PCREL_OPT. If it does not satisfy these conditions it is not a
   // link time GOT PC Rel opt instruction and we can ignore it and return
   // std::nullopt.
   const MCOperand &Operand = Inst.getOperand(LastOp);
   if (!Operand.isExpr())
     return std::nullopt;
 
-  // Check for the variant kind VK_PPC_PCREL_OPT in this expression.
+  // Check for the variant kind VK_PCREL_OPT in this expression.
   const MCExpr *Expr = Operand.getExpr();
   const MCSymbolRefExpr *SymExpr = static_cast<const MCSymbolRefExpr *>(Expr);
-  if (!SymExpr || SymExpr->getKind() != MCSymbolRefExpr::VK_PPC_PCREL_OPT)
+  if (!SymExpr || getVariantKind(SymExpr) != PPCMCExpr::VK_PCREL_OPT)
     return std::nullopt;
 
   return (Inst.getOpcode() == PPC::PLDpc);

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index faf9c38879ba4..8445c1ef67cec 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -13,6 +13,7 @@
 #include "MCTargetDesc/PPCInstPrinter.h"
 #include "MCTargetDesc/PPCMCTargetDesc.h"
 #include "MCTargetDesc/PPCPredicates.h"
+#include "PPCMCExpr.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
@@ -81,7 +82,7 @@ void PPCInstPrinter::printInst(const MCInst *MI, uint64_t Address,
   }
 
   // Check if the last operand is an expression with the variant kind
-  // VK_PPC_PCREL_OPT. If this is the case then this is a linker optimization
+  // VK_PCREL_OPT. If this is the case then this is a linker optimization
   // relocation and the .reloc directive needs to be added.
   unsigned LastOp = MI->getNumOperands() - 1;
   if (MI->getNumOperands() > 1) {
@@ -91,7 +92,7 @@ void PPCInstPrinter::printInst(const MCInst *MI, uint64_t Address,
       const MCSymbolRefExpr *SymExpr =
           static_cast<const MCSymbolRefExpr *>(Expr);
 
-      if (SymExpr && SymExpr->getKind() == MCSymbolRefExpr::VK_PPC_PCREL_OPT) {
+      if (SymExpr && getVariantKind(SymExpr) == PPCMCExpr::VK_PCREL_OPT) {
         const MCSymbol &Symbol = SymExpr->getSymbol();
         if (MI->getOpcode() == PPC::PLDpc) {
           printInstruction(MI, Address, STI, O);
@@ -575,17 +576,17 @@ void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
     RefExp = cast<MCSymbolRefExpr>(Op.getExpr());
 
   O << RefExp->getSymbol().getName();
-  // The variant kind VK_PPC_NOTOC needs to be handled as a special case
+  // The variant kind VK_NOTOC needs to be handled as a special case
   // because we do not want the assembly to print out the @notoc at the
   // end like __tls_get_addr(x at tlsgd)@notoc. Instead we want it to look
   // like __tls_get_addr at notoc(x at tlsgd).
-  if (RefExp->getKind() == MCSymbolRefExpr::VK_PPC_NOTOC)
+  if (getVariantKind(RefExp) == PPCMCExpr::VK_NOTOC)
     O << '@' << MAI.getVariantKindName(RefExp->getKind());
   O << '(';
   printOperand(MI, OpNo + 1, STI, O);
   O << ')';
-  if (RefExp->getKind() != MCSymbolRefExpr::VK_None &&
-      RefExp->getKind() != MCSymbolRefExpr::VK_PPC_NOTOC)
+  if (getVariantKind(RefExp) != PPCMCExpr::VK_None &&
+      getVariantKind(RefExp) != PPCMCExpr::VK_NOTOC)
     O << '@' << MAI.getVariantKindName(RefExp->getKind());
   if (Rhs) {
     SmallString<0> Buf;

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
index 15c2ad02d19d1..160ee07fad5cc 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
@@ -20,82 +20,82 @@ using namespace llvm;
 void PPCELFMCAsmInfo::anchor() { }
 
 const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
-    {MCSymbolRefExpr::VK_DTPREL, "DTPREL"},
-    {MCSymbolRefExpr::VK_GOT, "GOT"},
-    {MCSymbolRefExpr::VK_PCREL, "PCREL"},
-    {MCSymbolRefExpr::VK_PLT, "PLT"},
-    {MCSymbolRefExpr::VK_TLSGD, "tlsgd"},
-    {MCSymbolRefExpr::VK_TLSLD, "tlsld"},
-    {MCSymbolRefExpr::VK_TPREL, "TPREL"},
-    {PPCMCExpr::VK_LO, "l"},
+    {PPCMCExpr::VK_DTPREL, "DTPREL"},
+    {PPCMCExpr::VK_GOT, "GOT"},
+    {PPCMCExpr::VK_GOT_HA, "got at ha"},
+    {PPCMCExpr::VK_GOT_HI, "got at h"},
+    {PPCMCExpr::VK_GOT_LO, "got at l"},
+    {PPCMCExpr::VK_HA, "ha"},
     {PPCMCExpr::VK_HI, "h"},
-    {PPCMCExpr::VK_PPC_HA, "ha"},
     {PPCMCExpr::VK_HIGH, "high"},
     {PPCMCExpr::VK_HIGHA, "higha"},
     {PPCMCExpr::VK_HIGHER, "higher"},
     {PPCMCExpr::VK_HIGHERA, "highera"},
     {PPCMCExpr::VK_HIGHEST, "highest"},
     {PPCMCExpr::VK_HIGHESTA, "highesta"},
-    {MCSymbolRefExpr::VK_PPC_GOT_LO, "got at l"},
-    {MCSymbolRefExpr::VK_PPC_GOT_HI, "got at h"},
-    {MCSymbolRefExpr::VK_PPC_GOT_HA, "got at ha"},
-    {MCSymbolRefExpr::VK_PPC_TOCBASE, "tocbase"},
-    {MCSymbolRefExpr::VK_PPC_TOC, "toc"},
-    {MCSymbolRefExpr::VK_PPC_TOC_LO, "toc at l"},
-    {MCSymbolRefExpr::VK_PPC_TOC_HI, "toc at h"},
-    {MCSymbolRefExpr::VK_PPC_TOC_HA, "toc at ha"},
-    {MCSymbolRefExpr::VK_PPC_U, "u"},
-    {MCSymbolRefExpr::VK_PPC_L, "l"}, // FIXME: share the name with VK_LO
-    {MCSymbolRefExpr::VK_PPC_DTPMOD, "dtpmod"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_LO, "tprel at l"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HI, "tprel at h"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HA, "tprel at ha"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGH, "tprel at high"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGHA, "tprel at higha"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGHER, "tprel at higher"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA, "tprel at highera"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST, "tprel at highest"},
-    {MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA, "tprel at highesta"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_LO, "dtprel at l"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HI, "dtprel at h"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HA, "dtprel at ha"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGH, "dtprel at high"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGHA, "dtprel at higha"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER, "dtprel at higher"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA, "dtprel at highera"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST, "dtprel at highest"},
-    {MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA, "dtprel at highesta"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TPREL, "got at tprel"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO, "got at tprel@l"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI, "got at tprel@h"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA, "got at tprel@ha"},
-    {MCSymbolRefExpr::VK_PPC_GOT_DTPREL, "got at dtprel"},
-    {MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO, "got at dtprel@l"},
-    {MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI, "got at dtprel@h"},
-    {MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA, "got at dtprel@ha"},
-    {MCSymbolRefExpr::VK_PPC_TLS, "tls"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSGD, "got at tlsgd"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO, "got at tlsgd@l"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI, "got at tlsgd@h"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA, "got at tlsgd@ha"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSGD, "gd"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSGDM, "m"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSIE, "ie"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSLE, "le"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSLD, "ld"},
-    {MCSymbolRefExpr::VK_PPC_AIX_TLSML, "ml"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSLD, "got at tlsld"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO, "got at tlsld@l"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI, "got at tlsld@h"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA, "got at tlsld@ha"},
-    {MCSymbolRefExpr::VK_PPC_GOT_PCREL, "got at pcrel"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSGD_PCREL, "got at tlsgd@pcrel"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TLSLD_PCREL, "got at tlsld@pcrel"},
-    {MCSymbolRefExpr::VK_PPC_GOT_TPREL_PCREL, "got at tprel@pcrel"},
-    {MCSymbolRefExpr::VK_PPC_TLS_PCREL, "tls at pcrel"},
-    {MCSymbolRefExpr::VK_PPC_LOCAL, "local"},
-    {MCSymbolRefExpr::VK_PPC_NOTOC, "notoc"},
-    {MCSymbolRefExpr::VK_PPC_PCREL_OPT, "<<invalid>>"},
+    {PPCMCExpr::VK_LO, "l"},
+    {PPCMCExpr::VK_L, "l"}, // FIXME: share the name with VK_LO
+    {PPCMCExpr::VK_PCREL, "PCREL"},
+    {PPCMCExpr::VK_PLT, "PLT"},
+    {PPCMCExpr::VK_TLSGD, "tlsgd"},
+    {PPCMCExpr::VK_TLSLD, "tlsld"},
+    {PPCMCExpr::VK_TOC, "toc"},
+    {PPCMCExpr::VK_TOCBASE, "tocbase"},
+    {PPCMCExpr::VK_TOC_HA, "toc at ha"},
+    {PPCMCExpr::VK_TOC_HI, "toc at h"},
+    {PPCMCExpr::VK_TOC_LO, "toc at l"},
+    {PPCMCExpr::VK_TPREL, "TPREL"},
+    {PPCMCExpr::VK_AIX_TLSGD, "gd"},
+    {PPCMCExpr::VK_AIX_TLSGDM, "m"},
+    {PPCMCExpr::VK_AIX_TLSIE, "ie"},
+    {PPCMCExpr::VK_AIX_TLSLD, "ld"},
+    {PPCMCExpr::VK_AIX_TLSLE, "le"},
+    {PPCMCExpr::VK_AIX_TLSML, "ml"},
+    {PPCMCExpr::VK_DTPMOD, "dtpmod"},
+    {PPCMCExpr::VK_DTPREL_HA, "dtprel at ha"},
+    {PPCMCExpr::VK_DTPREL_HI, "dtprel at h"},
+    {PPCMCExpr::VK_DTPREL_HIGH, "dtprel at high"},
+    {PPCMCExpr::VK_DTPREL_HIGHA, "dtprel at higha"},
+    {PPCMCExpr::VK_DTPREL_HIGHER, "dtprel at higher"},
+    {PPCMCExpr::VK_DTPREL_HIGHERA, "dtprel at highera"},
+    {PPCMCExpr::VK_DTPREL_HIGHEST, "dtprel at highest"},
+    {PPCMCExpr::VK_DTPREL_HIGHESTA, "dtprel at highesta"},
+    {PPCMCExpr::VK_DTPREL_LO, "dtprel at l"},
+    {PPCMCExpr::VK_GOT_DTPREL, "got at dtprel"},
+    {PPCMCExpr::VK_GOT_DTPREL_HA, "got at dtprel@ha"},
+    {PPCMCExpr::VK_GOT_DTPREL_HI, "got at dtprel@h"},
+    {PPCMCExpr::VK_GOT_DTPREL_LO, "got at dtprel@l"},
+    {PPCMCExpr::VK_GOT_PCREL, "got at pcrel"},
+    {PPCMCExpr::VK_GOT_TLSGD, "got at tlsgd"},
+    {PPCMCExpr::VK_GOT_TLSGD_HA, "got at tlsgd@ha"},
+    {PPCMCExpr::VK_GOT_TLSGD_HI, "got at tlsgd@h"},
+    {PPCMCExpr::VK_GOT_TLSGD_LO, "got at tlsgd@l"},
+    {PPCMCExpr::VK_GOT_TLSGD_PCREL, "got at tlsgd@pcrel"},
+    {PPCMCExpr::VK_GOT_TLSLD, "got at tlsld"},
+    {PPCMCExpr::VK_GOT_TLSLD_HA, "got at tlsld@ha"},
+    {PPCMCExpr::VK_GOT_TLSLD_HI, "got at tlsld@h"},
+    {PPCMCExpr::VK_GOT_TLSLD_LO, "got at tlsld@l"},
+    {PPCMCExpr::VK_GOT_TLSLD_PCREL, "got at tlsld@pcrel"},
+    {PPCMCExpr::VK_GOT_TPREL, "got at tprel"},
+    {PPCMCExpr::VK_GOT_TPREL_HA, "got at tprel@ha"},
+    {PPCMCExpr::VK_GOT_TPREL_HI, "got at tprel@h"},
+    {PPCMCExpr::VK_GOT_TPREL_LO, "got at tprel@l"},
+    {PPCMCExpr::VK_GOT_TPREL_PCREL, "got at tprel@pcrel"},
+    {PPCMCExpr::VK_LOCAL, "local"},
+    {PPCMCExpr::VK_NOTOC, "notoc"},
+    {PPCMCExpr::VK_PCREL_OPT, "<<invalid>>"},
+    {PPCMCExpr::VK_TLS, "tls"},
+    {PPCMCExpr::VK_TLS_PCREL, "tls at pcrel"},
+    {PPCMCExpr::VK_TPREL_HA, "tprel at ha"},
+    {PPCMCExpr::VK_TPREL_HI, "tprel at h"},
+    {PPCMCExpr::VK_TPREL_HIGH, "tprel at high"},
+    {PPCMCExpr::VK_TPREL_HIGHA, "tprel at higha"},
+    {PPCMCExpr::VK_TPREL_HIGHER, "tprel at higher"},
+    {PPCMCExpr::VK_TPREL_HIGHERA, "tprel at highera"},
+    {PPCMCExpr::VK_TPREL_HIGHEST, "tprel at highest"},
+    {PPCMCExpr::VK_TPREL_HIGHESTA, "tprel at highesta"},
+    {PPCMCExpr::VK_TPREL_LO, "tprel at l"},
+    {PPCMCExpr::VK_U, "u"},
 };
 
 PPCELFMCAsmInfo::PPCELFMCAsmInfo(bool is64Bit, const Triple& T) {

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
index 2539c6e49686a..d8ca2e36ecbd6 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
@@ -12,6 +12,7 @@
 
 #include "PPCMCCodeEmitter.h"
 #include "MCTargetDesc/PPCFixupKinds.h"
+#include "PPCMCExpr.h"
 #include "PPCMCTargetDesc.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
@@ -328,14 +329,14 @@ PPCMCCodeEmitter::getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(Expr);
     (void)SRE;
     // Currently these are the only valid PCRelative Relocations.
-    assert((SRE->getKind() == MCSymbolRefExpr::VK_PCREL ||
-            SRE->getKind() == MCSymbolRefExpr::VK_PPC_GOT_PCREL ||
-            SRE->getKind() == MCSymbolRefExpr::VK_PPC_GOT_TLSGD_PCREL ||
-            SRE->getKind() == MCSymbolRefExpr::VK_PPC_GOT_TLSLD_PCREL ||
-            SRE->getKind() == MCSymbolRefExpr::VK_PPC_GOT_TPREL_PCREL) &&
-           "VariantKind must be VK_PCREL or VK_PPC_GOT_PCREL or "
-           "VK_PPC_GOT_TLSGD_PCREL or VK_PPC_GOT_TLSLD_PCREL or "
-           "VK_PPC_GOT_TPREL_PCREL.");
+    assert((getVariantKind(SRE) == PPCMCExpr::VK_PCREL ||
+            getVariantKind(SRE) == PPCMCExpr::VK_GOT_PCREL ||
+            getVariantKind(SRE) == PPCMCExpr::VK_GOT_TLSGD_PCREL ||
+            getVariantKind(SRE) == PPCMCExpr::VK_GOT_TLSLD_PCREL ||
+            getVariantKind(SRE) == PPCMCExpr::VK_GOT_TPREL_PCREL) &&
+           "VariantKind must be VK_PCREL or VK_GOT_PCREL or "
+           "VK_GOT_TLSGD_PCREL or VK_GOT_TLSLD_PCREL or "
+           "VK_GOT_TPREL_PCREL.");
     // Generate the fixup for the relocation.
     Fixups.push_back(
         MCFixup::create(0, Expr,
@@ -367,9 +368,9 @@ PPCMCCodeEmitter::getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
            "Value must fit in 34 bits.");
 
     // Currently these are the only valid PCRelative Relocations.
-    assert((SRE->getKind() == MCSymbolRefExpr::VK_PCREL ||
-            SRE->getKind() == MCSymbolRefExpr::VK_PPC_GOT_PCREL) &&
-           "VariantKind must be VK_PCREL or VK_PPC_GOT_PCREL");
+    assert((getVariantKind(SRE) == PPCMCExpr::VK_PCREL ||
+            getVariantKind(SRE) == PPCMCExpr::VK_GOT_PCREL) &&
+           "VariantKind must be VK_PCREL or VK_GOT_PCREL");
     // Generate the fixup for the relocation.
     Fixups.push_back(
         MCFixup::create(0, Expr,
@@ -432,7 +433,7 @@ unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
   // if using PC relative memops.
   const MCExpr *Expr = MO.getExpr();
   const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(Expr);
-  bool IsPCRel = SRE->getKind() == MCSymbolRefExpr::VK_PPC_TLS_PCREL;
+  bool IsPCRel = getVariantKind(SRE) == PPCMCExpr::VK_TLS_PCREL;
   Fixups.push_back(MCFixup::create(IsPCRel ? 1 : 0, Expr,
                                    (MCFixupKind)PPC::fixup_ppc_nofixup));
   const Triple &TT = STI.getTargetTriple();

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
index 03c86b1e8447f..5cd5a8f2cd4c9 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
@@ -8,10 +8,13 @@
 
 #include "PPCMCExpr.h"
 #include "PPCFixupKinds.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCObjectStreamer.h"
+#include "llvm/MC/MCSymbolELF.h"
+#include "llvm/Support/Casting.h"
 
 using namespace llvm;
 
@@ -49,7 +52,7 @@ std::optional<int64_t> PPCMCExpr::evaluateAsInt64(int64_t Value) const {
     return Value & 0xffff;
   case VK_HI:
     return (Value >> 16) & 0xffff;
-  case VK_PPC_HA:
+  case VK_HA:
     return ((Value + 0x8000) >> 16) & 0xffff;
   case VK_HIGH:
     return (Value >> 16) & 0xffff;

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h
index fd5351dfb799c..7f4b377302e54 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h
@@ -18,18 +18,87 @@ namespace llvm {
 class PPCMCExpr : public MCTargetExpr {
 public:
   enum VariantKind {
-    VK_PPC_None,
+    VK_None,
+
     // We currently use both MCSymbolRefExpr::VariantKind and
     // PPCMCExpr::VariantKind. Start at a larger number to avoid conflicts.
     VK_LO = 200,
     VK_HI,
-    VK_PPC_HA,
+    VK_HA,
     VK_HIGH,
     VK_HIGHA,
     VK_HIGHER,
     VK_HIGHERA,
     VK_HIGHEST,
     VK_HIGHESTA,
+
+    VK_AIX_TLSGD,       // symbol at gd
+    VK_AIX_TLSGDM,      // symbol at m
+    VK_AIX_TLSIE,       // symbol at ie
+    VK_AIX_TLSLD,       // symbol at ld
+    VK_AIX_TLSLE,       // symbol at le
+    VK_AIX_TLSML,       // symbol at ml
+    VK_DTPMOD,          // symbol at dtpmod
+    VK_DTPREL,          // symbol at dprel
+    VK_DTPREL_HA,       // symbol at dtprel@ha
+    VK_DTPREL_HI,       // symbol at dtprel@h
+    VK_DTPREL_HIGH,     // symbol at dtprel@high
+    VK_DTPREL_HIGHA,    // symbol at dtprel@higha
+    VK_DTPREL_HIGHER,   // symbol at dtprel@higher
+    VK_DTPREL_HIGHERA,  // symbol at dtprel@highera
+    VK_DTPREL_HIGHEST,  // symbol at dtprel@highest
+    VK_DTPREL_HIGHESTA, // symbol at dtprel@highesta
+    VK_DTPREL_LO,       // symbol at dtprel@l
+    VK_GOT,             // symbol at got
+    VK_GOT_DTPREL,      // symbol at got@dtprel
+    VK_GOT_DTPREL_HA,   // symbol at got@dtprel at ha
+    VK_GOT_DTPREL_HI,   // symbol at got@dtprel at h
+    VK_GOT_DTPREL_LO,   // symbol at got@dtprel at l
+    VK_GOT_HA,          // symbol at got@ha
+    VK_GOT_HI,          // symbol at got@h
+    VK_GOT_LO,          // symbol at got@l
+    VK_GOT_PCREL,       // symbol at got@pcrel
+    VK_GOT_TLSGD,       // symbol at got@tlsgd
+    VK_GOT_TLSGD_HA,    // symbol at got@tlsgd at ha
+    VK_GOT_TLSGD_HI,    // symbol at got@tlsgd at h
+    VK_GOT_TLSGD_LO,    // symbol at got@tlsgd at l
+    VK_GOT_TLSGD_PCREL, // symbol at got@tlsgd at pcrel
+    VK_GOT_TLSLD,       // symbol at got@tlsld
+    VK_GOT_TLSLD_HA,    // symbol at got@tlsld at ha
+    VK_GOT_TLSLD_HI,    // symbol at got@tlsld at h
+    VK_GOT_TLSLD_LO,    // symbol at got@tlsld at l
+    VK_GOT_TLSLD_PCREL, // symbol at got@tlsld at pcrel
+    VK_GOT_TPREL,       // symbol at got@tprel
+    VK_GOT_TPREL_HA,    // symbol at got@tprel at ha
+    VK_GOT_TPREL_HI,    // symbol at got@tprel at h
+    VK_GOT_TPREL_LO,    // symbol at got@tprel at l
+    VK_GOT_TPREL_PCREL, // symbol at got@tprel at pcrel
+    VK_L,               // symbol at l
+    VK_LOCAL,           // symbol at local
+    VK_NOTOC,           // symbol at notoc
+    VK_PCREL,
+    VK_PCREL_OPT,      // .reloc expr, R_PPC64_PCREL_OPT, expr
+    VK_PLT,            // symbol at plt
+    VK_TLS,            // symbol at tls
+    VK_TLSGD,          // symbol at tlsgd
+    VK_TLSLD,          // symbol at tlsld
+    VK_TLS_PCREL,      // symbol at tls@pcrel
+    VK_TOC,            // symbol at toc
+    VK_TOCBASE,        // symbol at tocbase
+    VK_TOC_HA,         // symbol at toc@ha
+    VK_TOC_HI,         // symbol at toc@h
+    VK_TOC_LO,         // symbol at toc@l
+    VK_TPREL,          // symbol at tprel
+    VK_TPREL_HA,       // symbol at tprel@ha
+    VK_TPREL_HI,       // symbol at tprel@h
+    VK_TPREL_HIGH,     // symbol at tprel@high
+    VK_TPREL_HIGHA,    // symbol at tprel@higha
+    VK_TPREL_HIGHER,   // symbol at tprel@higher
+    VK_TPREL_HIGHERA,  // symbol at tprel@highera
+    VK_TPREL_HIGHEST,  // symbol at tprel@highest
+    VK_TPREL_HIGHESTA, // symbol at tprel@highesta
+    VK_TPREL_LO,       // symbol at tprel@l
+    VK_U,              // symbol at u
   };
 
 private:
@@ -57,7 +126,7 @@ class PPCMCExpr : public MCTargetExpr {
   }
 
   static const PPCMCExpr *createHa(const MCExpr *Expr, MCContext &Ctx) {
-    return create(VK_PPC_HA, Expr, Ctx);
+    return create(VK_HA, Expr, Ctx);
   }
 
   /// @}
@@ -89,6 +158,12 @@ class PPCMCExpr : public MCTargetExpr {
     return E->getKind() == MCExpr::Target;
   }
 };
+
+static inline PPCMCExpr::VariantKind
+getVariantKind(const MCSymbolRefExpr *SRE) {
+  return PPCMCExpr::VariantKind(SRE->getKind());
+}
+
 } // end namespace llvm
 
 #endif

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
index 3454ef02ac174..1d4e8954d033d 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
@@ -14,6 +14,7 @@
 #include "MCTargetDesc/PPCInstPrinter.h"
 #include "MCTargetDesc/PPCMCAsmInfo.h"
 #include "PPCELFStreamer.h"
+#include "PPCMCExpr.h"
 #include "PPCTargetStreamer.h"
 #include "PPCXCOFFStreamer.h"
 #include "TargetInfo/PowerPCTargetInfo.h"
@@ -208,8 +209,7 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
   PPCTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
       : PPCTargetStreamer(S), OS(OS) {}
 
-  void emitTCEntry(const MCSymbol &S,
-                   MCSymbolRefExpr::VariantKind Kind) override {
+  void emitTCEntry(const MCSymbol &S, PPCMCExpr::VariantKind Kind) override {
     if (const MCSymbolXCOFF *XSym = dyn_cast<MCSymbolXCOFF>(&S)) {
       MCSymbolXCOFF *TCSym =
           cast<MCSectionXCOFF>(Streamer.getCurrentSectionOnly())
@@ -221,12 +221,9 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
       // variables. Finally for local-exec and initial-exec, we have a thread
       // pointer, in r13 for 64-bit mode and returned by .__get_tpointer for
       // 32-bit mode.
-      if (Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGD ||
-          Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM ||
-          Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSIE ||
-          Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLE ||
-          Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLD ||
-          Kind == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSML)
+      if (Kind == PPCMCExpr::VK_AIX_TLSGD || Kind == PPCMCExpr::VK_AIX_TLSGDM ||
+          Kind == PPCMCExpr::VK_AIX_TLSIE || Kind == PPCMCExpr::VK_AIX_TLSLE ||
+          Kind == PPCMCExpr::VK_AIX_TLSLD || Kind == PPCMCExpr::VK_AIX_TLSML)
         OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@"
            << getContext().getAsmInfo()->getVariantKindName(Kind) << '\n';
       else
@@ -271,8 +268,7 @@ class PPCTargetELFStreamer : public PPCTargetStreamer {
     return static_cast<MCELFStreamer &>(Streamer);
   }
 
-  void emitTCEntry(const MCSymbol &S,
-                   MCSymbolRefExpr::VariantKind Kind) override {
+  void emitTCEntry(const MCSymbol &S, PPCMCExpr::VariantKind Kind) override {
     // Creates a R_PPC64_TOC relocation
     Streamer.emitValueToAlignment(Align(8));
     Streamer.emitSymbolValue(&S, 8);
@@ -376,8 +372,7 @@ class PPCTargetMachOStreamer : public PPCTargetStreamer {
 public:
   PPCTargetMachOStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
 
-  void emitTCEntry(const MCSymbol &S,
-                   MCSymbolRefExpr::VariantKind Kind) override {
+  void emitTCEntry(const MCSymbol &S, PPCMCExpr::VariantKind Kind) override {
     llvm_unreachable("Unknown pseudo-op: .tc");
   }
 
@@ -399,13 +394,14 @@ class PPCTargetXCOFFStreamer : public PPCTargetStreamer {
 public:
   PPCTargetXCOFFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
 
-  void emitTCEntry(const MCSymbol &S,
-                   MCSymbolRefExpr::VariantKind Kind) override {
+  void emitTCEntry(const MCSymbol &S, PPCMCExpr::VariantKind Kind) override {
     const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
     const unsigned PointerSize = MAI->getCodePointerSize();
     Streamer.emitValueToAlignment(Align(PointerSize));
-    Streamer.emitValue(MCSymbolRefExpr::create(&S, Kind, Streamer.getContext()),
-                       PointerSize);
+    Streamer.emitValue(
+        MCSymbolRefExpr::create(&S, MCSymbolRefExpr::VariantKind(Kind),
+                                Streamer.getContext()),
+        PointerSize);
   }
 
   void emitMachine(StringRef CPU) override {

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCTargetStreamer.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCTargetStreamer.h
index daf5b93ff21f0..bc8e7d584928d 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCTargetStreamer.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCTargetStreamer.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIB_TARGET_POWERPC_PPCTARGETSTREAMER_H
 #define LLVM_LIB_TARGET_POWERPC_PPCTARGETSTREAMER_H
 
+#include "PPCMCExpr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCStreamer.h"
@@ -24,8 +25,7 @@ class PPCTargetStreamer : public MCTargetStreamer {
   PPCTargetStreamer(MCStreamer &S);
   ~PPCTargetStreamer() override;
 
-  virtual void emitTCEntry(const MCSymbol &S,
-                           MCSymbolRefExpr::VariantKind Kind){};
+  virtual void emitTCEntry(const MCSymbol &S, PPCMCExpr::VariantKind Kind) {}
   virtual void emitMachine(StringRef CPU){};
   virtual void emitAbiVersion(int AbiVersion){};
   virtual void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset){};

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp
index c0caf342f60ae..95e1e580ca08f 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp
@@ -9,6 +9,7 @@
 
 #include "MCTargetDesc/PPCFixupKinds.h"
 #include "MCTargetDesc/PPCMCTargetDesc.h"
+#include "PPCMCExpr.h"
 #include "llvm/BinaryFormat/XCOFF.h"
 #include "llvm/MC/MCFixup.h"
 #include "llvm/MC/MCValue.h"
@@ -39,9 +40,8 @@ llvm::createPPCXCOFFObjectWriter(bool Is64Bit) {
 
 std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
     const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const {
-  const MCSymbolRefExpr::VariantKind Modifier =
-      Target.isAbsolute() ? MCSymbolRefExpr::VK_None
-                          : Target.getSymA()->getKind();
+  const auto Modifier = Target.isAbsolute() ? PPCMCExpr::VK_None
+                                            : getVariantKind(Target.getSymA());
   // People from AIX OS team says AIX link editor does not care about
   // the sign bit in the relocation entry "most" of the time.
   // The system assembler seems to set the sign bit on relocation entry
@@ -62,15 +62,15 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
     switch (Modifier) {
     default:
       report_fatal_error("Unsupported modifier for half16 fixup.");
-    case MCSymbolRefExpr::VK_None:
+    case PPCMCExpr::VK_None:
       return {XCOFF::RelocationType::R_TOC, SignAndSizeForHalf16};
-    case MCSymbolRefExpr::VK_PPC_U:
+    case PPCMCExpr::VK_U:
       return {XCOFF::RelocationType::R_TOCU, SignAndSizeForHalf16};
-    case MCSymbolRefExpr::VK_PPC_L:
+    case PPCMCExpr::VK_L:
       return {XCOFF::RelocationType::R_TOCL, SignAndSizeForHalf16};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLE:
+    case PPCMCExpr::VK_AIX_TLSLE:
       return {XCOFF::RelocationType::R_TLS_LE, SignAndSizeForHalf16};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLD:
+    case PPCMCExpr::VK_AIX_TLSLD:
       return {XCOFF::RelocationType::R_TLS_LD, SignAndSizeForHalf16};
     }
   } break;
@@ -81,13 +81,13 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
     switch (Modifier) {
     default:
       llvm_unreachable("Unsupported Modifier");
-    case MCSymbolRefExpr::VK_None:
+    case PPCMCExpr::VK_None:
       return {XCOFF::RelocationType::R_TOC, 15};
-    case MCSymbolRefExpr::VK_PPC_L:
+    case PPCMCExpr::VK_L:
       return {XCOFF::RelocationType::R_TOCL, 15};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLE:
+    case PPCMCExpr::VK_AIX_TLSLE:
       return {XCOFF::RelocationType::R_TLS_LE, 15};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLD:
+    case PPCMCExpr::VK_AIX_TLSLD:
       return {XCOFF::RelocationType::R_TLS_LD, 15};
     }
   } break;
@@ -98,7 +98,7 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
   case PPC::fixup_ppc_br24abs:
     return {XCOFF::RelocationType::R_RBA, EncodedSignednessIndicator | 25};
   case PPC::fixup_ppc_nofixup: {
-    if (Modifier == MCSymbolRefExpr::VK_None)
+    if (Modifier == PPCMCExpr::VK_None)
       return {XCOFF::RelocationType::R_REF, 0};
     else
       llvm_unreachable("Unsupported Modifier");
@@ -111,19 +111,19 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
     switch (Modifier) {
     default:
       report_fatal_error("Unsupported modifier");
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSGD:
+    case PPCMCExpr::VK_AIX_TLSGD:
       return {XCOFF::RelocationType::R_TLS, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSGDM:
+    case PPCMCExpr::VK_AIX_TLSGDM:
       return {XCOFF::RelocationType::R_TLSM, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSIE:
+    case PPCMCExpr::VK_AIX_TLSIE:
       return {XCOFF::RelocationType::R_TLS_IE, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLE:
+    case PPCMCExpr::VK_AIX_TLSLE:
       return {XCOFF::RelocationType::R_TLS_LE, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSLD:
+    case PPCMCExpr::VK_AIX_TLSLD:
       return {XCOFF::RelocationType::R_TLS_LD, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_PPC_AIX_TLSML:
+    case PPCMCExpr::VK_AIX_TLSML:
       return {XCOFF::RelocationType::R_TLSML, SignAndSizeForFKData};
-    case MCSymbolRefExpr::VK_None:
+    case PPCMCExpr::VK_None:
       return {XCOFF::RelocationType::R_POS, SignAndSizeForFKData};
     }
   }

diff  --git a/llvm/lib/Target/PowerPC/PPC.h b/llvm/lib/Target/PowerPC/PPC.h
index acd111d8824b4..d95ee56d608ff 100644
--- a/llvm/lib/Target/PowerPC/PPC.h
+++ b/llvm/lib/Target/PowerPC/PPC.h
@@ -120,7 +120,7 @@ class ModulePass;
 
     /// MO_GOT_FLAG - If this bit is set the symbol reference is to be computed
     /// via the GOT. For example when combined with the MO_PCREL_FLAG it should
-    /// produce the relocation @got at pcrel. Fixup is VK_PPC_GOT_PCREL.
+    /// produce the relocation @got at pcrel. Fixup is VK_GOT_PCREL.
     MO_GOT_FLAG,
 
     /// MO_PCREL_OPT_FLAG - If this bit is set the operand is part of a
@@ -153,19 +153,19 @@ class ModulePass;
 
     /// MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set
     /// they should produce the relocation @got at tlsgd@pcrel.
-    /// Fix up is VK_PPC_GOT_TLSGD_PCREL
+    /// Fix up is VK_GOT_TLSGD_PCREL
     /// MO_GOT_TLSGD_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG | MO_TLSGD_FLAG,
     MO_GOT_TLSGD_PCREL_FLAG,
 
     /// MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set
     /// they should produce the relocation @got at tlsld@pcrel.
-    /// Fix up is VK_PPC_GOT_TLSLD_PCREL
+    /// Fix up is VK_GOT_TLSLD_PCREL
     /// MO_GOT_TLSLD_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG | MO_TLSLD_FLAG,
     MO_GOT_TLSLD_PCREL_FLAG,
 
     /// MO_GOT_TPREL_PCREL_FLAG - A combintaion of flags, if these bits are set
     /// they should produce the relocation @got at tprel@pcrel.
-    /// Fix up is VK_PPC_GOT_TPREL_PCREL
+    /// Fix up is VK_GOT_TPREL_PCREL
     /// MO_GOT_TPREL_PCREL_FLAG = MO_GOT_FLAG | MO_TPREL_FLAG | MO_PCREL_FLAG,
     MO_GOT_TPREL_PCREL_FLAG,
 
@@ -182,7 +182,7 @@ class ModulePass;
     MO_TLSLD_LO,
     MO_TOC_LO,
 
-    /// Symbol for VK_PPC_TLS fixup attached to an ADD instruction
+    /// Symbol for VK_TLS fixup attached to an ADD instruction
     MO_TLS,
 
     /// MO_PIC_HA_FLAG = MO_PIC_FLAG | MO_HA

diff  --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index c9e9b917e3175..79e52635a3675 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -100,19 +100,17 @@ static cl::opt<bool> EnableSSPCanaryBitInTB(
     cl::desc("Enable Passing SSP Canary info in Trackback on AIX"), cl::Hidden);
 
 // Specialize DenseMapInfo to allow
-// std::pair<const MCSymbol *, MCSymbolRefExpr::VariantKind> in DenseMap.
+// std::pair<const MCSymbol *, PPCMCExpr::VariantKind> in DenseMap.
 // This specialization is needed here because that type is used as keys in the
 // map representing TOC entries.
 namespace llvm {
 template <>
-struct DenseMapInfo<std::pair<const MCSymbol *, MCSymbolRefExpr::VariantKind>> {
-  using TOCKey = std::pair<const MCSymbol *, MCSymbolRefExpr::VariantKind>;
+struct DenseMapInfo<std::pair<const MCSymbol *, PPCMCExpr::VariantKind>> {
+  using TOCKey = std::pair<const MCSymbol *, PPCMCExpr::VariantKind>;
 
-  static inline TOCKey getEmptyKey() {
-    return {nullptr, MCSymbolRefExpr::VK_None};
-  }
+  static inline TOCKey getEmptyKey() { return {nullptr, PPCMCExpr::VK_None}; }
   static inline TOCKey getTombstoneKey() {
-    return {(const MCSymbol *)1, MCSymbolRefExpr::VK_None};
+    return {(const MCSymbol *)1, PPCMCExpr::VK_None};
   }
   static unsigned getHashValue(const TOCKey &PairVal) {
     return detail::combineHashValue(
@@ -151,8 +149,7 @@ class PPCAsmPrinter : public AsmPrinter {
   // entry as a TLSGD entry so we can add the @m relocation:
   //   .tc .i[TC],i[TL]@m
   // By default, VK_None is used for the VariantKind.
-  MapVector<std::pair<const MCSymbol *, MCSymbolRefExpr::VariantKind>,
-            MCSymbol *>
+  MapVector<std::pair<const MCSymbol *, PPCMCExpr::VariantKind>, MCSymbol *>
       TOC;
   const PPCSubtarget *Subtarget = nullptr;
 
@@ -178,9 +175,9 @@ class PPCAsmPrinter : public AsmPrinter {
     TOCType_EHBlock
   };
 
-  MCSymbol *lookUpOrCreateTOCEntry(const MCSymbol *Sym, TOCEntryType Type,
-                                   MCSymbolRefExpr::VariantKind Kind =
-                                       MCSymbolRefExpr::VariantKind::VK_None);
+  MCSymbol *
+  lookUpOrCreateTOCEntry(const MCSymbol *Sym, TOCEntryType Type,
+                         PPCMCExpr::VariantKind Kind = PPCMCExpr::VK_None);
 
   bool doInitialization(Module &M) override {
     if (!TOC.empty())
@@ -188,6 +185,8 @@ class PPCAsmPrinter : public AsmPrinter {
     return AsmPrinter::doInitialization(M);
   }
 
+  const MCExpr *symbolWithVariant(const MCSymbol *S,
+                                  PPCMCExpr::VariantKind Kind);
   void emitInstruction(const MachineInstr *MI) override;
 
   /// This function is for PrintAsmOperand and PrintAsmMemoryOperand,
@@ -203,7 +202,7 @@ class PPCAsmPrinter : public AsmPrinter {
 
   void LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI);
   void LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI);
-  void EmitTlsCall(const MachineInstr *MI, MCSymbolRefExpr::VariantKind VK);
+  void emitTlsCall(const MachineInstr *MI, PPCMCExpr::VariantKind VK);
   void EmitAIXTlsCallHelper(const MachineInstr *MI);
   const MCExpr *getAdjustedFasterLocalExpr(const MachineOperand &MO,
                                            int64_t Offset);
@@ -508,9 +507,9 @@ static void setOptionalCodeModel(MCSymbolXCOFF *XSym, CodeModel::Model CM) {
 /// lookUpOrCreateTOCEntry -- Given a symbol, look up whether a TOC entry
 /// exists for it.  If not, create one.  Then return a symbol that references
 /// the TOC entry.
-MCSymbol *
-PPCAsmPrinter::lookUpOrCreateTOCEntry(const MCSymbol *Sym, TOCEntryType Type,
-                                      MCSymbolRefExpr::VariantKind Kind) {
+MCSymbol *PPCAsmPrinter::lookUpOrCreateTOCEntry(const MCSymbol *Sym,
+                                                TOCEntryType Type,
+                                                PPCMCExpr::VariantKind Kind) {
   // If this is a new TOC entry add statistics about it.
   if (!TOC.contains({Sym, Kind}))
     collectTOCStats(Type);
@@ -684,17 +683,17 @@ void PPCAsmPrinter::EmitAIXTlsCallHelper(const MachineInstr *MI) {
   EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BLA).addExpr(TlsRef));
 }
 
-/// EmitTlsCall -- Given a GETtls[ld]ADDR[32] instruction, print a
-/// call to __tls_get_addr to the current output stream.
-void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
-                                MCSymbolRefExpr::VariantKind VK) {
-  MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
+/// Given a GETtls[ld]ADDR[32] instruction, print a call to __tls_get_addr to
+/// the current output stream.
+void PPCAsmPrinter::emitTlsCall(const MachineInstr *MI,
+                                PPCMCExpr::VariantKind VK) {
+  PPCMCExpr::VariantKind Kind = PPCMCExpr::VK_None;
   unsigned Opcode = PPC::BL8_NOP_TLS;
 
   assert(MI->getNumOperands() >= 3 && "Expecting at least 3 operands from MI");
   if (MI->getOperand(2).getTargetFlags() == PPCII::MO_GOT_TLSGD_PCREL_FLAG ||
       MI->getOperand(2).getTargetFlags() == PPCII::MO_GOT_TLSLD_PCREL_FLAG) {
-    Kind = MCSymbolRefExpr::VK_PPC_NOTOC;
+    Kind = PPCMCExpr::VK_NOTOC;
     Opcode = PPC::BL8_NOTOC_TLS;
   }
   const Module *M = MF->getFunction().getParent();
@@ -727,20 +726,21 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
   MCSymbol *TlsGetAddr = OutContext.getOrCreateSymbol("__tls_get_addr");
 
   if (Subtarget->is32BitELFABI() && isPositionIndependent())
-    Kind = MCSymbolRefExpr::VK_PLT;
+    Kind = PPCMCExpr::VK_PLT;
 
-  const MCExpr *TlsRef =
-    MCSymbolRefExpr::create(TlsGetAddr, Kind, OutContext);
+  const MCExpr *TlsRef = MCSymbolRefExpr::create(
+      TlsGetAddr, MCSymbolRefExpr::VariantKind(Kind), OutContext);
 
   // Add 32768 offset to the symbol so we follow up the latest GOT/PLT ABI.
-  if (Kind == MCSymbolRefExpr::VK_PLT && Subtarget->isSecurePlt() &&
+  if (Kind == PPCMCExpr::VK_PLT && Subtarget->isSecurePlt() &&
       M->getPICLevel() == PICLevel::BigPIC)
     TlsRef = MCBinaryExpr::createAdd(
         TlsRef, MCConstantExpr::create(32768, OutContext), OutContext);
   const MachineOperand &MO = MI->getOperand(2);
   const GlobalValue *GValue = MO.getGlobal();
   MCSymbol *MOSymbol = getSymbol(GValue);
-  const MCExpr *SymVar = MCSymbolRefExpr::create(MOSymbol, VK, OutContext);
+  const MCExpr *SymVar = MCSymbolRefExpr::create(
+      MOSymbol, MCSymbolRefExpr::VariantKind(VK), OutContext);
   EmitToStreamer(*OutStreamer,
                  MCInstBuilder(Subtarget->isPPC64() ? Opcode
                                                     : (unsigned)PPC::BL_TLS)
@@ -794,6 +794,13 @@ getTOCEntryTypeForMO(const MachineOperand &MO) {
     llvm_unreachable("Unexpected operand type to get TOC type.");
   }
 }
+
+const MCExpr *PPCAsmPrinter::symbolWithVariant(const MCSymbol *S,
+                                               PPCMCExpr::VariantKind Kind) {
+  return MCSymbolRefExpr::create(S, MCSymbolRefExpr::VariantKind(Kind),
+                                 OutContext);
+}
+
 /// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
 /// the current output stream.
 ///
@@ -850,8 +857,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
   auto getTOCEntryLoadingExprForXCOFF =
       [IsPPC64, getTOCRelocAdjustedExprForXCOFF,
        this](const MCSymbol *MOSymbol, const MCExpr *Expr,
-             MCSymbolRefExpr::VariantKind VK =
-                 MCSymbolRefExpr::VariantKind::VK_None) -> const MCExpr * {
+             PPCMCExpr::VariantKind VK = PPCMCExpr::VK_None) -> const MCExpr * {
     const unsigned EntryByteSize = IsPPC64 ? 8 : 4;
     const auto TOCEntryIter = TOC.find({MOSymbol, VK});
     assert(TOCEntryIter != TOC.end() &&
@@ -876,9 +882,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
       assert(MO.isGlobal() && "Only expecting a global MachineOperand here!\n");
       TLSModel::Model Model = TM.getTLSModel(MO.getGlobal());
       if (Model == TLSModel::LocalExec)
-        return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLE;
+        return PPCMCExpr::VK_AIX_TLSLE;
       if (Model == TLSModel::InitialExec)
-        return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSIE;
+        return PPCMCExpr::VK_AIX_TLSIE;
       // On AIX, TLS model opt may have turned local-dynamic accesses into
       // initial-exec accesses.
       PPCFunctionInfo *FuncInfo = MF->getInfo<PPCFunctionInfo>();
@@ -886,7 +892,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
           FuncInfo->isAIXFuncUseTLSIEForLD()) {
         LLVM_DEBUG(
             dbgs() << "Current function uses IE access for default LD vars.\n");
-        return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSIE;
+        return PPCMCExpr::VK_AIX_TLSIE;
       }
       llvm_unreachable("Only expecting local-exec or initial-exec accesses!");
     }
@@ -894,17 +900,17 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // the variable offset and the other for the region handle). They are
     // 
diff erentiated by MO_TLSGD_FLAG and MO_TLSGDM_FLAG.
     if (Flag == PPCII::MO_TLSGDM_FLAG)
-      return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM;
+      return PPCMCExpr::VK_AIX_TLSGDM;
     if (Flag == PPCII::MO_TLSGD_FLAG || Flag == PPCII::MO_GOT_TLSGD_PCREL_FLAG)
-      return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGD;
+      return PPCMCExpr::VK_AIX_TLSGD;
     // For local-dynamic TLS access on AIX, we have one TOC entry for the symbol
     // (the variable offset) and one shared TOC entry for the module handle.
     // They are 
diff erentiated by MO_TLSLD_FLAG and MO_TLSLDM_FLAG.
     if (Flag == PPCII::MO_TLSLD_FLAG && IsAIX)
-      return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLD;
+      return PPCMCExpr::VK_AIX_TLSLD;
     if (Flag == PPCII::MO_TLSLDM_FLAG && IsAIX)
-      return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSML;
-    return MCSymbolRefExpr::VariantKind::VK_None;
+      return PPCMCExpr::VK_AIX_TLSML;
+    return PPCMCExpr::VK_None;
   };
 
   // Lower multi-instruction pseudo operations.
@@ -943,12 +949,11 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // This will return the pointer to _GLOBAL_OFFSET_TABLE_ at local
     MCSymbol *GOTSymbol =
       OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_"));
-    const MCExpr *OffsExpr =
-      MCBinaryExpr::createSub(MCSymbolRefExpr::create(GOTSymbol,
-                                                      MCSymbolRefExpr::VK_PPC_LOCAL,
-                                                      OutContext),
-                              MCConstantExpr::create(4, OutContext),
-                              OutContext);
+    const MCExpr *OffsExpr = MCBinaryExpr::createSub(
+        MCSymbolRefExpr::create(
+            GOTSymbol, MCSymbolRefExpr::VariantKind(PPCMCExpr::VK_LOCAL),
+            OutContext),
+        MCConstantExpr::create(4, OutContext), OutContext);
 
     // Emit the 'bl'.
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL).addExpr(OffsExpr));
@@ -1046,15 +1051,13 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // Create a reference to the GOT entry for the symbol. The GOT entry will be
     // synthesized later.
     if (PL == PICLevel::SmallPIC && !IsAIX) {
-      const MCExpr *Exp =
-        MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_GOT,
-                                OutContext);
+      const MCExpr *Exp = symbolWithVariant(MOSymbol, PPCMCExpr::VK_GOT);
       TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
       EmitToStreamer(*OutStreamer, TmpInst);
       return;
     }
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
 
     // Otherwise, use the TOC. 'TOCEntry' is a label used to reference the
     // storage allocated in the TOC which contains the address of
@@ -1129,7 +1132,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // Map the operand to its corresponding MCSymbol.
     const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
 
     // Map the machine operand to its corresponding MCSymbol, then map the
     // global address operand to be a reference to the TOC entry we will
@@ -1137,9 +1140,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     MCSymbol *TOCEntry =
         lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
 
-    MCSymbolRefExpr::VariantKind VKExpr =
-        IsAIX ? MCSymbolRefExpr::VK_None : MCSymbolRefExpr::VK_PPC_TOC;
-    const MCExpr *Exp = MCSymbolRefExpr::create(TOCEntry, VKExpr, OutContext);
+    PPCMCExpr::VariantKind VKExpr =
+        IsAIX ? PPCMCExpr::VK_None : PPCMCExpr::VK_TOC;
+    const MCExpr *Exp = symbolWithVariant(TOCEntry, VKExpr);
     TmpInst.getOperand(1) = MCOperand::createExpr(
         IsAIX ? getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK) : Exp);
 
@@ -1168,7 +1171,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // Map the machine operand to its corresponding MCSymbol.
     MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
 
     // Map the global address operand to be a reference to the TOC entry we
     // will synthesize later. 'TOCEntry' is a label used to reference the
@@ -1188,8 +1191,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
       MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
     }
 
-    const MCExpr *Exp = MCSymbolRefExpr::create(
-        MOSymbol, MCSymbolRefExpr::VK_PPC_U, OutContext);
+    const MCExpr *Exp = symbolWithVariant(MOSymbol, PPCMCExpr::VK_U);
     TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
     EmitToStreamer(*OutStreamer, TmpInst);
     return;
@@ -1213,7 +1215,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // Map the machine operand to its corresponding MCSymbol.
     MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
 
     // Always use TOC on AIX. Map the global address operand to be a reference
     // to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
@@ -1221,9 +1223,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     // 'MOSymbol'.
     MCSymbol *TOCEntry =
         lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
-    const MCExpr *Exp = MCSymbolRefExpr::create(TOCEntry,
-                                                MCSymbolRefExpr::VK_PPC_L,
-                                                OutContext);
+    const MCExpr *Exp = symbolWithVariant(TOCEntry, PPCMCExpr::VK_L);
     TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
     EmitToStreamer(*OutStreamer, TmpInst);
     return;
@@ -1244,7 +1244,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
 
     const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
 
     const bool GlobalToc =
         MO.isGlobal() && Subtarget->isGVIndirectSymbol(MO.getGlobal());
@@ -1256,10 +1256,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
         (MO.isCPI() && CM == CodeModel::Large))
       MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
 
-    VK = IsAIX ? MCSymbolRefExpr::VK_PPC_U : MCSymbolRefExpr::VK_PPC_TOC_HA;
+    VK = IsAIX ? PPCMCExpr::VK_U : PPCMCExpr::VK_TOC_HA;
 
-    const MCExpr *Exp =
-        MCSymbolRefExpr::create(MOSymbol, VK, OutContext);
+    const MCExpr *Exp = symbolWithVariant(MOSymbol, VK);
 
     if (!MO.isJTI() && MO.getOffset())
       Exp = MCBinaryExpr::createAdd(Exp,
@@ -1293,15 +1292,14 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
 
     const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
 
-    MCSymbolRefExpr::VariantKind VK = GetVKForMO(MO);
+    PPCMCExpr::VariantKind VK = GetVKForMO(MO);
     CodeModel::Model CM =
         IsAIX ? getCodeModel(*Subtarget, TM, MO) : TM.getCodeModel();
     if (!MO.isCPI() || CM == CodeModel::Large)
       MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
 
-    VK = IsAIX ? MCSymbolRefExpr::VK_PPC_L : MCSymbolRefExpr::VK_PPC_TOC_LO;
-    const MCExpr *Exp =
-        MCSymbolRefExpr::create(MOSymbol, VK, OutContext);
+    VK = IsAIX ? PPCMCExpr::VK_L : PPCMCExpr::VK_TOC_LO;
+    const MCExpr *Exp = symbolWithVariant(MOSymbol, VK);
     TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
     EmitToStreamer(*OutStreamer, TmpInst);
     return;
@@ -1330,7 +1328,8 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
 
     const MCExpr *Exp = MCSymbolRefExpr::create(
         MOSymbol,
-        IsAIX ? MCSymbolRefExpr::VK_PPC_L : MCSymbolRefExpr::VK_PPC_TOC_LO,
+        MCSymbolRefExpr::VariantKind(IsAIX ? PPCMCExpr::VK_L
+                                           : PPCMCExpr::VK_TOC_LO),
         OutContext);
 
     TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
@@ -1345,8 +1344,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
     const MCExpr *SymGotTprel =
-        MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA,
-                                OutContext);
+        symbolWithVariant(MOSymbol, PPCMCExpr::VK_GOT_TPREL_HA);
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
                                  .addReg(MI->getOperand(0).getReg())
                                  .addReg(MI->getOperand(1).getReg())
@@ -1363,10 +1361,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const MachineOperand &MO = MI->getOperand(1);
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
-    const MCExpr *Exp = MCSymbolRefExpr::create(
-        MOSymbol, IsPPC64 ? MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO
-                          : MCSymbolRefExpr::VK_PPC_GOT_TPREL,
-        OutContext);
+    const MCExpr *Exp =
+        symbolWithVariant(MOSymbol, IsPPC64 ? PPCMCExpr::VK_GOT_TPREL_LO
+                                            : PPCMCExpr::VK_GOT_TPREL);
     TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
     EmitToStreamer(*OutStreamer, TmpInst);
     return;
@@ -1407,7 +1404,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
         PPCMCExpr::VK_LO, MCSymbolRefExpr::create(GOTSymbol, OutContext),
         OutContext);
     const MCExpr *SymGotTlsHA = PPCMCExpr::create(
-        PPCMCExpr::VK_PPC_HA, MCSymbolRefExpr::create(GOTSymbol, OutContext),
+        PPCMCExpr::VK_HA, MCSymbolRefExpr::create(GOTSymbol, OutContext),
         OutContext);
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LI)
                                  .addReg(MI->getOperand(0).getReg())
@@ -1426,8 +1423,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
     const MCExpr *SymGotTlsGD =
-      MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA,
-                              OutContext);
+        symbolWithVariant(MOSymbol, PPCMCExpr::VK_GOT_TLSGD_HA);
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
                                  .addReg(MI->getOperand(0).getReg())
                                  .addReg(MI->getOperand(1).getReg())
@@ -1443,10 +1439,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const MachineOperand &MO = MI->getOperand(2);
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
-    const MCExpr *SymGotTlsGD = MCSymbolRefExpr::create(
-        MOSymbol, IsPPC64 ? MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO
-                          : MCSymbolRefExpr::VK_PPC_GOT_TLSGD,
-        OutContext);
+    const MCExpr *SymGotTlsGD =
+        symbolWithVariant(MOSymbol, IsPPC64 ? PPCMCExpr::VK_GOT_TLSGD_LO
+                                            : PPCMCExpr::VK_GOT_TLSGD);
     EmitToStreamer(*OutStreamer,
                    MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
                    .addReg(MI->getOperand(0).getReg())
@@ -1471,7 +1466,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
   case PPC::GETtlsADDR32: {
     // Transform: %r3 = GETtlsADDR32 %r3, @sym
     // Into: BL_TLS __tls_get_addr(sym at tlsgd)@PLT
-    EmitTlsCall(MI, MCSymbolRefExpr::VK_TLSGD);
+    emitTlsCall(MI, PPCMCExpr::VK_TLSGD);
     return;
   }
   case PPC::GETtlsTpointer32AIX: {
@@ -1488,8 +1483,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
     const MCExpr *SymGotTlsLD =
-      MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA,
-                              OutContext);
+        symbolWithVariant(MOSymbol, PPCMCExpr::VK_GOT_TLSLD_HA);
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
                                  .addReg(MI->getOperand(0).getReg())
                                  .addReg(MI->getOperand(1).getReg())
@@ -1505,10 +1499,9 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const MachineOperand &MO = MI->getOperand(2);
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
-    const MCExpr *SymGotTlsLD = MCSymbolRefExpr::create(
-        MOSymbol, IsPPC64 ? MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO
-                          : MCSymbolRefExpr::VK_PPC_GOT_TLSLD,
-        OutContext);
+    const MCExpr *SymGotTlsLD =
+        symbolWithVariant(MOSymbol, IsPPC64 ? PPCMCExpr::VK_GOT_TLSLD_LO
+                                            : PPCMCExpr::VK_GOT_TLSLD);
     EmitToStreamer(*OutStreamer,
                    MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
                        .addReg(MI->getOperand(0).getReg())
@@ -1523,7 +1516,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
   case PPC::GETtlsldADDR32: {
     // Transform: %r3 = GETtlsldADDR32 %r3, @sym
     // Into: BL_TLS __tls_get_addr(sym at tlsld)@PLT
-    EmitTlsCall(MI, MCSymbolRefExpr::VK_TLSLD);
+    emitTlsCall(MI, PPCMCExpr::VK_TLSLD);
     return;
   }
   case PPC::ADDISdtprelHA:
@@ -1536,8 +1529,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
     const MCExpr *SymDtprel =
-      MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_DTPREL_HA,
-                              OutContext);
+        symbolWithVariant(MOSymbol, PPCMCExpr::VK_DTPREL_HA);
     EmitToStreamer(
         *OutStreamer,
         MCInstBuilder(IsPPC64 ? PPC::ADDIS8 : PPC::ADDIS)
@@ -1552,8 +1544,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const MachineOperand &MO = MI->getOperand(2);
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
-    const MCExpr *SymDtprel = MCSymbolRefExpr::create(
-        MOSymbol, MCSymbolRefExpr::VK_DTPREL, OutContext);
+    const MCExpr *SymDtprel = symbolWithVariant(MOSymbol, PPCMCExpr::VK_DTPREL);
     EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::PADDI8)
                                      .addReg(MI->getOperand(0).getReg())
                                      .addReg(MI->getOperand(1).getReg())
@@ -1571,8 +1562,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
     const GlobalValue *GValue = MO.getGlobal();
     MCSymbol *MOSymbol = getSymbol(GValue);
     const MCExpr *SymDtprel =
-      MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_PPC_DTPREL_LO,
-                              OutContext);
+        symbolWithVariant(MOSymbol, PPCMCExpr::VK_DTPREL_LO);
     EmitToStreamer(*OutStreamer,
                    MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
                        .addReg(MI->getOperand(0).getReg())
@@ -1742,8 +1732,9 @@ PPCAsmPrinter::getAdjustedFasterLocalExpr(const MachineOperand &MO,
   // assume that the address of extern TLS variables are zero.
   const MCExpr *Expr = MCSymbolRefExpr::create(
       getSymbol(GValue),
-      Model == TLSModel::LocalExec ? MCSymbolRefExpr::VK_PPC_AIX_TLSLE
-                                   : MCSymbolRefExpr::VK_PPC_AIX_TLSLD,
+      MCSymbolRefExpr::VariantKind(Model == TLSModel::LocalExec
+                                       ? PPCMCExpr::VK_AIX_TLSLE
+                                       : PPCMCExpr::VK_AIX_TLSLD),
       OutContext);
   Expr = MCBinaryExpr::createAdd(
       Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
@@ -2031,8 +2022,10 @@ void PPCLinuxAsmPrinter::emitFunctionEntryLabel() {
   MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(StringRef(".TOC."));
   // Generates a R_PPC64_TOC relocation for TOC base insertion.
   OutStreamer->emitValue(
-    MCSymbolRefExpr::create(Symbol2, MCSymbolRefExpr::VK_PPC_TOCBASE, OutContext),
-    8/*size*/);
+      MCSymbolRefExpr::create(
+          Symbol2, MCSymbolRefExpr::VariantKind(PPCMCExpr::VK_TOCBASE),
+          OutContext),
+      8 /*size*/);
   // Emit a null environment pointer.
   OutStreamer->emitIntValue(0, 8 /* size */);
   OutStreamer->switchSection(Current.first, Current.second);
@@ -3000,13 +2993,13 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
   for (auto &I : TOC) {
     MCSectionXCOFF *TCEntry;
     // Setup the csect for the current TC entry. If the variant kind is
-    // VK_PPC_AIX_TLSGDM the entry represents the region handle, we create a
+    // VK_AIX_TLSGDM the entry represents the region handle, we create a
     // new symbol to prefix the name with a dot.
     // If TLS model opt is turned on, create a new symbol to prefix the name
     // with a dot.
-    if (I.first.second == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM ||
+    if (I.first.second == PPCMCExpr::VK_AIX_TLSGDM ||
         (Subtarget->hasAIXShLibTLSModelOpt() &&
-         I.first.second == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLD)) {
+         I.first.second == PPCMCExpr::VK_AIX_TLSLD)) {
       SmallString<128> Name;
       StringRef Prefix = ".";
       Name += Prefix;

diff  --git a/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp b/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
index d8f3c29cb021f..e4b1971d84c42 100644
--- a/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
@@ -54,31 +54,31 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO,
 static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
                               AsmPrinter &Printer) {
   MCContext &Ctx = Printer.OutContext;
-  MCSymbolRefExpr::VariantKind RefKind = MCSymbolRefExpr::VK_None;
+  PPCMCExpr::VariantKind RefKind = PPCMCExpr::VK_None;
 
   unsigned access = MO.getTargetFlags();
 
   switch (access) {
     case PPCII::MO_TPREL_LO:
-      RefKind = MCSymbolRefExpr::VK_PPC_TPREL_LO;
+      RefKind = PPCMCExpr::VK_TPREL_LO;
       break;
     case PPCII::MO_TPREL_HA:
-      RefKind = MCSymbolRefExpr::VK_PPC_TPREL_HA;
+      RefKind = PPCMCExpr::VK_TPREL_HA;
       break;
     case PPCII::MO_DTPREL_LO:
-      RefKind = MCSymbolRefExpr::VK_PPC_DTPREL_LO;
+      RefKind = PPCMCExpr::VK_DTPREL_LO;
       break;
     case PPCII::MO_TLSLD_LO:
-      RefKind = MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO;
+      RefKind = PPCMCExpr::VK_GOT_TLSLD_LO;
       break;
     case PPCII::MO_TOC_LO:
-      RefKind = MCSymbolRefExpr::VK_PPC_TOC_LO;
+      RefKind = PPCMCExpr::VK_TOC_LO;
       break;
     case PPCII::MO_TLS:
-      RefKind = MCSymbolRefExpr::VK_PPC_TLS;
+      RefKind = PPCMCExpr::VK_TLS;
       break;
     case PPCII::MO_TLS_PCREL_FLAG:
-      RefKind = MCSymbolRefExpr::VK_PPC_TLS_PCREL;
+      RefKind = PPCMCExpr::VK_TLS_PCREL;
       break;
   }
 
@@ -87,19 +87,19 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
   const MachineFunction *MF = MI->getMF();
 
   if (MO.getTargetFlags() == PPCII::MO_PLT)
-    RefKind = MCSymbolRefExpr::VK_PLT;
+    RefKind = PPCMCExpr::VK_PLT;
   else if (MO.getTargetFlags() == PPCII::MO_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_PCREL;
+    RefKind = PPCMCExpr::VK_PCREL;
   else if (MO.getTargetFlags() == PPCII::MO_GOT_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_PPC_GOT_PCREL;
+    RefKind = PPCMCExpr::VK_GOT_PCREL;
   else if (MO.getTargetFlags() == PPCII::MO_TPREL_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_TPREL;
+    RefKind = PPCMCExpr::VK_TPREL;
   else if (MO.getTargetFlags() == PPCII::MO_GOT_TLSGD_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_PPC_GOT_TLSGD_PCREL;
+    RefKind = PPCMCExpr::VK_GOT_TLSGD_PCREL;
   else if (MO.getTargetFlags() == PPCII::MO_GOT_TLSLD_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_PPC_GOT_TLSLD_PCREL;
+    RefKind = PPCMCExpr::VK_GOT_TLSLD_PCREL;
   else if (MO.getTargetFlags() == PPCII::MO_GOT_TPREL_PCREL_FLAG)
-    RefKind = MCSymbolRefExpr::VK_PPC_GOT_TPREL_PCREL;
+    RefKind = PPCMCExpr::VK_GOT_TPREL_PCREL;
   else if (MO.getTargetFlags() == PPCII::MO_TPREL_FLAG ||
            MO.getTargetFlags() == PPCII::MO_TLSLD_FLAG) {
     assert(MO.isGlobal() && "Only expecting a global MachineOperand here!");
@@ -110,14 +110,14 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
     // the relocation type in case the result is used for purposes other than a
     // TOC reference. In TOC reference cases, this result is discarded.
     if (Model == TLSModel::LocalExec)
-      RefKind = MCSymbolRefExpr::VK_PPC_AIX_TLSLE;
+      RefKind = PPCMCExpr::VK_AIX_TLSLE;
     else if (Model == TLSModel::LocalDynamic &&
              FuncInfo->isAIXFuncUseTLSIEForLD())
       // On AIX, TLS model opt may have turned local-dynamic accesses into
       // initial-exec accesses.
-      RefKind = MCSymbolRefExpr::VK_PPC_AIX_TLSIE;
+      RefKind = PPCMCExpr::VK_AIX_TLSIE;
     else if (Model == TLSModel::LocalDynamic)
-      RefKind = MCSymbolRefExpr::VK_PPC_AIX_TLSLD;
+      RefKind = PPCMCExpr::VK_AIX_TLSLD;
   }
 
   const Module *M = MF->getFunction().getParent();
@@ -130,13 +130,14 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
     if (MIOpcode == PPC::TAILB || MIOpcode == PPC::TAILB8 ||
         MIOpcode == PPC::TCRETURNdi || MIOpcode == PPC::TCRETURNdi8 ||
         MIOpcode == PPC::BL8_NOTOC || MIOpcode == PPC::BL8_NOTOC_RM) {
-      RefKind = MCSymbolRefExpr::VK_PPC_NOTOC;
+      RefKind = PPCMCExpr::VK_NOTOC;
     }
     if (MO.getTargetFlags() == PPCII::MO_PCREL_OPT_FLAG)
-      RefKind = MCSymbolRefExpr::VK_PPC_PCREL_OPT;
+      RefKind = PPCMCExpr::VK_PCREL_OPT;
   }
 
-  const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, RefKind, Ctx);
+  const MCExpr *Expr = MCSymbolRefExpr::create(
+      Symbol, MCSymbolRefExpr::VariantKind(RefKind), Ctx);
   // If -msecure-plt -fPIC, add 32768 to symbol.
   if (Subtarget->isSecurePlt() && TM.isPositionIndependent() &&
       M->getPICLevel() == PICLevel::BigPIC &&

diff  --git a/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp b/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp
index 6939b57b44bc8..078f4b1effbb1 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "PPCTargetObjectFile.h"
+#include "MCTargetDesc/PPCMCExpr.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
@@ -48,8 +49,8 @@ MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
 
 const MCExpr *PPC64LinuxTargetObjectFile::
 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
-  const MCExpr *Expr =
-    MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext());
+  const MCExpr *Expr = MCSymbolRefExpr::create(
+      Sym, MCSymbolRefExpr::VariantKind(PPCMCExpr::VK_DTPREL), getContext());
   return MCBinaryExpr::createAdd(Expr,
                                  MCConstantExpr::create(0x8000, getContext()),
                                  getContext());


        


More information about the llvm-commits mailing list