]> granicus.if.org Git - clang/commitdiff
IRgen: Add CreateIRTemp, which creates a temporary alloca but with type converted...
authorDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 19:44:13 +0000 (19:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 19:44:13 +0000 (19:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96374 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/CodeGen/CodeGenFunction.h

index 01820c7aeef21f28c43aa12ad1200ae1f9b586e9..030d2c9c9f848a40115acc2d218be3e4da5c498e 100644 (file)
@@ -36,7 +36,17 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(const llvm::Type *Ty,
   return new llvm::AllocaInst(Ty, 0, Name, AllocaInsertPt);
 }
 
-llvm::Value *CodeGenFunction::CreateMemTemp(QualType Ty, const llvm::Twine &Name) {
+llvm::Value *CodeGenFunction::CreateIRTemp(QualType Ty,
+                                           const llvm::Twine &Name) {
+  llvm::AllocaInst *Alloc = CreateTempAlloca(ConvertType(Ty), Name);
+  // FIXME: Should we prefer the preferred type alignment here?
+  CharUnits Align = getContext().getTypeAlignInChars(Ty);
+  Alloc->setAlignment(Align.getQuantity());
+  return Alloc;
+}
+
+llvm::Value *CodeGenFunction::CreateMemTemp(QualType Ty,
+                                            const llvm::Twine &Name) {
   llvm::AllocaInst *Alloc = CreateTempAlloca(ConvertTypeForMem(Ty), Name);
   // FIXME: Should we prefer the preferred type alignment here?
   CharUnits Align = getContext().getTypeAlignInChars(Ty);
index fb2e5fee7309abadc2890d511b1f143367aa9596..a4db556d397c27f949589af2483a3d6463029538 100644 (file)
@@ -663,6 +663,13 @@ public:
   llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
                                      const llvm::Twine &Name = "tmp");
 
+  /// CreateIRTemp - Create a temporary IR object of the given type, with
+  /// appropriate alignment. This routine should only be used when an temporary
+  /// value needs to be stored into an alloca (for example, to avoid explicit
+  /// PHI construction), but the type is the IR type, not the type appropriate
+  /// for storing in memory.
+  llvm::Value *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp");
+
   /// CreateMemTemp - Create a temporary memory object of the given type, with
   /// appropriate alignment.
   llvm::Value *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp");