Fix CPP Backend for GEP API changes for opaque pointer types

Based on a patch by Jerome Witmann.

llvm-svn: 247047
This commit is contained in:
David Blaikie 2015-09-08 18:42:29 +00:00
parent 989a7558b8
commit 12dd3c4ebb
2 changed files with 20 additions and 15 deletions

View File

@ -1356,23 +1356,18 @@ void CppWriter::printInstruction(const Instruction *I,
}
case Instruction::GetElementPtr: {
const GetElementPtrInst* gep = cast<GetElementPtrInst>(I);
if (gep->getNumOperands() <= 2) {
Out << "GetElementPtrInst* " << iName << " = GetElementPtrInst::Create("
<< opNames[0];
if (gep->getNumOperands() == 2)
Out << ", " << opNames[1];
} else {
Out << "std::vector<Value*> " << iName << "_indices;";
nl(Out);
for (unsigned i = 1; i < gep->getNumOperands(); ++i ) {
Out << iName << "_indices.push_back("
<< opNames[i] << ");";
nl(Out);
Out << "GetElementPtrInst* " << iName << " = GetElementPtrInst::Create("
<< getCppName(gep->getSourceElementType()) << ", " << opNames[0] << ", {";
in();
for (unsigned i = 1; i < gep->getNumOperands(); ++i ) {
if (i != 1) {
Out << ", ";
}
Out << "Instruction* " << iName << " = GetElementPtrInst::Create("
<< opNames[0] << ", " << iName << "_indices";
nl(Out);
Out << opNames[i];
}
Out << ", \"";
out();
nl(Out) << "}, \"";
printEscapedString(gep->getName());
Out << "\", " << bbname << ");";
break;

View File

@ -0,0 +1,10 @@
; RUN: llc -march=cpp -o - %s | FileCheck %s
define void @f1(i32* %addr) {
%x = getelementptr i32, i32* %addr, i32 1
; CHECK: ConstantInt* [[INT_1:.*]] = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
; CHECK: GetElementPtrInst::Create(IntegerType::get(mod->getContext(), 32), ptr_addr,
; CHECK-NEXT: [[INT_1]]
; CHECK-NEXT: }, "x", label_3);
ret void
}