在源代码上添加一个新属性,该属性会传播到LLVM中的MC级别? [英] Adding a new attribute on source code that propagates until MC level in LLVM?

查看:69
本文介绍了在源代码上添加一个新属性,该属性会传播到LLVM中的MC级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下内容的传播方式很感兴趣:

I am interested in how the following is propagated:

void foo(int __attribute__((aligned(16)))* p) { ... }

在这种情况下,指针的对齐"在MC级别可用,但显然没有使用LLVM-IR元数据方法来实现.对齐信息对于某些目标将非常重要,这些目标将根据此值更改代码生成,我认为我需要的更像是此属性.

In this case the "alignedness" of the pointer is available at the MC level, but it is evidently not using the LLVM-IR metadata approach to achieve this. The alignment information is very important to some targets which will change code-generation dependent on this value, and I think that what I need is more like this attribute.

添加新属性以使其以与"aligned"相同的方式在编译器中传播是多么困难?因此,我已经在LLVM-IR中添加了一个新元素来执行此操作.我还希望最困难的部分是使LLVM的其他部分在不关心此新元素时忽略它们.

How difficult would it be to add a new attribute such that it propagates through the compiler in the same way as ‘aligned’? So, I already added a new element to the LLVM-IR to do this. I also expect that the hardest part would be making other parts of LLVM ignore this new element when they don’t care about it.

可惜的是,LLVM没有将目标相关信息从解析器传递到后端的通用目标独立方法.

It really is a pity that LLVM does not have a generic target independent way of passing target dependent information from parser to back-end.

在类似的中建议使用"DebugLoc"方法问题,但是我认为这有点麻烦,因为这与调试无关.但是,如果这种方式的实施难度较小,那么可以接受这种破解方法.

Using the ‘DebugLoc’ approach was suggested in a similar question, but I think it’s a bit-of-a-hack since this is not related to debugging. But if the implementation is less difficult this way, then the hack might be acceptable.

更新: 内联汇编而不是使用新属性会在这里起作用吗?如果是,优点/缺点是什么?

UPDATE: Would inline assembly instead of the use of a new attribute work here? If yes, what are the pros/cons?

推荐答案

正如您所展示的,对齐方式未使用元数据.

As you have demonstrated, alignment is not using metadata.

  • 对于任何不知道的人:在所有相关指令中都提到(隐式或显式)对齐,例如,问题中的函数将被编译为如下所示(注意对齐):


define void @foo(i32*) {
  %2 = alloca i32*, align 16        ; Allocate a 16-aligned pointer
  store i32* %0, i32** %2, align 16 ; An aligned store to place the arg there
  ...

现在,如果要将某些信息附加到现有指令上,并使其余大部分编译器都忽略它们,那么使用元数据是一个好主意.但是,由于元数据是编译器内部的抽象事物,因此在某些时候,您实际上必须对其进行处理.通常,通过添加自己的通行证来消费它并相应地做些事情.

Now, if you want to attach some information to existing instructions and have most of the rest of the compiler ignore them, using metadata is a good idea. However, since metadata is a compiler-internal abstract thing, at some point you'll have to actually do something with it. Typically, by adding a pass of your own to consume it and do something accordingly.

关于在何处放置通行证以及如何实施通行证,这实际上取决于您要传递的实际信息及其预期效果.

As for where to place your pass and how to implement it, it really depends on the actual information you're trying to pass and its intended effect.

这篇关于在源代码上添加一个新属性,该属性会传播到LLVM中的MC级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