This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][SPIRV] ModuleCombiner: deduplicate global vars and spec consts.
AbandonedPublic

Authored by ergawy on Nov 5 2020, 8:23 AM.

Details

Summary

This commit extends the functionality of the SPIR-V module combiner
library by adding new deduplication capabilities. In particular,
implementation of deduplication of global variables and specialization
constants is introduced. For global variables, 2 variables are
considered duplicate if they either have the same descriptor set +
binding or the same built_in attribute. For specialization constants, 2
spec constants are considered duplicate if they have the same spec_id
attribute.

Diff Detail

Event Timeline

ergawy created this revision.Nov 5 2020, 8:23 AM
ergawy requested review of this revision.Nov 5 2020, 8:23 AM
ergawy updated this revision to Diff 303129.Nov 5 2020, 8:26 AM
  • Remove unneeded comment.
ergawy added a comment.Nov 5 2020, 8:31 AM

I am not familiar with the implicit conversion rules within the spv dialect (or MLIR in general). But, I was expecting that replacing all uses of bar with foo in the following to snippet to fail:

module {
spv.module Logical GLSL450 {
  spv.specConstant @foo spec_id(5) = 1 : i1

  spv.func @use_foo() -> (i1) "None" {
    %0 = spv._reference_of @foo : i1
    spv.ReturnValue %0 : i1
  }
}

spv.module Logical GLSL450 {
  spv.specConstant @bar spec_id(5) = 1. : f32

  spv.func @use_bar() -> (f32) "None" {
    // expected-error @+1 {{floating point value not valid for specified type}}
    %0 = spv._reference_of @bar : f32
    spv.ReturnValue %0 : f32
  }
}
}

@antiagainst , just FYI in case we need more elaborate testing in this area.

ergawy retitled this revision from [MLIR][SPIRV] ModuleCombiner: deduplication global vars and spec consts. to [MLIR][SPIRV] ModuleCombiner: deduplicate global vars and spec consts..Nov 5 2020, 10:29 PM
ergawy added a comment.Nov 6 2020, 6:09 AM

General comment regarding this patch as well as this: https://reviews.llvm.org/D90932.

I think both can be greatly simplified and merged in a more compact patch if I introduce specialized functions to compute hash codes for each of: global vars, spec consts, and functions. Then we would need a single map that maps the hash code to the symbol op and deduplicate based on the hash code in a single walk through the module instead of separating things as I do now.

I will try to do that.

ergawy abandoned this revision.Nov 6 2020, 8:32 AM

Abandoned in favor of: https://reviews.llvm.org/D90951