Skip to content

Commit f912d21

Browse files
committed
[RISCV] Add RISCVISD opcodes for the rest of get*Addr.
This adds RISCVISD opccodes for LA, LA_TLS_IE, and LA_TLS_GD to remove creation of MachineSDNodes form get*Addr. This makes the code consistent with the previous patches that added RISCVISD::HI, ADD_LO, LLA, and TPREL_ADD. Reviewed By: asb Differential Revision: https://reviews.llvm.org/D128325
1 parent 88c279b commit f912d21

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,15 +3613,15 @@ SDValue RISCVTargetLowering::getAddr(NodeTy *N, SelectionDAG &DAG,
36133613
// Use PC-relative addressing to access the GOT for this symbol, then load
36143614
// the address from the GOT. This generates the pattern (PseudoLA sym),
36153615
// which expands to (ld (addi (auipc %got_pcrel_hi(sym)) %pcrel_lo(auipc))).
3616-
SDValue Load =
3617-
SDValue(DAG.getMachineNode(RISCV::PseudoLA, DL, Ty, Addr), 0);
36183616
MachineFunction &MF = DAG.getMachineFunction();
36193617
MachineMemOperand *MemOp = MF.getMachineMemOperand(
36203618
MachinePointerInfo::getGOT(MF),
36213619
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
36223620
MachineMemOperand::MOInvariant,
36233621
LLT(Ty.getSimpleVT()), Align(Ty.getFixedSizeInBits() / 8));
3624-
DAG.setNodeMemRefs(cast<MachineSDNode>(Load.getNode()), {MemOp});
3622+
SDValue Load =
3623+
DAG.getMemIntrinsicNode(RISCVISD::LA, DL, DAG.getVTList(Ty, MVT::Other),
3624+
{DAG.getEntryNode(), Addr}, Ty, MemOp);
36253625
return Load;
36263626
}
36273627

