简体   繁体   English

创建向量LLVM时出现问题

[英]Issue Creating Vector LLVM

I am trying to create a vector and return it as a value using llvm. 我正在尝试创建向量,并使用llvm将其作为值返回。 Here is what my code looks like: 这是我的代码:

  Value *ArrayAST::codeGen() {
    Type *dType = Type::getDoubleTy(mContext);
    Type *vectorType = VectorType::get(dType, 4);
    Value *emptyVector = UndefValue::get(vectorType);
    Constant *index0 = Constant::getIntegerValue(dType, llvm::APInt(32, 0));
    Value *numberValue = numbers[0] -> codeGen(); // double 1.000000e+00
    Value *fullVector = InsertElementInst::Create(emptyVector, numberValue, index0);
    return fullVector;
  }

This generates the following IR code: 这将生成以下IR代码:

define <4 x double> @x() {
entry:
  ret <4 x double> <badref>
}

But, as you can see above, there is an issue: <badref> . 但是,正如您在上面看到的那样,存在一个问题: <badref> And when I try to run it, it fails to build: 当我尝试运行它时,它无法构建:

llvm-as: out.ll:3:21: error: expected type
  ret <4 x double> <badref>

I am new to LLVM and I am not quite sure what the best way to fix this is. 我是LLVM的新手,我不太确定解决此问题的最佳方法是什么。

Edit 编辑

If it is helpful, all of the code is on GitHub here . 如果有帮助,所有代码都在GitHub此处

Edit 2 编辑2

If I am not mistaken (I totally could be) the IR code should look like this: 如果我没记错的话(我完全可以),IR代码应如下所示:

define <4 x double> @x() {
entry:
  %tmp4 = insertelement <4 x double> undef, double 1.000000e+01, i32 0
  ret <4 x double> %tmp4
}

The issue was that I did not add the vector to my builder. 问题是我没有将向量添加到构建器中。 The following did the trick for me: 以下对我有用:

Builder.Insert(fullVector);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM