mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Allow using structs with trivial initializers in globals that require static initialization (e.g. @_section attribute)
Before this change, if a global variable is required to be statically initialized (e.g. due to @_section attribute), we don't allow its type to be a struct, only a scalar type works. This change improves on that by teaching MandatoryPerformanceOptimizations pass to inline struct initializer calls into initializer of globals, as long as they are simple enough so that we can be sure that we don't trigger recursive/infinite inlining.
This commit is contained in:
@@ -342,6 +342,8 @@ ERROR(performance_callee_unavailable,none,
|
||||
"called function is not available in this module and can have unpredictable performance", ())
|
||||
ERROR(bad_attr_on_non_const_global,none,
|
||||
"global variable must be a compile-time constant to use %0 attribute", (StringRef))
|
||||
ERROR(global_must_be_compile_time_const,none,
|
||||
"global variable must be a compile-time constant", ())
|
||||
NOTE(performance_called_from,none,
|
||||
"called from here", ())
|
||||
|
||||
|
||||
@@ -369,6 +369,8 @@ struct BridgedGlobalVar {
|
||||
inline OptionalBridgedInstruction getStaticInitializerValue() const;
|
||||
|
||||
bool canBeInitializedStatically() const;
|
||||
|
||||
bool mustBeInitializedStatically() const;
|
||||
};
|
||||
|
||||
struct OptionalBridgedGlobalVar {
|
||||
|
||||
@@ -173,6 +173,8 @@ public:
|
||||
/// static initializer.
|
||||
SILInstruction *getStaticInitializerValue();
|
||||
|
||||
bool mustBeInitializedStatically() const;
|
||||
|
||||
/// Returns true if the global is a statically initialized heap object.
|
||||
bool isInitializedObject() {
|
||||
return dyn_cast_or_null<ObjectInst>(getStaticInitializerValue()) != nullptr;
|
||||
|
||||
Reference in New Issue
Block a user