Skip to content

Commit 23d6ee7

Browse files
committed
[embedded] Use ArrayRef<RuntimeEffect> as an argument
1 parent 2c24c12 commit 23d6ee7

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,40 @@ class SILLinker : public SILModuleTransform {
4343
// In embedded Swift, the stdlib contains all the runtime functions needed
4444
// (swift_retain, etc.). Link them in so they can be referenced in IRGen.
4545
if (M.getOptions().EmbeddedSwift && LinkEmbeddedRuntime) {
46-
linkEmbeddedRuntimeFromStdlib(!M.getOptions().NoAllocations);
46+
linkEmbeddedRuntimeFromStdlib();
4747
}
4848
}
4949

50-
void linkEmbeddedRuntimeFromStdlib(bool includeAllocatingFunctions) {
51-
#define FUNCTION(ID, NAME, CC, AVAILABILITY, RETURNS, ARGS, ATTRS, EFFECT, \
52-
MEMORY_EFFECTS) \
53-
{ \
54-
using namespace RuntimeConstants; \
55-
ArrayRef<RuntimeEffect> effects = {EFFECT}; \
56-
bool allocating = false; \
57-
for (RuntimeEffect rt : effects) { \
58-
if (rt == RuntimeEffect::Allocating || \
59-
rt == RuntimeEffect::Deallocating) \
60-
allocating = true; \
61-
} \
62-
bool include = true; \
63-
if (allocating) include = includeAllocatingFunctions; \
64-
if (include) linkEmbeddedRuntimeFunctionByName(#NAME); \
65-
}
50+
void linkEmbeddedRuntimeFromStdlib() {
51+
using namespace RuntimeConstants;
52+
#define FUNCTION(ID, NAME, CC, AVAILABILITY, RETURNS, ARGS, ATTRS, EFFECT, \
53+
MEMORY_EFFECTS) \
54+
linkEmbeddedRuntimeFunctionByName(#NAME, EFFECT);
6655

6756
#define RETURNS(...)
6857
#define ARGS(...)
6958
#define NO_ARGS
7059
#define ATTRS(...)
7160
#define NO_ATTRS
72-
#define EFFECT(...) __VA_ARGS__
61+
#define EFFECT(...) { __VA_ARGS__ }
7362
#define MEMORY_EFFECTS(...)
7463
#define UNKNOWN_MEMEFFECTS
7564

7665
#include "swift/Runtime/RuntimeFunctions.def"
7766
}
7867

79-
void linkEmbeddedRuntimeFunctionByName(StringRef name) {
68+
void linkEmbeddedRuntimeFunctionByName(StringRef name,
69+
ArrayRef<RuntimeEffect> effects) {
8070
SILModule &M = *getModule();
8171

72+
bool allocating = false;
73+
for (RuntimeEffect rt : effects)
74+
if (rt == RuntimeEffect::Allocating || rt == RuntimeEffect::Deallocating)
75+
allocating = true;
76+
77+
// Don't link allocating runtime functions in -no-allocations mode.
78+
if (M.getOptions().NoAllocations && allocating) return;
79+
8280
// Bail if runtime function is already loaded.
8381
if (M.lookUpFunction(name)) return;
8482

0 commit comments

Comments
 (0)