以下代码:
ConstantInt * Idx = cast<ConstantInt>(gepi->getOperand(2));
产生以下错误:
error: invalid use of incomplete type ‘struct llvm::ConstantInt’
error: forward declaration of ‘struct llvm::ConstantInt’
我不知道为什么这个演员不起作用。我正在使用 llvm 3.1。有什么帮助吗?
我希望能够按拓扑顺序获取函数中的基本块。有一个迭代器可以迭代函数中的基本块,但是我不确定它是否按拓扑顺序执行。我无法获得特定基本块的下一个基本块,也无法自己进行拓扑排序。
您可以假设 CFG 中没有循环。
我是 LLVM 的新手,我正在尝试构建自己的通行证。通读有关编写 LLVM 通行证的文档后。我试图通过在 Transforms 目录中添加一个目录来创建自己的通行证。但是,当我尝试制作我的源时,它给出了一个错误“制作:*没有制作目标的规则”。
如果我想进行新的传递,是否必须重建 LLVM?如果是这样,那将非常耗时,因为我在 Debian VM 上运行它并且构建它大约需要半小时。
让我知道是否有办法解决这个问题。任何建议表示赞赏。谢谢。
编辑:是的,我有 makefile。我正在按照文档中提到的步骤进行操作。
# Makefile for hello pass
# Path to top level of LLVM hierarchy
LEVEL = ../../..
# Name of the library to build
LIBRARYNAME = Trial
# Make the shared library become a loadable module so the tools can
# dlopen/dlsym on the resulting library.
LOADABLE_MODULE = 1
# Include the makefile implementation stuff
include $(LEVEL)/Makefile.common
我正在尝试制作一个名为 Trial 的简单函数传递。
使用LLVM clang ++ 4.9.2使用OMP指令编译cpp程序时,我看到了隐藏函数@ .omp_outlined。是在位码中生成的。我想知道这个隐藏函数是什么,是否有可能避免生成它。
我对从 LLVM 数组创建、存储和获取值的步骤有些困惑,到目前为止,我正在创建它:
auto type = llvm::ArrayType::get(<TYPE>, <SOME_UINT>);
auto array = builder.CreateAlloca(type);
有了这个,我试图让 llvm::InBoundGEP 到每个元素并将 llvm::Value 存储到他们,但这没有用......
是否有一些指南可以做到这一点?
所以我想使用llvm::Twine字符串块类.
我有以下样本:
#include <llvm/ADT/Twine.h>
#include <iostream>
int main()
{
  llvm::Twine twine1 = llvm::Twine("aaaa") + "bbbb" + "cccc" + "dddd";
  llvm::Twine twine2 = llvm::Twine(twine1) + "dddd" + "eeee";
  std::cout << twine1.str() << std::endl;
  std::cout << twine2.str() << std::endl;
  return 0;
}
它运行与clang++使用-O3,并g++与-O0但段错误g++使用-O3.我尝试了这个代码从3.4-3.9部分不同版本的clang库并试过g++ 4.8.4,g++ 4.8.5和mingw-5.3.0.
您需要llvm库并将代码与-lLLVMSupport -lLLVMCore其他代码链接起来llvm-config --ldflags
我知道该store指令用于将数据存储到内存中,但下面的llvm-ir代码是什么意思?你可以在这里看到很多空的"{}"结构.
; CHECK:      Function: foo:
; CHECK-NEXT:   NoAlias: {}* %p, {}* %q
define void @foo({}* %p, {}* %q) {
  store {} {}, {}* %p
  store {} {}, {}* %q
  ret void
}
仅供参考:https://github.com/llvm-mirror/llvm/blob/master/test/Analysis/CFLAliasAnalysis/Steensgaard/empty.ll
对于以下使用gcc和clang的代码,我得到了不同的结果,我相信这不是一个严重的错误,但是我想知道哪个结果与标准更一致?非常感谢您的回复。
我使用gcc(Ubuntu 7.3.0-27ubuntu1〜18.04)7.3.0和clang版本6.0.0-1ubuntu2(tags / RELEASE_600 / final)
#include <stdio.h>
int get_1(){
        printf("get_1\n");
        return 1;
}
int get_2(){
        printf("get_2\n");
        return 2;
}
int get_3(){
        printf("get_3\n");
        return 3;
}
int get_4(){
        printf("get_4\n");
        return 4;
}
int main(int argc, char *argv[])
{
        printf("%d\n",get_1() + get_2() - (get_3(), get_4()));
        return 0;
}
gcc的结果是
get_3
get_1
get_2
get_4
-1
of的结果是
get_1
get_2
get_3
get_4
-1
所以,这就是我构建 LLVM 的方式
1. Download LLVM from https://github.com/llvm/llvm-project as zip and extract. 
D:/llvm-project/
                |__clang-tools-extra
                |__clang
                |__llvm
                ...
                ...
2. Building using cmake gui
    source : D:/llvm-project/llvm
    Destination : D:/llvm-project/llvm/build
    Optional toolset : host=x64
Click configure
    LLVM_TARGETS_TO_BUILD : X86
Click generate
Now I have D:/llvm-project/llvm/build/llvm.sln 
I opened llvm.sln in visual studio 15 2017
And ALL_BUILD -->Build 
建立后我试过 
"C:\Program Files (x86)\LLVM\install\bin\clang.exe" –v
但没有叮当声
对于以下 C 代码片段,LLVM 将生成下面的 IR。
#include <stdio.h>
#include <stdlib.h>
int main(){
  printf("Hello world\n");
  fflush(NULL);
  return 0;
}
; ModuleID = 'a.c'
source_filename = "a.c"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"
%struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
%struct.__sFILEX = type opaque
%struct.__sbuf = type { i8*, …