Skip to content

Commit 8e977dc

Browse files
author
Dave Bartolomeo
committed
C++/C#: Move overrides of IRType::getByteSize() into leaf classes
See github#2272. I've added code comments in all of the places that future me will be tempted to hoist these overrides.
1 parent 24c3110 commit 8e977dc

File tree

2 files changed

+24
-6
lines changed
  • cpp/ql/src/semmle/code/cpp/ir/implementation
  • csharp/ql/src/experimental/ir/implementation

2 files changed

+24
-6
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/IRType.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ private class IRSizedType extends IRType {
111111
this = TIRFunctionAddressType(byteSize) or
112112
this = TIROpaqueType(_, byteSize)
113113
}
114+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
115+
// overridden only in the leaf classes.
114116
}
115117

116118
/**
@@ -137,6 +139,8 @@ class IRNumericType extends IRSizedType {
137139
this = TIRUnsignedIntegerType(byteSize) or
138140
this = TIRFloatingPointType(byteSize, _, _)
139141
}
142+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
143+
// overridden only in the leaf classes.
140144
}
141145

142146
/**
@@ -147,9 +151,8 @@ class IRIntegerType extends IRNumericType {
147151
this = TIRSignedIntegerType(byteSize) or
148152
this = TIRUnsignedIntegerType(byteSize)
149153
}
150-
151-
pragma[noinline]
152-
final override int getByteSize() { result = byteSize }
154+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
155+
// overridden only in the leaf classes.
153156
}
154157

155158
/**
@@ -162,6 +165,9 @@ class IRSignedIntegerType extends IRIntegerType, TIRSignedIntegerType {
162165
final override Language::LanguageType getCanonicalLanguageType() {
163166
result = Language::getCanonicalSignedIntegerType(byteSize)
164167
}
168+
169+
pragma[noinline]
170+
final override int getByteSize() { result = byteSize }
165171
}
166172

167173
/**
@@ -174,6 +180,9 @@ class IRUnsignedIntegerType extends IRIntegerType, TIRUnsignedIntegerType {
174180
final override Language::LanguageType getCanonicalLanguageType() {
175181
result = Language::getCanonicalUnsignedIntegerType(byteSize)
176182
}
183+
184+
pragma[noinline]
185+
final override int getByteSize() { result = byteSize }
177186
}
178187

179188
/**

csharp/ql/src/experimental/ir/implementation/IRType.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ private class IRSizedType extends IRType {
111111
this = TIRFunctionAddressType(byteSize) or
112112
this = TIROpaqueType(_, byteSize)
113113
}
114+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
115+
// overridden only in the leaf classes.
114116
}
115117

116118
/**
@@ -137,6 +139,8 @@ class IRNumericType extends IRSizedType {
137139
this = TIRUnsignedIntegerType(byteSize) or
138140
this = TIRFloatingPointType(byteSize, _, _)
139141
}
142+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
143+
// overridden only in the leaf classes.
140144
}
141145

142146
/**
@@ -147,9 +151,8 @@ class IRIntegerType extends IRNumericType {
147151
this = TIRSignedIntegerType(byteSize) or
148152
this = TIRUnsignedIntegerType(byteSize)
149153
}
150-
151-
pragma[noinline]
152-
final override int getByteSize() { result = byteSize }
154+
// Don't override `getByteSize()` here. The optimizer seems to generate better code when this is
155+
// overridden only in the leaf classes.
153156
}
154157

155158
/**
@@ -162,6 +165,9 @@ class IRSignedIntegerType extends IRIntegerType, TIRSignedIntegerType {
162165
final override Language::LanguageType getCanonicalLanguageType() {
163166
result = Language::getCanonicalSignedIntegerType(byteSize)
164167
}
168+
169+
pragma[noinline]
170+
final override int getByteSize() { result = byteSize }
165171
}
166172

167173
/**
@@ -174,6 +180,9 @@ class IRUnsignedIntegerType extends IRIntegerType, TIRUnsignedIntegerType {
174180
final override Language::LanguageType getCanonicalLanguageType() {
175181
result = Language::getCanonicalUnsignedIntegerType(byteSize)
176182
}
183+
184+
pragma[noinline]
185+
final override int getByteSize() { result = byteSize }
177186
}
178187

179188
/**

0 commit comments

Comments
 (0)