Skip to content

SIL: remove unused instructions thin_function_to_pointer and pointer_ to_thin_function #42030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6632,16 +6632,6 @@ passed to a function (materializeForSet) which escapes the closure in a way not
expressed by the convert's users. The mandatory pass must ensure the lifetime
in a conservative way.

thin_function_to_pointer
````````````````````````

TODO

pointer_to_thin_function
````````````````````````

TODO

classify_bridge_object
``````````````````````
::
Expand Down
12 changes: 0 additions & 12 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,18 +1060,6 @@ class SILBuilder {
lifetimeGuaranteed));
}

ThinFunctionToPointerInst *
createThinFunctionToPointer(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (getModule()) ThinFunctionToPointerInst(
getSILDebugLocation(Loc), Op, Ty));
}

PointerToThinFunctionInst *
createPointerToThinFunction(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(PointerToThinFunctionInst::create(
getSILDebugLocation(Loc), Op, Ty, getFunction()));
}

UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty) {
return createUpcast(Loc, Op, Ty, Op.getOwnershipKind());
}
Expand Down
20 changes: 0 additions & 20 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1434,26 +1434,6 @@ void SILCloner<ImplClass>::visitConvertEscapeToNoEscapeInst(
getOpType(Inst->getType()), Inst->isLifetimeGuaranteed()));
}

template<typename ImplClass>
void SILCloner<ImplClass>::visitThinFunctionToPointerInst(
ThinFunctionToPointerInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
recordClonedInstruction(Inst, getBuilder().createThinFunctionToPointer(
getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand()),
getOpType(Inst->getType())));
}

template<typename ImplClass>
void SILCloner<ImplClass>::visitPointerToThinFunctionInst(
PointerToThinFunctionInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
recordClonedInstruction(Inst, getBuilder().createPointerToThinFunction(
getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand()),
getOpType(Inst->getType())));
}

template<typename ImplClass>
void
SILCloner<ImplClass>::visitUpcastInst(UpcastInst *Inst) {
Expand Down
33 changes: 0 additions & 33 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -5241,39 +5241,6 @@ class ConvertEscapeToNoEscapeInst final
void setLifetimeGuaranteed() { lifetimeGuaranteed = true; }
};

/// ThinFunctionToPointerInst - Convert a thin function pointer to a
/// Builtin.RawPointer.
class ThinFunctionToPointerInst
: public UnaryInstructionBase<SILInstructionKind::ThinFunctionToPointerInst,
ConversionInst>
{
friend SILBuilder;

ThinFunctionToPointerInst(SILDebugLocation DebugLoc, SILValue operand,
SILType ty)
: UnaryInstructionBase(DebugLoc, operand, ty) {}
};

/// PointerToThinFunctionInst - Convert a Builtin.RawPointer to a thin
/// function pointer.
class PointerToThinFunctionInst final
: public UnaryInstructionWithTypeDependentOperandsBase<
SILInstructionKind::PointerToThinFunctionInst,
PointerToThinFunctionInst,
ConversionInst> {
friend SILBuilder;

PointerToThinFunctionInst(SILDebugLocation DebugLoc, SILValue operand,
ArrayRef<SILValue> TypeDependentOperands,
SILType ty)
: UnaryInstructionWithTypeDependentOperandsBase(
DebugLoc, operand, TypeDependentOperands, ty) {}

static PointerToThinFunctionInst *
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
SILFunction &F);
};

/// UpcastInst - Perform a conversion of a class instance to a supertype.
class UpcastInst final : public UnaryInstructionWithTypeDependentOperandsBase<
SILInstructionKind::UpcastInst, UpcastInst,
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ class alignas(8) SILNode :

