Add SIL instructions to convert between thin functions

and raw pointers.

Swift SVN r23992
This commit is contained in:
John McCall
2014-12-17 22:23:15 +00:00
parent e5c3b534fe
commit 5c8fbc704c
13 changed files with 140 additions and 4 deletions

View File

@@ -333,6 +333,16 @@ public:
return insert(new (F.getModule()) ConvertFunctionInst(Loc, Op, Ty));
}
ThinFunctionToPointerInst *
createThinFunctionToPointer(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) ThinFunctionToPointerInst(Loc, Op, Ty));
}
PointerToThinFunctionInst *
createPointerToThinFunction(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) PointerToThinFunctionInst(Loc, Op, Ty));
}
UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) UpcastInst(Loc, Op, Ty));
}

View File

@@ -652,6 +652,24 @@ SILCloner<ImplClass>::visitConvertFunctionInst(ConvertFunctionInst *Inst) {
getOpType(Inst->getType())));
}
template<typename ImplClass>
void SILCloner<ImplClass>::visitThinFunctionToPointerInst(
ThinFunctionToPointerInst *Inst) {
doPostProcess(Inst,
getBuilder().createThinFunctionToPointer(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand()),
getOpType(Inst->getType())));
}
template<typename ImplClass>
void SILCloner<ImplClass>::visitPointerToThinFunctionInst(
PointerToThinFunctionInst *Inst) {
doPostProcess(Inst,
getBuilder().createPointerToThinFunction(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand()),
getOpType(Inst->getType())));
}
template<typename ImplClass>
void
SILCloner<ImplClass>::visitUpcastInst(UpcastInst *Inst) {

View File

@@ -1231,8 +1231,8 @@ public:
}
};
/// ConvertFunctionInst - Change the type of some value without affecting how it
/// will codegen.
/// ConvertFunctionInst - Change the type of a function value without
/// affecting how it will codegen.
class ConvertFunctionInst
: public UnaryInstructionBase<ValueKind::ConvertFunctionInst, ConversionInst>
{
@@ -1241,6 +1241,28 @@ public:
: UnaryInstructionBase(Loc, Operand, Ty) {}
};
/// ThinFunctionToPointerInst - Convert a thin function pointer to a
/// Builtin.RawPointer.
class ThinFunctionToPointerInst
: public UnaryInstructionBase<ValueKind::ThinFunctionToPointerInst,
ConversionInst>
{
public:
ThinFunctionToPointerInst(SILLocation loc, SILValue operand, SILType ty)
: UnaryInstructionBase(loc, operand, ty) {}
};
/// PointerToThinFunctionInst - Convert a Builtin.RawPointer to a thin
/// function pointer.
class PointerToThinFunctionInst
: public UnaryInstructionBase<ValueKind::PointerToThinFunctionInst,
ConversionInst>
{
public:
PointerToThinFunctionInst(SILLocation loc, SILValue operand, SILType ty)
: UnaryInstructionBase(loc, operand, ty) {}
};
/// UpcastInst - Perform a conversion of a class instance to a supertype.
class UpcastInst
: public UnaryInstructionBase<ValueKind::UpcastInst, ConversionInst>

View File

@@ -192,6 +192,8 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
INST(RefToUnmanagedInst, ConversionInst, None)
INST(UnmanagedToRefInst, ConversionInst, None)
INST(ConvertFunctionInst, ConversionInst, None)
INST(ThinFunctionToPointerInst, ConversionInst, None)
INST(PointerToThinFunctionInst, ConversionInst, None)
INST(RefToBridgeObjectInst, ConversionInst, None)
INST(BridgeObjectToRefInst, ConversionInst, None)
INST(BridgeObjectToWordInst, ConversionInst, None)