[PATCH] D34708: [NVPTX] Allow to make libcalls that are defined in the current module.
Denys Zariaiev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 13:39:56 PDT 2017
denzp created this revision.
The patch adds a possibility to make library calls.
An important thing about library functions - they must be defined within the current module. This basically should guarantee that we produce a valid PTX assembly (without calls to not defined functions). The one who wants to use the libcalls is probably will have to link against `compiler-rt` or any other implementation.
Currently, it's completely impossible to make library calls because of error `LLVM ERROR: Cannot select: i32 = ExternalSymbol '...'`. But we can lower `ExternalSymbol` to `TargetExternalSymbol` and verify if the function definition is available.
Also, there was a problem with DAG. Apparently, libcall expander didn't take in account call chain. That means `CALLSEQ_END` node was deleted as //"dead node"// because our retval `LoadParam` is before `CALLSEQ_END`. To solve it I had to implement a way how to mark `CALLSEQ_END` node as //"alive"//. The approach utilises `HandleSDNode` to keep a reference to the dead node.
Before dead nodes removal:
SelectionDAG has 28 nodes:
t0: ch = EntryToken
t3: f64 = fpowi ConstantFP:f64<1.000000e+00>, undef:i32
t7: i32 = ExternalSymbol'__powidf2'
t9: ch,glue = callseq_start t0, TargetConstant:i32<0>, TargetConstant:i32<0>
t11: ch,glue = NVPTXISD::DeclareScalarParam t9, Constant:i32<0>, Constant:i32<64>, Constant:i32<0>, t9:1
t12: ch,glue = NVPTXISD::StoreParam<ST8[<unknown>]> t11, Constant:i32<0>, Constant:i32<0>, ConstantFP:f64<1.000000e+00>, t11:1
t15: ch,glue = NVPTXISD::DeclareScalarParam t12, Constant:i32<1>, Constant:i32<32>, Constant:i32<0>, t12:1
t16: ch,glue = NVPTXISD::StoreParam<ST4[<unknown>]> t15, Constant:i32<1>, Constant:i32<0>, undef:i32, t15:1
t17: ch,glue = NVPTXISD::DeclareRet t16, Constant:i32<1>, Constant:i32<64>, Constant:i32<0>, t16:1
t19: ch,glue = NVPTXISD::PrintCallUni t17, Constant:i32<1>, t17:1
t20: ch,glue = NVPTXISD::CallVoid t19, TargetExternalSymbol:i32'__powidf2', t19:1
t21: ch,glue = NVPTXISD::CallArgBegin t20, t20:1
t22: ch,glue = NVPTXISD::CallArg t21, Constant:i32<1>, Constant:i32<0>, t21:1
t23: ch,glue = NVPTXISD::LastCallArg t22, Constant:i32<1>, Constant:i32<1>, t22:1
t24: ch,glue = NVPTXISD::CallArgEnd t23, Constant:i32<1>, t23:1
t25: f64,ch,glue = NVPTXISD::LoadParam<LD8[<unknown>]> t24, Constant:i32<1>, Constant:i32<0>, t24:1
t27: ch,glue = callseq_end t25:1, TargetConstant:i32<0>, TargetConstant:i32<1>, t25:2
t5: ch = NVPTXISD::StoreRetval<ST8[<unknown>](align=1)> t0, Constant:i32<0>, t25
t6: ch = NVPTXISD::RET_FLAG t5
After dead nodes removal:
SelectionDAG has 24 nodes:
t0: ch = EntryToken
t9: ch,glue = callseq_start t0, TargetConstant:i32<0>, TargetConstant:i32<0>
t11: ch,glue = NVPTXISD::DeclareScalarParam t9, Constant:i32<0>, Constant:i32<64>, Constant:i32<0>, t9:1
t12: ch,glue = NVPTXISD::StoreParam<ST8[<unknown>]> t11, Constant:i32<0>, Constant:i32<0>, ConstantFP:f64<1.000000e+00>, t11:1
t15: ch,glue = NVPTXISD::DeclareScalarParam t12, Constant:i32<1>, Constant:i32<32>, Constant:i32<0>, t12:1
t16: ch,glue = NVPTXISD::StoreParam<ST4[<unknown>]> t15, Constant:i32<1>, Constant:i32<0>, undef:i32, t15:1
t17: ch,glue = NVPTXISD::DeclareRet t16, Constant:i32<1>, Constant:i32<64>, Constant:i32<0>, t16:1
t19: ch,glue = NVPTXISD::PrintCallUni t17, Constant:i32<1>, t17:1
t20: ch,glue = NVPTXISD::CallVoid t19, TargetExternalSymbol:i32'__powidf2', t19:1
t21: ch,glue = NVPTXISD::CallArgBegin t20, t20:1
t22: ch,glue = NVPTXISD::CallArg t21, Constant:i32<1>, Constant:i32<0>, t21:1
t23: ch,glue = NVPTXISD::LastCallArg t22, Constant:i32<1>, Constant:i32<1>, t22:1
t24: ch,glue = NVPTXISD::CallArgEnd t23, Constant:i32<1>, t23:1
t25: f64,ch,glue = NVPTXISD::LoadParam<LD8[<unknown>]> t24, Constant:i32<1>, Constant:i32<0>, t24:1
t5: ch = NVPTXISD::StoreRetval<ST8[<unknown>](align=1)> t0, Constant:i32<0>, t25
t6: ch = NVPTXISD::RET_FLAG t5
(as you see `t27` is no more available).
https://reviews.llvm.org/D34708
Files:
include/llvm/CodeGen/SelectionDAG.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/Target/NVPTX/NVPTXISelLowering.cpp
lib/Target/NVPTX/NVPTXISelLowering.h
test/CodeGen/NVPTX/libcall.ll
test/CodeGen/NVPTX/zero-cs.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34708.104228.patch
Type: text/x-patch
Size: 9016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170627/6694ad3b/attachment.bin>
More information about the llvm-commits
mailing list