소스 검색

[NFC] Add CreateMemTempWithoutCast and CreateTempAllocaWithoutCast

This is partial re-commit of r332982


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334837 91177308-0d34-0410-b5e6-96231b3b80d8
Yaxun Liu 7 년 전
부모
커밋
db3b4cb7ab
3개의 변경된 파일53개의 추가작업 그리고 34개의 파일을 삭제
  1. 4 6
      lib/CodeGen/CGCall.cpp
  2. 31 15
      lib/CodeGen/CGExpr.cpp
  3. 18 13
      lib/CodeGen/CodeGenFunction.h

+ 4 - 6
lib/CodeGen/CGCall.cpp

@@ -3901,9 +3901,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       assert(NumIRArgs == 1);
       assert(NumIRArgs == 1);
       if (!I->isAggregate()) {
       if (!I->isAggregate()) {
         // Make a temporary alloca to pass the argument.
         // Make a temporary alloca to pass the argument.
-        Address Addr = CreateMemTemp(I->Ty, ArgInfo.getIndirectAlign(),
-                                     "indirect-arg-temp", /*Alloca=*/nullptr,
-                                     /*Cast=*/false);
+        Address Addr = CreateMemTempWithoutCast(
+            I->Ty, ArgInfo.getIndirectAlign(), "indirect-arg-temp");
         IRCallArgs[FirstIRArg] = Addr.getPointer();
         IRCallArgs[FirstIRArg] = Addr.getPointer();
 
 
         I->copyInto(*this, Addr);
         I->copyInto(*this, Addr);
@@ -3948,9 +3947,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         }
         }
         if (NeedCopy) {
         if (NeedCopy) {
           // Create an aligned temporary, and copy to it.
           // Create an aligned temporary, and copy to it.
-          Address AI = CreateMemTemp(I->Ty, ArgInfo.getIndirectAlign(),
-                                     "byval-temp", /*Alloca=*/nullptr,
-                                     /*Cast=*/false);
+          Address AI = CreateMemTempWithoutCast(
+              I->Ty, ArgInfo.getIndirectAlign(), "byval-temp");
           IRCallArgs[FirstIRArg] = AI.getPointer();
           IRCallArgs[FirstIRArg] = AI.getPointer();
           I->copyInto(*this, AI);
           I->copyInto(*this, AI);
         } else {
         } else {

+ 31 - 15
lib/CodeGen/CGExpr.cpp

@@ -61,21 +61,30 @@ llvm::Value *CodeGenFunction::EmitCastToVoidPtr(llvm::Value *value) {
 
 
 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
 /// block.
 /// block.
+Address CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty,
+                                                     CharUnits Align,
+                                                     const Twine &Name,
+                                                     llvm::Value *ArraySize) {
+  auto Alloca = CreateTempAlloca(Ty, Name, ArraySize);
+  Alloca->setAlignment(Align.getQuantity());
+  return Address(Alloca, Align);
+}
+
+/// CreateTempAlloca - This creates a alloca and inserts it into the entry
+/// block. The alloca is casted to default address space if necessary.
 Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
 Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
                                           const Twine &Name,
                                           const Twine &Name,
                                           llvm::Value *ArraySize,
                                           llvm::Value *ArraySize,
-                                          Address *AllocaAddr,
-                                          bool CastToDefaultAddrSpace) {
-  auto Alloca = CreateTempAlloca(Ty, Name, ArraySize);
-  Alloca->setAlignment(Align.getQuantity());
+                                          Address *AllocaAddr) {
+  auto Alloca = CreateTempAllocaWithoutCast(Ty, Align, Name, ArraySize);
   if (AllocaAddr)
   if (AllocaAddr)
-    *AllocaAddr = Address(Alloca, Align);
-  llvm::Value *V = Alloca;
+    *AllocaAddr = Alloca;
+  llvm::Value *V = Alloca.getPointer();
   // Alloca always returns a pointer in alloca address space, which may
   // Alloca always returns a pointer in alloca address space, which may
   // be different from the type defined by the language. For example,
   // be different from the type defined by the language. For example,
   // in C++ the auto variables are in the default address space. Therefore
   // in C++ the auto variables are in the default address space. Therefore
   // cast alloca to the default address space when necessary.
   // cast alloca to the default address space when necessary.
-  if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) {
+  if (getASTAllocaAddressSpace() != LangAS::Default) {
     auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
     auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
     llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
     llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
     // When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
     // When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
@@ -128,19 +137,26 @@ Address CodeGenFunction::CreateIRTemp(QualType Ty, const Twine &Name) {
 }
 }
 
 
 Address CodeGenFunction::CreateMemTemp(QualType Ty, const Twine &Name,
 Address CodeGenFunction::CreateMemTemp(QualType Ty, const Twine &Name,
-                                       Address *Alloca,
-                                       bool CastToDefaultAddrSpace) {
+                                       Address *Alloca) {
   // FIXME: Should we prefer the preferred type alignment here?
   // FIXME: Should we prefer the preferred type alignment here?
-  return CreateMemTemp(Ty, getContext().getTypeAlignInChars(Ty), Name, Alloca,
-                       CastToDefaultAddrSpace);
+  return CreateMemTemp(Ty, getContext().getTypeAlignInChars(Ty), Name, Alloca);
 }
 }
 
 
 Address CodeGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
 Address CodeGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
-                                       const Twine &Name, Address *Alloca,
-                                       bool CastToDefaultAddrSpace) {
+                                       const Twine &Name, Address *Alloca) {
   return CreateTempAlloca(ConvertTypeForMem(Ty), Align, Name,
   return CreateTempAlloca(ConvertTypeForMem(Ty), Align, Name,
-                          /*ArraySize=*/nullptr, Alloca,
-                          CastToDefaultAddrSpace);
+                          /*ArraySize=*/nullptr, Alloca);
+}
+
+Address CodeGenFunction::CreateMemTempWithoutCast(QualType Ty, CharUnits Align,
+                                                  const Twine &Name) {
+  return CreateTempAllocaWithoutCast(ConvertTypeForMem(Ty), Align, Name);
+}
+
+Address CodeGenFunction::CreateMemTempWithoutCast(QualType Ty,
+                                                  const Twine &Name) {
+  return CreateMemTempWithoutCast(Ty, getContext().getTypeAlignInChars(Ty),
+                                  Name);
 }
 }
 
 
 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified

