Skip to content

Conversation

@aschwaighofer
Copy link
Contributor

Computing the explosion schema for large types can be expensive.

E.g the following example would spend multiple seconds to compute the explosion scheme for the array type. It is not worth adding the complexity to have a special case explosion schema that handles types like that since exploding a value like that is going to be detrimental.

struct Test {
  private var values: [0xfffffff of [UInt32]] =
  InlineArray(repeating: [])
}

rdar://165202495

@aschwaighofer
Copy link
Contributor Author

@swift-ci test

/// detrimential i.e should be kept indirect.
enum IsVeryLargeType_t : bool {
IsNotVeryLargeType = false,
IsVeryLargeType = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can use the TeX convention: large Large LARGE huge Huge :)

BuiltinFixedArrayType::MaximumLoadableSize;
entry.setNumRegisters(veryLargeTypeRegisterCount);
largeTypeProperties[ty] = entry;
return veryLargeTypeRegisterCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find most of the code here unnecessarily confusing — I don't know why we're using a bunch of magic values instead of a well-encapsulated type. But this code seems to just be using the wrong magic value — I believe the magic value that needs to be stored in entry is MaxNumRegisters, which you can set by just calling setVeryLargeType().

...also, I know this is pre-existing code, but do you know why MaxNumRegisters is a mutable global variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

We compute properties (struct Properties) to make a determination whether SIL should be register to memory converted. Among the properties is the number of registers we deem a type to use (Properties::numRegisters). This field is a uint16_t and MaxNumRegisters is used to clamp when we set the field.
We also use this value when we want to say that an SIL type is very large.

When we make the decision whether to reg2mem promote the SIL the heuristic (LargeLoadableHeuristic) looks at the properties we computed. If the number of registers is bigger than some cutoff (15 currently LargeLoadableHeuristic::NumRegistersVeryLargeType) we immediately decide to reg2mem. If the number of registers is in-between 8 and 16 (LargeLoadableHeuristic::NumRegistersLargeType) we look at other properties such as number of uses.

…he number of registers for very large types

Computing the explosion schema for large types can be expensive.

E.g the following example would spend multiple seconds to compute the
explosion scheme for the array type. It is not worth adding the
complexity to have a special case explosion schema that handles types
like that since exploding a value like that is going to be detrimental.

```
struct Test {
  private var values: [0xfffffff of [UInt32]] =
  InlineArray(repeating: [])
}
```

rdar://165202495
@aschwaighofer aschwaighofer force-pushed the large_types_reg2mem_large_inline_array_compile_time_fix branch from 6810a46 to 6c93043 Compare December 19, 2025 20:19
@aschwaighofer
Copy link
Contributor Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants