SIL: Remove 'ModuleInst'.

Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
This commit is contained in:
Joe Groff
2013-11-18 21:36:08 +00:00
parent f09950390c
commit f6b1745650
15 changed files with 4 additions and 100 deletions

View File

@@ -1624,18 +1624,6 @@ TODO: ``builtin_zero`` is a temporary hack to support our current AST-level
default initialization implementation. Definitive assignment analysis in SIL default initialization implementation. Definitive assignment analysis in SIL
will supersede this. will supersede this.
module
``````
::
sil-instruction ::= 'module' sil-decl-ref
%1 = module #M
// #M must be a module name
// %1 has type $module<M>
Creates a module value for the module ``M``.
Dynamic Dispatch Dynamic Dispatch
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

View File

@@ -594,10 +594,6 @@ public:
return insert(new (F.getModule()) ProtocolMetatypeInst(Loc, Metatype,Base)); return insert(new (F.getModule()) ProtocolMetatypeInst(Loc, Metatype,Base));
} }
ModuleInst *createModule(SILLocation Loc, SILType ModuleType) {
return insert(new (F.getModule()) ModuleInst(Loc, ModuleType));
}
StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand) { StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand) {
return insert(new (F.getModule()) StrongRetainInst(Loc, Operand)); return insert(new (F.getModule()) StrongRetainInst(Loc, Operand));
} }

View File

@@ -621,14 +621,6 @@ SILCloner<ImplClass>::visitProtocolMetatypeInst(ProtocolMetatypeInst *Inst) {
getOpValue(Inst->getOperand()))); getOpValue(Inst->getOperand())));
} }
template<typename ImplClass>
void
SILCloner<ImplClass>::visitModuleInst(ModuleInst *Inst) {
doPostProcess(Inst,
Builder.createModule(getOpLocation(Inst->getLoc()),
getOpType(Inst->getType())));
}
template<typename ImplClass> template<typename ImplClass>
void void
SILCloner<ImplClass>::visitTupleExtractInst(TupleExtractInst *Inst) { SILCloner<ImplClass>::visitTupleExtractInst(TupleExtractInst *Inst) {

View File

@@ -1344,23 +1344,6 @@ public:
: UnaryInstructionBase(Loc, Base, Metatype) {} : UnaryInstructionBase(Loc, Base, Metatype) {}
}; };
/// ModuleInst - Represents a reference to a module as a value.
class ModuleInst : public SILInstruction {
public:
ModuleInst(SILLocation Loc, SILType ModuleType);
/// getType() is ok since this is known to only have one type.
SILType getType(unsigned i = 0) const { return ValueBase::getType(i); }
ArrayRef<Operand> getAllOperands() const { return {}; }
MutableArrayRef<Operand> getAllOperands() { return {}; }
static bool classof(const ValueBase *V) {
return V->getKind() == ValueKind::ModuleInst;
}
};
/// Extract a numbered element out of a value of tuple type. /// Extract a numbered element out of a value of tuple type.
class TupleExtractInst class TupleExtractInst
: public UnaryInstructionBase<ValueKind::TupleExtractInst> : public UnaryInstructionBase<ValueKind::TupleExtractInst>

View File

@@ -106,7 +106,6 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
INST(FloatLiteralInst, SILInstruction, None) INST(FloatLiteralInst, SILInstruction, None)
INST(StringLiteralInst, SILInstruction, None) INST(StringLiteralInst, SILInstruction, None)
INST(BuiltinZeroInst, SILInstruction, None) INST(BuiltinZeroInst, SILInstruction, None)
INST(ModuleInst, SILInstruction, None)
// Dynamic Dispatch // Dynamic Dispatch
ABSTRACT_VALUE(MethodInst, SILInstruction) ABSTRACT_VALUE(MethodInst, SILInstruction)

View File

