Skip to content

Commit

Permalink
[llvm][clang] Remove uses of isOpaquePointerTy() (NFC)
Browse files Browse the repository at this point in the history
This now always returns true (for pointer types).
  • Loading branch information
nikic committed Jul 14, 2023
1 parent 8fe0449 commit 61e0822
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 66 deletions.
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/CGCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/FuzzMutate/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/FuzzMutate/RandomIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 0 additions & 14 deletions llvm/lib/Transforms/Coroutines/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 different type encoding.
if (GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset)) {
// Convert into offset representation, to recognize equivalent address
// calculations that use different type encoding.
LLVMContext &Context = GEP->getContext();
E.opcode = GEP->getOpcode();
E.type = nullptr;
Expand All @@ -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())
Expand Down
13 changes: 0 additions & 13 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 2 additions & 6 deletions llvm/tools/llvm-stress/llvm-stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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.
Expand Down

0 comments on commit 61e0822

Please sign in to comment.