【问题标题】:LLVM: member alignment from data-layoutLLVM:来自数据布局的成员对齐
【发布时间】:2016-12-29 21:31:27
【问题描述】:

我需要了解如何从数据布局中获取非压缩文字结构中的成员对齐。

根据here 的说明,可以获取此信息。

例如,我有这段代码:

; ModuleID = 'fy4vsjaw.hjq.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux"

%struct.S = type { i8, i64 }  

; Function Attrs: nounwind uwtable
define { i8, i64 } @foo() #0 !dbg !4 { 

%struct.S = type { i8, i64 } 行中,这里两个成员之间的填充是什么?

我希望是 32 位或 64 位,但我想确定一下。

谢谢!

【问题讨论】:

    标签: struct types padding llvm-ir


    【解决方案1】:

    确实写在数据布局里。如data layout spec中指定,布局的这部分i64:64表示int64是64位对齐的。

    在结构%struct.S = type { i8, i64 } 中,因此两个字段之间有一个7 字节的填充。

    以编程方式,可以通过索引获取成员的偏移量:

    uint64_t GetOffset(llvm::Module* mod, llvm::StructType* st, uint32_t int index) {
        return mod->getDataLayout()->getStructLayout(st)->getElementOffset(index);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      相关资源
      最近更新 更多