Skip to content

Commit 7d977b6

Browse files
committed
Add tests for internalize
1 parent 10dd489 commit 7d977b6

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

Tests/LLVMTests/IRPassManagerSpec.swift

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,83 @@ class IRPassManagerSpec : XCTestCase {
245245
})
246246
}
247247

248+
func testIdempotentInternalize() {
249+
let module = Module(name: "Internalize")
250+
let builder = IRBuilder(module: module)
251+
let addFunction: (String) -> Void = { (name) in
252+
var fun = module.addFunction(name, type: FunctionType([], VoidType()))
253+
fun.linkage = .external
254+
let block = fun.appendBasicBlock(named: "entry")
255+
builder.positionAtEnd(of: block)
256+
builder.buildRetVoid()
257+
}
258+
for name in [ "a", "b", "c", "d", "e", "f", "g" ] {
259+
addFunction(name)
260+
}
261+
let pipeliner = PassPipeliner(module: module)
262+
pipeliner.addStage("Internalize") { builder in
263+
builder.add(.internalize { g in
264+
print("Internalizing: \(g.name)")
265+
return true
266+
})
267+
}
268+
269+
XCTAssertTrue(fileCheckOutput(of: .stdout, withPrefixes: [ "CHECK-IDEMPOTENT-INTERNALIZE" ]) {
270+
for function in module.functions {
271+
XCTAssertTrue(function.linkage == .external)
272+
}
273+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: a
274+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: b
275+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: c
276+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: d
277+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: e
278+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: f
279+
// CHECK-IDEMPOTENT-INTERNALIZE: Internalizing: g
280+
pipeliner.execute()
281+
for function in module.functions {
282+
XCTAssertTrue(function.linkage == .external)
283+
}
284+
})
285+
}
286+
287+
func testInternalizeCallback() {
288+
let module = Module(name: "Internalize")
289+
let builder = IRBuilder(module: module)
290+
let addFunction: (String) -> Void = { (name) in
291+
var fun = module.addFunction(name, type: FunctionType([], VoidType()))
292+
fun.linkage = .external
293+
let block = fun.appendBasicBlock(named: "entry")
294+
builder.positionAtEnd(of: block)
295+
builder.buildRetVoid()
296+
}
297+
for name in [ "a", "b", "c", "d", "e", "f", "g" ] {
298+
addFunction(name)
299+
}
300+
let pipeliner = PassPipeliner(module: module)
301+
pipeliner.addStage("Internalize") { builder in
302+
builder.add(.internalize { g in
303+
print("Internalizing: \(g.name)")
304+
return false
305+
})
306+
}
307+
308+
XCTAssertTrue(fileCheckOutput(of: .stdout, withPrefixes: [ "CHECK-INTERNALIZE" ]) {
309+
for function in module.functions {
310+
XCTAssertTrue(function.linkage == .external)
311+
}
312+
// CHECK-INTERNALIZE: Internalizing: a
313+
// CHECK-INTERNALIZE: Internalizing: b
314+
// CHECK-INTERNALIZE: Internalizing: c
315+
// CHECK-INTERNALIZE: Internalizing: d
316+
// CHECK-INTERNALIZE: Internalizing: e
317+
// CHECK-INTERNALIZE: Internalizing: f
318+
// CHECK-INTERNALIZE: Internalizing: g
319+
pipeliner.execute()
320+
for function in module.functions {
321+
XCTAssertTrue(function.linkage == .internal)
322+
}
323+
})
324+
}
248325

249326
private func createModule() -> Module {
250327
let module = Module(name: "Test")
@@ -298,7 +375,9 @@ class IRPassManagerSpec : XCTestCase {
298375
("testAppendStages", testAppendStages),
299376
("testAppendStandardStages", testAppendStandardStages),
300377
("testExecute", testExecute),
301-
("testExecuteWithMask", testExecuteWithMask)
378+
("testExecuteWithMask", testExecuteWithMask),
379+
("testIdempotentInternalize", testIdempotentInternalize),
380+
("testInternalizeCallback", testInternalizeCallback),
302381
])
303382
#endif
304383
}

0 commit comments

Comments
 (0)