[PATCH] - Union types, replaceUsesOfWithOnConstant

Here’s the implementation of ConstantUnion::replaceUsesOfWithOnConstant(). No tests yet :frowning:

Two questions:

– Any suggestions as to an existing test I could use as a model for testing this?
– I could also use some advice on what part of the code to work on next (in terms of finishing up union support).

replunion.patch (2.09 KB)

Here's the implementation of ConstantUnion::replaceUsesOfWithOnConstant(). No tests yet :frowning:

Seems basically ok, please commit.

Two questions:

-- Any suggestions as to an existing test I could use as a model for testing this?

IS this what is causing this to be broken?

$ cat t.ll
@union1 = constant union { i32*, i8 } { i32* @G }
@G = global i32 4
$ llvm-as <t.ll | llvm-dis
; ModuleID = '<stdin>'

@union1 = constant union { i32*, i8 } undef ; <union { i32*, i8 }*> [#uses=0]
@G = global i32 4

-- I could also use some advice on what part of the code to work on next (in terms of finishing up union support).

What is missing?

-Chris

Here’s the implementation of ConstantUnion::replaceUsesOfWithOnConstant(). No tests yet :frowning:

Seems basically ok, please commit.

I suppose that means that I’ll have to send in the info to get commit access then :frowning:

Two questions:

– Any suggestions as to an existing test I could use as a model for testing this?

IS this what is causing this to be broken?

No no, nothing’s broken. I just wanted to write some tests for the replaceAllUsesOf case, and wondered if there was an existing test to use as a model.

$ cat t.ll
@union1 = constant union { i32*, i8 } { i32* @G }
@G = global i32 4
$ llvm-as <t.ll | llvm-dis
; ModuleID = ‘’

@union1 = constant union { i32*, i8 } undef ; <union { i32*, i8 }*> [#uses=0]
@G = global i32 4

– I could also use some advice on what part of the code to work on next (in terms of finishing up union support).

What is missing?

Almost everything :slight_smile: At this point, the only parts of the code that are aware of unions are:

  • Derived type definitions (Type.cpp and so on)
  • BitReader and BitWriter.
  • LLParser.
  • Constants.
    There’s no code that calculates the offsets of the union fields for example. None of the code generators know about unions yet.

That’s why I was wondering what area to work on next - I’m unfamiliar with the code and could use a few hints :slight_smile:

Here’s the implementation of ConstantUnion::replaceUsesOfWithOnConstant(). No tests yet :frowning:

Seems basically ok, please commit.

I suppose that means that I’ll have to send in the info to get commit access then :frowning:

Yep, plz do.

IS this what is causing this to be broken?

No no, nothing’s broken. I just wanted to write some tests for the replaceAllUsesOf case, and wondered if there was an existing test to use as a model.

I’m pointing out that the test doesn’t work with mainline, and was hoping that your patch fixes it.

$ cat t.ll
@union1 = constant union { i32*, i8 } { i32* @G }
@G = global i32 4
$ llvm-as <t.ll | llvm-dis
; ModuleID = ‘’

@union1 = constant union { i32*, i8 } undef ; <union { i32*, i8 }*> [#uses=0]
@G = global i32 4

– I could also use some advice on what part of the code to work on next (in terms of finishing up union support).

What is missing?

Almost everything :slight_smile: At this point, the only parts of the code that are aware of unions are:

  • Derived type definitions (Type.cpp and so on)
  • BitReader and BitWriter.
  • LLParser.
  • Constants.
    There’s no code that calculates the offsets of the union fields for example. None of the code generators know about unions yet.

That’s why I was wondering what area to work on next - I’m unfamiliar with the code and could use a few hints :slight_smile:

Making TargetData’s handle it would make sense which will teach various GEP iteration stuff about unions. After that I’d try sending various union cases through the code generator to expose the obvious issues there.

-Chris