From 292bebbb6fdd2f3b6b7ae9dacd6803fbacb7115b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 15 Oct 2007 17:47:20 +0000 Subject: [PATCH] add a new CreateStackTemporary helper method. llvm-svn: 42994 --- include/llvm/CodeGen/SelectionDAG.h | 4 ++++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index 0120e99c8b6..aef63d6edc1 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -492,6 +492,10 @@ public: void dump() const; + /// CreateStackTemporary - Create a stack temporary, suitable for holding the + /// specified value type. + SDOperand CreateStackTemporary(MVT::ValueType VT); + /// FoldSetCC - Constant fold a setcc to true or false. SDOperand FoldSetCC(MVT::ValueType VT, SDOperand N1, SDOperand N2, ISD::CondCode Cond); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 9a1ea7cb386..b1b3bd4fb85 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -19,6 +19,7 @@ #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineConstantPool.h" +#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/MRegisterInfo.h" #include "llvm/Target/TargetData.h" @@ -913,6 +914,18 @@ SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) { return SDOperand(N, 0); } +/// CreateStackTemporary - Create a stack temporary, suitable for holding the +/// specified value type. +SDOperand SelectionDAG::CreateStackTemporary(MVT::ValueType VT) { + MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo(); + unsigned ByteSize = MVT::getSizeInBits(VT)/8; + const Type *Ty = MVT::getTypeForValueType(VT); + unsigned StackAlign = (unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty); + int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign); + return getFrameIndex(FrameIdx, TLI.getPointerTy()); +} + + SDOperand SelectionDAG::FoldSetCC(MVT::ValueType VT, SDOperand N1, SDOperand N2, ISD::CondCode Cond) { // These setcc operations always fold.