Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private extension BeginCOWMutationInst {
return
}
let builder = Builder(before: self, location: location, context)
let zero = builder.createIntegerLiteral(0, type: uniquenessResult.type);
uniquenessResult.uses.replaceAll(with: zero, context)
let falseLiteral = builder.createBoolLiteral(false)
uniquenessResult.uses.replaceAll(with: falseLiteral, context)
}

func optimizeEmptyBeginEndPair(_ context: SimplifyContext) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private extension BuiltinInst {
return
}
let builder = Builder(before: self, context)
let result = builder.createIntegerLiteral(hasArchetype ? 0 : 1, type: type)
let result = builder.createBoolLiteral(!hasArchetype)
uses.replaceAll(with: result, context)
context.erase(instruction: self)
}
Expand All @@ -94,7 +94,7 @@ private extension BuiltinInst {
return
}
let builder = Builder(before: self, context)
let result = builder.createIntegerLiteral(equal ? 1 : 0, type: type)
let result = builder.createBoolLiteral(equal)

uses.replaceAll(with: result, context)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ private extension BuiltinInst {
operands[0].value.lookThroughScalarCasts is StringLiteralInst
{
let builder = Builder(before: self, context)
let result = builder.createIntegerLiteral(isEqual ? 0 : 1, type: type)
let result = builder.createBoolLiteral(!isEqual)
uses.replaceAll(with: result, context)
context.erase(instruction: self)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension ClassifyBridgeObjectInst : OnoneSimplifiable, SILCombineSimplifiable {
}

let builder = Builder(before: self, context)
let falseLiteral = builder.createIntegerLiteral(0, type: context.getBuiltinIntegerType(bitWidth: 1))
let falseLiteral = builder.createBoolLiteral(false)
let tp = builder.createTuple(type: self.type, elements: [falseLiteral, falseLiteral])
uses.replaceAll(with: tp, context)
context.erase(instruction: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private func devirtualize(builtinDestroyArray: BuiltinInst, _ context: some Muta
let preheaderBuilder = Builder(atEndOf: preheaderBlock, location: builtinDestroyArray.location, context)
let zero = preheaderBuilder.createIntegerLiteral(0, type: indexType)
let one = preheaderBuilder.createIntegerLiteral(1, type: indexType)
let falseValue = preheaderBuilder.createIntegerLiteral(0, type: boolType)
let falseValue = preheaderBuilder.createBoolLiteral(false);
let baseAddress = preheaderBuilder.createPointerToAddress(pointer: basePointer,
addressType: elementType.addressType,
isStrict: true, isInvariant: false)
Expand Down
16 changes: 13 additions & 3 deletions SwiftCompilerSources/Sources/SIL/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,21 @@ public struct Builder {
}
}

public func createIntegerLiteral(_ value: Int, type: Type) -> IntegerLiteralInst {
let literal = bridged.createIntegerLiteral(type.bridged, value)
private func createIntegerLiteral(_ value: Int, type: Type, treatAsSigned: Bool) -> IntegerLiteralInst {
let literal = bridged.createIntegerLiteral(type.bridged, value, treatAsSigned)
return notifyNew(literal.getAs(IntegerLiteralInst.self))
}


public func createIntegerLiteral(_ value: Int, type: Type) -> IntegerLiteralInst {
createIntegerLiteral(value, type: type, treatAsSigned: true)
}

/// Creates a `Builtin.Int1` integer literal instruction with the given value.
public func createBoolLiteral(_ value: Bool) -> IntegerLiteralInst {
let boolType = notificationHandler.getBuiltinIntegerType(1).type
return createIntegerLiteral(value ? 1 : 0, type: boolType, treatAsSigned: false)
}

public func createAllocRef(_ type: Type, isObjC: Bool = false, canAllocOnStack: Bool = false, isBare: Bool = false,
tailAllocatedTypes: TypeArray, tailAllocatedCounts: [Value]) -> AllocRefInst {
return tailAllocatedCounts.withBridgedValues { countsRef in
Expand Down
3 changes: 2 additions & 1 deletion include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ struct BridgedBuilder{
BridgedValueArray arguments) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createCondFail(BridgedValue condition,
BridgedStringRef message) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createIntegerLiteral(BridgedType type, SwiftInt value) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createIntegerLiteral(
BridgedType type, SwiftInt value, bool treatAsSigned) const;

SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createAllocRef(BridgedType type,
bool objc, bool canAllocOnStack, bool isBare,
Expand Down
8 changes: 5 additions & 3 deletions include/swift/SIL/SILBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2219,9 +2219,11 @@ BridgedInstruction BridgedBuilder::createCondFail(BridgedValue condition, Bridge
message.unbridged())};
}

BridgedInstruction BridgedBuilder::createIntegerLiteral(BridgedType type, SwiftInt value) const {
return {
unbridged().createIntegerLiteral(regularLoc(), type.unbridged(), value)};
BridgedInstruction
BridgedBuilder::createIntegerLiteral(BridgedType type, SwiftInt value,
bool treatAsSigned) const {
return {unbridged().createIntegerLiteral(regularLoc(), type.unbridged(),
value, treatAsSigned)};
}

BridgedInstruction BridgedBuilder::createAllocRef(BridgedType type,
Expand Down