summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Target/CppBackend/CPPBackend.cpp25
-rw-r--r--llvm/test/CodeGen/CPP/gep.ll10
2 files changed, 20 insertions, 15 deletions
diff --git a/llvm/lib/Target/CppBackend/CPPBackend.cpp b/llvm/lib/Target/CppBackend/CPPBackend.cpp
index d9d2de42f3e..58b0ee8dd96 100644
--- a/llvm/lib/Target/CppBackend/CPPBackend.cpp
+++ b/llvm/lib/Target/CppBackend/CPPBackend.cpp
@@ -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;
diff --git a/llvm/test/CodeGen/CPP/gep.ll b/llvm/test/CodeGen/CPP/gep.ll
new file mode 100644
index 00000000000..88a0bf1f216
--- /dev/null
+++ b/llvm/test/CodeGen/CPP/gep.ll
@@ -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
+}
OpenPOWER on IntegriCloud