Skip to content

Commit 20a878f

Browse files
committed
Populate MatchRuleRegistry with both vector and normal node match rules
1 parent e176dc4 commit 20a878f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/GraalConfiguration.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.List;
2929
import java.util.ListIterator;
3030

31+
import jdk.graal.compiler.core.aarch64.AArch64NodeMatchRules;
32+
import jdk.graal.compiler.core.amd64.AMD64NodeMatchRules;
3133
import org.graalvm.collections.EconomicMap;
3234
import org.graalvm.nativeimage.ImageSingletons;
3335

@@ -134,20 +136,28 @@ public String getCompilerConfigurationName() {
134136
return COMPILER_CONFIGURATION_NAME;
135137
}
136138

139+
protected void populateMatchRuleRegistry(HashMap<Class<? extends NodeMatchRules>, EconomicMap<Class<? extends Node>, List<MatchStatement>>> matchRuleRegistry, Class<? extends NodeMatchRules> c) {
140+
matchRuleRegistry.put(c, MatchRuleRegistry.createRules(c));
141+
}
142+
137143
public void populateMatchRuleRegistry(HashMap<Class<? extends NodeMatchRules>, EconomicMap<Class<? extends Node>, List<MatchStatement>>> matchRuleRegistry) {
138-
Class<? extends NodeMatchRules> matchRuleClass;
144+
/*
145+
* We create both types of match rules so the target machine could use vectorization for
146+
* run-time compilation even if the image does not support vectorization. This allows
147+
* Truffle to produce optimal code on a target machine.
148+
*/
139149
final Architecture hostedArchitecture = ConfigurationValues.getTarget().arch;
140150
if (hostedArchitecture instanceof AMD64) {
141-
matchRuleClass = AMD64VectorNodeMatchRules.class;
151+
populateMatchRuleRegistry(matchRuleRegistry, AMD64NodeMatchRules.class);
152+
populateMatchRuleRegistry(matchRuleRegistry, AMD64VectorNodeMatchRules.class);
142153
} else if (hostedArchitecture instanceof AArch64) {
143-
matchRuleClass = AArch64VectorNodeMatchRules.class;
154+
populateMatchRuleRegistry(matchRuleRegistry, AArch64NodeMatchRules.class);
155+
populateMatchRuleRegistry(matchRuleRegistry, AArch64VectorNodeMatchRules.class);
144156
} else if (hostedArchitecture instanceof RISCV64) {
145-
matchRuleClass = RISCV64NodeMatchRules.class;
157+
populateMatchRuleRegistry(matchRuleRegistry, RISCV64NodeMatchRules.class);
146158
} else {
147159
throw VMError.shouldNotReachHere("Can not instantiate NodeMatchRules for architecture " + hostedArchitecture.getName());
148160
}
149-
150-
matchRuleRegistry.put(matchRuleClass, MatchRuleRegistry.createRules(matchRuleClass));
151161
}
152162

153163
public SubstrateBackend createBackend(Providers newProviders) {

0 commit comments

Comments
 (0)