mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Similarly to how we've always handled parameter types, we now recursively expand tuples in result types and separately determine a result convention for each result. The most important code-generation change here is that indirect results are now returned separately from each other and from any direct results. It is generally far better, when receiving an indirect result, to receive it as an independent result; the caller is much more likely to be able to directly receive the result in the address they want to initialize, rather than having to receive it in temporary memory and then copy parts of it into the target. The most important conceptual change here that clients and producers of SIL must be aware of is the new distinction between a SILFunctionType's *parameters* and its *argument list*. The former is just the formal parameters, derived purely from the parameter types of the original function; indirect results are no longer in this list. The latter includes the indirect result arguments; as always, all the indirect results strictly precede the parameters. Apply instructions and entry block arguments follow the argument list, not the parameter list. A relatively minor change is that there can now be multiple direct results, each with its own result convention. This is a minor change because I've chosen to leave return instructions as taking a single operand and apply instructions as producing a single result; when the type describes multiple results, they are implicitly bound up in a tuple. It might make sense to split these up and allow e.g. return instructions to take a list of operands; however, it's not clear what to do on the caller side, and this would be a major change that can be separated out from this already over-large patch. Unsurprisingly, the most invasive changes here are in SILGen; this requires substantial reworking of both call emission and reabstraction. It also proved important to switch several SILGen operations over to work with RValue instead of ManagedValue, since otherwise they would be forced to spuriously "implode" buffers.
96 lines
2.6 KiB
C++
96 lines
2.6 KiB
C++
//===--- CallEmission.h - Utility for emitting calls ------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the CallEmitter class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_IRGEN_CALLEMISSION_H
|
|
#define SWIFT_IRGEN_CALLEMISSION_H
|
|
|
|
#include "Callee.h"
|
|
|
|
namespace llvm {
|
|
class CallSite;
|
|
}
|
|
|
|
namespace swift {
|
|
namespace irgen {
|
|
|
|
class LoadableTypeInfo;
|
|
struct WitnessMetadata;
|
|
|
|
/// A plan for emitting a series of calls.
|
|
class CallEmission {
|
|
public:
|
|
IRGenFunction &IGF;
|
|
|
|
private:
|
|
/// The function attributes for the call.
|
|
llvm::AttributeSet Attrs;
|
|
|
|
/// The builtin/special arguments to pass to the call.
|
|
SmallVector<llvm::Value*, 8> Args;
|
|
|
|
/// The function we're going to call.
|
|
Callee CurCallee;
|
|
|
|
unsigned LastArgWritten;
|
|
|
|
/// Whether we've emitted the call for the current callee yet. This
|
|
/// is just for debugging purposes --- e.g. the destructor asserts
|
|
/// that it's true --- but is otherwise derivable from
|
|
/// RemainingArgsForCallee, at least between calls.
|
|
bool EmittedCall;
|
|
|
|
void setFromCallee();
|
|
void emitToUnmappedMemory(Address addr);
|
|
void emitToUnmappedExplosion(Explosion &out);
|
|
llvm::CallSite emitCallSite();
|
|
llvm::CallSite emitInvoke(llvm::CallingConv::ID cc, llvm::Value *fn,
|
|
ArrayRef<llvm::Value*> args,
|
|
const llvm::AttributeSet &attrs);
|
|
|
|
public:
|
|
CallEmission(IRGenFunction &IGF, const Callee &callee)
|
|
: IGF(IGF), CurCallee(callee) {
|
|
setFromCallee();
|
|
}
|
|
CallEmission(const CallEmission &other) = delete;
|
|
CallEmission(CallEmission &&other);
|
|
CallEmission &operator=(const CallEmission &other) = delete;
|
|
~CallEmission();
|
|
|
|
Callee &getMutableCallee() { return CurCallee; }
|
|
const Callee &getCallee() const { return CurCallee; }
|
|
|
|
ArrayRef<Substitution> getSubstitutions() const {
|
|
return CurCallee.getSubstitutions();
|
|
}
|
|
|
|
/// Set the arguments to the function from an explosion.
|
|
void setArgs(Explosion &arg, WitnessMetadata *witnessMetadata = nullptr);
|
|
|
|
void addAttribute(unsigned Index, llvm::Attribute::AttrKind Attr);
|
|
|
|
void emitToMemory(Address addr, const LoadableTypeInfo &substResultTI);
|
|
void emitToExplosion(Explosion &out);
|
|
|
|
void invalidate();
|
|
};
|
|
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|