@@ -539,7 +539,6 @@ public:
void visitStructExtractInst(StructExtractInst *i); void visitStructExtractInst(StructExtractInst *i);
void visitStructElementAddrInst(StructElementAddrInst *i); void visitStructElementAddrInst(StructElementAddrInst *i);
void visitRefElementAddrInst(RefElementAddrInst *i); void visitRefElementAddrInst(RefElementAddrInst *i);
void visitModuleInst(ModuleInst *i);
void visitClassMethodInst(ClassMethodInst *i); void visitClassMethodInst(ClassMethodInst *i);
void visitSuperMethodInst(SuperMethodInst *i); void visitSuperMethodInst(SuperMethodInst *i);
@@ -2044,12 +2043,6 @@ void IRGenSILFunction::visitRefElementAddrInst(swift::RefElementAddrInst *i) {
setLoweredAddress(SILValue(i, 0), field); setLoweredAddress(SILValue(i, 0), field);
} }
void IRGenSILFunction::visitModuleInst(swift::ModuleInst *i) {
// Currently, module values are always empty.
Explosion empty(ExplosionKind::Maximal);
setLoweredExplosion(SILValue(i, 0), empty);
}
void IRGenSILFunction::visitLoadInst(swift::LoadInst *i) { void IRGenSILFunction::visitLoadInst(swift::LoadInst *i) {
Explosion lowered(ExplosionKind::Maximal); Explosion lowered(ExplosionKind::Maximal);
Address source = getLoweredAddress(i->getOperand()); Address source = getLoweredAddress(i->getOperand());

View File

@@ -923,7 +923,6 @@ bool SILParser::parseSILOpcode(ValueKind &Opcode, SourceLoc &OpcodeLoc,
.Case("mark_uninitialized", ValueKind::MarkUninitializedInst) .Case("mark_uninitialized", ValueKind::MarkUninitializedInst)
.Case("mark_function_escape", ValueKind::MarkFunctionEscapeInst) .Case("mark_function_escape", ValueKind::MarkFunctionEscapeInst)
.Case("metatype", ValueKind::MetatypeInst) .Case("metatype", ValueKind::MetatypeInst)
.Case("module", ValueKind::ModuleInst)
.Case("object_pointer_to_ref", ValueKind::ObjectPointerToRefInst) .Case("object_pointer_to_ref", ValueKind::ObjectPointerToRefInst)
.Case("partial_apply", ValueKind::PartialApplyInst) .Case("partial_apply", ValueKind::PartialApplyInst)
.Case("pointer_to_address", ValueKind::PointerToAddressInst) .Case("pointer_to_address", ValueKind::PointerToAddressInst)
@@ -2100,21 +2099,6 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB) {
ArrayRef<ProtocolConformance*>()); ArrayRef<ProtocolConformance*>());
break; break;
} }
case ValueKind::ModuleInst: {
Identifier ModuleName;
SourceLoc ModuleLoc;
// Parse reference to a module.
if (P.parseToken(tok::sil_pound, diag::expected_sil_constant) ||
parseSILIdentifier(ModuleName, ModuleLoc, diag::expected_sil_constant))
return true;
llvm::PointerUnion<ValueDecl*, Module *> Res = lookupTopDecl(P, ModuleName);
assert(Res.is<Module*>() && "Expect a module name in ModuleInst");
auto Mod = Res.get<Module*>();
ResultVal = B.createModule(InstLoc,
SILType::getPrimitiveObjectType(
ModuleType::get(Mod)->getCanonicalType()));
break;
}
case ValueKind::DynamicMethodBranchInst: { case ValueKind::DynamicMethodBranchInst: {
SILDeclRef Member; SILDeclRef Member;
Identifier BBName, BBName2; Identifier BBName, BBName2;

View File

@@ -550,9 +550,6 @@ TupleInst::TupleInst(SILLocation Loc, SILType Ty, ArrayRef<SILValue> Elems)
MetatypeInst::MetatypeInst(SILLocation Loc, SILType Metatype) MetatypeInst::MetatypeInst(SILLocation Loc, SILType Metatype)
: SILInstruction(ValueKind::MetatypeInst, Loc, Metatype) {} : SILInstruction(ValueKind::MetatypeInst, Loc, Metatype) {}
ModuleInst::ModuleInst(SILLocation Loc, SILType ModuleType)
: SILInstruction(ValueKind::ModuleInst, Loc, ModuleType) {}
ProjectExistentialInst::ProjectExistentialInst(SILLocation Loc, ProjectExistentialInst::ProjectExistentialInst(SILLocation Loc,
SILValue Operand, SILValue Operand,
SILType SelfTy) SILType SelfTy)

View File

@@ -893,9 +893,6 @@ public:
void visitMetatypeInst(MetatypeInst *MI) { void visitMetatypeInst(MetatypeInst *MI) {
OS << "metatype " << MI->getType(); OS << "metatype " << MI->getType();
} }
void visitModuleInst(ModuleInst *MI) {
OS << "module #" << MI->getType().castTo<ModuleType>()->getModule()->Name;
}
void visitStrongRetainInst(StrongRetainInst *RI) { void visitStrongRetainInst(StrongRetainInst *RI) {
OS << "strong_retain " << getIDAndType(RI->getOperand()); OS << "strong_retain " << getIDAndType(RI->getOperand());

View File

@@ -586,10 +586,6 @@ public:
CanType(MI->getType().castTo<MetaTypeType>()->getInstanceType()), CanType(MI->getType().castTo<MetaTypeType>()->getInstanceType()),
"protocol_metatype result must be metatype of operand type"); "protocol_metatype result must be metatype of operand type");
} }
void checkModuleInst(ModuleInst *MI) {
require(MI->getType(0).is<ModuleType>(),
"module instruction must be of module type");
}
void checkStrongRetainInst(StrongRetainInst *RI) { void checkStrongRetainInst(StrongRetainInst *RI) {
requireReferenceValue(RI->getOperand(), "Operand of strong_retain"); requireReferenceValue(RI->getOperand(), "Operand of strong_retain");

View File

@@ -20,6 +20,7 @@
#include "swift/Basic/SourceManager.h" #include "swift/Basic/SourceManager.h"
#include "swift/Basic/type_traits.h" #include "swift/Basic/type_traits.h"
#include "swift/SIL/SILArgument.h" #include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILUndef.h"
#include "swift/SIL/TypeLowering.h" #include "swift/SIL/TypeLowering.h"
#include "Initialization.h" #include "Initialization.h"
#include "LValue.h" #include "LValue.h"
@@ -1167,8 +1168,9 @@ RValue RValueEmitter::visitDotSyntaxBaseIgnoredExpr(
} }
RValue RValueEmitter::visitModuleExpr(ModuleExpr *E, SGFContext C) { RValue RValueEmitter::visitModuleExpr(ModuleExpr *E, SGFContext C) {
SILValue module = // Produce an undef value. The module value should never actually be used.
SGF.B.createModule(E, SGF.getLoweredLoadableType(E->getType())); SILValue module = SILUndef::get(SGF.getLoweredLoadableType(E->getType()),
SGF.SGM.M);
return RValue(SGF, ManagedValue(module, ManagedValue::Unmanaged), E); return RValue(SGF, ManagedValue(module, ManagedValue::Unmanaged), E);
} }

View File

@@ -748,13 +748,6 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
ResultVal = Builder.createMarkFunctionEscape(Loc, OpList); ResultVal = Builder.createMarkFunctionEscape(Loc, OpList);
break; break;
} }
case ValueKind::ModuleInst: {
// Has IdentifierID for the module reference. Use SILOneTypeLayout.
auto Mod = MF->getModule(MF->getIdentifier(TyID));
ResultVal = Builder.createModule(Loc,
getSILType(ModuleType::get(Mod), SILValueCategory::Object));
break;
}
// Checked Conversion instructions. // Checked Conversion instructions.
case ValueKind::UnconditionalCheckedCastInst: { case ValueKind::UnconditionalCheckedCastInst: {
SILValue Val = getLocalValue(ValID, ValResNum, SILValue Val = getLocalValue(ValID, ValResNum,

View File

@@ -663,16 +663,6 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
(unsigned)MI->getType().getCategory()); (unsigned)MI->getType().getCategory());
break; break;
} }
case ValueKind::ModuleInst: {
// Has IdentifierID for the module reference. Use SILOneTypeLayout.
const ModuleInst *MI = cast<ModuleInst>(&SI);
ModuleType *MT = MI->getType().castTo<ModuleType>();
SILOneTypeLayout::emitRecord(Out, ScratchRecord,
SILAbbrCodes[SILOneTypeLayout::Code],
(unsigned)SI.getKind(),
S.addModuleRef(MT->getModule()), 0);
break;
}
case ValueKind::ProjectExistentialInst: { case ValueKind::ProjectExistentialInst: {
const ProjectExistentialInst *PEI = cast<ProjectExistentialInst>(&SI); const ProjectExistentialInst *PEI = cast<ProjectExistentialInst>(&SI);
SILOneTypeOneOperandLayout::emitRecord(Out, ScratchRecord, SILOneTypeOneOperandLayout::emitRecord(Out, ScratchRecord,

View File

@@ -528,7 +528,6 @@ bb0(%0 : $Builtin.RawPointer, %1 : $Builtin.Int64):
%3 = alloc_box $Builtin.Int64 // CHECK: alloc_box %3 = alloc_box $Builtin.Int64 // CHECK: alloc_box
%4 = store %0 to %2#1 : $*Builtin.RawPointer %4 = store %0 to %2#1 : $*Builtin.RawPointer
%5 = store %1 to %3#1 : $*Builtin.Int64 %5 = store %1 to %3#1 : $*Builtin.Int64
// %6 = module #Builtin
%7 = load %2#1 : $*Builtin.RawPointer // CHECK: load %7 = load %2#1 : $*Builtin.RawPointer // CHECK: load
%8 = load %3#1 : $*Builtin.Int64 // CHECK: load %8 = load %3#1 : $*Builtin.Int64 // CHECK: load
// CHECK: index_raw_pointer {{%.*}} : $Builtin.RawPointer, {{%.*}} : $Builtin.Int64 // CHECK: index_raw_pointer {{%.*}} : $Builtin.RawPointer, {{%.*}} : $Builtin.Int64
@@ -672,7 +671,6 @@ bb0(%0 : $Builtin.Int1, %1 : $Builtin.Int1):
%3 = alloc_box $Builtin.Int1 %3 = alloc_box $Builtin.Int1
store %0 to %2#1 : $*Builtin.Int1 store %0 to %2#1 : $*Builtin.Int1
store %1 to %3#1 : $*Builtin.Int1 store %1 to %3#1 : $*Builtin.Int1
%6 = module #Builtin // CHECK: module #Builtin
// CHECK: builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1 // CHECK: builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1
%7 = builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1 %7 = builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1
%8 = load %2#1 : $*Builtin.Int1 %8 = load %2#1 : $*Builtin.Int1
@@ -988,7 +986,6 @@ bb0(%0 : $Int64, %1 : $Int64, %2 : $Foo):
%8 = alloc_stack $Foo // var self // users: %15, %14, %9 %8 = alloc_stack $Foo // var self // users: %15, %14, %9
store %2 to %8#1 : $*Foo store %2 to %8#1 : $*Foo
%10 = metatype $Int64.metatype %10 = metatype $Int64.metatype
%11 = module #Builtin
%12 = integer_literal $Builtin.Int64, 0 // user: %13 %12 = integer_literal $Builtin.Int64, 0 // user: %13
%13 = struct $Int64 (%12 : $Builtin.Int64) // user: %18 %13 = struct $Int64 (%12 : $Builtin.Int64) // user: %18
destroy_addr %8#1 : $*Foo destroy_addr %8#1 : $*Foo

View File

@@ -456,7 +456,6 @@ bb0(%0 : $Builtin.RawPointer, %1 : $Builtin.Int64):
%3 = alloc_box $Builtin.Int64 %3 = alloc_box $Builtin.Int64
%4 = store %0 to %2#1 : $*Builtin.RawPointer %4 = store %0 to %2#1 : $*Builtin.RawPointer
%5 = store %1 to %3#1 : $*Builtin.Int64 %5 = store %1 to %3#1 : $*Builtin.Int64
// %6 = module #Builtin
%7 = load %2#1 : $*Builtin.RawPointer %7 = load %2#1 : $*Builtin.RawPointer
%8 = load %3#1 : $*Builtin.Int64 %8 = load %3#1 : $*Builtin.Int64
// CHECK: index_raw_pointer {{%.*}} : $Builtin.RawPointer, {{%.*}} : $Builtin.Int64 // CHECK: index_raw_pointer {{%.*}} : $Builtin.RawPointer, {{%.*}} : $Builtin.Int64
@@ -666,7 +665,6 @@ bb0(%0 : $Builtin.Int1, %1 : $Builtin.Int1):
%3 = alloc_box $Builtin.Int1 %3 = alloc_box $Builtin.Int1
store %0 to %2#1 : $*Builtin.Int1 store %0 to %2#1 : $*Builtin.Int1
store %1 to %3#1 : $*Builtin.Int1 store %1 to %3#1 : $*Builtin.Int1
%6 = module #Builtin // CHECK: module #Builtin
// CHECK: builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1 // CHECK: builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1
%7 = builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1 %7 = builtin_function_ref #Builtin.cmp_eq_Int1 : $@thin (Builtin.Int1, Builtin.Int1) -> Builtin.Int1
%8 = load %2#1 : $*Builtin.Int1 %8 = load %2#1 : $*Builtin.Int1
@@ -953,7 +951,6 @@ bb0(%0 : $Int64, %1 : $Int64, %2 : $Foo):
%8 = alloc_stack $Foo // var self // users: %15, %14, %9 %8 = alloc_stack $Foo // var self // users: %15, %14, %9
store %2 to %8#1 : $*Foo store %2 to %8#1 : $*Foo
%10 = metatype $Int64.metatype %10 = metatype $Int64.metatype
%11 = module #Builtin
%12 = integer_literal $Builtin.Int64, 0 // user: %13 %12 = integer_literal $Builtin.Int64, 0 // user: %13
%13 = struct $Int64 (%12 : $Builtin.Int64) // user: %18 %13 = struct $Int64 (%12 : $Builtin.Int64) // user: %18
destroy_addr %8#1 : $*Foo destroy_addr %8#1 : $*Foo