@@ -139,6 +139,9 @@ class RISCVAsmParser : public MCTargetAsmParser {
139
139
// Helper to emit pseudo instruction "lla" used in PC-rel addressing.
140
140
void emitLoadLocalAddress (MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
141
141
142
+ // Helper to emit pseudo instruction "lga" used in GOT-rel addressing.
143
+ void emitLoadGlobalAddress (MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
144
+
142
145
// Helper to emit pseudo instruction "la" used in GOT/PC-rel addressing.
143
146
void emitLoadAddress (MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
144
147
@@ -3088,29 +3091,34 @@ void RISCVAsmParser::emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc,
3088
3091
RISCV::ADDI, IDLoc, Out);
3089
3092
}
3090
3093
3094
+ void RISCVAsmParser::emitLoadGlobalAddress (MCInst &Inst, SMLoc IDLoc,
3095
+ MCStreamer &Out) {
3096
+ // The load global address pseudo-instruction "lga" is used in GOT-indirect
3097
+ // addressing of global symbols:
3098
+ // lga rdest, symbol
3099
+ // expands to
3100
+ // TmpLabel: AUIPC rdest, %got_pcrel_hi(symbol)
3101
+ // Lx rdest, %pcrel_lo(TmpLabel)(rdest)
3102
+ MCOperand DestReg = Inst.getOperand (0 );
3103
+ const MCExpr *Symbol = Inst.getOperand (1 ).getExpr ();
3104
+ unsigned SecondOpcode = isRV64 () ? RISCV::LD : RISCV::LW;
3105
+ emitAuipcInstPair (DestReg, DestReg, Symbol, RISCVMCExpr::VK_RISCV_GOT_HI,
3106
+ SecondOpcode, IDLoc, Out);
3107
+ }
3108
+
3091
3109
void RISCVAsmParser::emitLoadAddress (MCInst &Inst, SMLoc IDLoc,
3092
3110
MCStreamer &Out) {
3093
3111
// The load address pseudo-instruction "la" is used in PC-relative and
3094
3112
// GOT-indirect addressing of global symbols:
3095
3113
// la rdest, symbol
3096
- // expands to either (for non-PIC)
3097
- // TmpLabel: AUIPC rdest, %pcrel_hi(symbol)
3098
- // ADDI rdest, rdest, %pcrel_lo(TmpLabel)
3114
+ // is an alias for either (for non-PIC)
3115
+ // lla rdest, symbol
3099
3116
// or (for PIC)
3100
- // TmpLabel: AUIPC rdest, %got_pcrel_hi(symbol)
3101
- // Lx rdest, %pcrel_lo(TmpLabel)(rdest)
3102
- MCOperand DestReg = Inst.getOperand (0 );
3103
- const MCExpr *Symbol = Inst.getOperand (1 ).getExpr ();
3104
- unsigned SecondOpcode;
3105
- RISCVMCExpr::VariantKind VKHi;
3106
- if (ParserOptions.IsPicEnabled ) {
3107
- SecondOpcode = isRV64 () ? RISCV::LD : RISCV::LW;
3108
- VKHi = RISCVMCExpr::VK_RISCV_GOT_HI;
3109
- } else {
3110
- SecondOpcode = RISCV::ADDI;
3111
- VKHi = RISCVMCExpr::VK_RISCV_PCREL_HI;
3112
- }
3113
- emitAuipcInstPair (DestReg, DestReg, Symbol, VKHi, SecondOpcode, IDLoc, Out);
3117
+ // lga rdest, symbol
3118
+ if (ParserOptions.IsPicEnabled )
3119
+ emitLoadGlobalAddress (Inst, IDLoc, Out);
3120
+ else
3121
+ emitLoadLocalAddress (Inst, IDLoc, Out);
3114
3122
}
3115
3123
3116
3124
void RISCVAsmParser::emitLoadTLSIEAddress (MCInst &Inst, SMLoc IDLoc,
@@ -3438,6 +3446,9 @@ bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
3438
3446
case RISCV::PseudoLLA:
3439
3447
emitLoadLocalAddress (Inst, IDLoc, Out);
3440
3448
return false ;
3449
+ case RISCV::PseudoLGA:
3450
+ emitLoadGlobalAddress (Inst, IDLoc, Out);
3451
+ return false ;
3441
3452
case RISCV::PseudoLA:
3442
3453
emitLoadAddress (Inst, IDLoc, Out);
3443
3454
return false ;
0 commit comments