+ 18 - 13
lib/CodeGen/CodeGenFunction.h

@@ -2021,18 +2021,20 @@ public:
   /// to the stack.
   /// to the stack.
   ///
   ///
   /// Because the address of a temporary is often exposed to the program in
   /// Because the address of a temporary is often exposed to the program in
-  /// various ways, this function will perform the cast by default. The cast
-  /// may be avoided by passing false as \p CastToDefaultAddrSpace; this is
+  /// various ways, this function will perform the cast. The original alloca
+  /// instruction is returned through \p Alloca if it is not nullptr.
+  ///
+  /// The cast is not performaed in CreateTempAllocaWithoutCast. This is
   /// more efficient if the caller knows that the address will not be exposed.
   /// more efficient if the caller knows that the address will not be exposed.
-  /// The original alloca instruction is returned through \p Alloca if it is
-  /// not nullptr.
   llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp",
   llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp",
                                      llvm::Value *ArraySize = nullptr);
                                      llvm::Value *ArraySize = nullptr);
   Address CreateTempAlloca(llvm::Type *Ty, CharUnits align,
   Address CreateTempAlloca(llvm::Type *Ty, CharUnits align,
                            const Twine &Name = "tmp",
                            const Twine &Name = "tmp",
                            llvm::Value *ArraySize = nullptr,
                            llvm::Value *ArraySize = nullptr,
-                           Address *Alloca = nullptr,
-                           bool CastToDefaultAddrSpace = true);
+                           Address *Alloca = nullptr);
+  Address CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align,
+                                      const Twine &Name = "tmp",
+                                      llvm::Value *ArraySize = nullptr);
 
 
   /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
   /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
   /// default ABI alignment of the given LLVM type.
   /// default ABI alignment of the given LLVM type.
@@ -2067,15 +2069,18 @@ public:
   Address CreateIRTemp(QualType T, const Twine &Name = "tmp");
   Address CreateIRTemp(QualType T, const Twine &Name = "tmp");
 
 
   /// CreateMemTemp - Create a temporary memory object of the given type, with
   /// CreateMemTemp - Create a temporary memory object of the given type, with
-  /// appropriate alignment. Cast it to the default address space if
-  /// \p CastToDefaultAddrSpace is true. Returns the original alloca
-  /// instruction by \p Alloca if it is not nullptr.
+  /// appropriate alignmen and cast it to the default address space. Returns
+  /// the original alloca instruction by \p Alloca if it is not nullptr.
   Address CreateMemTemp(QualType T, const Twine &Name = "tmp",
   Address CreateMemTemp(QualType T, const Twine &Name = "tmp",
-                        Address *Alloca = nullptr,
-                        bool CastToDefaultAddrSpace = true);
+                        Address *Alloca = nullptr);
   Address CreateMemTemp(QualType T, CharUnits Align, const Twine &Name = "tmp",
   Address CreateMemTemp(QualType T, CharUnits Align, const Twine &Name = "tmp",
-                        Address *Alloca = nullptr,
-                        bool CastToDefaultAddrSpace = true);
+                        Address *Alloca = nullptr);
+
+  /// CreateMemTemp - Create a temporary memory object of the given type, with
+  /// appropriate alignmen without casting it to the default address space.
+  Address CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp");
+  Address CreateMemTempWithoutCast(QualType T, CharUnits Align,
+                                   const Twine &Name = "tmp");
 
 
   /// CreateAggTemp - Create a temporary memory object for the given
   /// CreateAggTemp - Create a temporary memory object for the given
   /// aggregate type.
   /// aggregate type.