[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

Sergei Barannikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 9 09:47:54 PDT 2023


barannikov88 added a comment.

Please use clang-format on the modified lines.



================
Comment at: clang/lib/CodeGen/CGBuilder.h:170
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,
                                const llvm::Twine &Name = "") {
+    return Address(Addr.getPointer(), Ty,
----------------
The argument can be removed.

Idea for a follow-up: I would also consider removing this method because it does not do what its name says.
Maybe replace it with `Address::withElementType` analagous to `Address::withPointer` / `Address::withAlignment`?



================
Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9351
   // Implement the index operand if not omitted.
   if (Ops.size() > 3) {
     BasePtr = Builder.CreateGEP(MemoryTy, BasePtr, Ops[2]);
----------------
Braces are now redundant.


================
Comment at: clang/lib/CodeGen/CGCUDANV.cpp:238-240
   CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
   VoidPtrTy = cast<llvm::PointerType>(Types.ConvertType(Ctx.VoidPtrTy));
+  VoidPtrPtrTy = llvm::PointerType::get(CGM.getLLVMContext(), 0);
----------------
These are all the same types. Replace the variables with single `PtrTy`?



================
Comment at: clang/lib/CodeGen/CGCUDANV.cpp:272
   auto *RegisterGlobalsFnTy = getRegisterGlobalsFnTy();
-  llvm::Type *Params[] = {RegisterGlobalsFnTy->getPointerTo(), VoidPtrTy,
-                          VoidPtrTy, CallbackFnTy->getPointerTo()};
+  llvm::Type *Params[] = {llvm::PointerType::getUnqual(RegisterGlobalsFnTy), VoidPtrTy,
+                          VoidPtrTy, llvm::PointerType::get(Context, 0)};
----------------
Pass Context


================
Comment at: clang/lib/CodeGen/CGCUDANV.cpp:540
       VoidPtrPtrTy, CharPtrTy, CharPtrTy, CharPtrTy, IntTy,
-      VoidPtrTy,    VoidPtrTy, VoidPtrTy, VoidPtrTy, IntTy->getPointerTo()};
+      VoidPtrTy,    VoidPtrTy, VoidPtrTy, VoidPtrTy, llvm::PointerType::getUnqual(IntTy)};
   llvm::FunctionCallee RegisterFunc = CGM.CreateRuntimeFunction(
----------------
Pass Context


================
Comment at: clang/lib/CodeGen/CGCXX.cpp:175
   // Create the alias with no name.
+  llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl);
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
----------------
This looks wrong. It used to be `GetFunctionType(TargetDecl)`.



================
Comment at: clang/lib/CodeGen/CGCXX.cpp:184
   if (Entry) {
-    assert(Entry->getType() == AliasType &&
+    assert(Entry->getValueType() == AliasValueType &&
+           Entry->getAddressSpace() == Alias->getAddressSpace() &&
----------------
What's the reason for this change?


================
Comment at: clang/lib/CodeGen/CGException.cpp:2117
+  llvm::Type *PtrTy = llvm::PointerType::get(getLLVMContext(), 0);
+  llvm::Type *PtrsTy = llvm::StructType::get(PtrTy, CGM.VoidPtrTy);
+  llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, SEHInfo, 0);
----------------
I guess this was intended to be named `RecordTy`.



================
Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1945-1949
   if (TypeInfoLValue TI = base.dyn_cast<TypeInfoLValue>()) {
-    llvm::Type *StdTypeInfoPtrTy =
-        CGM.getTypes().ConvertType(base.getTypeInfoType())->getPointerTo();
     llvm::Constant *TypeInfo =
         CGM.GetAddrOfRTTIDescriptor(QualType(TI.getType(), 0));
-    if (TypeInfo->getType() != StdTypeInfoPtrTy)
-      TypeInfo = llvm::ConstantExpr::getBitCast(TypeInfo, StdTypeInfoPtrTy);
     return TypeInfo;
   }
----------------



================
Comment at: clang/lib/CodeGen/CGObjCRuntime.cpp:373
     llvm::PointerType *signatureType =
-      CGM.getTypes().GetFunctionType(signature)->getPointerTo(ProgramAS);
+      llvm::PointerType::get(CGM.getTypes().GetFunctionType(signature),
+                             ProgramAS);
----------------
Pass context here


================
Comment at: clang/lib/CodeGen/CGObjCRuntime.cpp:388
   llvm::PointerType *signatureType =
-    CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo(ProgramAS);
+    llvm::PointerType::get(CGM.getTypes().GetFunctionType(argsInfo),
+                           ProgramAS);
----------------
Pass context here.
Can also be moved above `if`.



================
Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:816-818
   llvm::Value *Addr = Builder.CreateInBoundsGEP(
       Base.getElementType(), Base.getPointer(), MemPtr, "memptr.offset");
+  return Addr;
----------------



================
Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1924-1927
       llvm::Value *Load = CGF.Builder.CreateCall(
           CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
           {VTable, llvm::ConstantInt::get(CGM.Int32Ty, 4 * VTableIndex)});
+      VFuncLoad = Load;
----------------



================
Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2552-2554
   auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
-  auto AddrInt8PtrTy =
-      AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy;
+  auto AddrPtrTy =
+    AddrAS ? llvm::PointerType::get(CGF.getLLVMContext(), AddrAS) : CGF.Int8PtrTy;
----------------
I think this can be simplified further to just:
`llvm::Type *AddrPtrTy = addr->getType();`



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152321/new/

https://reviews.llvm.org/D152321



More information about the cfe-commits mailing list