Could metadata ever be mandatory for correctness in LLVM IR?

Hi everyone,

Currently it looks like metadata is used in LLVM IR essentially as an
'optional extra', in that any pass is allowed to remove metadata
(though preserving metadata is useful) and the program should remain
valid. In other words the metadata only communicates information about
code quality or associated information rather than issues relevant to
correctness.

First question: Is this is a long term design intention OR something
that just currently happens to be true?

The context for this is that I'm considering how to represent ABI
information in a language-agnostic way in LLVM IR. I've seen/heard
some suggestions about using metadata to represent ABI information
(e.g. to say this 'i32' is actually an 'int'), but it does seem like
metadata is not intended for this kind of use case since removing the
metadata would affect the correctness of the lowering in the backend.

Second question: Given that context, would it be reasonable to say
that metadata would not be considered an appropriate mechanism for
communicating ABI information?

Thanks,
Stephen

From: "Stephen Cross" <scross@scross.co.uk>
To: llvmdev@cs.uiuc.edu
Sent: Friday, June 19, 2015 5:19:33 PM
Subject: [LLVMdev] Could metadata ever be mandatory for correctness in LLVM IR?

Hi everyone,

Currently it looks like metadata is used in LLVM IR essentially as an
'optional extra', in that any pass is allowed to remove metadata
(though preserving metadata is useful) and the program should remain
valid. In other words the metadata only communicates information
about
code quality or associated information rather than issues relevant to
correctness.

First question: Is this is a long term design intention OR something
that just currently happens to be true?

That is intentional.

The context for this is that I'm considering how to represent ABI
information in a language-agnostic way in LLVM IR. I've seen/heard
some suggestions about using metadata to represent ABI information
(e.g. to say this 'i32' is actually an 'int'), but it does seem like
metadata is not intended for this kind of use case since removing the
metadata would affect the correctness of the lowering in the backend.

We might be able to make different guarantees for module-level metadata, but I'm not certain.

Second question: Given that context, would it be reasonable to say
that metadata would not be considered an appropriate mechanism for
communicating ABI information?

That's right. Is there a reason you can't use function attributes for the ABI information?

-Hal

From: “Stephen Cross” <scross@scross.co.uk>
To: llvmdev@cs.uiuc.edu
Sent: Friday, June 19, 2015 5:19:33 PM
Subject: [LLVMdev] Could metadata ever be mandatory for correctness in LLVM IR?

Hi everyone,

Currently it looks like metadata is used in LLVM IR essentially as an
‘optional extra’, in that any pass is allowed to remove metadata
(though preserving metadata is useful) and the program should remain
valid. In other words the metadata only communicates information
about
code quality or associated information rather than issues relevant to
correctness.

First question: Is this is a long term design intention OR something
that just currently happens to be true?

That is intentional.

The context for this is that I’m considering how to represent ABI
information in a language-agnostic way in LLVM IR. I’ve seen/heard
some suggestions about using metadata to represent ABI information
(e.g. to say this ‘i32’ is actually an ‘int’), but it does seem like
metadata is not intended for this kind of use case since removing the
metadata would affect the correctness of the lowering in the backend.

We might be able to make different guarantees for module-level metadata, but I’m not certain.

I’d definitely be against it. If we want to make it guaranteed then we should just make it a part of the non-metadata IR.

-eric

That's right. Is there a reason you can't use function attributes for the ABI information?

I'm basically gathering information in advance of making a proposal
for modifications to LLVM IR for encoding ABI information. However, no
aspects of the current design I'm thinking about involve function
attributes; the focus is instead to encode ABI information for types
so we can map from each IR parameter to the relevant source language
type (but clearly in a language-agnostic way). It is of course a
complex area and I'll be writing up an extensive proposal in the next
week or so and submitting that to the mailing list.

I'd definitely be against it. If we want to make it guaranteed then we should just make it a part of the non-metadata IR.

I probably should've mentioned that I am also strongly against using
metadata for this purpose; the intention is to safely rule out this
option and to clarify the use cases for metadata.