This is an archive of the discontinued LLVM Phabricator instance.

Implement the x86 lowering for inalloca
AbandonedPublic

Authored by rnk on Dec 19 2013, 6:52 PM.

Details

Reviewers
sunfish
Summary

This implements inalloca lowering in SelectionDAGBuilder, which is
target independent. The core idea is to move the frame adjustment from
the CALLSEQ_START node to a dominating DYNAMIC_STACKALLOC and let the
frontend emit stackrestore calls to clear the stack when necessary.

With the current rules for inalloca, the last inalloca argument must
dominate the rest. For simplicity, I emit code for all inalloca
arguments for a call at the site of the last inalloca alloca.

I added a new target hook, AnalyzeCallArgs, which is split from
LowerCallTo. It exposes the argument frame size and the locations of
all the arguments to the SD builder. With that, I can create an
appopriately sized DYNAMIC_STACKALLOC and set the virtual result
registers for the allocas to the appropriate stack offsets.

Depends On: D2449

Diff Detail

Event Timeline

sunfish accepted this revision.Jan 3 2014, 4:53 PM

Index: include/llvm/Target/TargetCallingConv.h

  • include/llvm/Target/TargetCallingConv.h

+++ include/llvm/Target/TargetCallingConv.h
@@ -42,6 +42,8 @@

static const uint64_t ByValAlignOffs = 7;
static const uint64_t Split          = 1ULL<<11;
static const uint64_t SplitOffs      = 11;

+ static const uint64_t InAlloca = 1ULL<<12; ///< Passed in alloca
+ static const uint64_t InAllocaOffs = 12;

Change the comment to say "Passed with inalloca" since inalloca means a bunch of things beyond just using an alloca.

Index: include/llvm/Target/TargetLowering.h

  • include/llvm/Target/TargetLowering.h

+++ include/llvm/Target/TargetLowering.h
@@ -24,6 +24,7 @@
#define LLVM_TARGET_TARGETLOWERING_H

#include "llvm/ADT/DenseMap.h"
+#include "llvm/CodeGen/CallingConvLower.h"

Is this #include needed? It looks like it's for CallLoweringInfo and CCState, which could
be forward-declared.

Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

  • lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

[...]

+ Dynamically allocate space for the stack frame.
+
TODO: Can we support args aligned to greater than the stack alignment?
+ unsigned Align = 0;

The (unchecked) assumption that default stack alignment is enough seems dangerous. How hard would it be to implement this? Is it just a matter of computing the greatest alignment from the arguments, or does it require additional codegen support?

[...]

+ if (Args[i].isInAlloca) {
+ Flags.setByVal(); // TODO: Remove when isInAlloca() works.

Does isInAlloca not work yet?

Index: lib/Target/X86/X86ISelLowering.cpp

  • lib/Target/X86/X86ISelLowering.cpp

+++ lib/Target/X86/X86ISelLowering.cpp
@@ -2501,6 +2501,21 @@

return Chain;

}

+void X86TargetLowering::AnalyzeCallArgs(TargetLowering::CallLoweringInfo &CLI,
+ CCState &CCInfo) const {
+ SelectionDAG &DAG = CLI.DAG;
+ SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
+ CallingConv::ID CallConv = CLI.CallConv;
+ bool isVarArg = CLI.IsVarArg;
+ MachineFunction &MF = DAG.getMachineFunction();

DAG, isVarArg, and MF are unused here.

Some regression were committed as part of D2637. Is this patch obsolete?

rnk abandoned this revision.Oct 5 2016, 10:21 AM

We changed the design to make this patch obsolete. D2637 / rL200596 implement the current design.