[llvm-dev] Handling argument for an intrinsic

Louis Li via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 1 16:01:24 PST 2016


Hi, I'm trying to implement a target-agnostic intrinsic, first targeting
X86. I'm trying to map the intrinsic SD node to an instruction with a
certain target opcode that I've introduced. The issue that I'm running into
is what the correct way to lower the argument is. I've done a couple loops
on the docs so any help would be appreciated!

Some options I've explored but have been missing some crucial step/concept:
- tablegen matching?
- SelectionDAGBuilder.cpp + BuildMI call (but then this runs into the issue
of lowering the argument correctly - not sure if that's feasible at this
point in instruction selection)
- X86ISelLowering -- same confusion as above

Here's how the dag currently looks (before erroring out, since I haven't
handled the intrinsic)
https://drive.google.com/file/d/0B5G4m_mQneSjRWQzRVltdDJOQnM/view?usp=sharing
Would it be problematic if I somehow extracted the pointer address arg to
the intrisic from TargetConstant and passed it as MachineOperand to the
MachineInstruction?

Opcode definition (Target/Target.td)
==============
+def PATCHABLE_LOG_CALL : Instruction {
+  let OutOperandList = (outs);
+  let InOperandList = (ins unknown:$entry);
+  let AsmString = "# XRay Custom Log.";
+  let usesCustomInserter = 1;
+  let hasSideEffects = 1;
+}

Example IR for the graph above
===========
define i32 @caller() nounwind noinline uwtable
"function-instrument"="xray-always" {
    %logentryptr = alloca i8
    call void @llvm.xray.customlog(i8* %logentryptr)
    ret i32 0
}

declare void @llvm.xray.customlog(i8*)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161202/e2aeaf3c/attachment.html>


More information about the llvm-dev mailing list