如何通过LLVM传递将加载指令放入InsertElement指令?

时间:2016-11-24 05:42:08

标签: llvm llvm-ir

我想通过llvm pass自动生成Load和InsertElement指令。

我的问题是如何将加载指令(例如%4,%6,%8,%10)放入InsertElement指令中,就像我的LLVM-IR代码目标一样:

%4 = load i32, i32* %1, align 4
%5 = insertelement <4 x i32> undef, i32 %4, i32 0
%6 = load i32, i32* %1, align 4
%7 = insertelement <4 x i32> %5, i32 %6, i32 1
%8 = load i32, i32* %1, align 4
%9 = insertelement <4 x i32> %7, i32 %8, i32 2
%10 = load i32, i32* %1, align 4
%11 = insertelement <4 x i32> %9, i32 %10, i32 3

和我的通行证:

if (auto *op = dyn_cast<LoadInst>(&I)) {
            ...
            Value* loadinst_ptr=op->getPointerOperand();
            Type* load_ty= loadinst_ptr->getType();
            Value* val = UndefValue::get(VectorType::get(load_ty, 4));
            for (unsigned i = 0; i < 4; i++)//for 4 copies
            {
                LoadInst* load_val=builder.CreateLoad(loadinst_ptr);
                load_val->setAlignment(4);
                //my problem is here, parameter load_val is invalid on CreateInsertElement.
                val = builder.CreateInsertElement(val,load_val, builder.getInt32(i));

            }
        }

这是错误消息:

opt: /home/shun/llvm-proj/llvm/lib/IR/Instructions.cpp:1748: 
llvm::InsertElementInst::InsertElementInst(llvm::Value*, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::Instruction*): 
Assertion `isValidOperands(Vec, Elt, Index) && "Invalid insertelement instruction operands!"' failed.

0 个答案:

没有答案