Use 'final' specifier on leaf classes

Tint makes heavy use of RTTI via virtual methods. Give the compiler the
opportunity to optimize away some of these virtuals.

Bug: tint:1383
Change-Id: I28edfaa0a05bb1a9c506c61c0084542c0aeb37f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82745
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-03-07 18:37:46 +00:00
committed by Tint LUCI CQ
parent dc0e31cfaa
commit 41f8d2ad52
119 changed files with 174 additions and 159 deletions

View File

@@ -21,7 +21,8 @@ namespace tint {
namespace transform {
/// Add an empty entry point to the module, if no other entry points exist.
class AddEmptyEntryPoint : public Castable<AddEmptyEntryPoint, Transform> {
class AddEmptyEntryPoint final
: public Castable<AddEmptyEntryPoint, Transform> {
public:
/// Constructor
AddEmptyEntryPoint();

View File

@@ -28,12 +28,12 @@ namespace transform {
/// store type of a buffer. If that structure is nested inside another structure
/// or an array, then it is wrapped inside another structure which gets the
/// `@internal(spirv_block)` attribute instead.
class AddSpirvBlockAttribute
class AddSpirvBlockAttribute final
: public Castable<AddSpirvBlockAttribute, Transform> {
public:
/// SpirvBlockAttribute is an InternalAttribute that is used to decorate a
// structure that needs a SPIR-V block attribute.
class SpirvBlockAttribute
class SpirvBlockAttribute final
: public Castable<SpirvBlockAttribute, ast::InternalAttribute> {
public:
/// Constructor

View File

@@ -52,7 +52,7 @@ namespace transform {
///
/// @note Depends on the following transforms to have been run first:
/// * SimplifyPointers
class ArrayLengthFromUniform
class ArrayLengthFromUniform final
: public Castable<ArrayLengthFromUniform, Transform> {
public:
/// Constructor
@@ -61,7 +61,7 @@ class ArrayLengthFromUniform
~ArrayLengthFromUniform() override;
/// Configuration options for the ArrayLengthFromUniform transform.
struct Config : public Castable<Data, transform::Data> {
struct Config final : public Castable<Data, transform::Data> {
/// Constructor
/// @param ubo_bp the binding point to use for the generated uniform buffer.
explicit Config(sem::BindingPoint ubo_bp);
@@ -86,7 +86,7 @@ class ArrayLengthFromUniform
/// Information produced about what the transform did.
/// If there were no calls to the arrayLength() builtin, then no Result will
/// be emitted.
struct Result : public Castable<Result, transform::Data> {
struct Result final : public Castable<Result, transform::Data> {
/// Constructor
/// @param used_size_indices Indices into the UBO that are statically used.
explicit Result(std::unordered_set<uint32_t> used_size_indices);

View File

@@ -29,7 +29,7 @@ using BindingPoint = sem::BindingPoint;
/// BindingRemapper is a transform used to remap resource binding points and
/// access controls.
class BindingRemapper : public Castable<BindingRemapper, Transform> {
class BindingRemapper final : public Castable<BindingRemapper, Transform> {
public:
/// BindingPoints is a map of old binding point to new binding point
using BindingPoints = std::unordered_map<BindingPoint, BindingPoint>;
@@ -39,7 +39,7 @@ class BindingRemapper : public Castable<BindingRemapper, Transform> {
/// Remappings is consumed by the BindingRemapper transform.
/// Data holds information about shader usage and constant buffer offsets.
struct Remappings : public Castable<Data, transform::Data> {
struct Remappings final : public Castable<Data, transform::Data> {
/// Constructor
/// @param bp a map of new binding points
/// @param ac a map of new access controls

View File

@@ -21,7 +21,7 @@ namespace tint {
namespace transform {
/// Implements builtins for backends that do not have a native implementation.
class BuiltinPolyfill : public Castable<BuiltinPolyfill, Transform> {
class BuiltinPolyfill final : public Castable<BuiltinPolyfill, Transform> {
public:
/// Constructor
BuiltinPolyfill();
@@ -56,7 +56,7 @@ class BuiltinPolyfill : public Castable<BuiltinPolyfill, Transform> {
/// Config is consumed by the BuiltinPolyfill transform.
/// Config specifies the builtins that should be polyfilled.
struct Config : public Castable<Data, transform::Data> {
struct Config final : public Castable<Data, transform::Data> {
/// Constructor
/// @param b the list of builtins to polyfill
explicit Config(const Builtins& b);

View File

@@ -32,11 +32,12 @@ namespace transform {
///
/// @note Depends on the following transforms to have been run first:
/// * SimplifyPointers
class CalculateArrayLength : public Castable<CalculateArrayLength, Transform> {
class CalculateArrayLength final
: public Castable<CalculateArrayLength, Transform> {
public:
/// BufferSizeIntrinsic is an InternalAttribute that's applied to intrinsic
/// functions used to obtain the runtime size of a storage buffer.
class BufferSizeIntrinsic
class BufferSizeIntrinsic final
: public Castable<BufferSizeIntrinsic, ast::InternalAttribute> {
public:
/// Constructor

View File

@@ -83,7 +83,7 @@ namespace transform {
///
/// @note Depends on the following transforms to have been run first:
/// * Unshadow
class CanonicalizeEntryPointIO
class CanonicalizeEntryPointIO final
: public Castable<CanonicalizeEntryPointIO, Transform> {
public:
/// ShaderStyle is an enumerator of different ways to emit shader IO.
@@ -99,7 +99,7 @@ class CanonicalizeEntryPointIO
};
/// Configuration options for the transform.
struct Config : public Castable<Config, Data> {
struct Config final : public Castable<Config, Data> {
/// Constructor
/// @param style the approach to use for emitting shader IO.
/// @param sample_mask an optional sample mask to combine with shader masks

View File

@@ -53,7 +53,7 @@ namespace transform {
/// information needed to represent a combined sampler in GLSL
/// (dimensionality, component type, etc). The GLSL writer outputs such
/// (Tint) Textures as (GLSL) Samplers.
class CombineSamplers : public Castable<CombineSamplers, Transform> {
class CombineSamplers final : public Castable<CombineSamplers, Transform> {
public:
/// A pair of binding points.
using SamplerTexturePair = sem::SamplerTexturePair;
@@ -63,7 +63,7 @@ class CombineSamplers : public Castable<CombineSamplers, Transform> {
/// The client-provided mapping from separate texture and sampler binding
/// points to combined sampler binding point.
struct BindingInfo : public Castable<Data, transform::Data> {
struct BindingInfo final : public Castable<Data, transform::Data> {
/// Constructor
/// @param map the map of all (texture, sampler) -> (combined) pairs
/// @param placeholder the binding point to use for placeholder samplers.

View File

@@ -30,14 +30,14 @@ namespace transform {
/// DecomposeMemoryAccess is a transform used to replace storage and uniform
/// buffer accesses with a combination of load, store or atomic functions on
/// primitive types.
class DecomposeMemoryAccess
class DecomposeMemoryAccess final
: public Castable<DecomposeMemoryAccess, Transform> {
public:
/// Intrinsic is an InternalAttribute that's used to decorate a stub function
/// so that the HLSL transforms this into calls to
/// `[RW]ByteAddressBuffer.Load[N]()` or `[RW]ByteAddressBuffer.Store[N]()`,
/// with a possible cast.
class Intrinsic : public Castable<Intrinsic, ast::InternalAttribute> {
class Intrinsic final : public Castable<Intrinsic, ast::InternalAttribute> {
public:
/// Intrinsic op
enum class Op {

View File

@@ -28,7 +28,7 @@ namespace transform {
///
/// @note Depends on the following transforms to have been run first:
/// * SimplifyPointers
class DecomposeStridedArray
class DecomposeStridedArray final
: public Castable<DecomposeStridedArray, Transform> {
public:
/// Constructor

View File

@@ -28,7 +28,7 @@ namespace transform {
///
/// @note Depends on the following transforms to have been run first:
/// * SimplifyPointers
class DecomposeStridedMatrix
class DecomposeStridedMatrix final
: public Castable<DecomposeStridedMatrix, Transform> {
public:
/// Constructor

View File

@@ -58,12 +58,12 @@ namespace transform {
/// }
/// ```
///
class FirstIndexOffset : public Castable<FirstIndexOffset, Transform> {
class FirstIndexOffset final : public Castable<FirstIndexOffset, Transform> {
public:
/// BindingPoint is consumed by the FirstIndexOffset transform.
/// BindingPoint specifies the binding point of the first index uniform
/// buffer.
struct BindingPoint : public Castable<BindingPoint, transform::Data> {
struct BindingPoint final : public Castable<BindingPoint, transform::Data> {
/// Constructor
BindingPoint();
@@ -83,7 +83,7 @@ class FirstIndexOffset : public Castable<FirstIndexOffset, Transform> {
/// Data is outputted by the FirstIndexOffset transform.
/// Data holds information about shader usage and constant buffer offsets.
struct Data : public Castable<Data, transform::Data> {
struct Data final : public Castable<Data, transform::Data> {
/// Constructor
/// @param has_vtx_index True if the shader uses vertex_index
/// @param has_inst_index True if the shader uses instance_index

View File

@@ -21,7 +21,7 @@ namespace tint {
namespace transform {
/// FoldConstants transforms the AST by folding constant expressions
class FoldConstants : public Castable<FoldConstants, Transform> {
class FoldConstants final : public Castable<FoldConstants, Transform> {
public:
/// Constructor
FoldConstants();

View File

@@ -34,7 +34,7 @@ namespace transform {
/// single usage.
/// These rules prevent any hoisting of the let that may affect execution
/// behaviour.
class FoldTrivialSingleUseLets
class FoldTrivialSingleUseLets final
: public Castable<FoldTrivialSingleUseLets, Transform> {
public:
/// Constructor

View File

@@ -22,7 +22,7 @@ namespace transform {
/// ForLoopToLoop is a Transform that converts a for-loop statement into a loop
/// statement. This is required by the SPIR-V writer.
class ForLoopToLoop : public Castable<ForLoopToLoop, Transform> {
class ForLoopToLoop final : public Castable<ForLoopToLoop, Transform> {
public:
/// Constructor
ForLoopToLoop();

View File

@@ -29,10 +29,10 @@ namespace transform {
/// Glsl is a transform used to sanitize a Program for use with the Glsl writer.
/// Passing a non-sanitized Program to the Glsl writer will result in undefined
/// behavior.
class Glsl : public Castable<Glsl, Transform> {
class Glsl final : public Castable<Glsl, Transform> {
public:
/// Configuration options for the Glsl sanitizer transform.
struct Config : public Castable<Data, transform::Data> {
struct Config final : public Castable<Data, transform::Data> {
/// Constructor
/// @param entry_point the root entry point function to generate
/// @param disable_workgroup_init `true` to disable workgroup memory zero