mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module. Initially it defines following AST datastructures: * declarations: `Decl` + derived classes * `Conformance` * `SubstitutionMap` * `Type` and `CanonicalType` Some of those were already defined in the SIL module and are now moved to the AST module. This change also cleans up a few things: * proper definition of `NominalTypeDecl`-related APIs in `SIL.Type` * rename `ProtocolConformance` to `Conformance` * use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
33 lines
1.2 KiB
Swift
33 lines
1.2 KiB
Swift
//===--- SimplifyMisc.swift -----------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import SIL
|
|
|
|
extension TypeValueInst: OnoneSimplifyable, SILCombineSimplifyable {
|
|
func simplify(_ context: SimplifyContext) {
|
|
// If our parameter is not known statically, then bail.
|
|
guard paramType.isInteger else {
|
|
return
|
|
}
|
|
|
|
// Note: Right now, value generics only support 'Int'. If we ever expand the
|
|
// scope of types supported, then this should change.
|
|
let fieldType = type.getNominalFields(in: parentFunction)![0]
|
|
|
|
let builder = Builder(before: self, context)
|
|
let intLiteral = builder.createIntegerLiteral(value, type: fieldType)
|
|
let structInst = builder.createStruct(type: type, elements: [intLiteral])
|
|
uses.replaceAll(with: structInst, context)
|
|
context.erase(instruction: self)
|
|
}
|
|
}
|