Skip to content

Commit

Permalink
Add missing instructions to the SIL model (tensorflow#252)
Browse files Browse the repository at this point in the history
The additions are:
- destructure_tuple
- index_addr
- pointer_to_address
  • Loading branch information
Adam Paszke authored and Eugene Burmako committed Aug 27, 2019
1 parent 85cca9b commit 046544b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/SIL/SIL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public enum Instruction {
// debug_value_addr %0 : $*Array<Float>, var, name "out", argno 1
case debugValueAddr(_ operand: Operand, _ attributes: [DebugAttribute])

// https://github.com/apple/swift/blob/master/docs/SIL.rst#destructure-tuple
// destructure_tuple %2 : $(Array<Int>, Builtin.RawPointer)
case destructureTuple(_ operand: Operand)

// https://github.com/apple/swift/blob/master/docs/SIL.rst#end-access
// end_access %265 : $*Array<Float>
// end_access [abort] %42 : $T
Expand All @@ -151,6 +155,10 @@ public enum Instruction {
// function_ref @$s4main11threadCountSiyF : $@convention(thin) () -> Int
case functionRef(_ name: String, _ type: Type)

// https://github.com/apple/swift/blob/master/docs/SIL.rst#index-addr
// index_addr %5 : $*Int, %11 : $Builtin.Word
case indexAddr(_ addr: Operand, _ index: Operand)

// https://github.com/apple/swift/blob/master/docs/SIL.rst#integer-literal
// integer_literal $Builtin.Int1, -1
case integerLiteral(_ type: Type, _ value: Int)
Expand All @@ -163,6 +171,10 @@ public enum Instruction {
// metatype $@thin Int.Type
case metatype(_ type: Type)

// https://github.com/apple/swift/blob/master/docs/SIL.rst#pointer-to-address
// pointer_to_address %4 : $Builtin.RawPointer to [strict] $*Int
case pointerToAddress(_ operand: Operand, _ strict: Bool, _ type: Type)

// https://github.com/apple/swift/blob/master/docs/SIL.rst#return
// return %11 : $Int
case `return`(_ operand: Operand)
Expand Down
14 changes: 14 additions & 0 deletions Sources/SIL/SILParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class SILParser: Parser {
let operand = try parseOperand()
let attributes = try parseNilOrMany(", ") { try parseDebugAttribute() } ?? []
return .debugValueAddr(operand, attributes)
case "destructure_tuple":
let operand = try parseOperand()
return .destructureTuple(operand)
case "end_access":
let abort = skip("[abort]")
let operand = try parseOperand()
Expand All @@ -150,6 +153,11 @@ class SILParser: Parser {
try take(":")
let type = try parseType()
return .functionRef(name, type)
case "index_addr":
let addr = try parseOperand()
try take(",")
let index = try parseOperand()
return .indexAddr(addr, index)
case "integer_literal":
let type = try parseType()
try take(",")
Expand All @@ -161,6 +169,12 @@ class SILParser: Parser {
case "metatype":
let type = try parseType()
return .metatype(type)
case "pointer_to_address":
let operand = try parseOperand()
try take("to")
let strict = skip("[strict]")
let type = try parseType()
return .pointerToAddress(operand, strict, type)
case "return":
let operand = try parseOperand()
return .return(operand)
Expand Down
16 changes: 16 additions & 0 deletions Sources/SIL/SILPrinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class SILPrinter: Printer {
print("debug_value_addr ")
print(operand)
print(whenEmpty: false, ", ", attributes, ", ", "") { print($0) }
case let .destructureTuple(operand):
print("destructure_tuple ")
print(operand)
case let .endAccess(abort, operand):
print("end_access ")
print(when: abort, "[abort] ")
Expand All @@ -123,6 +126,11 @@ class SILPrinter: Printer {
print(name)
print(" : ")
print(type)
case let .indexAddr(addr, index):
print("index_addr ")
print(addr)
print(", ")
print(index)
case let .integerLiteral(type, value):
print("integer_literal ")
print(type)
Expand All @@ -134,6 +142,14 @@ class SILPrinter: Printer {
case let .metatype(type):
print("metatype ")
print(type)
case let .pointerToAddress(operand, strict, type):
print("pointer_to_address ")
print(operand)
print(" to ")
if strict {
print("[strict] ")
}
print(type)
case let .return(operand):
print("return ")
print(operand)
Expand Down
4 changes: 4 additions & 0 deletions Tests/SILTests/InstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ let instructionDefs = [
"function_ref @$ss6stride4from2to2bys8StrideToVyxGx_x0E0QztSxRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : Strideable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @in_guaranteed τ_0_0.Stride) -> @out StrideTo<τ_0_0>",
"function_ref @$s4main1CV3fooyyqd___qd_0_tSayqd__GRszSxRd_0_r0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1 where τ_0_0 == Array<τ_1_0>, τ_1_1 : Strideable> (@in_guaranteed τ_1_0, @in_guaranteed τ_1_1, C<Array<τ_1_0>>) -> ()",
"function_ref @$ss8StrideToV12makeIterators0abD0VyxGyF : $@convention(method) <τ_0_0 where τ_0_0 : Strideable> (@in StrideTo<τ_0_0>) -> @out StrideToIterator<τ_0_0>",
"(%5, %6) = destructure_tuple %2 : $(Array<Int>, Builtin.RawPointer)",
"%42 = index_addr %35 : $*Int, %41 : $Builtin.Word",
"%7 = pointer_to_address %6 : $Builtin.RawPointer to [strict] $*Int",
"%7 = pointer_to_address %6 : $Builtin.RawPointer to $*Int",
"load %117 : $*Optional<Int>",
"metatype $@thick Self.Type",
"metatype $@thin Int.Type",
Expand Down

0 comments on commit 046544b

Please sign in to comment.