Skip to content

Commit 45375c7

Browse files
committed
[NVPTX] Mark callseq insts as reading and writing memory
1 parent d639f0a commit 45375c7

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

llvm/lib/Target/NVPTX/NVPTXInstrInfo.td

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,18 @@ def : Pat<(declare_array_param externalsym:$a, imm:$align, imm:$size),
18301830
def : Pat<(declare_scalar_param externalsym:$a, imm:$size),
18311831
(DECLARE_PARAM_scalar (to_texternsym $a), imm:$size)>;
18321832

1833+
// Call prototype wrapper, this is a dummy instruction that just prints it's
1834+
// operand which is string defining the prototype.
1835+
def SDTCallPrototype : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
1836+
def CallPrototype :
1837+
SDNode<"NVPTXISD::CallPrototype", SDTCallPrototype,
1838+
[SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1839+
def ProtoIdent : Operand<i32> { let PrintMethod = "printProtoIdent"; }
1840+
def CALL_PROTOTYPE :
1841+
NVPTXInst<(outs), (ins ProtoIdent:$ident),
1842+
"$ident", [(CallPrototype (i32 texternalsym:$ident))]>;
1843+
1844+
18331845
foreach t = [I32RT, I64RT] in {
18341846
defvar inst_name = "MOV" # t.Size # "_PARAM";
18351847
def inst_name : BasicNVPTXInst<(outs t.RC:$dst), (ins t.RC:$src), "mov.b" # t.Size>;
@@ -1849,6 +1861,32 @@ defm ProxyRegB16 : ProxyRegInst<"b16", B16>;
18491861
defm ProxyRegB32 : ProxyRegInst<"b32", B32>;
18501862
defm ProxyRegB64 : ProxyRegInst<"b64", B64>;
18511863

1864+
1865+
// Callseq start and end
1866+
1867+
// Note: these nodes are marked as SDNPMayStore and SDNPMayLoad because
1868+
// they define the scope in which the declared params may be used. Therefore
1869+
// we add these flags to ensure ld.param and st.param are not sunk or hoisted
1870+
// out of that scope.
1871+
1872+
def callseq_start : SDNode<"ISD::CALLSEQ_START",
1873+
SDCallSeqStart<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>,
1874+
[SDNPHasChain, SDNPOutGlue,
1875+
SDNPSideEffect, SDNPMayStore, SDNPMayLoad]>;
1876+
def callseq_end : SDNode<"ISD::CALLSEQ_END",
1877+
SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>,
1878+
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
1879+
SDNPSideEffect, SDNPMayStore, SDNPMayLoad]>;
1880+
1881+
def Callseq_Start :
1882+
NVPTXInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
1883+
"\\{ // callseq $amt1, $amt2",
1884+
[(callseq_start timm:$amt1, timm:$amt2)]>;
1885+
def Callseq_End :
1886+
NVPTXInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
1887+
"\\} // callseq $amt1",
1888+
[(callseq_end timm:$amt1, timm:$amt2)]>;
1889+
18521890
//
18531891
// Load / Store Handling
18541892
//
@@ -2392,26 +2430,6 @@ def : Pat<(brcond i32:$a, bb:$target),
23922430
def : Pat<(brcond (i1 (setne i1:$a, -1)), bb:$target),
23932431
(CBranchOther $a, bb:$target)>;
23942432

2395-
// Call
2396-
def SDT_NVPTXCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>,
2397-
SDTCisVT<1, i32>]>;
2398-
def SDT_NVPTXCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
2399-
2400-
def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_NVPTXCallSeqStart,
2401-
[SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>;
2402-
def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_NVPTXCallSeqEnd,
2403-
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
2404-
SDNPSideEffect]>;
2405-
2406-
def Callseq_Start :
2407-
NVPTXInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
2408-
"\\{ // callseq $amt1, $amt2",
2409-
[(callseq_start timm:$amt1, timm:$amt2)]>;
2410-
def Callseq_End :
2411-
NVPTXInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
2412-
"\\} // callseq $amt1",
2413-
[(callseq_end timm:$amt1, timm:$amt2)]>;
2414-
24152433
// trap instruction
24162434
def trapinst : BasicNVPTXInst<(outs), (ins), "trap", [(trap)]>, Requires<[noPTXASUnreachableBug]>;
24172435
// Emit an `exit` as well to convey to ptxas that `trap` exits the CFG.
@@ -2420,18 +2438,6 @@ def trapexitinst : NVPTXInst<(outs), (ins), "trap; exit;", [(trap)]>, Requires<[
24202438
// brkpt instruction
24212439
def debugtrapinst : BasicNVPTXInst<(outs), (ins), "brkpt", [(debugtrap)]>;
24222440

2423-
// Call prototype wrapper
2424-
def SDTCallPrototype : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
2425-
def CallPrototype :
2426-
SDNode<"NVPTXISD::CallPrototype", SDTCallPrototype,
2427-
[SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
2428-
def ProtoIdent : Operand<i32> {
2429-
let PrintMethod = "printProtoIdent";
2430-
}
2431-
def CALL_PROTOTYPE :
2432-
NVPTXInst<(outs), (ins ProtoIdent:$ident),
2433-
"$ident", [(CallPrototype (i32 texternalsym:$ident))]>;
2434-
24352441
def SDTDynAllocaOp :
24362442
SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisInt<1>, SDTCisVT<2, i32>]>;
24372443

llvm/test/CodeGen/NVPTX/ld-param-sink.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ define ptr @foo(i1 %cond) {
2121
; CHECK-NEXT: { // callseq 0, 0
2222
; CHECK-NEXT: .param .b64 retval0;
2323
; CHECK-NEXT: call.uni (retval0), baz, ();
24+
; CHECK-NEXT: ld.param.b64 %rd2, [retval0];
2425
; CHECK-NEXT: } // callseq 0
2526
; CHECK-NEXT: @%p1 bra $L__BB0_2;
2627
; CHECK-NEXT: // %bb.1: // %bb
27-
; CHECK-NEXT: ld.param.b64 %rd2, [retval0];
2828
; CHECK-NEXT: { // callseq 1, 0
2929
; CHECK-NEXT: .param .b64 param0;
3030
; CHECK-NEXT: .param .b64 retval0;

0 commit comments

Comments
 (0)