[llvm] 61e0822 - [llvm][clang] Remove uses of isOpaquePointerTy() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 01:28:10 PDT 2023
Author: Nikita Popov
Date: 2023-07-14T10:27:58+02:00
New Revision: 61e0822efab14dd922f9c3ee479a0a51952526d9
URL: https://github.com/llvm/llvm-project/commit/61e0822efab14dd922f9c3ee479a0a51952526d9
DIFF: https://github.com/llvm/llvm-project/commit/61e0822efab14dd922f9c3ee479a0a51952526d9.diff
LOG: [llvm][clang] Remove uses of isOpaquePointerTy() (NFC)
This now always returns true (for pointer types).
Added:
Modified:
clang/lib/CodeGen/CGCall.h
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/FuzzMutate/Operations.cpp
llvm/lib/FuzzMutate/RandomIRBuilder.cpp
llvm/lib/IR/Core.cpp
llvm/lib/Transforms/Coroutines/Coroutines.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/tools/llvm-stress/llvm-stress.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 824f0a9a882990..eaaf10c4eec687 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -109,9 +109,6 @@ class CGCallee {
AbstractInfo = abstractInfo;
assert(functionPtr && "configuring callee without function pointer");
assert(functionPtr->getType()->isPointerTy());
- assert(functionPtr->getType()->isOpaquePointerTy() ||
- functionPtr->getType()->getNonOpaquePointerElementType()
- ->isFunctionTy());
}
static CGCallee forBuiltin(unsigned builtinID,
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 038268d0705f85..6cc919afa0285f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4888,10 +4888,8 @@ static Value *simplifyGEPInst(Type *SrcTy, Value *Ptr,
}
}
- // For opaque pointers an all-zero GEP is a no-op. For typed pointers,
- // it may be equivalent to a bitcast.
- if (Ptr->getType()->getScalarType()->isOpaquePointerTy() &&
- Ptr->getType() == GEPTy &&
+ // All-zero GEP is a no-op, unless it performs a vector splat.
+ if (Ptr->getType() == GEPTy &&
all_of(Indices, [](const auto *V) { return match(V, m_Zero()); }))
return Ptr;
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index dcb3476a2d840a..ed9e1d6ebfa210 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2675,7 +2675,7 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) {
// Handle "ptr" opaque pointer type.
//
// Type ::= ptr ('addrspace' '(' uint32 ')')?
- if (Result->isOpaquePointerTy()) {
+ if (Result->isPointerTy()) {
unsigned AddrSpace;
if (parseOptionalAddrSpace(AddrSpace))
return true;
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index c31f2afadc516f..4095545240ca11 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1381,17 +1381,6 @@ unsigned BitcodeReader::getVirtualTypeID(Type *Ty,
return It->second;
}
-#ifndef NDEBUG
- if (!Ty->isOpaquePointerTy()) {
- assert(Ty->getNumContainedTypes() == ChildTypeIDs.size() &&
- "Wrong number of contained types");
- for (auto Pair : zip(Ty->subtypes(), ChildTypeIDs)) {
- assert(std::get<0>(Pair) == getTypeByID(std::get<1>(Pair)) &&
- "Incorrect contained type ID");
- }
- }
-#endif
-
unsigned TypeID = TypeList.size();
TypeList.push_back(Ty);
if (!ChildTypeIDs.empty())
diff --git a/llvm/lib/FuzzMutate/Operations.cpp b/llvm/lib/FuzzMutate/Operations.cpp
index 48455c781629f2..408f35879acd3b 100644
--- a/llvm/lib/FuzzMutate/Operations.cpp
+++ b/llvm/lib/FuzzMutate/Operations.cpp
@@ -196,9 +196,7 @@ OpDescriptor llvm::fuzzerop::gepDescriptor(unsigned Weight) {
auto buildGEP = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
// TODO: It would be better to generate a random type here, rather than
// generating a random value and picking its type.
- Type *Ty = Srcs[0]->getType()->isOpaquePointerTy()
- ? Srcs[1]->getType()
- : Srcs[0]->getType()->getNonOpaquePointerElementType();
+ Type *Ty = Srcs[1]->getType();
auto Indices = ArrayRef(Srcs).drop_front(2);
return GetElementPtrInst::Create(Ty, Srcs[0], Indices, "G", Inst);
};
diff --git a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
index bbacfedf456d37..548ba7956fd5a1 100644
--- a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
+++ b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
@@ -211,10 +211,8 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
IP = ++I->getIterator();
assert(IP != BB.end() && "guaranteed by the findPointer");
}
- // For opaque pointers, pick the type independently.
- Type *AccessTy = Ptr->getType()->isOpaquePointerTy()
- ? RS.getSelection()->getType()
- : Ptr->getType()->getNonOpaquePointerElementType();
+ // Pick the type independently.
+ Type *AccessTy = RS.getSelection()->getType();
auto *NewLoad = new LoadInst(AccessTy, Ptr, "L", &*IP);
// Only sample this load if it really matches the descriptor
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 964e51e545210d..f7b6d54013de54 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -793,7 +793,7 @@ LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
}
LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty) {
- return unwrap(Ty)->isOpaquePointerTy();
+ return true;
}
LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index ce4262e593b6eb..399bff72b8ae6b 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -596,20 +596,6 @@ static void checkAsyncFuncPointer(const Instruction *I, Value *V) {
auto *AsyncFuncPtrAddr = dyn_cast<GlobalVariable>(V->stripPointerCasts());
if (!AsyncFuncPtrAddr)
fail(I, "llvm.coro.id.async async function pointer not a global", V);
-
- if (AsyncFuncPtrAddr->getType()->isOpaquePointerTy())
- return;
-
- auto *StructTy = cast<StructType>(
- AsyncFuncPtrAddr->getType()->getNonOpaquePointerElementType());
- if (StructTy->isOpaque() || !StructTy->isPacked() ||
- StructTy->getNumElements() != 2 ||
- !StructTy->getElementType(0)->isIntegerTy(32) ||
- !StructTy->getElementType(1)->isIntegerTy(32))
- fail(I,
- "llvm.coro.id.async async function pointer argument's type is not "
- "<{i32, i32}>",
- V);
}
void CoroIdAsyncInst::checkWellFormed() const {
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 69e64bdb0de0ed..03e8a2507b45c9 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -423,10 +423,9 @@ GVNPass::Expression GVNPass::ValueTable::createGEPExpr(GetElementPtrInst *GEP) {
unsigned BitWidth = DL.getIndexTypeSizeInBits(PtrTy);
MapVector<Value *, APInt> VariableOffsets;
APInt ConstantOffset(BitWidth, 0);
- if (PtrTy->isOpaquePointerTy() &&
- GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset)) {
- // For opaque pointers, convert into offset representation, to recognize
- // equivalent address calculations that use
diff erent type encoding.
+ if (GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset)) {
+ // Convert into offset representation, to recognize equivalent address
+ // calculations that use
diff erent type encoding.
LLVMContext &Context = GEP->getContext();
E.opcode = GEP->getOpcode();
E.type = nullptr;
@@ -439,8 +438,8 @@ GVNPass::Expression GVNPass::ValueTable::createGEPExpr(GetElementPtrInst *GEP) {
E.varargs.push_back(
lookupOrAdd(ConstantInt::get(Context, ConstantOffset)));
} else {
- // If converting to offset representation fails (for typed pointers and
- // scalable vectors), fall back to type-based implementation:
+ // If converting to offset representation fails (for scalable vectors),
+ // fall back to type-based implementation:
E.opcode = GEP->getOpcode();
E.type = GEP->getSourceElementType();
for (Use &Op : GEP->operands())
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index f6848d1ea838ad..983a75e1d708dc 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1628,12 +1628,6 @@ static void speculateSelectInstLoads(SelectInst &SI, LoadInst &LI,
IRB.SetInsertPoint(&LI);
- if (auto *TypedPtrTy = LI.getPointerOperandType();
- !TypedPtrTy->isOpaquePointerTy() && SI.getType() != TypedPtrTy) {
- TV = IRB.CreateBitOrPointerCast(TV, TypedPtrTy, "");
- FV = IRB.CreateBitOrPointerCast(FV, TypedPtrTy, "");
- }
-
LoadInst *TL =
IRB.CreateAlignedLoad(LI.getType(), TV, LI.getAlign(),
LI.getName() + ".sroa.speculate.load.true");
@@ -1702,11 +1696,6 @@ static void rewriteMemOpOfSelect(SelectInst &SI, T &I,
}
CondMemOp.insertBefore(NewMemOpBB->getTerminator());
Value *Ptr = SI.getOperand(1 + SuccIdx);
- if (auto *PtrTy = Ptr->getType();
- !PtrTy->isOpaquePointerTy() &&
- PtrTy != CondMemOp.getPointerOperandType())
- Ptr = BitCastInst::CreatePointerBitCastOrAddrSpaceCast(
- Ptr, CondMemOp.getPointerOperandType(), "", &CondMemOp);
CondMemOp.setOperand(I.getPointerOperandIndex(), Ptr);
if (isa<LoadInst>(I)) {
CondMemOp.setName(I.getName() + (IsThen ? ".then" : ".else") + ".val");
@@ -1769,8 +1758,6 @@ static bool rewriteSelectInstMemOps(SelectInst &SI,
static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr,
APInt Offset, Type *PointerTy,
const Twine &NamePrefix) {
- assert(Ptr->getType()->isOpaquePointerTy() &&
- "Only opaque pointers supported");
if (Offset != 0)
Ptr = IRB.CreateInBoundsGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(Offset),
NamePrefix + "sroa_idx");
diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp
index 722120d7aae816..d1cf1607b94bed 100644
--- a/llvm/tools/llvm-stress/llvm-stress.cpp
+++ b/llvm/tools/llvm-stress/llvm-stress.cpp
@@ -341,9 +341,7 @@ struct LoadModifier: public Modifier {
void Act() override {
// Try to use predefined pointers. If non-exist, use undef pointer value;
Value *Ptr = getRandomPointerValue();
- Type *Ty = Ptr->getType()->isOpaquePointerTy()
- ? pickType()
- : Ptr->getType()->getNonOpaquePointerElementType();
+ Type *Ty = pickType();
Value *V = new LoadInst(Ty, Ptr, "L", BB->getTerminator());
PT->push_back(V);
}
@@ -356,9 +354,7 @@ struct StoreModifier: public Modifier {
void Act() override {
// Try to use predefined pointers. If non-exist, use undef pointer value;
Value *Ptr = getRandomPointerValue();
- Type *ValTy = Ptr->getType()->isOpaquePointerTy()
- ? pickType()
- : Ptr->getType()->getNonOpaquePointerElementType();
+ Type *ValTy = pickType();
// Do not store vectors of i1s because they are unsupported
// by the codegen.
More information about the llvm-commits
mailing list