UIWTDOB_BITFIELD(ConvertFunctionInst, ConversionInst, 1,
WithoutActuallyEscaping : 1);
UIWTDOB_BITFIELD_EMPTY(PointerToThinFunctionInst, ConversionInst);
UIWTDOB_BITFIELD_EMPTY(UnconditionalCheckedCastInst, ConversionInst);
UIWTDOB_BITFIELD_EMPTY(UpcastInst, ConversionInst);
UIWTDOB_BITFIELD_EMPTY(UncheckedRefCastInst, ConversionInst);
Expand Down
4 changes: 0 additions & 4 deletions include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(ConvertEscapeToNoEscapeInst, convert_escape_to_noescape,
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(ThinFunctionToPointerInst, thin_function_to_pointer,
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(PointerToThinFunctionInst, pointer_to_thin_function,
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(RefToBridgeObjectInst, ref_to_bridge_object,
ConversionInst, None, DoesNotRelease)
BRIDGED_SINGLE_VALUE_INST(BridgeObjectToRefInst, bridge_object_to_ref,
Expand Down
19 changes: 19 additions & 0 deletions include/swift/SIL/SILNodes.def.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***************
*** 405,414 ****
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(ConvertEscapeToNoEscapeInst, convert_escape_to_noescape,
ConversionInst, None, DoesNotRelease)
- SINGLE_VALUE_INST(ThinFunctionToPointerInst, thin_function_to_pointer,
- ConversionInst, None, DoesNotRelease)
- SINGLE_VALUE_INST(PointerToThinFunctionInst, pointer_to_thin_function,
- ConversionInst, None, DoesNotRelease)
BRIDGED_SINGLE_VALUE_INST(RefToBridgeObjectInst, ref_to_bridge_object,
ConversionInst, None, DoesNotRelease)
BRIDGED_SINGLE_VALUE_INST(BridgeObjectToRefInst, bridge_object_to_ref,
--- 405,410 ----
ConversionInst, None, DoesNotRelease)
SINGLE_VALUE_INST(ConvertEscapeToNoEscapeInst, convert_escape_to_noescape,
ConversionInst, None, DoesNotRelease)
BRIDGED_SINGLE_VALUE_INST(RefToBridgeObjectInst, ref_to_bridge_object,
ConversionInst, None, DoesNotRelease)
BRIDGED_SINGLE_VALUE_INST(BridgeObjectToRefInst, bridge_object_to_ref,
22 changes: 0 additions & 22 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,8 +1311,6 @@ class IRGenSILFunction :

void visitConvertFunctionInst(ConvertFunctionInst *i);
void visitConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *i);
void visitThinFunctionToPointerInst(ThinFunctionToPointerInst *i);
void visitPointerToThinFunctionInst(PointerToThinFunctionInst *i);
void visitUpcastInst(UpcastInst *i);
void visitAddressToPointerInst(AddressToPointerInst *i);
void visitPointerToAddressInst(PointerToAddressInst *i);
Expand Down Expand Up @@ -5856,26 +5854,6 @@ void IRGenSILFunction::visitConvertEscapeToNoEscapeInst(
setLoweredExplosion(i, out);
}

void IRGenSILFunction::visitThinFunctionToPointerInst(
swift::ThinFunctionToPointerInst *i) {
Explosion in = getLoweredExplosion(i->getOperand());
llvm::Value *fn = in.claimNext();
fn = Builder.CreateBitCast(fn, IGM.Int8PtrTy);
Explosion out;
out.add(fn);
setLoweredExplosion(i, out);
}

void IRGenSILFunction::visitPointerToThinFunctionInst(
swift::PointerToThinFunctionInst *i) {
Explosion in = getLoweredExplosion(i->getOperand());
llvm::Value *fn = in.claimNext();
fn = Builder.CreateBitCast(fn, IGM.FunctionPtrTy);
Explosion out;
out.add(fn);
setLoweredExplosion(i, out);
}

void IRGenSILFunction::visitAddressToPointerInst(swift::AddressToPointerInst *i)
{
Explosion to;
Expand Down
12 changes: 0 additions & 12 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2782,9 +2782,6 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
IRGenModule *currIRMod =
getIRGenModule()->IRGen.getGenModule(convInstr->getFunction());
SILType currSILType = convInstr->getType();
if (auto *thinToPointer = dyn_cast<ThinFunctionToPointerInst>(convInstr)) {
currSILType = thinToPointer->getOperand()->getType();
}
auto currSILFunctionType = currSILType.castTo<SILFunctionType>();
GenericEnvironment *genEnv =
getSubstGenericEnvironment(convInstr->getFunction());
Expand Down Expand Up @@ -2813,14 +2810,6 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
instr->getLoc(), instr->getOperand(), newType);
break;
}
case SILInstructionKind::ThinFunctionToPointerInst: {
auto instr = cast<ThinFunctionToPointerInst>(convInstr);
newType =
MapperCache.getNewSILType(genEnv, instr->getType(), *getIRGenModule());
newInstr = convBuilder.createThinFunctionToPointer(
instr->getLoc(), instr->getOperand(), newType);
break;
}
case SILInstructionKind::ConvertFunctionInst: {
auto instr = cast<ConvertFunctionInst>(convInstr);
newInstr = convBuilder.createConvertFunction(
Expand Down Expand Up @@ -2956,7 +2945,6 @@ void LoadableByAddress::run() {
case SILInstructionKind::ConvertFunctionInst:
case SILInstructionKind::ConvertEscapeToNoEscapeInst:
case SILInstructionKind::MarkDependenceInst:
case SILInstructionKind::ThinFunctionToPointerInst:
case SILInstructionKind::ThinToThickFunctionInst:
case SILInstructionKind::DifferentiableFunctionInst:
case SILInstructionKind::LinearFunctionInst:
Expand Down
2 changes: 0 additions & 2 deletions lib/SIL/IR/OperandOwnership.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ OPERAND_OWNERSHIP(TrivialUse, ObjCToThickMetatype)
OPERAND_OWNERSHIP(TrivialUse, OpenExistentialAddr)
OPERAND_OWNERSHIP(TrivialUse, OpenExistentialMetatype)
OPERAND_OWNERSHIP(TrivialUse, PointerToAddress)
OPERAND_OWNERSHIP(TrivialUse, PointerToThinFunction)
OPERAND_OWNERSHIP(TrivialUse, ProjectBlockStorage)
OPERAND_OWNERSHIP(TrivialUse, RawPointerToRef)
OPERAND_OWNERSHIP(TrivialUse, SelectEnumAddr)
Expand All @@ -180,7 +179,6 @@ OPERAND_OWNERSHIP(TrivialUse, SwitchEnumAddr)
OPERAND_OWNERSHIP(TrivialUse, SwitchValue)
OPERAND_OWNERSHIP(TrivialUse, TailAddr)
OPERAND_OWNERSHIP(TrivialUse, ThickToObjCMetatype)
OPERAND_OWNERSHIP(TrivialUse, ThinFunctionToPointer)
OPERAND_OWNERSHIP(TrivialUse, ThinToThickFunction)
OPERAND_OWNERSHIP(TrivialUse, TupleElementAddr)
OPERAND_OWNERSHIP(TrivialUse, UncheckedAddrCast)
Expand Down
6 changes: 0 additions & 6 deletions lib/SIL/IR/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,12 +844,6 @@ namespace {
bool visitClassifyBridgeObjectInst(ClassifyBridgeObjectInst *X) {
return true;
}
bool visitThinFunctionToPointerInst(ThinFunctionToPointerInst *X) {
return true;
}
bool visitPointerToThinFunctionInst(PointerToThinFunctionInst *X) {
return true;
}

bool visitObjCProtocolInst(ObjCProtocolInst *RHS) {
auto *X = cast<ObjCProtocolInst>(LHS);
Expand Down
13 changes: 0 additions & 13 deletions lib/SIL/IR/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,19 +2335,6 @@ ThinToThickFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
DebugLoc, Operand, TypeDependentOperands, Ty, forwardingOwnershipKind);
}

PointerToThinFunctionInst *
PointerToThinFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty, SILFunction &F) {
SILModule &Mod = F.getModule();
SmallVector<SILValue, 8> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, F, Ty.getASTType());
unsigned size =
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
void *Buffer = Mod.allocateInst(size, alignof(PointerToThinFunctionInst));
return ::new (Buffer) PointerToThinFunctionInst(DebugLoc, Operand,
TypeDependentOperands, Ty);
}

ConvertFunctionInst *ConvertFunctionInst::create(
SILDebugLocation DebugLoc, SILValue Operand, SILType Ty, SILModule &Mod,
SILFunction *F,
Expand Down
6 changes: 0 additions & 6 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,12 +1791,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
*this << (CI->isLifetimeGuaranteed() ? "" : "[not_guaranteed] ")
<< getIDAndType(CI->getOperand()) << " to " << CI->getType();
}
void visitThinFunctionToPointerInst(ThinFunctionToPointerInst *CI) {
printUncheckedConversionInst(CI, CI->getOperand());
}
void visitPointerToThinFunctionInst(PointerToThinFunctionInst *CI) {
printUncheckedConversionInst(CI, CI->getOperand());
}
void visitUpcastInst(UpcastInst *CI) {
printUncheckedConversionInst(CI, CI->getOperand());
}
Expand Down
2 changes: 0 additions & 2 deletions lib/SIL/IR/ValueOwnership.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ CONSTANT_OWNERSHIP_INST(None, OpenExistentialAddr)
CONSTANT_OWNERSHIP_INST(None, OpenExistentialBox)
CONSTANT_OWNERSHIP_INST(None, OpenExistentialMetatype)
CONSTANT_OWNERSHIP_INST(None, PointerToAddress)
CONSTANT_OWNERSHIP_INST(None, PointerToThinFunction)
CONSTANT_OWNERSHIP_INST(None, ProjectBlockStorage)
CONSTANT_OWNERSHIP_INST(None, ProjectBox)
CONSTANT_OWNERSHIP_INST(None, ProjectExistentialBox)
Expand All @@ -135,7 +134,6 @@ CONSTANT_OWNERSHIP_INST(None, SuperMethod)
CONSTANT_OWNERSHIP_INST(None, ObjCSuperMethod)
CONSTANT_OWNERSHIP_INST(None, TailAddr)
CONSTANT_OWNERSHIP_INST(None, ThickToObjCMetatype)
CONSTANT_OWNERSHIP_INST(None, ThinFunctionToPointer)
CONSTANT_OWNERSHIP_INST(None, TupleElementAddr)
CONSTANT_OWNERSHIP_INST(None, UncheckedAddrCast)
CONSTANT_OWNERSHIP_INST(None, UncheckedTakeEnumDataAddr)
Expand Down
8 changes: 0 additions & 8 deletions lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3608,8 +3608,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
case SILInstructionKind::RefTo##Name##Inst: \
case SILInstructionKind::Name##ToRefInst:
#include "swift/AST/ReferenceStorage.def"
case SILInstructionKind::ThinFunctionToPointerInst:
case SILInstructionKind::PointerToThinFunctionInst:
case SILInstructionKind::ThinToThickFunctionInst:
case SILInstructionKind::ThickToObjCMetatypeInst:
case SILInstructionKind::ObjCToThickMetatypeInst:
Expand Down Expand Up @@ -3717,12 +3715,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
ResultVal = B.create##Name##ToRef(InstLoc, Val, Ty); \
break;
#include "swift/AST/ReferenceStorage.def"
case SILInstructionKind::ThinFunctionToPointerInst:
ResultVal = B.createThinFunctionToPointer(InstLoc, Val, Ty);
break;
case SILInstructionKind::PointerToThinFunctionInst:
ResultVal = B.createPointerToThinFunction(InstLoc, Val, Ty);
break;
case SILInstructionKind::ThinToThickFunctionInst:
ResultVal =
B.createThinToThickFunction(InstLoc, Val, Ty, forwardingOwnership);
Expand Down
2 changes: 0 additions & 2 deletions lib/SIL/Utils/InstructionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
#undef LOADABLE_REF_STORAGE_HELPER
case SILInstructionKind::ConvertFunctionInst:
case SILInstructionKind::ConvertEscapeToNoEscapeInst:
case SILInstructionKind::ThinFunctionToPointerInst:
case SILInstructionKind::PointerToThinFunctionInst:
case SILInstructionKind::RefToBridgeObjectInst:
case SILInstructionKind::BridgeObjectToRefInst:
case SILInstructionKind::BridgeObjectToWordInst:
Expand Down
28 changes: 0 additions & 28 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4417,34 +4417,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}
}

void checkThinFunctionToPointerInst(ThinFunctionToPointerInst *CI) {
auto opTI = requireObjectType(SILFunctionType, CI->getOperand(),
"thin_function_to_pointer operand");
requireObjectType(BuiltinRawPointerType, CI,
"thin_function_to_pointer result");

auto rep = opTI->getRepresentation();
require(rep == SILFunctionTypeRepresentation::Thin ||
rep == SILFunctionTypeRepresentation::Method ||
rep == SILFunctionTypeRepresentation::WitnessMethod,
"thin_function_to_pointer only works on thin, method or "
"witness_method functions");
}

void checkPointerToThinFunctionInst(PointerToThinFunctionInst *CI) {
auto resultTI = requireObjectType(SILFunctionType, CI,
"pointer_to_thin_function result");
requireObjectType(BuiltinRawPointerType, CI->getOperand(),
"pointer_to_thin_function operand");

auto rep = resultTI->getRepresentation();
require(rep == SILFunctionTypeRepresentation::Thin ||
rep == SILFunctionTypeRepresentation::Method ||
rep == SILFunctionTypeRepresentation::WitnessMethod,
"pointer_to_thin_function only works on thin, method or "
"witness_method functions");
}

void checkCondFailInst(CondFailInst *CFI) {
requireSameType(CFI->getOperand()->getType(),
SILType::getBuiltinIntegerType(1, F.getASTContext()),
Expand Down
2 changes: 0 additions & 2 deletions lib/SILOptimizer/Analysis/EscapeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ static bool isNonWritableMemoryAddress(SILValue V) {
case ValueKind::ObjCSuperMethodInst:
case ValueKind::StringLiteralInst:
case ValueKind::ThinToThickFunctionInst:
case ValueKind::ThinFunctionToPointerInst:
case ValueKind::PointerToThinFunctionInst:
// These instructions return pointers to memory which can't be a
// destination of a store.
return true;
Expand Down
20 changes: 0 additions & 20 deletions lib/SILOptimizer/Analysis/SimplifyInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ namespace {
SILValue
visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI);
SILValue visitEndCOWMutationInst(EndCOWMutationInst *ECM);
SILValue visitThinFunctionToPointerInst(ThinFunctionToPointerInst *TFTPI);
SILValue visitPointerToThinFunctionInst(PointerToThinFunctionInst *PTTFI);
SILValue visitBeginAccessInst(BeginAccessInst *BAI);
SILValue visitMetatypeInst(MetatypeInst *MTI);
SILValue visitConvertFunctionInst(ConvertFunctionInst *cfi);
Expand Down Expand Up @@ -464,24 +462,6 @@ visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
return SILValue();
}

SILValue InstSimplifier::visitThinFunctionToPointerInst(ThinFunctionToPointerInst *TFTPI) {
// (thin_function_to_pointer (pointer_to_thin_function x)) -> x
if (auto *PTTFI = dyn_cast<PointerToThinFunctionInst>(TFTPI->getOperand()))
if (PTTFI->getOperand()->getType() == TFTPI->getType())
return PTTFI->getOperand();

return SILValue();
}

SILValue InstSimplifier::visitPointerToThinFunctionInst(PointerToThinFunctionInst *PTTFI) {
// (pointer_to_thin_function (thin_function_to_pointer x)) -> x
if (auto *TFTPI = dyn_cast<ThinFunctionToPointerInst>(PTTFI->getOperand()))
if (TFTPI->getOperand()->getType() == PTTFI->getType())
return TFTPI->getOperand();

return SILValue();
}

SILValue InstSimplifier::visitBeginAccessInst(BeginAccessInst *BAI) {
// Remove "dead" begin_access.
if (llvm::all_of(BAI->getUses(), [](Operand *operand) -> bool {
Expand Down
Loading