Skip to content

Commit

Permalink
Remove the SIL is_nonnull instruction. It's no longer useful.
Browse files Browse the repository at this point in the history
Swift SVN r21707
  • Loading branch information
DougGregor committed Sep 4, 2014
1 parent a775b40 commit cdf9488
Show file tree
Hide file tree
Showing 17 changed files with 2 additions and 105 deletions.
14 changes: 0 additions & 14 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3381,20 +3381,6 @@ Applying the resulting thick function value is equivalent to applying the
original thin value. The ``thin_to_thick_function`` conversion may be
eliminated if the context is proven not to be needed.

is_nonnull
``````````
::

sil-instruction ::= 'is_nonnull' sil-operand

%1 = is_nonnull %0 : $C
// %0 must be of reference or function type $C
// %1 will be of type Builtin.Int1

Checks whether a reference type value is null, returning 1 if
the value is not null, or 0 if it is null. If the value is a function
type, it checks the function pointer (not the data pointer) for null.

Checked Conversions
~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ UNARY_OP_MATCH_WITH_ARG_MATCHER(ThickToObjCMetatypeInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(ObjCToThickMetatypeInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(ObjCMetatypeToObjectInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(ObjCExistentialMetatypeToObjectInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(IsNonnullInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(RetainValueInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(ReleaseValueInst)
UNARY_OP_MATCH_WITH_ARG_MATCHER(AutoreleaseValueInst)
Expand Down
7 changes: 0 additions & 7 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,6 @@ class SILBuilder {
return insert(new (F.getModule()) RefToUnmanagedInst(loc, op, ty));
}

IsNonnullInst *createIsNonnull(SILLocation loc,
SILValue operand) {
return insert(new (F.getModule())
IsNonnullInst(loc, operand,
SILType::getBuiltinIntegerType(1, getASTContext())));
}

UnconditionalCheckedCastInst *createUnconditionalCheckedCast(SILLocation loc,
SILValue op,
SILType destTy) {
Expand Down
8 changes: 0 additions & 8 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,6 @@ visitObjCToThickMetatypeInst(ObjCToThickMetatypeInst *Inst) {
getOpType(Inst->getType())));
}

template<typename ImplClass>
void
SILCloner<ImplClass>::visitIsNonnullInst(IsNonnullInst *Inst) {
doPostProcess(Inst,
getBuilder().createIsNonnull(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand())));
}

template<typename ImplClass>
void
SILCloner<ImplClass>::visitUnconditionalCheckedCastInst(
Expand Down
7 changes: 0 additions & 7 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,13 +1385,6 @@ class ObjCProtocolInst : public SILInstruction
}
};

/// Test that an address or reference type is not null.
class IsNonnullInst : public UnaryInstructionBase<ValueKind::IsNonnullInst> {
public:
IsNonnullInst(SILLocation Loc, SILValue Operand, SILType BoolTy)
: UnaryInstructionBase(Loc, Operand, BoolTy) {}
};

/// Perform an unconditional checked cast that aborts if the cast fails.
class UnconditionalCheckedCastInst
: public UnaryInstructionBase<ValueKind::UnconditionalCheckedCastInst,
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
INST(ObjCExistentialMetatypeToObjectInst, ConversionInst, None)
INST(UnconditionalCheckedCastInst, ConversionInst, None)
VALUE_RANGE(ConversionInst, UpcastInst, UnconditionalCheckedCastInst)
INST(IsNonnullInst, SILInstruction, None)
INST(UnconditionalCheckedCastAddrInst, SILInstruction, MayReadWrite)

// Runtime failure
Expand Down
29 changes: 0 additions & 29 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,6 @@ class IRGenSILFunction :
void visitObjCExistentialMetatypeToObjectInst(
ObjCExistentialMetatypeToObjectInst *i);

void visitIsNonnullInst(IsNonnullInst *i);

void visitIndexAddrInst(IndexAddrInst *i);
void visitIndexRawPointerInst(IndexRawPointerInst *i);

Expand Down Expand Up @@ -3071,33 +3069,6 @@ void IRGenSILFunction::visitCheckedCastAddrBranchInst(
getLoweredBB(i->getFailureBB()).bb);
}

void IRGenSILFunction::visitIsNonnullInst(swift::IsNonnullInst *i) {
// Get the value we're testing, which may be a function, an address or an
// instance pointer.
llvm::Value *val;
const LoweredValue &lv = getLoweredValue(i->getOperand());

if (i->getOperand().getType().getSwiftType()->is<SILFunctionType>()) {
Explosion values = lv.getExplosion(*this);
val = values.claimNext(); // Function pointer.
values.claimNext(); // Ignore the data pointer.
} else if (lv.isAddress()) {
val = lv.getAddress().getAddress();
} else {
Explosion values = lv.getExplosion(*this);
val = values.claimNext();
}

// Check that the result isn't null.
auto *valTy = cast<llvm::PointerType>(val->getType());
llvm::Value *result = Builder.CreateICmp(llvm::CmpInst::ICMP_NE,
val, llvm::ConstantPointerNull::get(valTy));

Explosion out;
out.add(result);
setLoweredExplosion(SILValue(i, 0), out);
}

void IRGenSILFunction::visitUpcastInst(swift::UpcastInst *i) {
auto toTy = getTypeInfo(i->getType()).getStorageType();

Expand Down
8 changes: 0 additions & 8 deletions lib/Parse/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,6 @@ bool SILParser::parseSILOpcode(ValueKind &Opcode, SourceLoc &OpcodeLoc,
.Case("init_existential_ref", ValueKind::InitExistentialRefInst)
.Case("inject_enum_addr", ValueKind::InjectEnumAddrInst)
.Case("integer_literal", ValueKind::IntegerLiteralInst)
.Case("is_nonnull", ValueKind::IsNonnullInst)
.Case("function_ref", ValueKind::FunctionRefInst)
.Case("load", ValueKind::LoadInst)
.Case("load_weak", ValueKind::LoadWeakInst)
Expand Down Expand Up @@ -2505,13 +2504,6 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB) {
ResultVal = B.createRefElementAddr(InstLoc, Val, Field, ResultTy);
break;
}
case ValueKind::IsNonnullInst: {
SourceLoc Loc;
if (parseTypedValueRef(Val, Loc))
return true;
ResultVal = B.createIsNonnull(InstLoc, Val);
break;
}
case ValueKind::IndexAddrInst: {
SILValue IndexVal;
if (parseTypedValueRef(Val) ||
Expand Down
4 changes: 0 additions & 4 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,6 @@ class SILPrinter : public SILVisitor<SILPrinter> {
<< " : " << CI->getType();
}

void visitIsNonnullInst(IsNonnullInst *I) {
OS << "is_nonnull " << getIDAndType(I->getOperand());
}

void visitRetainValueInst(RetainValueInst *I) {
OS << "retain_value " << getIDAndType(I->getOperand());
}
Expand Down
7 changes: 0 additions & 7 deletions lib/SIL/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,13 +1649,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}
}

void checkIsNonnullInst(IsNonnullInst *II) {
// The operand must be a function type or a class type.
auto OpTy = II->getOperand().getType().getSwiftType();
require(OpTy->mayHaveSuperclass() || OpTy->is<SILFunctionType>(),
"is_nonnull operand must be a class or function type");
}

void checkAddressToPointerInst(AddressToPointerInst *AI) {
require(AI->getOperand().getType().isAddress(),
"address-to-pointer operand must be an address");
Expand Down
1 change: 0 additions & 1 deletion lib/SILAnalysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ static bool isTransitiveEscapeInst(SILInstruction *Inst) {
case ValueKind::InjectEnumAddrInst:
case ValueKind::DeinitExistentialInst:
case ValueKind::UnreachableInst:
case ValueKind::IsNonnullInst:
case ValueKind::CondFailInst:
case ValueKind::DynamicMethodBranchInst:
case ValueKind::ReturnInst:
Expand Down
1 change: 0 additions & 1 deletion lib/SILPasses/Utils/SILInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ static InlineCost instructionInlineCost(SILInstruction &I,
case ValueKind::InitExistentialInst:
case ValueKind::InitExistentialRefInst:
case ValueKind::InjectEnumAddrInst:
case ValueKind::IsNonnullInst:
case ValueKind::LoadInst:
case ValueKind::LoadWeakInst:
case ValueKind::OpenExistentialInst:
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
UNARY_INSTRUCTION(AutoreleaseValue)
UNARY_INSTRUCTION(DeinitExistential)
UNARY_INSTRUCTION(DestroyAddr)
UNARY_INSTRUCTION(IsNonnull)
UNARY_INSTRUCTION(Load)
UNARY_INSTRUCTION(Return)
UNARY_INSTRUCTION(FixLifetime)
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
case ValueKind::DeallocRefInst:
case ValueKind::DeinitExistentialInst:
case ValueKind::DestroyAddrInst:
case ValueKind::IsNonnullInst:
case ValueKind::LoadInst:
case ValueKind::LoadWeakInst:
case ValueKind::MarkUninitializedInst:
Expand Down
13 changes: 0 additions & 13 deletions test/IRGen/function_types.sil
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,3 @@ entry(%x : $*X):
return %z : $()
}

// CHECK-LABEL: define i1 @test_is_nonnull_function(i8*, %swift.refcounted*) {
// CHECK-NEXT: entry:
// CHECK-NEXT: %2 = icmp ne i8* %0, null
// CHECK-NEXT: ret i1 %2
// CHECK-NEXT: }

sil @test_is_nonnull_function : $@thin (() -> ()) -> Builtin.Int1 {
bb0(%0 : $() -> ()):
%3 = is_nonnull %0 : $() -> ()
return %3 : $Builtin.Int1 // id: %5
}


2 changes: 1 addition & 1 deletion utils/sil-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"ref_to_raw_pointer" "raw_pointer_to_ref"
"convert_function"
"thick_to_objc_metatype" "objc_to_thick_metatype"
"thin_to_thick_function" "is_nonnull"
"thin_to_thick_function"
"unchecked_ref_bit_cast" "unchecked_trivial_bit_cast")
'words) . font-lock-keyword-face)
;; Checked Conversions
Expand Down
2 changes: 1 addition & 1 deletion utils/vim/syntax/sil.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ syn keyword swiftKeyword metatype value_metatype existential_metatype skipwhite
syn keyword swiftKeyword retain_value release_value tuple tuple_extract tuple_element_addr struct struct_extract struct_element_addr ref_element_addr skipwhite
syn keyword swiftKeyword init_enum_data_addr unchecked_enum_data unchecked_take_enum_data_addr inject_enum_addr skipwhite
syn keyword swiftKeyword init_existential upcast_existential deinit_existential project_existential open_existential init_existential_ref upcast_existential_ref project_existential_ref open_existential_ref skipwhite
syn keyword swiftKeyword upcast address_to_pointer pointer_to_address unchecked_addr_cast unchecked_ref_cast ref_to_raw_pointer raw_pointer_to_ref convert_function thick_to_objc_metatype objc_to_thick_metatype thin_to_thick_function is_nonnull unchecked_ref_bit_cast unchecked_trivial_bit_cast skipwhite
syn keyword swiftKeyword upcast address_to_pointer pointer_to_address unchecked_addr_cast unchecked_ref_cast ref_to_raw_pointer raw_pointer_to_ref convert_function thick_to_objc_metatype objc_to_thick_metatype thin_to_thick_function unchecked_ref_bit_cast unchecked_trivial_bit_cast skipwhite
syn keyword swiftKeyword unconditional_checked_cast skipwhite
syn keyword swiftKeyword cond_fail skipwhite
syn keyword swiftKeyword unreachable return autorelease_return br cond_br switch_int switch_enum switch_enum_addr dynamic_method_br checked_cast_br skipwhite
Expand Down

0 comments on commit cdf9488

Please sign in to comment.