From 18c26f3dad1a358e0e224abf83c8eb2e76ef1f9b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Mar 2008 03:57:08 +0000 Subject: [PATCH] implement extractelement. llvm-svn: 47812 --- lib/Target/CBackend/CBackend.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index bdef34d7ebd..5e98798b397 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -191,8 +191,10 @@ namespace { // Don't inline a load across a store or other bad things! return false; - // Must not be used in inline asm - if (I.hasOneUse() && isInlineAsm(*I.use_back())) return false; + // Must not be used in inline asm or extractelement. + if (I.hasOneUse() && + (isInlineAsm(*I.use_back()) || isa(I))) + return false; // Only inline instruction it if it's use is in the same BB as the inst. return I.getParent() == cast(I.use_back())->getParent(); @@ -253,6 +255,7 @@ namespace { void visitVAArgInst (VAArgInst &I); void visitInsertElementInst(InsertElementInst &I); + void visitExtractElementInst(ExtractElementInst &I); void visitInstruction(Instruction &I) { cerr << "C Writer does not know about " << I; @@ -3037,6 +3040,18 @@ void CWriter::visitInsertElementInst(InsertElementInst &I) { Out << ")"; } +void CWriter::visitExtractElementInst(ExtractElementInst &I) { + // We know that our operand is not inlined. + Out << "(("; + const Type *EltTy = + cast(I.getOperand(0)->getType())->getElementType(); + printType(Out, PointerType::getUnqual(EltTy)); + Out << ")(&" << GetValueName(I.getOperand(0)) << "))["; + writeOperand(I.getOperand(1)); + Out << "]"; +} + + //===----------------------------------------------------------------------===// // External Interface declaration