@@ -3692,15 +3692,15 @@ SDValue RISCVTargetLowering::getStaticTLSAddr(GlobalAddressSDNode *N,
36923692
// the pattern (PseudoLA_TLS_IE sym), which expands to
36933693
// (ld (auipc %tls_ie_pcrel_hi(sym)) %pcrel_lo(auipc)).
36943694
SDValue Addr = DAG.getTargetGlobalAddress(GV, DL, Ty, 0, 0);
3695-
SDValue Load =
3696-
SDValue(DAG.getMachineNode(RISCV::PseudoLA_TLS_IE, DL, Ty, Addr), 0);
36973695
MachineFunction &MF = DAG.getMachineFunction();
36983696
MachineMemOperand *MemOp = MF.getMachineMemOperand(
36993697
MachinePointerInfo::getGOT(MF),
37003698
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
37013699
MachineMemOperand::MOInvariant,
37023700
LLT(Ty.getSimpleVT()), Align(Ty.getFixedSizeInBits() / 8));
3703-
DAG.setNodeMemRefs(cast<MachineSDNode>(Load.getNode()), {MemOp});
3701+
SDValue Load = DAG.getMemIntrinsicNode(
3702+
RISCVISD::LA_TLS_IE, DL, DAG.getVTList(Ty, MVT::Other),
3703+
{DAG.getEntryNode(), Addr}, Ty, MemOp);
37043704

37053705
// Add the thread pointer.
37063706
SDValue TPReg = DAG.getRegister(RISCV::X4, XLenVT);
@@ -3736,8 +3736,7 @@ SDValue RISCVTargetLowering::getDynamicTLSAddr(GlobalAddressSDNode *N,
37363736
// This generates the pattern (PseudoLA_TLS_GD sym), which expands to
37373737
// (addi (auipc %tls_gd_pcrel_hi(sym)) %pcrel_lo(auipc)).
37383738
SDValue Addr = DAG.getTargetGlobalAddress(GV, DL, Ty, 0, 0);
3739-
SDValue Load =
3740-
SDValue(DAG.getMachineNode(RISCV::PseudoLA_TLS_GD, DL, Ty, Addr), 0);
3739+
SDValue Load = DAG.getNode(RISCVISD::LA_TLS_GD, DL, Ty, Addr);
37413740

37423741
// Prepare argument list to generate call.
37433742
ArgListTy Args;
@@ -11184,6 +11183,9 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
1118411183
NODE_NAME_CASE(HI)
1118511184
NODE_NAME_CASE(LLA)
1118611185
NODE_NAME_CASE(ADD_TPREL)
11186+
NODE_NAME_CASE(LA)
11187+
NODE_NAME_CASE(LA_TLS_IE)
11188+
NODE_NAME_CASE(LA_TLS_GD)
1118711189
NODE_NAME_CASE(MULHSU)
1118811190
NODE_NAME_CASE(SLLW)
1118911191
NODE_NAME_CASE(SRAW)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ enum NodeType : unsigned {
5353
// Selected as PseudoAddTPRel. Used to emit a TP-relative relocation.
5454
ADD_TPREL,
5555

56+
// Load address.
57+
LA_TLS_GD,
58+
5659
// Multiply high for signedxunsigned.
5760
MULHSU,
5861
// RV64I shifts, directly matching the semantics of the named RISC-V
@@ -326,6 +329,10 @@ enum NodeType : unsigned {
326329
// WARNING: Do not add anything in the end unless you want the node to
327330
// have memop! In fact, starting from FIRST_TARGET_MEMORY_OPCODE all
328331
// opcodes will be thought as target memory ops!
332+
333+
// Load address.
334+
LA = ISD::FIRST_TARGET_MEMORY_OPCODE,
335+
LA_TLS_IE,
329336
};
330337
} // namespace RISCVISD
331338

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def riscv_add_tprel : SDNode<"RISCVISD::ADD_TPREL",
9292
SDTCisSameAs<0, 3>,
9393
SDTCisInt<0>]>>;
9494

95+
def riscv_la : SDNode<"RISCVISD::LA", SDTLoad,
96+
[SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
97+
def riscv_la_tls_ie : SDNode<"RISCVISD::LA_TLS_IE", SDTLoad,
98+
[SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
99+
def riscv_la_tls_gd : SDNode<"RISCVISD::LA_TLS_GD", SDTIntUnaryOp>;
100+
95101
//===----------------------------------------------------------------------===//
96102
// Operand and SDNode transformation definitions.
97103
//===----------------------------------------------------------------------===//
@@ -1400,16 +1406,23 @@ let hasSideEffects = 0, mayLoad = 1, mayStore = 0, Size = 8, isCodeGenOnly = 0,
14001406
def PseudoLA : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [],
14011407
"la", "$dst, $src">;
14021408

1409+
def : Pat<(riscv_la tglobaladdr:$in), (PseudoLA tglobaladdr:$in)>;
1410+
14031411
let hasSideEffects = 0, mayLoad = 1, mayStore = 0, Size = 8, isCodeGenOnly = 0,
14041412
isAsmParserOnly = 1 in
14051413
def PseudoLA_TLS_IE : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [],
14061414
"la.tls.ie", "$dst, $src">;
14071415

1416+
def : Pat<(riscv_la_tls_ie tglobaltlsaddr:$in),
1417+
(PseudoLA_TLS_IE tglobaltlsaddr:$in)>;
1418+
14081419
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 8, isCodeGenOnly = 0,
14091420
isAsmParserOnly = 1 in
14101421
def PseudoLA_TLS_GD : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [],
14111422
"la.tls.gd", "$dst, $src">;
14121423

1424+
def : Pat<(riscv_la_tls_gd tglobaltlsaddr:$in),
1425+
(PseudoLA_TLS_GD tglobaltlsaddr:$in)>;
14131426

14141427
/// Sign/Zero Extends
14151428

0 commit comments

Comments
 (0)