mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Add a "builtin" instruction to represent builtin invocations.
Modeling builtins as first-class function values doesn't really make sense because there's no real function value to emit, and modeling them this way complicates passes that work with builtins because they have to invent function types for builtin invocations. It's much more straightforward to have a single instruction that references the builtin by ID, along with the type information for the necessary values, type parameters, and results, so add a new "builtin" instruction that directly represents a builtin invocation. NFC yet. Swift SVN r22690
This commit is contained in:
@@ -713,6 +713,36 @@ VarDecl *DebugValueAddrInst::getDecl() const {
|
||||
return getLoc().getAsASTNode<VarDecl>();
|
||||
}
|
||||
|
||||
BuiltinInst *BuiltinInst::create(SILLocation Loc, Identifier Name,
|
||||
SILType ReturnType,
|
||||
ArrayRef<Substitution> Substitutions,
|
||||
ArrayRef<SILValue> Args,
|
||||
SILFunction &F) {
|
||||
void *Buffer = F.getModule().allocate(
|
||||
sizeof(BuiltinInst)
|
||||
+ decltype(Operands)::getExtraSize(Args.size())
|
||||
+ sizeof(Substitution) * Substitutions.size(),
|
||||
alignof(BuiltinInst));
|
||||
return ::new (Buffer) BuiltinInst(Loc, Name, ReturnType, Substitutions,
|
||||
Args);
|
||||
}
|
||||
|
||||
BuiltinInst::BuiltinInst(SILLocation Loc,
|
||||
Identifier Name,
|
||||
SILType ReturnType,
|
||||
ArrayRef<Substitution> Subs,
|
||||
ArrayRef<SILValue> Args)
|
||||
: SILInstruction(ValueKind::BuiltinInst, Loc, ReturnType),
|
||||
Name(Name),
|
||||
NumSubstitutions(Subs.size()),
|
||||
Operands(this, Args)
|
||||
{
|
||||
static_assert(IsTriviallyCopyable<Substitution>::value,
|
||||
"assuming Substitution is trivially copyable");
|
||||
memcpy(getSubstitutionsStorage(), Subs.begin(),
|
||||
sizeof(Substitution) * Subs.size());
|
||||
}
|
||||
|
||||
ApplyInst::ApplyInst(SILLocation Loc, SILValue Callee,
|
||||
SILType SubstCalleeTy,
|
||||
SILType Result,
|
||||
|
||||
Reference in New Issue
Block a user