[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
//===-- StatepointLowering.cpp - SDAGBuilder's statepoint code -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file includes support code use by SelectionDAGBuilder when lowering a
|
|
|
|
// statepoint sequence in SelectionDAG IR.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "StatepointLowering.h"
|
|
|
|
#include "SelectionDAGBuilder.h"
|
|
|
|
#include "llvm/ADT/SmallSet.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
2015-12-24 00:44:28 +01:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/CodeGen/GCMetadata.h"
|
2015-01-26 19:26:35 +01:00
|
|
|
#include "llvm/CodeGen/GCStrategy.h"
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/StackMaps.h"
|
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Statepoint.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include <algorithm>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "statepoint-lowering"
|
|
|
|
|
|
|
|
STATISTIC(NumSlotsAllocatedForStatepoints,
|
|
|
|
"Number of stack slots allocated for statepoints");
|
|
|
|
STATISTIC(NumOfStatepoints, "Number of statepoint nodes encountered");
|
|
|
|
STATISTIC(StatepointMaxSlotsRequired,
|
|
|
|
"Maximum number of stack slots required for a singe statepoint");
|
|
|
|
|
2015-05-12 21:50:19 +02:00
|
|
|
static void pushStackMapConstant(SmallVectorImpl<SDValue>& Ops,
|
|
|
|
SelectionDAGBuilder &Builder, uint64_t Value) {
|
|
|
|
SDLoc L = Builder.getCurSDLoc();
|
|
|
|
Ops.push_back(Builder.DAG.getTargetConstant(StackMaps::ConstantOp, L,
|
|
|
|
MVT::i64));
|
|
|
|
Ops.push_back(Builder.DAG.getTargetConstant(Value, L, MVT::i64));
|
|
|
|
}
|
|
|
|
|
2015-04-29 23:52:45 +02:00
|
|
|
void StatepointLoweringState::startNewStatepoint(SelectionDAGBuilder &Builder) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Consistency check
|
|
|
|
assert(PendingGCRelocateCalls.empty() &&
|
|
|
|
"Trying to visit statepoint before finished processing previous one");
|
|
|
|
Locations.clear();
|
|
|
|
NextSlotToAllocate = 0;
|
2016-02-19 18:15:26 +01:00
|
|
|
// Need to resize this on each safepoint - we need the two to stay in sync and
|
|
|
|
// the clear patterns of a SelectionDAGBuilder have no relation to
|
|
|
|
// FunctionLoweringInfo. SmallBitVector::reset initializes all bits to false.
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
AllocatedStackSlots.resize(Builder.FuncInfo.StatepointStackSlots.size());
|
|
|
|
}
|
2015-05-20 13:37:25 +02:00
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
void StatepointLoweringState::clear() {
|
|
|
|
Locations.clear();
|
|
|
|
AllocatedStackSlots.clear();
|
|
|
|
assert(PendingGCRelocateCalls.empty() &&
|
|
|
|
"cleared before statepoint sequence completed");
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue
|
|
|
|
StatepointLoweringState::allocateStackSlot(EVT ValueType,
|
|
|
|
SelectionDAGBuilder &Builder) {
|
|
|
|
NumSlotsAllocatedForStatepoints++;
|
2016-02-19 18:15:22 +01:00
|
|
|
auto *MFI = Builder.DAG.getMachineFunction().getFrameInfo();
|
|
|
|
|
|
|
|
unsigned SpillSize = ValueType.getSizeInBits() / 8;
|
|
|
|
assert((SpillSize * 8) == ValueType.getSizeInBits() && "Size not in bytes?");
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2016-02-19 18:15:17 +01:00
|
|
|
// First look for a previously created stack slot which is not in
|
|
|
|
// use (accounting for the fact arbitrary slots may already be
|
|
|
|
// reserved), or to create a new stack slot and use it.
|
|
|
|
|
|
|
|
const size_t NumSlots = AllocatedStackSlots.size();
|
|
|
|
assert(NextSlotToAllocate <= NumSlots && "Broken invariant");
|
|
|
|
|
2016-02-19 18:15:26 +01:00
|
|
|
// The stack slots in StatepointStackSlots beyond the first NumSlots were
|
|
|
|
// added in this instance of StatepointLoweringState, and cannot be re-used.
|
|
|
|
assert(NumSlots <= Builder.FuncInfo.StatepointStackSlots.size() &&
|
|
|
|
"Broken invariant");
|
|
|
|
|
2016-02-19 18:15:17 +01:00
|
|
|
for (; NextSlotToAllocate < NumSlots; NextSlotToAllocate++) {
|
2016-02-19 19:15:53 +01:00
|
|
|
if (!AllocatedStackSlots.test(NextSlotToAllocate)) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
const int FI = Builder.FuncInfo.StatepointStackSlots[NextSlotToAllocate];
|
2016-02-19 19:15:53 +01:00
|
|
|
if (MFI->getObjectSize(FI) == SpillSize) {
|
|
|
|
AllocatedStackSlots.set(NextSlotToAllocate);
|
|
|
|
return Builder.DAG.getFrameIndex(FI, ValueType);
|
|
|
|
}
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-19 18:15:17 +01:00
|
|
|
|
|
|
|
// Couldn't find a free slot, so create a new one:
|
|
|
|
|
|
|
|
SDValue SpillSlot = Builder.DAG.CreateStackTemporary(ValueType);
|
|
|
|
const unsigned FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
|
|
|
|
MFI->markAsStatepointSpillSlotObjectIndex(FI);
|
|
|
|
|
|
|
|
Builder.FuncInfo.StatepointStackSlots.push_back(FI);
|
2016-02-19 19:15:56 +01:00
|
|
|
|
|
|
|
StatepointMaxSlotsRequired = std::max<unsigned long>(
|
|
|
|
StatepointMaxSlotsRequired, Builder.FuncInfo.StatepointStackSlots.size());
|
|
|
|
|
2016-02-19 18:15:17 +01:00
|
|
|
return SpillSlot;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 14:31:53 +02:00
|
|
|
/// Utility function for reservePreviousStackSlotForValue. Tries to find
|
|
|
|
/// stack slot index to which we have spilled value for previous statepoints.
|
|
|
|
/// LookUpDepth specifies maximum DFS depth this function is allowed to look.
|
|
|
|
static Optional<int> findPreviousSpillSlot(const Value *Val,
|
|
|
|
SelectionDAGBuilder &Builder,
|
|
|
|
int LookUpDepth) {
|
2015-08-08 20:27:36 +02:00
|
|
|
// Can not look any further - give up now
|
2015-06-10 14:31:53 +02:00
|
|
|
if (LookUpDepth <= 0)
|
2016-02-06 00:40:04 +01:00
|
|
|
return None;
|
2015-06-10 14:31:53 +02:00
|
|
|
|
|
|
|
// Spill location is known for gc relocates
|
2016-01-05 05:03:00 +01:00
|
|
|
if (const auto *Relocate = dyn_cast<GCRelocateInst>(Val)) {
|
2016-02-19 20:37:07 +01:00
|
|
|
const auto &SpillMap =
|
2016-03-24 19:57:39 +01:00
|
|
|
Builder.FuncInfo.StatepointSpillMaps[Relocate->getStatepoint()];
|
2015-06-10 14:31:53 +02:00
|
|
|
|
2016-01-05 05:03:00 +01:00
|
|
|
auto It = SpillMap.find(Relocate->getDerivedPtr());
|
2015-06-10 14:31:53 +02:00
|
|
|
if (It == SpillMap.end())
|
2016-02-06 00:40:04 +01:00
|
|
|
return None;
|
2015-06-10 14:31:53 +02:00
|
|
|
|
|
|
|
return It->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look through bitcast instructions.
|
2016-02-19 20:37:07 +01:00
|
|
|
if (const BitCastInst *Cast = dyn_cast<BitCastInst>(Val))
|
2015-06-10 14:31:53 +02:00
|
|
|
return findPreviousSpillSlot(Cast->getOperand(0), Builder, LookUpDepth - 1);
|
|
|
|
|
|
|
|
// Look through phi nodes
|
|
|
|
// All incoming values should have same known stack slot, otherwise result
|
|
|
|
// is unknown.
|
|
|
|
if (const PHINode *Phi = dyn_cast<PHINode>(Val)) {
|
|
|
|
Optional<int> MergedResult = None;
|
|
|
|
|
|
|
|
for (auto &IncomingValue : Phi->incoming_values()) {
|
|
|
|
Optional<int> SpillSlot =
|
|
|
|
findPreviousSpillSlot(IncomingValue, Builder, LookUpDepth - 1);
|
|
|
|
if (!SpillSlot.hasValue())
|
2016-02-06 00:40:04 +01:00
|
|
|
return None;
|
2015-06-10 14:31:53 +02:00
|
|
|
|
|
|
|
if (MergedResult.hasValue() && *MergedResult != *SpillSlot)
|
2016-02-06 00:40:04 +01:00
|
|
|
return None;
|
2015-06-10 14:31:53 +02:00
|
|
|
|
|
|
|
MergedResult = SpillSlot;
|
|
|
|
}
|
|
|
|
return MergedResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We can do better for PHI nodes. In cases like this:
|
|
|
|
// ptr = phi(relocated_pointer, not_relocated_pointer)
|
|
|
|
// statepoint(ptr)
|
|
|
|
// We will return that stack slot for ptr is unknown. And later we might
|
|
|
|
// assign different stack slots for ptr and relocated_pointer. This limits
|
|
|
|
// llvm's ability to remove redundant stores.
|
|
|
|
// Unfortunately it's hard to accomplish in current infrastructure.
|
|
|
|
// We use this function to eliminate spill store completely, while
|
|
|
|
// in example we still need to emit store, but instead of any location
|
|
|
|
// we need to use special "preferred" location.
|
|
|
|
|
|
|
|
// TODO: handle simple updates. If a value is modified and the original
|
|
|
|
// value is no longer live, it would be nice to put the modified value in the
|
|
|
|
// same slot. This allows folding of the memory accesses for some
|
|
|
|
// instructions types (like an increment).
|
|
|
|
// statepoint (i)
|
|
|
|
// i1 = i+1
|
|
|
|
// statepoint (i1)
|
|
|
|
// However we need to be careful for cases like this:
|
|
|
|
// statepoint(i)
|
|
|
|
// i1 = i+1
|
|
|
|
// statepoint(i, i1)
|
|
|
|
// Here we want to reserve spill slot for 'i', but not for 'i+1'. If we just
|
|
|
|
// put handling of simple modifications in this function like it's done
|
|
|
|
// for bitcasts we might end up reserving i's slot for 'i+1' because order in
|
|
|
|
// which we visit values is unspecified.
|
|
|
|
|
|
|
|
// Don't know any information about this instruction
|
2016-02-06 00:40:04 +01:00
|
|
|
return None;
|
2015-06-10 14:31:53 +02:00
|
|
|
}
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
/// Try to find existing copies of the incoming values in stack slots used for
|
|
|
|
/// statepoint spilling. If we can find a spill slot for the incoming value,
|
|
|
|
/// mark that slot as allocated, and reuse the same slot for this safepoint.
|
2015-08-08 20:27:36 +02:00
|
|
|
/// This helps to avoid series of loads and stores that only serve to reshuffle
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
/// values on the stack between calls.
|
2015-06-10 14:31:53 +02:00
|
|
|
static void reservePreviousStackSlotForValue(const Value *IncomingValue,
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
SelectionDAGBuilder &Builder) {
|
|
|
|
|
2015-06-10 14:31:53 +02:00
|
|
|
SDValue Incoming = Builder.getValue(IncomingValue);
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
if (isa<ConstantSDNode>(Incoming) || isa<FrameIndexSDNode>(Incoming)) {
|
|
|
|
// We won't need to spill this, so no need to check for previously
|
|
|
|
// allocated stack slots
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-10 14:31:53 +02:00
|
|
|
SDValue OldLocation = Builder.StatepointLowering.getLocation(Incoming);
|
|
|
|
if (OldLocation.getNode())
|
2016-02-19 20:37:07 +01:00
|
|
|
// Duplicates in input
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
return;
|
|
|
|
|
2015-06-10 14:31:53 +02:00
|
|
|
const int LookUpDepth = 6;
|
|
|
|
Optional<int> Index =
|
|
|
|
findPreviousSpillSlot(IncomingValue, Builder, LookUpDepth);
|
|
|
|
if (!Index.hasValue())
|
|
|
|
return;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2016-02-19 20:37:07 +01:00
|
|
|
const auto &StatepointSlots = Builder.FuncInfo.StatepointStackSlots;
|
|
|
|
|
|
|
|
auto SlotIt = find(StatepointSlots, *Index);
|
|
|
|
assert(SlotIt != StatepointSlots.end() &&
|
|
|
|
"Value spilled to the unknown stack slot");
|
2015-06-10 14:31:53 +02:00
|
|
|
|
|
|
|
// This is one of our dedicated lowering slots
|
2016-02-19 20:37:07 +01:00
|
|
|
const int Offset = std::distance(StatepointSlots.begin(), SlotIt);
|
2015-06-10 14:31:53 +02:00
|
|
|
if (Builder.StatepointLowering.isStackSlotAllocated(Offset)) {
|
|
|
|
// stack slot already assigned to someone else, can't use it!
|
|
|
|
// TODO: currently we reserve space for gc arguments after doing
|
|
|
|
// normal allocation for deopt arguments. We should reserve for
|
|
|
|
// _all_ deopt and gc arguments, then start allocating. This
|
|
|
|
// will prevent some moves being inserted when vm state changes,
|
|
|
|
// but gc state doesn't between two calls.
|
|
|
|
return;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
2015-06-10 14:31:53 +02:00
|
|
|
// Reserve this stack slot
|
|
|
|
Builder.StatepointLowering.reserveStackSlot(Offset);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-06-10 14:31:53 +02:00
|
|
|
// Cache this slot so we find it when going through the normal
|
|
|
|
// assignment loop.
|
|
|
|
SDValue Loc = Builder.DAG.getTargetFrameIndex(*Index, Incoming.getValueType());
|
|
|
|
Builder.StatepointLowering.setLocation(Incoming, Loc);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove any duplicate (as SDValues) from the derived pointer pairs. This
|
|
|
|
/// is not required for correctness. It's purpose is to reduce the size of
|
|
|
|
/// StackMap section. It has no effect on the number of spill slots required
|
|
|
|
/// or the actual lowering.
|
2016-03-12 03:54:27 +01:00
|
|
|
static void
|
2016-03-24 19:57:31 +01:00
|
|
|
removeDuplicateGCPtrs(SmallVectorImpl<const Value *> &Bases,
|
|
|
|
SmallVectorImpl<const Value *> &Ptrs,
|
|
|
|
SmallVectorImpl<const GCRelocateInst *> &Relocs,
|
2016-03-24 19:57:39 +01:00
|
|
|
SelectionDAGBuilder &Builder,
|
|
|
|
FunctionLoweringInfo::StatepointSpillMap &SSM) {
|
|
|
|
DenseMap<SDValue, const Value *> Seen;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2016-03-12 03:54:27 +01:00
|
|
|
SmallVector<const Value *, 64> NewBases, NewPtrs;
|
|
|
|
SmallVector<const GCRelocateInst *, 64> NewRelocs;
|
2016-02-19 20:37:07 +01:00
|
|
|
for (size_t i = 0, e = Ptrs.size(); i < e; i++) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
SDValue SD = Builder.getValue(Ptrs[i]);
|
2016-03-24 19:57:39 +01:00
|
|
|
auto SeenIt = Seen.find(SD);
|
|
|
|
|
|
|
|
if (SeenIt == Seen.end()) {
|
|
|
|
// Only add non-duplicates
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
NewBases.push_back(Bases[i]);
|
|
|
|
NewPtrs.push_back(Ptrs[i]);
|
|
|
|
NewRelocs.push_back(Relocs[i]);
|
2016-03-24 19:57:39 +01:00
|
|
|
Seen[SD] = Ptrs[i];
|
|
|
|
} else {
|
|
|
|
// Duplicate pointer found, note in SSM and move on:
|
|
|
|
SSM.DuplicateMap[Ptrs[i]] = SeenIt->second;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(Bases.size() >= NewBases.size());
|
|
|
|
assert(Ptrs.size() >= NewPtrs.size());
|
|
|
|
assert(Relocs.size() >= NewRelocs.size());
|
|
|
|
Bases = NewBases;
|
|
|
|
Ptrs = NewPtrs;
|
|
|
|
Relocs = NewRelocs;
|
|
|
|
assert(Ptrs.size() == Bases.size());
|
|
|
|
assert(Ptrs.size() == Relocs.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Extract call from statepoint, lower it and return pointer to the
|
|
|
|
/// call node. Also update NodeMap so that getValue(statepoint) will
|
|
|
|
/// reference lowered call result
|
2016-03-17 00:08:00 +01:00
|
|
|
static std::pair<SDValue, SDNode *> lowerCallFromStatepointLoweringInfo(
|
|
|
|
SelectionDAGBuilder::StatepointLoweringInfo &SI,
|
|
|
|
SelectionDAGBuilder &Builder, SmallVectorImpl<SDValue> &PendingExports) {
|
2016-03-16 21:49:31 +01:00
|
|
|
|
2015-05-06 04:36:20 +02:00
|
|
|
SDValue ReturnValue, CallEndVal;
|
2016-03-17 00:08:00 +01:00
|
|
|
std::tie(ReturnValue, CallEndVal) =
|
|
|
|
Builder.lowerInvokable(SI.CLI, SI.EHPadBB);
|
2015-05-06 04:36:20 +02:00
|
|
|
SDNode *CallEnd = CallEndVal.getNode();
|
|
|
|
|
|
|
|
// Get a call instruction from the call sequence chain. Tail calls are not
|
|
|
|
// allowed. The following code is essentially reverse engineering X86's
|
|
|
|
// LowerCallTo.
|
|
|
|
//
|
|
|
|
// We are expecting DAG to have the following form:
|
|
|
|
//
|
|
|
|
// ch = eh_label (only in case of invoke statepoint)
|
|
|
|
// ch, glue = callseq_start ch
|
|
|
|
// ch, glue = X86::Call ch, glue
|
|
|
|
// ch, glue = callseq_end ch, glue
|
|
|
|
// get_return_value ch, glue
|
|
|
|
//
|
2015-11-17 17:04:21 +01:00
|
|
|
// get_return_value can either be a sequence of CopyFromReg instructions
|
|
|
|
// to grab the return value from the return register(s), or it can be a LOAD
|
|
|
|
// to load a value returned by reference via a stack slot.
|
|
|
|
|
2016-03-17 00:08:00 +01:00
|
|
|
bool HasDef = !SI.CLI.RetTy->isVoidTy();
|
2015-11-17 17:04:21 +01:00
|
|
|
if (HasDef) {
|
|
|
|
if (CallEnd->getOpcode() == ISD::LOAD)
|
|
|
|
CallEnd = CallEnd->getOperand(0).getNode();
|
|
|
|
else
|
|
|
|
while (CallEnd->getOpcode() == ISD::CopyFromReg)
|
|
|
|
CallEnd = CallEnd->getOperand(0).getNode();
|
|
|
|
}
|
2015-05-06 04:36:20 +02:00
|
|
|
|
|
|
|
assert(CallEnd->getOpcode() == ISD::CALLSEQ_END && "expected!");
|
2016-03-17 00:08:00 +01:00
|
|
|
return std::make_pair(ReturnValue, CallEnd->getOperand(0).getNode());
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Spill a value incoming to the statepoint. It might be either part of
|
|
|
|
/// vmstate
|
|
|
|
/// or gcstate. In both cases unconditionally spill it on the stack unless it
|
|
|
|
/// is a null constant. Return pair with first element being frame index
|
|
|
|
/// containing saved value and second element with outgoing chain from the
|
|
|
|
/// emitted store
|
|
|
|
static std::pair<SDValue, SDValue>
|
|
|
|
spillIncomingStatepointValue(SDValue Incoming, SDValue Chain,
|
|
|
|
SelectionDAGBuilder &Builder) {
|
|
|
|
SDValue Loc = Builder.StatepointLowering.getLocation(Incoming);
|
|
|
|
|
|
|
|
// Emit new store if we didn't do it for this ptr before
|
|
|
|
if (!Loc.getNode()) {
|
|
|
|
Loc = Builder.StatepointLowering.allocateStackSlot(Incoming.getValueType(),
|
|
|
|
Builder);
|
|
|
|
int Index = cast<FrameIndexSDNode>(Loc)->getIndex();
|
|
|
|
// We use TargetFrameIndex so that isel will not select it into LEA
|
|
|
|
Loc = Builder.DAG.getTargetFrameIndex(Index, Incoming.getValueType());
|
|
|
|
|
|
|
|
// TODO: We can create TokenFactor node instead of
|
|
|
|
// chaining stores one after another, this may allow
|
|
|
|
// a bit more optimal scheduling for them
|
2016-02-19 18:15:22 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Right now we always allocate spill slots that are of the same
|
|
|
|
// size as the value we're about to spill (the size of spillee can
|
|
|
|
// vary since we spill vectors of pointers too). At some point we
|
|
|
|
// can consider allowing spills of smaller values to larger slots
|
|
|
|
// (i.e. change the '==' in the assert below to a '>=').
|
|
|
|
auto *MFI = Builder.DAG.getMachineFunction().getFrameInfo();
|
|
|
|
assert((MFI->getObjectSize(Index) * 8) ==
|
|
|
|
Incoming.getValueType().getSizeInBits() &&
|
|
|
|
"Bad spill: stack slot does not match!");
|
|
|
|
#endif
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
Chain = Builder.DAG.getStore(Chain, Builder.getCurSDLoc(), Incoming, Loc,
|
2015-08-12 01:09:45 +02:00
|
|
|
MachinePointerInfo::getFixedStack(
|
|
|
|
Builder.DAG.getMachineFunction(), Index),
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
false, false, 0);
|
|
|
|
|
|
|
|
Builder.StatepointLowering.setLocation(Incoming, Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(Loc.getNode());
|
|
|
|
return std::make_pair(Loc, Chain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lower a single value incoming to a statepoint node. This value can be
|
|
|
|
/// either a deopt value or a gc value, the handling is the same. We special
|
|
|
|
/// case constants and allocas, then fall back to spilling if required.
|
|
|
|
static void lowerIncomingStatepointValue(SDValue Incoming,
|
|
|
|
SmallVectorImpl<SDValue> &Ops,
|
|
|
|
SelectionDAGBuilder &Builder) {
|
|
|
|
SDValue Chain = Builder.getRoot();
|
|
|
|
|
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Incoming)) {
|
|
|
|
// If the original value was a constant, make sure it gets recorded as
|
|
|
|
// such in the stackmap. This is required so that the consumer can
|
|
|
|
// parse any internal format to the deopt state. It also handles null
|
2016-01-07 05:15:31 +01:00
|
|
|
// pointers and other constant pointers in GC states. Note the constant
|
|
|
|
// vectors do not appear to actually hit this path and that anything larger
|
|
|
|
// than an i64 value (not type!) will fail asserts here.
|
2015-05-12 21:50:19 +02:00
|
|
|
pushStackMapConstant(Ops, Builder, C->getSExtValue());
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
} else if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Incoming)) {
|
2015-03-27 05:52:48 +01:00
|
|
|
// This handles allocas as arguments to the statepoint (this is only
|
|
|
|
// really meaningful for a deopt value. For GC, we'd be trying to
|
|
|
|
// relocate the address of the alloca itself?)
|
2015-04-29 23:52:45 +02:00
|
|
|
Ops.push_back(Builder.DAG.getTargetFrameIndex(FI->getIndex(),
|
2015-03-27 05:52:48 +01:00
|
|
|
Incoming.getValueType()));
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
} else {
|
|
|
|
// Otherwise, locate a spill slot and explicitly spill it so it
|
|
|
|
// can be found by the runtime later. We currently do not support
|
|
|
|
// tracking values through callee saved registers to their eventual
|
|
|
|
// spill location. This would be a useful optimization, but would
|
|
|
|
// need to be optional since it requires a lot of complexity on the
|
|
|
|
// runtime side which not all would support.
|
2016-02-19 20:37:07 +01:00
|
|
|
auto Res = spillIncomingStatepointValue(Incoming, Chain, Builder);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
Ops.push_back(Res.first);
|
|
|
|
Chain = Res.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
Builder.DAG.setRoot(Chain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lower deopt state and gc pointer arguments of the statepoint. The actual
|
|
|
|
/// lowering is described in lowerIncomingStatepointValue. This function is
|
|
|
|
/// responsible for lowering everything in the right position and playing some
|
|
|
|
/// tricks to avoid redundant stack manipulation where possible. On
|
|
|
|
/// completion, 'Ops' will contain ready to use operands for machine code
|
|
|
|
/// statepoint. The chain nodes will have already been created and the DAG root
|
|
|
|
/// will be set to the last value spilled (if any were).
|
2016-03-17 00:08:00 +01:00
|
|
|
static void
|
|
|
|
lowerStatepointMetaArgs(SmallVectorImpl<SDValue> &Ops,
|
|
|
|
SelectionDAGBuilder::StatepointLoweringInfo &SI,
|
|
|
|
SelectionDAGBuilder &Builder) {
|
2016-03-17 00:11:21 +01:00
|
|
|
// Lower the deopt and gc arguments for this statepoint. Layout will be:
|
|
|
|
// deopt argument length, deopt arguments.., gc arguments...
|
2015-01-07 20:07:50 +01:00
|
|
|
#ifndef NDEBUG
|
2016-03-22 01:59:13 +01:00
|
|
|
if (auto *GFI = Builder.GFI) {
|
|
|
|
// Check that each of the gc pointer and bases we've gotten out of the
|
|
|
|
// safepoint is something the strategy thinks might be a pointer (or vector
|
|
|
|
// of pointers) into the GC heap. This is basically just here to help catch
|
|
|
|
// errors during statepoint insertion. TODO: This should actually be in the
|
|
|
|
// Verifier, but we can't get to the GCStrategy from there (yet).
|
|
|
|
GCStrategy &S = GFI->getStrategy();
|
|
|
|
for (const Value *V : SI.Bases) {
|
|
|
|
auto Opt = S.isGCManagedPointer(V->getType()->getScalarType());
|
|
|
|
if (Opt.hasValue()) {
|
|
|
|
assert(Opt.getValue() &&
|
|
|
|
"non gc managed base pointer found in statepoint");
|
|
|
|
}
|
2015-01-07 20:07:50 +01:00
|
|
|
}
|
2016-03-22 01:59:13 +01:00
|
|
|
for (const Value *V : SI.Ptrs) {
|
|
|
|
auto Opt = S.isGCManagedPointer(V->getType()->getScalarType());
|
|
|
|
if (Opt.hasValue()) {
|
|
|
|
assert(Opt.getValue() &&
|
|
|
|
"non gc managed derived pointer found in statepoint");
|
|
|
|
}
|
2015-01-07 20:07:50 +01:00
|
|
|
}
|
2016-03-22 01:59:13 +01:00
|
|
|
} else {
|
|
|
|
assert(SI.Bases.empty() && "No gc specified, so cannot relocate pointers!");
|
|
|
|
assert(SI.Ptrs.empty() && "No gc specified, so cannot relocate pointers!");
|
2015-03-27 06:09:33 +01:00
|
|
|
}
|
2015-01-07 20:07:50 +01:00
|
|
|
#endif
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Before we actually start lowering (and allocating spill slots for values),
|
|
|
|
// reserve any stack slots which we judge to be profitable to reuse for a
|
|
|
|
// particular value. This is purely an optimization over the code below and
|
|
|
|
// doesn't change semantics at all. It is important for performance that we
|
|
|
|
// reserve slots for both deopt and gc values before lowering either.
|
2016-03-17 00:08:00 +01:00
|
|
|
for (const Value *V : SI.DeoptState) {
|
2015-06-10 14:31:53 +02:00
|
|
|
reservePreviousStackSlotForValue(V, Builder);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
2016-03-17 00:08:00 +01:00
|
|
|
for (unsigned i = 0; i < SI.Bases.size(); ++i) {
|
|
|
|
reservePreviousStackSlotForValue(SI.Bases[i], Builder);
|
|
|
|
reservePreviousStackSlotForValue(SI.Ptrs[i], Builder);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// First, prefix the list with the number of unique values to be
|
|
|
|
// lowered. Note that this is the number of *Values* not the
|
|
|
|
// number of SDValues required to lower them.
|
2016-03-17 00:08:00 +01:00
|
|
|
const int NumVMSArgs = SI.DeoptState.size();
|
2015-05-12 21:50:19 +02:00
|
|
|
pushStackMapConstant(Ops, Builder, NumVMSArgs);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2016-03-17 00:08:00 +01:00
|
|
|
// The vm state arguments are lowered in an opaque manner. We do not know
|
|
|
|
// what type of values are contained within.
|
|
|
|
for (const Value *V : SI.DeoptState) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
SDValue Incoming = Builder.getValue(V);
|
|
|
|
lowerIncomingStatepointValue(Incoming, Ops, Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, go ahead and lower all the gc arguments. There's no prefixed
|
|
|
|
// length for this one. After lowering, we'll have the base and pointer
|
|
|
|
// arrays interwoven with each (lowered) base pointer immediately followed by
|
|
|
|
// it's (lowered) derived pointer. i.e
|
|
|
|
// (base[0], ptr[0], base[1], ptr[1], ...)
|
2016-03-17 00:08:00 +01:00
|
|
|
for (unsigned i = 0; i < SI.Bases.size(); ++i) {
|
|
|
|
const Value *Base = SI.Bases[i];
|
2015-05-12 15:12:14 +02:00
|
|
|
lowerIncomingStatepointValue(Builder.getValue(Base), Ops, Builder);
|
|
|
|
|
2016-03-17 00:08:00 +01:00
|
|
|
const Value *Ptr = SI.Ptrs[i];
|
2015-05-12 15:12:14 +02:00
|
|
|
lowerIncomingStatepointValue(Builder.getValue(Ptr), Ops, Builder);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
2015-03-27 05:52:48 +01:00
|
|
|
|
2015-04-29 23:52:45 +02:00
|
|
|
// If there are any explicit spill slots passed to the statepoint, record
|
2015-03-27 05:52:48 +01:00
|
|
|
// them, but otherwise do not do anything special. These are user provided
|
2015-04-29 23:52:45 +02:00
|
|
|
// allocas and give control over placement to the consumer. In this case,
|
2015-03-27 05:52:48 +01:00
|
|
|
// it is the contents of the slot which may get updated, not the pointer to
|
|
|
|
// the alloca
|
2016-03-17 00:08:00 +01:00
|
|
|
for (Value *V : SI.GCArgs) {
|
2015-03-27 05:52:48 +01:00
|
|
|
SDValue Incoming = Builder.getValue(V);
|
|
|
|
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Incoming)) {
|
|
|
|
// This handles allocas as arguments to the statepoint
|
2015-04-29 23:52:45 +02:00
|
|
|
Ops.push_back(Builder.DAG.getTargetFrameIndex(FI->getIndex(),
|
2015-03-27 05:52:48 +01:00
|
|
|
Incoming.getValueType()));
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 13:37:25 +02:00
|
|
|
|
|
|
|
// Record computed locations for all lowered values.
|
|
|
|
// This can not be embedded in lowering loops as we need to record *all*
|
|
|
|
// values, while previous loops account only values with unique SDValues.
|
2016-03-17 00:08:00 +01:00
|
|
|
const Instruction *StatepointInstr = SI.StatepointInstr;
|
2016-03-24 19:57:39 +01:00
|
|
|
auto &SpillMap = Builder.FuncInfo.StatepointSpillMaps[StatepointInstr];
|
2015-05-20 13:37:25 +02:00
|
|
|
|
2016-03-17 00:08:00 +01:00
|
|
|
for (const GCRelocateInst *Relocate : SI.GCRelocates) {
|
2016-01-05 05:03:00 +01:00
|
|
|
const Value *V = Relocate->getDerivedPtr();
|
2015-05-20 13:37:25 +02:00
|
|
|
SDValue SDV = Builder.getValue(V);
|
|
|
|
SDValue Loc = Builder.StatepointLowering.getLocation(SDV);
|
|
|
|
|
|
|
|
if (Loc.getNode()) {
|
2016-03-24 19:57:39 +01:00
|
|
|
SpillMap.SlotMap[V] = cast<FrameIndexSDNode>(Loc)->getIndex();
|
2015-05-20 13:37:25 +02:00
|
|
|
} else {
|
|
|
|
// Record value as visited, but not spilled. This is case for allocas
|
2015-08-08 20:27:36 +02:00
|
|
|
// and constants. For this values we can avoid emitting spill load while
|
2015-05-20 13:37:25 +02:00
|
|
|
// visiting corresponding gc_relocate.
|
|
|
|
// Actually we do not need to record them in this map at all.
|
2015-08-08 20:27:36 +02:00
|
|
|
// We do this only to check that we are not relocating any unvisited
|
|
|
|
// value.
|
2016-03-24 19:57:39 +01:00
|
|
|
SpillMap.SlotMap[V] = None;
|
2015-05-20 13:37:25 +02:00
|
|
|
|
|
|
|
// Default llvm mechanisms for exporting values which are used in
|
|
|
|
// different basic blocks does not work for gc relocates.
|
|
|
|
// Note that it would be incorrect to teach llvm that all relocates are
|
2015-08-08 20:27:36 +02:00
|
|
|
// uses of the corresponding values so that it would automatically
|
2015-05-20 13:37:25 +02:00
|
|
|
// export them. Relocates of the spilled values does not use original
|
|
|
|
// value.
|
2016-01-05 05:03:00 +01:00
|
|
|
if (Relocate->getParent() != StatepointInstr->getParent())
|
2015-05-20 13:37:25 +02:00
|
|
|
Builder.ExportFromCurrentBlock(V);
|
|
|
|
}
|
|
|
|
}
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
2015-02-20 16:28:35 +01:00
|
|
|
|
2016-03-22 01:59:13 +01:00
|
|
|
SDValue SelectionDAGBuilder::LowerAsSTATEPOINT(
|
2016-03-17 00:08:00 +01:00
|
|
|
SelectionDAGBuilder::StatepointLoweringInfo &SI) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// The basic scheme here is that information about both the original call and
|
|
|
|
// the safepoint is encoded in the CallInst. We create a temporary call and
|
|
|
|
// lower it, then reverse engineer the calling sequence.
|
|
|
|
|
|
|
|
NumOfStatepoints++;
|
|
|
|
// Clear state
|
|
|
|
StatepointLowering.startNewStatepoint(*this);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2016-03-24 19:57:31 +01:00
|
|
|
// We schedule gc relocates before removeDuplicateGCPtrs since we _will_
|
|
|
|
// encounter the duplicate gc relocates we elide in removeDuplicateGCPtrs.
|
2016-03-17 00:08:00 +01:00
|
|
|
for (auto *Reloc : SI.GCRelocates)
|
|
|
|
if (Reloc->getParent() == SI.StatepointInstr->getParent())
|
|
|
|
StatepointLowering.scheduleRelocCall(*Reloc);
|
2014-12-02 22:01:48 +01:00
|
|
|
#endif
|
|
|
|
|
2016-03-23 03:24:07 +01:00
|
|
|
// Remove any redundant llvm::Values which map to the same SDValue as another
|
|
|
|
// input. Also has the effect of removing duplicates in the original
|
|
|
|
// llvm::Value input list as well. This is a useful optimization for
|
|
|
|
// reducing the size of the StackMap section. It has no other impact.
|
2016-03-24 19:57:39 +01:00
|
|
|
removeDuplicateGCPtrs(SI.Bases, SI.Ptrs, SI.GCRelocates, *this,
|
|
|
|
FuncInfo.StatepointSpillMaps[SI.StatepointInstr]);
|
2016-03-23 03:24:07 +01:00
|
|
|
assert(SI.Bases.size() == SI.Ptrs.size() &&
|
|
|
|
SI.Ptrs.size() == SI.GCRelocates.size());
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Lower statepoint vmstate and gcstate arguments
|
2015-05-06 01:06:49 +02:00
|
|
|
SmallVector<SDValue, 10> LoweredMetaArgs;
|
2016-03-17 00:08:00 +01:00
|
|
|
lowerStatepointMetaArgs(LoweredMetaArgs, SI, *this);
|
|
|
|
|
|
|
|
// Now that we've emitted the spills, we need to update the root so that the
|
|
|
|
// call sequence is ordered correctly.
|
|
|
|
SI.CLI.setChain(getRoot());
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Get call node, we will replace it later with statepoint
|
2016-03-17 00:08:00 +01:00
|
|
|
SDValue ReturnVal;
|
|
|
|
SDNode *CallNode;
|
|
|
|
std::tie(ReturnVal, CallNode) =
|
|
|
|
lowerCallFromStatepointLoweringInfo(SI, *this, PendingExports);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
// Construct the actual GC_TRANSITION_START, STATEPOINT, and GC_TRANSITION_END
|
|
|
|
// nodes with all the appropriate arguments and return values.
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Call Node: Chain, Target, {Args}, RegMask, [Glue]
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
SDValue Chain = CallNode->getOperand(0);
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
SDValue Glue;
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
bool CallHasIncomingGlue = CallNode->getGluedNode();
|
|
|
|
if (CallHasIncomingGlue) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Glue is always last operand
|
|
|
|
Glue = CallNode->getOperand(CallNode->getNumOperands() - 1);
|
|
|
|
}
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
|
|
|
|
// Build the GC_TRANSITION_START node if necessary.
|
|
|
|
//
|
|
|
|
// The operands to the GC_TRANSITION_{START,END} nodes are laid out in the
|
|
|
|
// order in which they appear in the call to the statepoint intrinsic. If
|
|
|
|
// any of the operands is a pointer-typed, that operand is immediately
|
|
|
|
// followed by a SRCVALUE for the pointer that may be used during lowering
|
|
|
|
// (e.g. to form MachinePointerInfo values for loads/stores).
|
|
|
|
const bool IsGCTransition =
|
2016-03-17 00:08:00 +01:00
|
|
|
(SI.StatepointFlags & (uint64_t)StatepointFlags::GCTransition) ==
|
|
|
|
(uint64_t)StatepointFlags::GCTransition;
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
if (IsGCTransition) {
|
|
|
|
SmallVector<SDValue, 8> TSOps;
|
|
|
|
|
|
|
|
// Add chain
|
|
|
|
TSOps.push_back(Chain);
|
|
|
|
|
|
|
|
// Add GC transition arguments
|
2016-03-17 00:08:00 +01:00
|
|
|
for (const Value *V : SI.GCTransitionArgs) {
|
2015-05-12 23:33:48 +02:00
|
|
|
TSOps.push_back(getValue(V));
|
|
|
|
if (V->getType()->isPointerTy())
|
|
|
|
TSOps.push_back(DAG.getSrcValue(V));
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add glue if necessary
|
|
|
|
if (CallHasIncomingGlue)
|
|
|
|
TSOps.push_back(Glue);
|
|
|
|
|
|
|
|
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
|
|
|
|
|
|
|
|
SDValue GCTransitionStart =
|
|
|
|
DAG.getNode(ISD::GC_TRANSITION_START, getCurSDLoc(), NodeTys, TSOps);
|
|
|
|
|
|
|
|
Chain = GCTransitionStart.getValue(0);
|
|
|
|
Glue = GCTransitionStart.getValue(1);
|
|
|
|
}
|
|
|
|
|
2015-05-13 01:52:24 +02:00
|
|
|
// TODO: Currently, all of these operands are being marked as read/write in
|
|
|
|
// PrologEpilougeInserter.cpp, we should special case the VMState arguments
|
|
|
|
// and flags to be read-only.
|
|
|
|
SmallVector<SDValue, 40> Ops;
|
|
|
|
|
|
|
|
// Add the <id> and <numBytes> constants.
|
2016-03-17 00:08:00 +01:00
|
|
|
Ops.push_back(DAG.getTargetConstant(SI.ID, getCurSDLoc(), MVT::i64));
|
2015-05-13 01:52:24 +02:00
|
|
|
Ops.push_back(
|
2016-03-17 00:08:00 +01:00
|
|
|
DAG.getTargetConstant(SI.NumPatchBytes, getCurSDLoc(), MVT::i32));
|
2015-05-13 01:52:24 +02:00
|
|
|
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
// Calculate and push starting position of vmstate arguments
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Get number of arguments incoming directly into call node
|
|
|
|
unsigned NumCallRegArgs =
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
CallNode->getNumOperands() - (CallHasIncomingGlue ? 4 : 3);
|
2015-04-28 16:05:47 +02:00
|
|
|
Ops.push_back(DAG.getTargetConstant(NumCallRegArgs, getCurSDLoc(), MVT::i32));
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Add call target
|
|
|
|
SDValue CallTarget = SDValue(CallNode->getOperand(1).getNode(), 0);
|
|
|
|
Ops.push_back(CallTarget);
|
|
|
|
|
|
|
|
// Add call arguments
|
|
|
|
// Get position of register mask in the call
|
|
|
|
SDNode::op_iterator RegMaskIt;
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
if (CallHasIncomingGlue)
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
RegMaskIt = CallNode->op_end() - 2;
|
|
|
|
else
|
|
|
|
RegMaskIt = CallNode->op_end() - 1;
|
|
|
|
Ops.insert(Ops.end(), CallNode->op_begin() + 2, RegMaskIt);
|
|
|
|
|
2015-05-12 21:50:19 +02:00
|
|
|
// Add a constant argument for the calling convention
|
2016-03-17 00:08:00 +01:00
|
|
|
pushStackMapConstant(Ops, *this, SI.CLI.CallConv);
|
2015-05-12 21:50:19 +02:00
|
|
|
|
|
|
|
// Add a constant argument for the flags
|
2016-03-17 00:08:00 +01:00
|
|
|
uint64_t Flags = SI.StatepointFlags;
|
2016-02-19 20:37:07 +01:00
|
|
|
assert(((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0) &&
|
|
|
|
"Unknown flag used");
|
2015-05-12 21:50:19 +02:00
|
|
|
pushStackMapConstant(Ops, *this, Flags);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Insert all vmstate and gcstate arguments
|
2015-05-06 01:06:49 +02:00
|
|
|
Ops.insert(Ops.end(), LoweredMetaArgs.begin(), LoweredMetaArgs.end());
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Add register mask from call node
|
|
|
|
Ops.push_back(*RegMaskIt);
|
|
|
|
|
|
|
|
// Add chain
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
Ops.push_back(Chain);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
|
|
|
// Same for the glue, but we add it only if original call had it
|
|
|
|
if (Glue.getNode())
|
|
|
|
Ops.push_back(Glue);
|
|
|
|
|
2015-02-19 16:26:17 +01:00
|
|
|
// Compute return values. Provide a glue output since we consume one as
|
|
|
|
// input. This allows someone else to chain off us as needed.
|
|
|
|
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-04-29 23:52:45 +02:00
|
|
|
SDNode *StatepointMCNode =
|
|
|
|
DAG.getMachineNode(TargetOpcode::STATEPOINT, getCurSDLoc(), NodeTys, Ops);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
SDNode *SinkNode = StatepointMCNode;
|
|
|
|
|
|
|
|
// Build the GC_TRANSITION_END node if necessary.
|
|
|
|
//
|
|
|
|
// See the comment above regarding GC_TRANSITION_START for the layout of
|
|
|
|
// the operands to the GC_TRANSITION_END node.
|
|
|
|
if (IsGCTransition) {
|
|
|
|
SmallVector<SDValue, 8> TEOps;
|
|
|
|
|
|
|
|
// Add chain
|
|
|
|
TEOps.push_back(SDValue(StatepointMCNode, 0));
|
|
|
|
|
|
|
|
// Add GC transition arguments
|
2016-03-17 00:08:00 +01:00
|
|
|
for (const Value *V : SI.GCTransitionArgs) {
|
2015-05-12 23:33:48 +02:00
|
|
|
TEOps.push_back(getValue(V));
|
|
|
|
if (V->getType()->isPointerTy())
|
|
|
|
TEOps.push_back(DAG.getSrcValue(V));
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add glue
|
|
|
|
TEOps.push_back(SDValue(StatepointMCNode, 1));
|
|
|
|
|
|
|
|
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
|
|
|
|
|
|
|
|
SDValue GCTransitionStart =
|
|
|
|
DAG.getNode(ISD::GC_TRANSITION_END, getCurSDLoc(), NodeTys, TEOps);
|
|
|
|
|
|
|
|
SinkNode = GCTransitionStart.getNode();
|
|
|
|
}
|
|
|
|
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// Replace original call
|
Extend the statepoint intrinsic to allow statepoints to be marked as transitions from GC-aware code to code that is not GC-aware.
This changes the shape of the statepoint intrinsic from:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 unused, ...call args, i32 # deopt args, ...deopt args, ...gc args)
to:
@llvm.experimental.gc.statepoint(anyptr target, i32 # call args, i32 flags, ...call args, i32 # transition args, ...transition args, i32 # deopt args, ...deopt args, ...gc args)
This extension offers the backend the opportunity to insert (somewhat) arbitrary code to manage the transition from GC-aware code to code that is not GC-aware and back.
In order to support the injection of transition code, this extension wraps the STATEPOINT ISD node generated by the usual lowering lowering with two additional nodes: GC_TRANSITION_START and GC_TRANSITION_END. The transition arguments that were passed passed to the intrinsic (if any) are lowered and provided as operands to these nodes and may be used by the backend during code generation.
Eventually, the lowering of the GC_TRANSITION_{START,END} nodes should be informed by the GC strategy in use for the function containing the intrinsic call; for now, these nodes are instead replaced with no-ops.
Differential Revision: http://reviews.llvm.org/D9501
llvm-svn: 236888
2015-05-08 20:07:42 +02:00
|
|
|
DAG.ReplaceAllUsesWith(CallNode, SinkNode); // This may update Root
|
2015-08-08 20:27:36 +02:00
|
|
|
// Remove original call node
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
DAG.DeleteNode(CallNode);
|
|
|
|
|
|
|
|
// DON'T set the root - under the assumption that it's already set past the
|
|
|
|
// inserted node we created.
|
|
|
|
|
|
|
|
// TODO: A better future implementation would be to emit a single variable
|
|
|
|
// argument, variable return value STATEPOINT node here and then hookup the
|
|
|
|
// return value of each gc.relocate to the respective output of the
|
|
|
|
// previously emitted STATEPOINT value. Unfortunately, this doesn't appear
|
|
|
|
// to actually be possible today.
|
2016-03-17 00:08:00 +01:00
|
|
|
|
|
|
|
return ReturnVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SelectionDAGBuilder::LowerStatepoint(ImmutableStatepoint ISP,
|
|
|
|
const BasicBlock *EHPadBB /*= nullptr*/) {
|
|
|
|
assert(ISP.getCallSite().getCallingConv() != CallingConv::AnyReg &&
|
|
|
|
"anyregcc is not supported on statepoints!");
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// If this is a malformed statepoint, report it early to simplify debugging.
|
|
|
|
// This should catch any IR level mistake that's made when constructing or
|
|
|
|
// transforming statepoints.
|
|
|
|
ISP.verify();
|
|
|
|
|
|
|
|
// Check that the associated GCStrategy expects to encounter statepoints.
|
|
|
|
assert(GFI->getStrategy().useStatepoints() &&
|
|
|
|
"GCStrategy does not expect to encounter statepoints");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SDValue ActualCallee;
|
|
|
|
|
|
|
|
if (ISP.getNumPatchBytes() > 0) {
|
|
|
|
// If we've been asked to emit a nop sequence instead of a call instruction
|
|
|
|
// for this statepoint then don't lower the call target, but use a constant
|
|
|
|
// `null` instead. Not lowering the call target lets statepoint clients get
|
|
|
|
// away without providing a physical address for the symbolic call target at
|
|
|
|
// link time.
|
|
|
|
|
|
|
|
const auto &TLI = DAG.getTargetLoweringInfo();
|
|
|
|
const auto &DL = DAG.getDataLayout();
|
|
|
|
|
|
|
|
unsigned AS = ISP.getCalledValue()->getType()->getPointerAddressSpace();
|
|
|
|
ActualCallee = DAG.getConstant(0, getCurSDLoc(), TLI.getPointerTy(DL, AS));
|
|
|
|
} else {
|
|
|
|
ActualCallee = getValue(ISP.getCalledValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
StatepointLoweringInfo SI(DAG);
|
|
|
|
populateCallLoweringInfo(SI.CLI, ISP.getCallSite(),
|
|
|
|
ImmutableStatepoint::CallArgsBeginPos,
|
|
|
|
ISP.getNumCallArgs(), ActualCallee,
|
|
|
|
ISP.getActualReturnType(), false /* IsPatchPoint */);
|
|
|
|
|
2016-03-23 03:24:10 +01:00
|
|
|
for (const GCRelocateInst *Relocate : ISP.getRelocates()) {
|
|
|
|
SI.GCRelocates.push_back(Relocate);
|
|
|
|
SI.Bases.push_back(Relocate->getBasePtr());
|
|
|
|
SI.Ptrs.push_back(Relocate->getDerivedPtr());
|
|
|
|
}
|
|
|
|
|
2016-03-17 00:08:00 +01:00
|
|
|
SI.GCArgs = ArrayRef<const Use>(ISP.gc_args_begin(), ISP.gc_args_end());
|
|
|
|
SI.StatepointInstr = ISP.getInstruction();
|
|
|
|
SI.GCTransitionArgs =
|
|
|
|
ArrayRef<const Use>(ISP.gc_args_begin(), ISP.gc_args_end());
|
|
|
|
SI.ID = ISP.getID();
|
|
|
|
SI.DeoptState = ArrayRef<const Use>(ISP.vm_state_begin(), ISP.vm_state_end());
|
|
|
|
SI.StatepointFlags = ISP.getFlags();
|
|
|
|
SI.NumPatchBytes = ISP.getNumPatchBytes();
|
|
|
|
SI.EHPadBB = EHPadBB;
|
|
|
|
|
2016-03-22 01:59:13 +01:00
|
|
|
SDValue ReturnValue = LowerAsSTATEPOINT(SI);
|
2016-03-17 00:08:00 +01:00
|
|
|
|
|
|
|
// Export the result value if needed
|
2016-04-12 20:05:10 +02:00
|
|
|
const GCResultInst *GCResult = ISP.getGCResult();
|
2016-03-17 00:08:00 +01:00
|
|
|
Type *RetTy = ISP.getActualReturnType();
|
|
|
|
if (!RetTy->isVoidTy() && GCResult) {
|
|
|
|
if (GCResult->getParent() != ISP.getCallSite().getParent()) {
|
|
|
|
// Result value will be used in a different basic block so we need to
|
|
|
|
// export it now. Default exporting mechanism will not work here because
|
|
|
|
// statepoint call has a different type than the actual call. It means
|
|
|
|
// that by default llvm will create export register of the wrong type
|
|
|
|
// (always i32 in our case). So instead we need to create export register
|
|
|
|
// with correct type manually.
|
|
|
|
// TODO: To eliminate this problem we can remove gc.result intrinsics
|
|
|
|
// completely and make statepoint call to return a tuple.
|
|
|
|
unsigned Reg = FuncInfo.CreateRegs(RetTy);
|
|
|
|
RegsForValue RFV(*DAG.getContext(), DAG.getTargetLoweringInfo(),
|
|
|
|
DAG.getDataLayout(), Reg, RetTy);
|
|
|
|
SDValue Chain = DAG.getEntryNode();
|
|
|
|
|
|
|
|
RFV.getCopyToRegs(ReturnValue, DAG, getCurSDLoc(), Chain, nullptr);
|
|
|
|
PendingExports.push_back(Chain);
|
|
|
|
FuncInfo.ValueMap[ISP.getInstruction()] = Reg;
|
|
|
|
} else {
|
|
|
|
// Result value will be used in a same basic block. Don't export it or
|
|
|
|
// perform any explicit register copies.
|
|
|
|
// We'll replace the actuall call node shortly. gc_result will grab
|
|
|
|
// this value.
|
|
|
|
setValue(ISP.getInstruction(), ReturnValue);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The token value is never used from here on, just generate a poison value
|
|
|
|
setValue(ISP.getInstruction(), DAG.getIntPtrConstant(-1, getCurSDLoc()));
|
|
|
|
}
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 23:51:49 +01:00
|
|
|
void SelectionDAGBuilder::LowerCallSiteWithDeoptBundleImpl(
|
|
|
|
ImmutableCallSite CS, SDValue Callee, const BasicBlock *EHPadBB,
|
2016-04-06 03:33:49 +02:00
|
|
|
bool VarArgDisallowed, bool ForceVoidReturnTy) {
|
2016-03-22 01:59:13 +01:00
|
|
|
StatepointLoweringInfo SI(DAG);
|
|
|
|
unsigned ArgBeginIndex = CS.arg_begin() - CS.getInstruction()->op_begin();
|
2016-04-06 03:33:49 +02:00
|
|
|
populateCallLoweringInfo(
|
|
|
|
SI.CLI, CS, ArgBeginIndex, CS.getNumArgOperands(), Callee,
|
|
|
|
ForceVoidReturnTy ? Type::getVoidTy(*DAG.getContext()) : CS.getType(),
|
|
|
|
false);
|
2016-03-24 23:51:49 +01:00
|
|
|
if (!VarArgDisallowed)
|
|
|
|
SI.CLI.IsVarArg = CS.getFunctionType()->isVarArg();
|
2016-03-22 01:59:13 +01:00
|
|
|
|
2016-03-22 19:10:39 +01:00
|
|
|
auto DeoptBundle = *CS.getOperandBundle(LLVMContext::OB_deopt);
|
2016-03-22 01:59:13 +01:00
|
|
|
|
|
|
|
unsigned DefaultID = StatepointDirectives::DeoptBundleStatepointID;
|
|
|
|
|
|
|
|
auto SD = parseStatepointDirectivesFromAttrs(CS.getAttributes());
|
|
|
|
SI.ID = SD.StatepointID.getValueOr(DefaultID);
|
|
|
|
SI.NumPatchBytes = SD.NumPatchBytes.getValueOr(0);
|
|
|
|
|
|
|
|
SI.DeoptState =
|
|
|
|
ArrayRef<const Use>(DeoptBundle.Inputs.begin(), DeoptBundle.Inputs.end());
|
|
|
|
SI.StatepointFlags = static_cast<uint64_t>(StatepointFlags::None);
|
|
|
|
SI.EHPadBB = EHPadBB;
|
|
|
|
|
2016-03-24 23:51:49 +01:00
|
|
|
// NB! The GC arguments are deliberately left empty.
|
|
|
|
|
2016-03-22 01:59:13 +01:00
|
|
|
if (SDValue ReturnVal = LowerAsSTATEPOINT(SI)) {
|
|
|
|
const Instruction *Inst = CS.getInstruction();
|
|
|
|
ReturnVal = lowerRangeToAssertZExt(DAG, *Inst, ReturnVal);
|
|
|
|
setValue(Inst, ReturnVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 23:51:49 +01:00
|
|
|
void SelectionDAGBuilder::LowerCallSiteWithDeoptBundle(
|
|
|
|
ImmutableCallSite CS, SDValue Callee, const BasicBlock *EHPadBB) {
|
|
|
|
LowerCallSiteWithDeoptBundleImpl(CS, Callee, EHPadBB,
|
2016-04-06 03:33:49 +02:00
|
|
|
/* VarArgDisallowed = */ false,
|
|
|
|
/* ForceVoidReturnTy = */ false);
|
2016-03-24 23:51:49 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 20:05:10 +02:00
|
|
|
void SelectionDAGBuilder::visitGCResult(const GCResultInst &CI) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
// The result value of the gc_result is simply the result of the actual
|
|
|
|
// call. We've already emitted this, so just grab the value.
|
2016-04-12 20:05:10 +02:00
|
|
|
const Instruction *I = CI.getStatepoint();
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-11-04 02:16:10 +01:00
|
|
|
if (I->getParent() != CI.getParent()) {
|
|
|
|
// Statepoint is in different basic block so we should have stored call
|
|
|
|
// result in a virtual register.
|
2015-03-10 17:26:48 +01:00
|
|
|
// We can not use default getValue() functionality to copy value from this
|
2016-04-12 20:05:10 +02:00
|
|
|
// register because statepoint and actual call return types can be
|
2015-03-10 17:26:48 +01:00
|
|
|
// different, and getValue() will use CopyFromReg of the wrong type,
|
|
|
|
// which is always i32 in our case.
|
2015-07-02 04:53:45 +02:00
|
|
|
PointerType *CalleeType = cast<PointerType>(
|
|
|
|
ImmutableStatepoint(I).getCalledValue()->getType());
|
2015-04-29 23:52:45 +02:00
|
|
|
Type *RetTy =
|
|
|
|
cast<FunctionType>(CalleeType->getElementType())->getReturnType();
|
2015-03-10 17:26:48 +01:00
|
|
|
SDValue CopyFromReg = getCopyFromRegs(I, RetTy);
|
|
|
|
|
|
|
|
assert(CopyFromReg.getNode());
|
|
|
|
setValue(&CI, CopyFromReg);
|
2015-04-29 23:52:45 +02:00
|
|
|
} else {
|
2015-03-10 17:26:48 +01:00
|
|
|
setValue(&CI, getValue(I));
|
|
|
|
}
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 05:03:00 +01:00
|
|
|
void SelectionDAGBuilder::visitGCRelocate(const GCRelocateInst &Relocate) {
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Consistency check
|
2015-11-04 02:16:10 +01:00
|
|
|
// We skip this check for relocates not in the same basic block as thier
|
|
|
|
// statepoint. It would be too expensive to preserve validation info through
|
|
|
|
// different basic blocks.
|
2016-02-19 20:37:07 +01:00
|
|
|
if (Relocate.getStatepoint()->getParent() == Relocate.getParent())
|
2016-01-05 05:03:00 +01:00
|
|
|
StatepointLowering.relocCallVisited(Relocate);
|
2016-03-15 02:16:31 +01:00
|
|
|
|
|
|
|
auto *Ty = Relocate.getType()->getScalarType();
|
|
|
|
if (auto IsManaged = GFI->getStrategy().isGCManagedPointer(Ty))
|
|
|
|
assert(*IsManaged && "Non gc managed pointer relocated!");
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2016-01-05 05:03:00 +01:00
|
|
|
const Value *DerivedPtr = Relocate.getDerivedPtr();
|
2015-05-20 13:37:25 +02:00
|
|
|
SDValue SD = getValue(DerivedPtr);
|
|
|
|
|
2016-03-24 19:57:39 +01:00
|
|
|
auto &SpillMap = FuncInfo.StatepointSpillMaps[Relocate.getStatepoint()];
|
|
|
|
auto SlotIt = SpillMap.find(DerivedPtr);
|
|
|
|
assert(SlotIt != SpillMap.end() && "Relocating not lowered gc value");
|
|
|
|
Optional<int> DerivedPtrLocation = SlotIt->second;
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
// We didn't need to spill these special cases (constants and allocas).
|
|
|
|
// See the handling in spillIncomingValueForStatepoint for detail.
|
|
|
|
if (!DerivedPtrLocation) {
|
2016-01-05 05:03:00 +01:00
|
|
|
setValue(&Relocate, SD);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
SDValue SpillSlot = DAG.getTargetFrameIndex(*DerivedPtrLocation,
|
|
|
|
SD.getValueType());
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
// Be conservative: flush all pending loads
|
|
|
|
// TODO: Probably we can be less restrictive on this,
|
2015-08-08 20:27:36 +02:00
|
|
|
// it may allow more scheduling opportunities.
|
2015-05-20 13:37:25 +02:00
|
|
|
SDValue Chain = getRoot();
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
SDValue SpillLoad =
|
2015-08-12 01:09:45 +02:00
|
|
|
DAG.getLoad(SpillSlot.getValueType(), getCurSDLoc(), Chain, SpillSlot,
|
|
|
|
MachinePointerInfo::getFixedStack(DAG.getMachineFunction(),
|
|
|
|
*DerivedPtrLocation),
|
|
|
|
false, false, false, 0);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
// Again, be conservative, don't emit pending loads
|
|
|
|
DAG.setRoot(SpillLoad.getValue(1));
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
|
2015-05-20 13:37:25 +02:00
|
|
|
assert(SpillLoad.getNode());
|
2016-01-05 05:03:00 +01:00
|
|
|
setValue(&Relocate, SpillLoad);
|
[Statepoints 3/4] Statepoint infrastructure for garbage collection: SelectionDAGBuilder
This is the third patch in a small series. It contains the CodeGen support for lowering the gc.statepoint intrinsic sequences (223078) to the STATEPOINT pseudo machine instruction (223085). The change also includes the set of helper routines and classes for working with gc.statepoints, gc.relocates, and gc.results since the lowering code uses them.
With this change, gc.statepoints should be functionally complete. The documentation will follow in the fourth change, and there will likely be some cleanup changes, but interested parties can start experimenting now.
I'm not particularly happy with the amount of code or complexity involved with the lowering step, but at least it's fairly well isolated. The statepoint lowering code is split into it's own files and anyone not working on the statepoint support itself should be able to ignore it.
During the lowering process, we currently spill aggressively to stack. This is not entirely ideal (and we have plans to do better), but it's functional, relatively straight forward, and matches closely the implementations of the patchpoint intrinsics. Most of the complexity comes from trying to keep relocated copies of values in the same stack slots across statepoints. Doing so avoids the insertion of pointless load and store instructions to reshuffle the stack. The current implementation isn't as effective as I'd like, but it is functional and 'good enough' for many common use cases.
In the long term, I'd like to figure out how to integrate the statepoint lowering with the register allocator. In principal, we shouldn't need to eagerly spill at all. The register allocator should do any spilling required and the statepoint should simply record that fact. Depending on how challenging that turns out to be, we may invest in a smarter global stack slot assignment mechanism as a stop gap measure.
Reviewed by: atrick, ributzka
llvm-svn: 223137
2014-12-02 19:50:36 +01:00
|
|
|
}
|
2016-03-24 21:23:29 +01:00
|
|
|
|
|
|
|
void SelectionDAGBuilder::LowerDeoptimizeCall(const CallInst *CI) {
|
|
|
|
const auto &TLI = DAG.getTargetLoweringInfo();
|
|
|
|
SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(RTLIB::DEOPTIMIZE),
|
|
|
|
TLI.getPointerTy(DAG.getDataLayout()));
|
|
|
|
|
2016-03-24 23:51:49 +01:00
|
|
|
// We don't lower calls to __llvm_deoptimize as varargs, but as a regular
|
2016-04-06 03:33:49 +02:00
|
|
|
// call. We also do not lower the return value to any virtual register, and
|
|
|
|
// change the immediately following return to a trap instruction.
|
2016-03-24 23:51:49 +01:00
|
|
|
LowerCallSiteWithDeoptBundleImpl(CI, Callee, /* EHPadBB = */ nullptr,
|
2016-04-06 03:33:49 +02:00
|
|
|
/* VarArgDisallowed = */ true,
|
|
|
|
/* ForceVoidReturnTy = */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionDAGBuilder::LowerDeoptimizingReturn() {
|
|
|
|
// We do not lower the return value from llvm.deoptimize to any virtual
|
|
|
|
// register, and change the immediately following return to a trap
|
|
|
|
// instruction.
|
|
|
|
if (DAG.getTarget().Options.TrapUnreachable)
|
|
|
|
DAG.setRoot(
|
|
|
|
DAG.getNode(ISD::TRAP, getCurSDLoc(), MVT::Other, DAG.getRoot()));
|
2016-03-24 21:23:29 +01:00
|
|
|
}
|