[arch] arm64/instgen: allow only certain AClasses in gen

0 views
Skip to first unread message

Junyang Shao (Gerrit)

unread,
12:08 PM (3 hours ago) 12:08 PM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Junyang Shao has uploaded the change for review

Commit message

arm64/instgen: allow only certain AClasses in gen

This CL adds logic to allow only certain AClasses to be generated.

It is useful for partial code gen for assembler without all AClasses
support.
Change-Id: Icea821e8ae366edbcc3922e3f8411fe6054f446e

Change diff

diff --git a/arm64/instgen/xmlspec/generator.go b/arm64/instgen/xmlspec/generator.go
index f81584f..e37a93f 100644
--- a/arm64/instgen/xmlspec/generator.go
+++ b/arm64/instgen/xmlspec/generator.go
@@ -125,11 +125,11 @@

const (
{{- range $i, $e := .NewGoOps}}
- {{if eq $i 0}}
+ {{- if eq $i 0}}
{{$e}} obj.As = obj.ABaseARM64 + obj.A_ARCHSPECIFIC + 1000 + iota
- {{else}}
+ {{- else}}
{{$e}}
- {{end}}
+ {{- end}}
{{- end}}
)
`
@@ -182,6 +182,16 @@
newGoOps := make(map[string]bool)
existingGoOps := readExistingGoOps(filepath.Join(outputDir, "a.out.go"))

+ allowedOperandTypes := map[string]bool{
+ "AC_ARNG": true,
+ "AC_PREG": true,
+ "AC_PREGZ": true,
+ "AC_PREGM": true,
+ "AC_ZREG": true,
+ }
+
+ usedFuncIndices := make(map[int]bool)
+
for _, inst := range insts {
for _, iclass := range inst.Classes.Iclass {
if !iclass.Regdiagram.parsed {
@@ -192,6 +202,26 @@
if !encoding.parsed {
continue
}
+
+ // Filtering logic:
+ // 1. If 0 operands (len <= 1), keep with warning.
+ // 2. If > 0 operands, ALL must be in allowedOperandTypes.
+ keep := true
+ if len(encoding.operands) <= 1 {
+ log.Printf("Warning: instruction with 0 operands kept: %s", encoding.asm)
+ } else {
+ for _, op := range encoding.operands[1:] {
+ if !allowedOperandTypes[op.typ] {
+ keep = false
+ break
+ }
+ }
+ }
+
+ if !keep {
+ continue
+ }
+
if _, ok := goOps[encoding.goOp]; !ok {
goOps[encoding.goOp] = struct{}{}
}
@@ -224,6 +254,7 @@
Index: j,
FuncIndex: idx,
})
+ usedFuncIndices[idx] = true
}
}
instData.Args = append(instData.Args, arg)
@@ -241,6 +272,8 @@
// Collect constants
encodedInMap := make(map[string]string) // raw string -> constant name
var uniqueEncodedIn []string
+
+ // Collect ALL constants from global map to ensure invariant names (ENC_X)
for _, v := range encodingDescsToEncodedIn {
if v == "" || v == "nil" {
continue
@@ -252,17 +285,33 @@
}
sort.Strings(uniqueEncodedIn)

+ // Identify used constants
+ neededEncodedIn := make(map[string]bool)
+ for k, idx := range encodingFuncs {
+ if usedFuncIndices[idx] {
+ if v := encodingDescsToEncodedIn[k]; v != "" && v != "nil" {
+ neededEncodedIn[v] = true
+ }
+ }
+ }
+
var constants []constantData
for i, v := range uniqueEncodedIn {
name := fmt.Sprintf("ENC_%d", i)
encodedInMap[v] = name
- constants = append(constants, constantData{
- ConstName: name,
- BinName: v,
- })
+ // Only add to output if used
+ if neededEncodedIn[v] {
+ constants = append(constants, constantData{
+ ConstName: name,
+ BinName: v,
+ })
+ }
}

for i, k := range sortedEncodings {
+ if !usedFuncIndices[i+1] {
+ continue
+ }
sym := encodingDescsToEncodedIn[k]
if name, ok := encodedInMap[sym]; ok {
sym = name

Change information

Files:
  • M arm64/instgen/xmlspec/generator.go
Change size: M
Delta: 1 file changed, 56 insertions(+), 7 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: arch
Gerrit-Branch: master
Gerrit-Change-Id: Icea821e8ae366edbcc3922e3f8411fe6054f446e
Gerrit-Change-Number: 749940
Gerrit-PatchSet: 1
Gerrit-Owner: Junyang Shao <shaoj...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages