Skip to content

Instantly share code, notes, and snippets.

@nikic
Created February 16, 2020 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/1e6ab5bbf42cfe48e7b848e60a2df180 to your computer and use it in GitHub Desktop.
Save nikic/1e6ab5bbf42cfe48e7b848e60a2df180 to your computer and use it in GitHub Desktop.
commit 5ffa9f0d2bf9b60a94c9952fbf1b8454128853f7
Author: Nikita Popov <nikita.ppv@gmail.com>
Date: Sun Feb 16 17:46:26 2020 +0100
Delete IRBuilder copy constructor
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 706aa43a507..8d9bf17969a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4683,7 +4683,7 @@ struct GEPOffsetAndOverflow {
static GEPOffsetAndOverflow EmitGEPOffsetInBytes(Value *BasePtr, Value *GEPVal,
llvm::LLVMContext &VMContext,
CodeGenModule &CGM,
- CGBuilderTy Builder) {
+ CGBuilderTy &Builder) {
const auto &DL = CGM.getDataLayout();
// The total (signed) byte offset for the GEP.
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index bca153b68ae..22bbf26d932 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2997,6 +2997,9 @@ public:
SetInsertPoint(TheBB, IP);
}
+ // Self-referential structure, default copy constructor not safe.
+ IRBuilder(const IRBuilder &) = delete;
+
InserterTy &getInserter() { return Inserter; }
};
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 0fcac7d402c..995f6f3887f 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -895,19 +895,20 @@ Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
}
-/// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
+/// An IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
/// abstracts over the various ways to specify an insert position.
-static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL,
- BasicBlock *InsertBB,
- Instruction *InsertBefore) {
- IRBuilder<> B(DL->getContext());
- if (InsertBefore)
- B.SetInsertPoint(InsertBefore);
- else if (InsertBB)
- B.SetInsertPoint(InsertBB);
- B.SetCurrentDebugLocation(DL);
- return B;
-}
+class IRBuilderForDbg : public IRBuilder<> {
+public:
+ IRBuilderForDbg(const DILocation *DL, BasicBlock *InsertBB,
+ Instruction *InsertBefore)
+ : IRBuilder(DL->getContext()) {
+ if (InsertBefore)
+ SetInsertPoint(InsertBefore);
+ else if (InsertBB)
+ SetInsertPoint(InsertBB);
+ SetCurrentDebugLocation(DL);
+ }
+};
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
assert(V && "no value passed to dbg intrinsic");
@@ -936,7 +937,7 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
+ IRBuilderForDbg B(DL, InsertBB, InsertBefore);
return B.CreateCall(DeclareFn, Args);
}
@@ -958,7 +959,7 @@ Instruction *DIBuilder::insertDbgValueIntrinsic(
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
+ IRBuilderForDbg B(DL, InsertBB, InsertBefore);
return B.CreateCall(ValueFn, Args);
}
@@ -976,7 +977,7 @@ Instruction *DIBuilder::insertLabel(
trackIfUnresolved(LabelInfo);
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
- IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
+ IRBuilderForDbg B(DL, InsertBB, InsertBefore);
return B.CreateCall(LabelFn, Args);
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index fdd4901d443..e92991c1881 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -27721,7 +27721,7 @@ X86TargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
AI->use_empty())
return nullptr;
- auto Builder = IRBuilder<>(AI);
+ IRBuilder<> Builder(AI);
Module *M = Builder.GetInsertBlock()->getParent()->getParent();
auto SSID = AI->getSyncScopeID();
// We must restrict the ordering to avoid generating loads with Release or
diff --git a/llvm/lib/Target/X86/X86InterleavedAccess.cpp b/llvm/lib/Target/X86/X86InterleavedAccess.cpp
index 36ee9d4ad38..f0288adf52c 100644
--- a/llvm/lib/Target/X86/X86InterleavedAccess.cpp
+++ b/llvm/lib/Target/X86/X86InterleavedAccess.cpp
@@ -284,7 +284,7 @@ static void genShuffleBland(MVT VT, ArrayRef<uint32_t> Mask,
static void reorderSubVector(MVT VT, SmallVectorImpl<Value *> &TransposedMatrix,
ArrayRef<Value *> Vec, ArrayRef<uint32_t> VPShuf,
unsigned VecElems, unsigned Stride,
- IRBuilder<> Builder) {
+ IRBuilder<> &Builder) {
if (VecElems == 16) {
for (unsigned i = 0; i < Stride; i++)
@@ -519,7 +519,7 @@ static void DecodePALIGNRMask(MVT VT, unsigned Imm,
// Invec[2] - |8|9|10|11| Vec[2] - |2|5|8|11|
static void concatSubVector(Value **Vec, ArrayRef<Instruction *> InVec,
- unsigned VecElems, IRBuilder<> Builder) {
+ unsigned VecElems, IRBuilder<> &Builder) {
if (VecElems == 16) {
for (int i = 0; i < 3; i++)
Vec[i] = InVec[i];
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 1c81ac4e645..6aa3d19e93f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -85,8 +85,8 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
AllocaInst &AI) {
PointerType *PTy = cast<PointerType>(CI.getType());
- BuilderTy AllocaBuilder(Builder);
- AllocaBuilder.SetInsertPoint(&AI);
+ IRBuilderBase::InsertPointGuard Guard(Builder);
+ Builder.SetInsertPoint(&AI);
// Get the type really allocated and the type casted to.
Type *AllocElTy = AI.getAllocatedType();
@@ -131,16 +131,16 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
} else {
Amt = ConstantInt::get(AI.getArraySize()->getType(), Scale);
// Insert before the alloca, not before the cast.
- Amt = AllocaBuilder.CreateMul(Amt, NumElements);
+ Amt = Builder.CreateMul(Amt, NumElements);
}
if (uint64_t Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
Value *Off = ConstantInt::get(AI.getArraySize()->getType(),
Offset, true);
- Amt = AllocaBuilder.CreateAdd(Amt, Off);
+ Amt = Builder.CreateAdd(Amt, Off);
}
- AllocaInst *New = AllocaBuilder.CreateAlloca(CastElTy, Amt);
+ AllocaInst *New = Builder.CreateAlloca(CastElTy, Amt);
New->setAlignment(MaybeAlign(AI.getAlignment()));
New->takeName(&AI);
New->setUsedWithInAlloca(AI.isUsedWithInAlloca());
@@ -151,7 +151,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
if (!AI.hasOneUse()) {
// New is the allocation instruction, pointer typed. AI is the original
// allocation instruction, also pointer typed. Thus, cast to use is BitCast.
- Value *NewCast = AllocaBuilder.CreateBitCast(New, AI.getType(), "tmpcast");
+ Value *NewCast = Builder.CreateBitCast(New, AI.getType(), "tmpcast");
replaceInstUsesWith(AI, NewCast);
}
return replaceInstUsesWith(CI, New);
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 98cbd2ca841..af6434cd603 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -787,7 +787,7 @@ private:
StringRef OriginalName);
void SetComdatForGlobalMetadata(GlobalVariable *G, GlobalVariable *Metadata,
StringRef InternalSuffix);
- IRBuilder<> CreateAsanModuleDtor(Module &M);
+ Instruction *CreateAsanModuleDtor(Module &M);
bool ShouldInstrumentGlobal(GlobalVariable *G);
bool ShouldUseMachOGlobalsSection() const;
@@ -2030,13 +2030,13 @@ ModuleAddressSanitizer::CreateMetadataGlobal(Module &M, Constant *Initializer,
return Metadata;
}
-IRBuilder<> ModuleAddressSanitizer::CreateAsanModuleDtor(Module &M) {
+Instruction *ModuleAddressSanitizer::CreateAsanModuleDtor(Module &M) {
AsanDtorFunction =
Function::Create(FunctionType::get(Type::getVoidTy(*C), false),
GlobalValue::InternalLinkage, kAsanModuleDtorName, &M);
BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
- return IRBuilder<>(ReturnInst::Create(*C, AsanDtorBB));
+ return ReturnInst::Create(*C, AsanDtorBB);
}
void ModuleAddressSanitizer::InstrumentGlobalsCOFF(
@@ -2115,7 +2115,7 @@ void ModuleAddressSanitizer::InstrumentGlobalsELF(
// We also need to unregister globals at the end, e.g., when a shared library
// gets closed.
- IRBuilder<> IRB_Dtor = CreateAsanModuleDtor(M);
+ IRBuilder<> IRB_Dtor(CreateAsanModuleDtor(M));
IRB_Dtor.CreateCall(AsanUnregisterElfGlobals,
{IRB.CreatePointerCast(RegisteredFlag, IntptrTy),
IRB.CreatePointerCast(StartELFMetadata, IntptrTy),
@@ -2174,7 +2174,7 @@ void ModuleAddressSanitizer::InstrumentGlobalsMachO(
// We also need to unregister globals at the end, e.g., when a shared library
// gets closed.
- IRBuilder<> IRB_Dtor = CreateAsanModuleDtor(M);
+ IRBuilder<> IRB_Dtor(CreateAsanModuleDtor(M));
IRB_Dtor.CreateCall(AsanUnregisterImageGlobals,
{IRB.CreatePointerCast(RegisteredFlag, IntptrTy)});
}
@@ -2202,7 +2202,7 @@ void ModuleAddressSanitizer::InstrumentGlobalsWithMetadataArray(
// We also need to unregister globals at the end, e.g., when a shared library
// gets closed.
- IRBuilder<> IRB_Dtor = CreateAsanModuleDtor(M);
+ IRBuilder<> IRB_Dtor(CreateAsanModuleDtor(M));
IRB_Dtor.CreateCall(AsanUnregisterGlobals,
{IRB.CreatePointerCast(AllGlobals, IntptrTy),
ConstantInt::get(IntptrTy, N)});
diff --git a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
index 9abb62ac788..3e7ebe54a00 100644
--- a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
+++ b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
@@ -112,7 +112,7 @@ static Value *getBoundsCheckCond(Value *Ptr, Value *InstVal,
///
/// \p GetTrapBB is a callable that returns the trap BB to use on failure.
template <typename GetTrapBBT>
-static void insertBoundsCheck(Value *Or, BuilderTy IRB, GetTrapBBT GetTrapBB) {
+static void insertBoundsCheck(Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) {
// check if the comparison is always false
ConstantInt *C = dyn_cast_or_null<ConstantInt>(Or);
if (C) {
diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 4047de13d0e..5cfcb45e4bc 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -290,7 +290,7 @@ public:
/// Otherwie split the flat vector \p MatrixVal containing a matrix with
/// shape \p SI into column vectors.
ColumnMatrixTy getMatrix(Value *MatrixVal, const ShapeInfo &SI,
- IRBuilder<> Builder) {
+ IRBuilder<> &Builder) {
VectorType *VType = dyn_cast<VectorType>(MatrixVal->getType());
assert(VType && "MatrixVal must be a vector type");
assert(VType->getNumElements() == SI.NumRows * SI.NumColumns &&
@@ -584,13 +584,13 @@ public:
}
LoadInst *createColumnLoad(Value *ColumnPtr, Type *EltType,
- IRBuilder<> Builder) {
+ IRBuilder<> &Builder) {
return Builder.CreateAlignedLoad(
ColumnPtr, Align(DL.getABITypeAlignment(EltType)), "col.load");
}
StoreInst *createColumnStore(Value *ColumnValue, Value *ColumnPtr,
- Type *EltType, IRBuilder<> Builder) {
+ Type *EltType, IRBuilder<> &Builder) {
return Builder.CreateAlignedStore(ColumnValue, ColumnPtr,
DL.getABITypeAlign(EltType));
}
@@ -690,7 +690,7 @@ public:
/// Extract a column vector of \p NumElts starting at index (\p I, \p J) from
/// the matrix \p LM represented as a vector of column vectors.
Value *extractVector(const ColumnMatrixTy &LM, unsigned I, unsigned J,
- unsigned NumElts, IRBuilder<> Builder) {
+ unsigned NumElts, IRBuilder<> &Builder) {
Value *Col = LM.getColumn(J);
Value *Undef = UndefValue::get(Col->getType());
Constant *Mask = createSequentialMask(Builder, I, NumElts, 0);
@@ -699,7 +699,7 @@ public:
// Set elements I..I+NumElts-1 to Block
Value *insertVector(Value *Col, unsigned I, Value *Block,
- IRBuilder<> Builder) {
+ IRBuilder<> &Builder) {
// First, bring Block to the same size as Col
unsigned BlockNumElts =
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index b242f100faf..562a9f81809 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1270,7 +1270,7 @@ static void CreateGCRelocates(ArrayRef<Value *> LiveVariables,
const int LiveStart,
ArrayRef<Value *> BasePtrs,
Instruction *StatepointToken,
- IRBuilder<> Builder) {
+ IRBuilder<> &Builder) {
if (LiveVariables.empty())
return;
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 9bbc06eb95b..c65244c1045 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3146,14 +3146,14 @@ private:
// as local as possible to the PHI. To do that, we re-use the location of
// the old pointer, which necessarily must be in the right position to
// dominate the PHI.
- IRBuilderTy PtrBuilder(IRB);
+ IRBuilderBase::InsertPointGuard Guard(IRB);
if (isa<PHINode>(OldPtr))
- PtrBuilder.SetInsertPoint(&*OldPtr->getParent()->getFirstInsertionPt());
+ IRB.SetInsertPoint(&*OldPtr->getParent()->getFirstInsertionPt());
else
- PtrBuilder.SetInsertPoint(OldPtr);
- PtrBuilder.SetCurrentDebugLocation(OldPtr->getDebugLoc());
+ IRB.SetInsertPoint(OldPtr);
+ IRB.SetCurrentDebugLocation(OldPtr->getDebugLoc());
- Value *NewPtr = getNewAllocaSlicePtr(PtrBuilder, OldPtr->getType());
+ Value *NewPtr = getNewAllocaSlicePtr(IRB, OldPtr->getType());
// Replace the operands which were using the old pointer.
std::replace(PN.op_begin(), PN.op_end(), cast<Value>(OldPtr), NewPtr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment