【问题标题】:LLVM: Updating a Data structure at runtimeLLVM:在运行时更新数据结构
【发布时间】:2018-08-21 23:03:40
【问题描述】:

我想存储有关正在分配和更改的每个堆栈内存的数据。

为此,我认为我需要某种数据结构,我可以在其中存储相关数据,例如局部变量的值以及它的任何更改,例如在store 指令之前。

此外,在读取任何局部变量(例如load 指令)之前,我应该能够使用保存在数据结构中的值来检查值。

如果我们假设 IR 看起来像这样

%1 = alloca i32, 
[...]
%20 = store i32 0, %1

我需要将上面的代码更改为如下所示

%18 = call __Checking
%19 = <storing the return value from __Checking into a data structure>
%20 = store i32 0, %1

我的问题是我不知道如何将名为 __Checking 的库中的返回值存储到我在开头定义的 StructType 中。

我的相关代码

if (StoreInst *SI = dyn_cast<StoreInst>(&I)){
   Value* newValue = IRB.CreateCall(....);
   Type* strTy[] = { Type::getInt64Ty(m.getContext()),                                                                              
                     Type::getInt64Ty(m.getContext()) };
   Type* t = StructType::create(strTy);
}

【问题讨论】:

  • 发布的 IR 不完整,有错误/错别字

标签: c++ llvm llvm-clang llvm-ir


【解决方案1】:

您没有提供任何关于__Checking 返回的类型(甚至__Checking 来自哪里)和StructType 内部的具体信息,所以我建议将这种行为抽象化在 runtime library 中(很可能在 C 中)。

这将允许您在 IR 的那些您需要存储(或比较等)值的部分中设置函数调用。函数会将值和StructType(以及其他任何需要的内容)作为参数,并在纯 C 中执行所需的操作(例如存储值)。

例如,使用您发布的部分 IR(以 myruntime_ 为前缀的名称应在您的运行时库中定义):

%0 = alloca %myruntime_struct
[...]
%18 = call @__Checking
%19 = call @myruntime_storevalue(%2, %18, /* other arguments? */)
%20 = store i32 0, %1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多