<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hey Nikita,<div class=""><br class=""></div><div class="">We’re seeing some cyclic dependency issues on the lldb modules-enabled bot, could you please take a look?</div><div class=""><br class=""></div><div class=""><a href="http://lab.llvm.org:8080/green/view/LLDB/job/lldb-cmake/9404/consoleFull#-361314398a1ca8a51-895e-46c6-af87-ce24fa4cd561" class="">http://lab.llvm.org:8080/green/view/LLDB/job/lldb-cmake/9404/consoleFull#-361314398a1ca8a51-895e-46c6-af87-ce24fa4cd561</a></div><div class=""><br class=""></div><div class="">```</div><div class=""><div class="">/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/IR/IRBuilderFolder.h:18:10: fatal error: cyclic dependency in module 'LLVM_intrinsic_gen': LLVM_intrinsic_gen -> LLVM_IR -> LLVM_intrinsic_gen</div><br class="Apple-interchange-newline"><div class="">#include "llvm/IR/InstrTypes.h"</div><div class=""> ^</div><div class="">While building module 'LLVM_intrinsic_gen' imported from /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/lib/IR/IRBuilder.cpp:14:</div><div class="">In file included from <module-includes>:1:</div><div class="">/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/IR/Argument.h:19:10: fatal error: could not build module 'LLVM_IR'</div><div class="">#include "llvm/IR/Value.h"</div><div class=""> ~~~~~~~~^~~~~~~~~~~~~~~~~</div><div class="">/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/lib/IR/IRBuilder.cpp:14:10: fatal error: could not build module 'LLVM_intrinsic_gen'</div><div class="">#include "llvm/IR/IRBuilder.h”</div><div class="">```</div><div class=""><br class=""></div><div class="">I’m trying to reproduce this now and will try to fix forwards if possible. Here’s my configure command:</div><div class=""><br class=""></div><div class="">cmake -G Ninja /Users/vsk/src/llvm-backup-master/llvm -DCLANG_ENABLE_ARCMT=Off -DCLANG_ENABLE_STATIC_ANALYZER=Off -D<br class="">LLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld;libcxx;libcxxabi;compiler-rt;libunwind;lldb' -DLLDB_USE_SYSTEM_DEBUGSERVER=On -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=<br class="">On -DLLVM_ENABLE_MODULES=On</div><div class=""><br class=""></div><div class="">vedant</div><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 17, 2020, at 10:18 AM, Nikita Popov via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">Author: Nikita Popov<br class="">Date: 2020-02-17T19:04:11+01:00<br class="">New Revision: 3eaa53e80543813a2274391956e91d275950fbf8<br class=""><br class="">URL: <a href="https://github.com/llvm/llvm-project/commit/3eaa53e80543813a2274391956e91d275950fbf8" class="">https://github.com/llvm/llvm-project/commit/3eaa53e80543813a2274391956e91d275950fbf8</a><br class="">DIFF: <a href="https://github.com/llvm/llvm-project/commit/3eaa53e80543813a2274391956e91d275950fbf8.diff" class="">https://github.com/llvm/llvm-project/commit/3eaa53e80543813a2274391956e91d275950fbf8.diff</a><br class=""><br class="">LOG: Reapply "[IRBuilder] Virtualize IRBuilder"<br class=""><br class="">Relative to the original commit, this fixes some warnings,<br class="">and is based on the deletion of the IRBuilder copy constructor<br class="">in D74693. The automatic copy constructor would no longer be<br class="">safe.<br class=""><br class="">-----<br class=""><br class="">Related llvm-dev thread:<br class=""><a href="http://lists.llvm.org/pipermail/llvm-dev/2020-February/138951.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2020-February/138951.html</a><br class=""><br class="">This patch moves the IRBuilder from templating over the constant<br class="">folder and inserter towards making both of these virtual.<br class="">There are a couple of motivations for this:<br class=""><br class="">1. It's not possible to share code between use-sites that use<br class="">different IRBuilder folders/inserters (short of templating the code<br class="">and moving it into headers).<br class="">2. Methods currently defined on IRBuilderBase (which is not templated)<br class="">do not use the custom inserter, resulting in subtle bugs (e.g.<br class="">incorrect InstCombine worklist management). It would be possible to<br class="">move those into the templated IRBuilder, but...<br class="">3. The vast majority of the IRBuilder implementation has to live<br class="">in the header, because it depends on the template arguments.<br class="">4. We have many unnecessary dependencies on IRBuilder.h,<br class="">because it is not easy to forward-declare. (Significant parts of<br class="">the backend depend on it via TargetLowering.h, for example.)<br class=""><br class="">This patch addresses the issue by making the following changes:<br class=""><br class="">* IRBuilderDefaultInserter::InsertHelper becomes virtual.<br class=""> IRBuilderBase accepts a reference to it.<br class="">* IRBuilderFolder is introduced as a virtual base class. It is<br class=""> implemented by ConstantFolder (default), NoFolder and TargetFolder.<br class=""> IRBuilderBase has a reference to this as well.<br class="">* All the logic is moved from IRBuilder to IRBuilderBase. This means<br class=""> that methods can in the future replace their IRBuilder<> & uses<br class=""> (or other specific IRBuilder types) with IRBuilderBase & and thus<br class=""> be usable with different IRBuilders.<br class="">* The IRBuilder class is now a thin wrapper around IRBuilderBase.<br class=""> Essentially it only stores the folder and inserter and takes care<br class=""> of constructing the base builder.<br class=""><br class="">What this patch doesn't do, but should be simple followups after this change:<br class=""><br class="">* Fixing use of the inserter for creation methods originally defined<br class=""> on IRBuilderBase.<br class="">* Replacing IRBuilder<> uses in arguments with IRBuilderBase, where useful.<br class="">* Moving code from the IRBuilder header to the source file.<br class=""><br class=""><blockquote type="cite" class="">From the user perspective, these changes should be mostly transparent:<br class=""></blockquote>The only thing that consumers using a custom inserted may need to do is<br class="">inherit from IRBuilderDefaultInserter publicly and mark their InsertHelper<br class="">as public.<br class=""><br class="">Differential Revision: https://reviews.llvm.org/D73835<br class=""><br class="">Added: <br class=""> llvm/include/llvm/IR/IRBuilderFolder.h<br class=""><br class="">Modified: <br class=""> clang/lib/CodeGen/CGBuilder.h<br class=""> llvm/include/llvm/Analysis/TargetFolder.h<br class=""> llvm/include/llvm/IR/ConstantFolder.h<br class=""> llvm/include/llvm/IR/IRBuilder.h<br class=""> llvm/include/llvm/IR/NoFolder.h<br class=""> llvm/lib/Analysis/ConstantFolding.cpp<br class=""> llvm/lib/IR/IRBuilder.cpp<br class=""> llvm/lib/Transforms/Scalar/SROA.cpp<br class=""> polly/include/polly/CodeGen/IRBuilder.h<br class=""><br class="">Removed: <br class=""><br class=""><br class=""><br class="">################################################################################<br class="">diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h<br class="">index 7687f7990d99..38e96c0f4ee6 100644<br class="">--- a/clang/lib/CodeGen/CGBuilder.h<br class="">+++ b/clang/lib/CodeGen/CGBuilder.h<br class="">@@ -22,16 +22,15 @@ class CodeGenFunction;<br class=""> /// This is an IRBuilder insertion helper that forwards to<br class=""> /// CodeGenFunction::InsertHelper, which adds necessary metadata to<br class=""> /// instructions.<br class="">-class CGBuilderInserter : protected llvm::IRBuilderDefaultInserter {<br class="">+class CGBuilderInserter final : public llvm::IRBuilderDefaultInserter {<br class=""> public:<br class=""> CGBuilderInserter() = default;<br class=""> explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}<br class=""><br class="">-protected:<br class=""> /// This forwards to CodeGenFunction::InsertHelper.<br class=""> void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,<br class=""> llvm::BasicBlock *BB,<br class="">- llvm::BasicBlock::iterator InsertPt) const;<br class="">+ llvm::BasicBlock::iterator InsertPt) const override;<br class=""> private:<br class=""> CodeGenFunction *CGF = nullptr;<br class=""> };<br class=""><br class="">diff --git a/llvm/include/llvm/Analysis/TargetFolder.h b/llvm/include/llvm/Analysis/TargetFolder.h<br class="">index 7ab6562be440..712c1a2e8118 100644<br class="">--- a/llvm/include/llvm/Analysis/TargetFolder.h<br class="">+++ b/llvm/include/llvm/Analysis/TargetFolder.h<br class="">@@ -22,13 +22,14 @@<br class=""> #include "llvm/Analysis/ConstantFolding.h"<br class=""> #include "llvm/IR/Constants.h"<br class=""> #include "llvm/IR/InstrTypes.h"<br class="">+#include "llvm/IR/IRBuilderFolder.h"<br class=""><br class=""> namespace llvm {<br class=""><br class=""> class DataLayout;<br class=""><br class=""> /// TargetFolder - Create constants with target dependent folding.<br class="">-class TargetFolder {<br class="">+class TargetFolder final : public IRBuilderFolder {<br class=""> const DataLayout &DL;<br class=""><br class=""> /// Fold - Fold the constant using target specific information.<br class="">@@ -38,6 +39,8 @@ class TargetFolder {<br class=""> return C;<br class=""> }<br class=""><br class="">+ virtual void anchor();<br class="">+<br class=""> public:<br class=""> explicit TargetFolder(const DataLayout &DL) : DL(DL) {}<br class=""><br class="">@@ -46,66 +49,70 @@ class TargetFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateAdd(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return Fold(ConstantExpr::getAdd(LHS, RHS, HasNUW, HasNSW));<br class=""> }<br class="">- Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFAdd(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getFAdd(LHS, RHS));<br class=""> }<br class=""> Constant *CreateSub(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return Fold(ConstantExpr::getSub(LHS, RHS, HasNUW, HasNSW));<br class=""> }<br class="">- Constant *CreateFSub(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFSub(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getFSub(LHS, RHS));<br class=""> }<br class=""> Constant *CreateMul(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return Fold(ConstantExpr::getMul(LHS, RHS, HasNUW, HasNSW));<br class=""> }<br class="">- Constant *CreateFMul(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFMul(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getFMul(LHS, RHS));<br class=""> }<br class="">- Constant *CreateUDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{<br class="">+ Constant *CreateUDiv(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const override {<br class=""> return Fold(ConstantExpr::getUDiv(LHS, RHS, isExact));<br class=""> }<br class="">- Constant *CreateSDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{<br class="">+ Constant *CreateSDiv(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const override {<br class=""> return Fold(ConstantExpr::getSDiv(LHS, RHS, isExact));<br class=""> }<br class="">- Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFDiv(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getFDiv(LHS, RHS));<br class=""> }<br class="">- Constant *CreateURem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateURem(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getURem(LHS, RHS));<br class=""> }<br class="">- Constant *CreateSRem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateSRem(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getSRem(LHS, RHS));<br class=""> }<br class="">- Constant *CreateFRem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFRem(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getFRem(LHS, RHS));<br class=""> }<br class=""> Constant *CreateShl(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return Fold(ConstantExpr::getShl(LHS, RHS, HasNUW, HasNSW));<br class=""> }<br class="">- Constant *CreateLShr(Constant *LHS, Constant *RHS, bool isExact = false)const{<br class="">+ Constant *CreateLShr(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const override {<br class=""> return Fold(ConstantExpr::getLShr(LHS, RHS, isExact));<br class=""> }<br class="">- Constant *CreateAShr(Constant *LHS, Constant *RHS, bool isExact = false)const{<br class="">+ Constant *CreateAShr(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const override {<br class=""> return Fold(ConstantExpr::getAShr(LHS, RHS, isExact));<br class=""> }<br class="">- Constant *CreateAnd(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateAnd(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getAnd(LHS, RHS));<br class=""> }<br class="">- Constant *CreateOr(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateOr(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getOr(LHS, RHS));<br class=""> }<br class="">- Constant *CreateXor(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateXor(Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getXor(LHS, RHS));<br class=""> }<br class=""><br class=""> Constant *CreateBinOp(Instruction::BinaryOps Opc,<br class="">- Constant *LHS, Constant *RHS) const {<br class="">+ Constant *LHS, Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::get(Opc, LHS, RHS));<br class=""> }<br class=""><br class="">@@ -114,17 +121,17 @@ class TargetFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateNeg(Constant *C,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return Fold(ConstantExpr::getNeg(C, HasNUW, HasNSW));<br class=""> }<br class="">- Constant *CreateFNeg(Constant *C) const {<br class="">+ Constant *CreateFNeg(Constant *C) const override {<br class=""> return Fold(ConstantExpr::getFNeg(C));<br class=""> }<br class="">- Constant *CreateNot(Constant *C) const {<br class="">+ Constant *CreateNot(Constant *C) const override {<br class=""> return Fold(ConstantExpr::getNot(C));<br class=""> }<br class=""><br class="">- Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const {<br class="">+ Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override {<br class=""> return Fold(ConstantExpr::get(Opc, C));<br class=""> }<br class=""><br class="">@@ -133,33 +140,34 @@ class TargetFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ ArrayRef<Constant *> IdxList) const override {<br class=""> return Fold(ConstantExpr::getGetElementPtr(Ty, C, IdxList));<br class=""> }<br class="">- Constant *CreateGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const {<br class="">+ Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class=""> return Fold(ConstantExpr::getGetElementPtr(Ty, C, Idx));<br class=""> }<br class=""> Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ ArrayRef<Value *> IdxList) const override {<br class=""> return Fold(ConstantExpr::getGetElementPtr(Ty, C, IdxList));<br class=""> }<br class=""><br class="">- Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ Constant *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Constant *> IdxList) const override {<br class=""> return Fold(ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList));<br class=""> }<br class=""> Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class=""> return Fold(ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx));<br class=""> }<br class="">- Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ Constant *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Value *> IdxList) const override {<br class=""> return Fold(ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList));<br class=""> }<br class=""><br class="">@@ -168,54 +176,54 @@ class TargetFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateCast(Instruction::CastOps Op, Constant *C,<br class="">- Type *DestTy) const {<br class="">+ Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getCast(Op, C, DestTy));<br class=""> }<br class=""> Constant *CreateIntCast(Constant *C, Type *DestTy,<br class="">- bool isSigned) const {<br class="">+ bool isSigned) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getIntegerCast(C, DestTy, isSigned));<br class=""> }<br class="">- Constant *CreatePointerCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreatePointerCast(Constant *C, Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getPointerCast(C, DestTy));<br class=""> }<br class="">- Constant *CreateFPCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateFPCast(Constant *C, Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getFPCast(C, DestTy));<br class=""> }<br class="">- Constant *CreateBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::BitCast, C, DestTy);<br class=""> }<br class="">- Constant *CreateIntToPtr(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateIntToPtr(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::IntToPtr, C, DestTy);<br class=""> }<br class="">- Constant *CreatePtrToInt(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreatePtrToInt(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::PtrToInt, C, DestTy);<br class=""> }<br class="">- Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getZExtOrBitCast(C, DestTy));<br class=""> }<br class="">- Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getSExtOrBitCast(C, DestTy));<br class=""> }<br class="">- Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getTruncOrBitCast(C, DestTy));<br class=""> }<br class=""><br class=""> Constant *CreatePointerBitCastOrAddrSpaceCast(Constant *C,<br class="">- Type *DestTy) const {<br class="">+ Type *DestTy) const override {<br class=""> if (C->getType() == DestTy)<br class=""> return C; // avoid calling Fold<br class=""> return Fold(ConstantExpr::getPointerBitCastOrAddrSpaceCast(C, DestTy));<br class="">@@ -226,11 +234,11 @@ class TargetFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS,<br class="">- Constant *RHS) const {<br class="">+ Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getCompare(P, LHS, RHS));<br class=""> }<br class=""> Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS,<br class="">- Constant *RHS) const {<br class="">+ Constant *RHS) const override {<br class=""> return Fold(ConstantExpr::getCompare(P, LHS, RHS));<br class=""> }<br class=""><br class="">@@ -238,31 +246,32 @@ class TargetFolder {<br class=""> // Other Instructions<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class="">- Constant *CreateSelect(Constant *C, Constant *True, Constant *False) const {<br class="">+ Constant *CreateSelect(Constant *C, Constant *True,<br class="">+ Constant *False) const override {<br class=""> return Fold(ConstantExpr::getSelect(C, True, False));<br class=""> }<br class=""><br class="">- Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const {<br class="">+ Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const override {<br class=""> return Fold(ConstantExpr::getExtractElement(Vec, Idx));<br class=""> }<br class=""><br class=""> Constant *CreateInsertElement(Constant *Vec, Constant *NewElt,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> return Fold(ConstantExpr::getInsertElement(Vec, NewElt, Idx));<br class=""> }<br class=""><br class=""> Constant *CreateShuffleVector(Constant *V1, Constant *V2,<br class="">- Constant *Mask) const {<br class="">+ Constant *Mask) const override {<br class=""> return Fold(ConstantExpr::getShuffleVector(V1, V2, Mask));<br class=""> }<br class=""><br class=""> Constant *CreateExtractValue(Constant *Agg,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return Fold(ConstantExpr::getExtractValue(Agg, IdxList));<br class=""> }<br class=""><br class=""> Constant *CreateInsertValue(Constant *Agg, Constant *Val,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return Fold(ConstantExpr::getInsertValue(Agg, Val, IdxList));<br class=""> }<br class=""> };<br class=""><br class="">diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h<br class="">index 5a5cabfd0206..32939e79cd1d 100644<br class="">--- a/llvm/include/llvm/IR/ConstantFolder.h<br class="">+++ b/llvm/include/llvm/IR/ConstantFolder.h<br class="">@@ -20,11 +20,14 @@<br class=""> #include "llvm/IR/Constants.h"<br class=""> #include "llvm/IR/InstrTypes.h"<br class=""> #include "llvm/IR/Instruction.h"<br class="">+#include "llvm/IR/IRBuilderFolder.h"<br class=""><br class=""> namespace llvm {<br class=""><br class=""> /// ConstantFolder - Create constants with minimum, target independent, folding.<br class="">-class ConstantFolder {<br class="">+class ConstantFolder final : public IRBuilderFolder {<br class="">+ virtual void anchor();<br class="">+<br class=""> public:<br class=""> explicit ConstantFolder() = default;<br class=""><br class="">@@ -33,87 +36,87 @@ class ConstantFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateAdd(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return ConstantExpr::getAdd(LHS, RHS, HasNUW, HasNSW);<br class=""> }<br class=""><br class="">- Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFAdd(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getFAdd(LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateSub(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return ConstantExpr::getSub(LHS, RHS, HasNUW, HasNSW);<br class=""> }<br class=""><br class="">- Constant *CreateFSub(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFSub(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getFSub(LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateMul(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return ConstantExpr::getMul(LHS, RHS, HasNUW, HasNSW);<br class=""> }<br class=""><br class="">- Constant *CreateFMul(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFMul(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getFMul(LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateUDiv(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> return ConstantExpr::getUDiv(LHS, RHS, isExact);<br class=""> }<br class=""><br class=""> Constant *CreateSDiv(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> return ConstantExpr::getSDiv(LHS, RHS, isExact);<br class=""> }<br class=""><br class="">- Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFDiv(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getFDiv(LHS, RHS);<br class=""> }<br class=""><br class="">- Constant *CreateURem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateURem(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getURem(LHS, RHS);<br class=""> }<br class=""><br class="">- Constant *CreateSRem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateSRem(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getSRem(LHS, RHS);<br class=""> }<br class=""><br class="">- Constant *CreateFRem(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateFRem(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getFRem(LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateShl(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return ConstantExpr::getShl(LHS, RHS, HasNUW, HasNSW);<br class=""> }<br class=""><br class=""> Constant *CreateLShr(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> return ConstantExpr::getLShr(LHS, RHS, isExact);<br class=""> }<br class=""><br class=""> Constant *CreateAShr(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> return ConstantExpr::getAShr(LHS, RHS, isExact);<br class=""> }<br class=""><br class="">- Constant *CreateAnd(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateAnd(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getAnd(LHS, RHS);<br class=""> }<br class=""><br class="">- Constant *CreateOr(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateOr(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getOr(LHS, RHS);<br class=""> }<br class=""><br class="">- Constant *CreateXor(Constant *LHS, Constant *RHS) const {<br class="">+ Constant *CreateXor(Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::getXor(LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateBinOp(Instruction::BinaryOps Opc,<br class="">- Constant *LHS, Constant *RHS) const {<br class="">+ Constant *LHS, Constant *RHS) const override {<br class=""> return ConstantExpr::get(Opc, LHS, RHS);<br class=""> }<br class=""><br class="">@@ -122,19 +125,19 @@ class ConstantFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateNeg(Constant *C,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false, bool HasNSW = false) const override {<br class=""> return ConstantExpr::getNeg(C, HasNUW, HasNSW);<br class=""> }<br class=""><br class="">- Constant *CreateFNeg(Constant *C) const {<br class="">+ Constant *CreateFNeg(Constant *C) const override {<br class=""> return ConstantExpr::getFNeg(C);<br class=""> }<br class=""><br class="">- Constant *CreateNot(Constant *C) const {<br class="">+ Constant *CreateNot(Constant *C) const override {<br class=""> return ConstantExpr::getNot(C);<br class=""> }<br class=""><br class="">- Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const {<br class="">+ Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override {<br class=""> return ConstantExpr::get(Opc, C);<br class=""> }<br class=""><br class="">@@ -143,11 +146,12 @@ class ConstantFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ ArrayRef<Constant *> IdxList) const override {<br class=""> return ConstantExpr::getGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class="">- Constant *CreateGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const {<br class="">+ Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class="">@@ -155,25 +159,25 @@ class ConstantFolder {<br class=""> }<br class=""><br class=""> Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ ArrayRef<Value *> IdxList) const override {<br class=""> return ConstantExpr::getGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class="">- Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ Constant *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Constant *> IdxList) const override {<br class=""> return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class=""> Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class=""> return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx);<br class=""> }<br class=""><br class="">- Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ Constant *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Value *> IdxList) const override {<br class=""> return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class="">@@ -182,49 +186,49 @@ class ConstantFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateCast(Instruction::CastOps Op, Constant *C,<br class="">- Type *DestTy) const {<br class="">+ Type *DestTy) const override {<br class=""> return ConstantExpr::getCast(Op, C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreatePointerCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreatePointerCast(Constant *C, Type *DestTy) const override {<br class=""> return ConstantExpr::getPointerCast(C, DestTy);<br class=""> }<br class=""><br class=""> Constant *CreatePointerBitCastOrAddrSpaceCast(Constant *C,<br class="">- Type *DestTy) const {<br class="">+ Type *DestTy) const override {<br class=""> return ConstantExpr::getPointerBitCastOrAddrSpaceCast(C, DestTy);<br class=""> }<br class=""><br class=""> Constant *CreateIntCast(Constant *C, Type *DestTy,<br class="">- bool isSigned) const {<br class="">+ bool isSigned) const override {<br class=""> return ConstantExpr::getIntegerCast(C, DestTy, isSigned);<br class=""> }<br class=""><br class="">- Constant *CreateFPCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateFPCast(Constant *C, Type *DestTy) const override {<br class=""> return ConstantExpr::getFPCast(C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreateBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::BitCast, C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreateIntToPtr(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateIntToPtr(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::IntToPtr, C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreatePtrToInt(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreatePtrToInt(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::PtrToInt, C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return ConstantExpr::getZExtOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return ConstantExpr::getSExtOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">- Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return ConstantExpr::getTruncOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">@@ -233,12 +237,12 @@ class ConstantFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS,<br class="">- Constant *RHS) const {<br class="">+ Constant *RHS) const override {<br class=""> return ConstantExpr::getCompare(P, LHS, RHS);<br class=""> }<br class=""><br class=""> Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS,<br class="">- Constant *RHS) const {<br class="">+ Constant *RHS) const override {<br class=""> return ConstantExpr::getCompare(P, LHS, RHS);<br class=""> }<br class=""><br class="">@@ -246,31 +250,32 @@ class ConstantFolder {<br class=""> // Other Instructions<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class="">- Constant *CreateSelect(Constant *C, Constant *True, Constant *False) const {<br class="">+ Constant *CreateSelect(Constant *C, Constant *True,<br class="">+ Constant *False) const override {<br class=""> return ConstantExpr::getSelect(C, True, False);<br class=""> }<br class=""><br class="">- Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const {<br class="">+ Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const override {<br class=""> return ConstantExpr::getExtractElement(Vec, Idx);<br class=""> }<br class=""><br class=""> Constant *CreateInsertElement(Constant *Vec, Constant *NewElt,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> return ConstantExpr::getInsertElement(Vec, NewElt, Idx);<br class=""> }<br class=""><br class=""> Constant *CreateShuffleVector(Constant *V1, Constant *V2,<br class="">- Constant *Mask) const {<br class="">+ Constant *Mask) const override {<br class=""> return ConstantExpr::getShuffleVector(V1, V2, Mask);<br class=""> }<br class=""><br class=""> Constant *CreateExtractValue(Constant *Agg,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return ConstantExpr::getExtractValue(Agg, IdxList);<br class=""> }<br class=""><br class=""> Constant *CreateInsertValue(Constant *Agg, Constant *Val,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return ConstantExpr::getInsertValue(Agg, Val, IdxList);<br class=""> }<br class=""> };<br class=""><br class="">diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h<br class="">index c9ae136f4d6c..825a2426b742 100644<br class="">--- a/llvm/include/llvm/IR/IRBuilder.h<br class="">+++ b/llvm/include/llvm/IR/IRBuilder.h<br class="">@@ -59,9 +59,12 @@ class Use;<br class=""> ///<br class=""> /// By default, this inserts the instruction at the insertion point.<br class=""> class IRBuilderDefaultInserter {<br class="">-protected:<br class="">- void InsertHelper(Instruction *I, const Twine &Name,<br class="">- BasicBlock *BB, BasicBlock::iterator InsertPt) const {<br class="">+public:<br class="">+ virtual ~IRBuilderDefaultInserter();<br class="">+<br class="">+ virtual void InsertHelper(Instruction *I, const Twine &Name,<br class="">+ BasicBlock *BB,<br class="">+ BasicBlock::iterator InsertPt) const {<br class=""> if (BB) BB->getInstList().insert(InsertPt, I);<br class=""> I->setName(Name);<br class=""> }<br class="">@@ -69,16 +72,18 @@ class IRBuilderDefaultInserter {<br class=""><br class=""> /// Provides an 'InsertHelper' that calls a user-provided callback after<br class=""> /// performing the default insertion.<br class="">-class IRBuilderCallbackInserter : IRBuilderDefaultInserter {<br class="">+class IRBuilderCallbackInserter : public IRBuilderDefaultInserter {<br class=""> std::function<void(Instruction *)> Callback;<br class=""><br class=""> public:<br class="">+ virtual ~IRBuilderCallbackInserter();<br class="">+<br class=""> IRBuilderCallbackInserter(std::function<void(Instruction *)> Callback)<br class=""> : Callback(std::move(Callback)) {}<br class=""><br class="">-protected:<br class=""> void InsertHelper(Instruction *I, const Twine &Name,<br class="">- BasicBlock *BB, BasicBlock::iterator InsertPt) const {<br class="">+ BasicBlock *BB,<br class="">+ BasicBlock::iterator InsertPt) const override {<br class=""> IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);<br class=""> Callback(I);<br class=""> }<br class="">@@ -92,6 +97,8 @@ class IRBuilderBase {<br class=""> BasicBlock *BB;<br class=""> BasicBlock::iterator InsertPt;<br class=""> LLVMContext &Context;<br class="">+ const IRBuilderFolder &Folder;<br class="">+ const IRBuilderDefaultInserter &Inserter;<br class=""><br class=""> MDNode *DefaultFPMathTag;<br class=""> FastMathFlags FMF;<br class="">@@ -103,15 +110,37 @@ class IRBuilderBase {<br class=""> ArrayRef<OperandBundleDef> DefaultOperandBundles;<br class=""><br class=""> public:<br class="">- IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : Context(context), DefaultFPMathTag(FPMathTag), IsFPConstrained(false),<br class="">+ IRBuilderBase(LLVMContext &context, const IRBuilderFolder &Folder,<br class="">+ const IRBuilderDefaultInserter &Inserter,<br class="">+ MDNode *FPMathTag, ArrayRef<OperandBundleDef> OpBundles)<br class="">+ : Context(context), Folder(Folder), Inserter(Inserter),<br class="">+ DefaultFPMathTag(FPMathTag), IsFPConstrained(false),<br class=""> DefaultConstrainedExcept(fp::ebStrict),<br class=""> DefaultConstrainedRounding(fp::rmDynamic),<br class=""> DefaultOperandBundles(OpBundles) {<br class=""> ClearInsertionPoint();<br class=""> }<br class=""><br class="">+ /// Insert and return the specified instruction.<br class="">+ template<typename InstTy><br class="">+ InstTy *Insert(InstTy *I, const Twine &Name = "") const {<br class="">+ Inserter.InsertHelper(I, Name, BB, InsertPt);<br class="">+ SetInstDebugLocation(I);<br class="">+ return I;<br class="">+ }<br class="">+<br class="">+ /// No-op overload to handle constants.<br class="">+ Constant *Insert(Constant *C, const Twine& = "") const {<br class="">+ return C;<br class="">+ }<br class="">+<br class="">+ Value *Insert(Value *V, const Twine& = "") const {<br class="">+ if (Instruction *I = dyn_cast<Instruction>(V))<br class="">+ return Insert(I);<br class="">+ assert(isa<Constant>(V));<br class="">+ return V;<br class="">+ }<br class="">+<br class=""> //===--------------------------------------------------------------------===//<br class=""> // Builder configuration methods<br class=""> //===--------------------------------------------------------------------===//<br class="">@@ -920,89 +949,6 @@ class IRBuilderBase {<br class=""> const Twine &Name = "");<br class=""><br class=""> Value *getCastedInt8PtrValue(Value *Ptr);<br class="">-};<br class="">-<br class="">-/// This provides a uniform API for creating instructions and inserting<br class="">-/// them into a basic block: either at the end of a BasicBlock, or at a specific<br class="">-/// iterator location in a block.<br class="">-///<br class="">-/// Note that the builder does not expose the full generality of LLVM<br class="">-/// instructions. For access to extra instruction properties, use the mutators<br class="">-/// (e.g. setVolatile) on the instructions after they have been<br class="">-/// created. Convenience state exists to specify fast-math flags and fp-math<br class="">-/// tags.<br class="">-///<br class="">-/// The first template argument specifies a class to use for creating constants.<br class="">-/// This defaults to creating minimally folded constants. The second template<br class="">-/// argument allows clients to specify custom insertion hooks that are called on<br class="">-/// every newly created insertion.<br class="">-template <typename T = ConstantFolder,<br class="">- typename Inserter = IRBuilderDefaultInserter><br class="">-class IRBuilder : public IRBuilderBase, public Inserter {<br class="">- T Folder;<br class="">-<br class="">-public:<br class="">- IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(),<br class="">- MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)),<br class="">- Folder(F) {}<br class="">-<br class="">- explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(C, FPMathTag, OpBundles) {}<br class="">-<br class="">- explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {<br class="">- SetInsertPoint(TheBB);<br class="">- }<br class="">-<br class="">- explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) {<br class="">- SetInsertPoint(TheBB);<br class="">- }<br class="">-<br class="">- explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles) {<br class="">- SetInsertPoint(IP);<br class="">- }<br class="">-<br class="">- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F,<br class="">- MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {<br class="">- SetInsertPoint(TheBB, IP);<br class="">- }<br class="">-<br class="">- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,<br class="">- MDNode *FPMathTag = nullptr,<br class="">- ArrayRef<OperandBundleDef> OpBundles = None)<br class="">- : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) {<br class="">- SetInsertPoint(TheBB, IP);<br class="">- }<br class="">-<br class="">- /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard<br class="">- /// or FastMathFlagGuard instead.<br class="">- IRBuilder(const IRBuilder &) = delete;<br class="">-<br class="">- /// Get the constant folder being used.<br class="">- const T &getFolder() { return Folder; }<br class="">-<br class="">- /// Insert and return the specified instruction.<br class="">- template<typename InstTy><br class="">- InstTy *Insert(InstTy *I, const Twine &Name = "") const {<br class="">- this->InsertHelper(I, Name, BB, InsertPt);<br class="">- this->SetInstDebugLocation(I);<br class="">- return I;<br class="">- }<br class="">-<br class="">- /// No-op overload to handle constants.<br class="">- Constant *Insert(Constant *C, const Twine& = "") const {<br class="">- return C;<br class="">- }<br class=""><br class=""> //===--------------------------------------------------------------------===//<br class=""> // Instruction creation methods: Terminators<br class="">@@ -2980,6 +2926,83 @@ class IRBuilder : public IRBuilderBase, public Inserter {<br class=""> }<br class=""> };<br class=""><br class="">+/// This provides a uniform API for creating instructions and inserting<br class="">+/// them into a basic block: either at the end of a BasicBlock, or at a specific<br class="">+/// iterator location in a block.<br class="">+///<br class="">+/// Note that the builder does not expose the full generality of LLVM<br class="">+/// instructions. For access to extra instruction properties, use the mutators<br class="">+/// (e.g. setVolatile) on the instructions after they have been<br class="">+/// created. Convenience state exists to specify fast-math flags and fp-math<br class="">+/// tags.<br class="">+///<br class="">+/// The first template argument specifies a class to use for creating constants.<br class="">+/// This defaults to creating minimally folded constants. The second template<br class="">+/// argument allows clients to specify custom insertion hooks that are called on<br class="">+/// every newly created insertion.<br class="">+template <typename FolderTy = ConstantFolder,<br class="">+ typename InserterTy = IRBuilderDefaultInserter><br class="">+class IRBuilder : public IRBuilderBase {<br class="">+private:<br class="">+ FolderTy Folder;<br class="">+ InserterTy Inserter;<br class="">+<br class="">+public:<br class="">+ IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter = InserterTy(),<br class="">+ MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),<br class="">+ Folder(Folder), Inserter(Inserter) {}<br class="">+<br class="">+ explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}<br class="">+<br class="">+ explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,<br class="">+ MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,<br class="">+ FPMathTag, OpBundles), Folder(Folder) {<br class="">+ SetInsertPoint(TheBB);<br class="">+ }<br class="">+<br class="">+ explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,<br class="">+ FPMathTag, OpBundles) {<br class="">+ SetInsertPoint(TheBB);<br class="">+ }<br class="">+<br class="">+ explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter,<br class="">+ FPMathTag, OpBundles) {<br class="">+ SetInsertPoint(IP);<br class="">+ }<br class="">+<br class="">+ IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,<br class="">+ MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,<br class="">+ FPMathTag, OpBundles), Folder(Folder) {<br class="">+ SetInsertPoint(TheBB, IP);<br class="">+ }<br class="">+<br class="">+ IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,<br class="">+ MDNode *FPMathTag = nullptr,<br class="">+ ArrayRef<OperandBundleDef> OpBundles = None)<br class="">+ : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,<br class="">+ FPMathTag, OpBundles) {<br class="">+ SetInsertPoint(TheBB, IP);<br class="">+ }<br class="">+<br class="">+ /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard<br class="">+ /// or FastMathFlagGuard instead.<br class="">+ IRBuilder(const IRBuilder &) = delete;<br class="">+<br class="">+ InserterTy &getInserter() { return Inserter; }<br class="">+};<br class="">+<br class=""> // Create wrappers for C Binding types (see CBindingWrapping.h).<br class=""> DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)<br class=""><br class=""><br class="">diff --git a/llvm/include/llvm/IR/IRBuilderFolder.h b/llvm/include/llvm/IR/IRBuilderFolder.h<br class="">new file mode 100644<br class="">index 000000000000..a77a5213dcea<br class="">--- /dev/null<br class="">+++ b/llvm/include/llvm/IR/IRBuilderFolder.h<br class="">@@ -0,0 +1,141 @@<br class="">+//===- IRBuilderFolder.h - Const folder interface for IRBuilder -*- C++ -*-===//<br class="">+//<br class="">+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br class="">+// See https://llvm.org/LICENSE.txt for license information.<br class="">+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br class="">+//<br class="">+//===----------------------------------------------------------------------===//<br class="">+//<br class="">+// This file defines for constant folding interface used by IRBuilder.<br class="">+// It is implemented by ConstantFolder (default), TargetFolder and NoFoler.<br class="">+//<br class="">+//===----------------------------------------------------------------------===//<br class="">+<br class="">+#ifndef LLVM_IR_IRBUILDERFOLDER_H<br class="">+#define LLVM_IR_IRBUILDERFOLDER_H<br class="">+<br class="">+#include "llvm/ADT/ArrayRef.h"<br class="">+#include "llvm/IR/InstrTypes.h"<br class="">+#include "llvm/IR/Instruction.h"<br class="">+<br class="">+namespace llvm {<br class="">+<br class="">+/// IRBuilderFolder - Interface for constant folding in IRBuilder.<br class="">+class IRBuilderFolder {<br class="">+public:<br class="">+ virtual ~IRBuilderFolder();<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Binary Operators<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateAdd(Constant *LHS, Constant *RHS,<br class="">+ bool HasNUW = false, bool HasNSW = false) const = 0;<br class="">+ virtual Value *CreateFAdd(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateSub(Constant *LHS, Constant *RHS,<br class="">+ bool HasNUW = false, bool HasNSW = false) const = 0;<br class="">+ virtual Value *CreateFSub(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateMul(Constant *LHS, Constant *RHS,<br class="">+ bool HasNUW = false, bool HasNSW = false) const = 0;<br class="">+ virtual Value *CreateFMul(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateUDiv(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const = 0;<br class="">+ virtual Value *CreateSDiv(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const = 0;<br class="">+ virtual Value *CreateFDiv(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateURem(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateSRem(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateFRem(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateShl(Constant *LHS, Constant *RHS,<br class="">+ bool HasNUW = false, bool HasNSW = false) const = 0;<br class="">+ virtual Value *CreateLShr(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const = 0;<br class="">+ virtual Value *CreateAShr(Constant *LHS, Constant *RHS,<br class="">+ bool isExact = false) const = 0;<br class="">+ virtual Value *CreateAnd(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateOr(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateXor(Constant *LHS, Constant *RHS) const = 0;<br class="">+ virtual Value *CreateBinOp(Instruction::BinaryOps Opc,<br class="">+ Constant *LHS, Constant *RHS) const = 0;<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Unary Operators<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateNeg(Constant *C,<br class="">+ bool HasNUW = false, bool HasNSW = false) const = 0;<br class="">+ virtual Value *CreateFNeg(Constant *C) const = 0;<br class="">+ virtual Value *CreateNot(Constant *C) const = 0;<br class="">+ virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const = 0;<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Memory Instructions<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ ArrayRef<Constant *> IdxList) const = 0;<br class="">+ // This form of the function only exists to avoid ambiguous overload<br class="">+ // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class="">+ // ArrayRef<Value *>.<br class="">+ virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ Constant *Idx) const = 0;<br class="">+ virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ ArrayRef<Value *> IdxList) const = 0;<br class="">+ virtual Value *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Constant *> IdxList) const = 0;<br class="">+ // This form of the function only exists to avoid ambiguous overload<br class="">+ // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class="">+ // ArrayRef<Value *>.<br class="">+ virtual Value *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">+ Constant *Idx) const = 0;<br class="">+ virtual Value *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Value *> IdxList) const = 0;<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Cast/Conversion Operators<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateCast(Instruction::CastOps Op, Constant *C,<br class="">+ Type *DestTy) const = 0;<br class="">+ virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,<br class="">+ Type *DestTy) const = 0;<br class="">+ virtual Value *CreateIntCast(Constant *C, Type *DestTy,<br class="">+ bool isSigned) const = 0;<br class="">+ virtual Value *CreateFPCast(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreateBitCast(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreateIntToPtr(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreatePtrToInt(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreateZExtOrBitCast(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreateSExtOrBitCast(Constant *C, Type *DestTy) const = 0;<br class="">+ virtual Value *CreateTruncOrBitCast(Constant *C, Type *DestTy) const = 0;<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Compare Instructions<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateICmp(CmpInst::Predicate P, Constant *LHS,<br class="">+ Constant *RHS) const = 0;<br class="">+ virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,<br class="">+ Constant *RHS) const = 0;<br class="">+<br class="">+ //===--------------------------------------------------------------------===//<br class="">+ // Other Instructions<br class="">+ //===--------------------------------------------------------------------===//<br class="">+<br class="">+ virtual Value *CreateSelect(Constant *C, Constant *True,<br class="">+ Constant *False) const = 0;<br class="">+ virtual Value *CreateExtractElement(Constant *Vec, Constant *Idx) const = 0;<br class="">+ virtual Value *CreateInsertElement(Constant *Vec, Constant *NewElt,<br class="">+ Constant *Idx) const = 0;<br class="">+ virtual Value *CreateShuffleVector(Constant *V1, Constant *V2,<br class="">+ Constant *Mask) const = 0;<br class="">+ virtual Value *CreateExtractValue(Constant *Agg,<br class="">+ ArrayRef<unsigned> IdxList) const = 0;<br class="">+ virtual Value *CreateInsertValue(Constant *Agg, Constant *Val,<br class="">+ ArrayRef<unsigned> IdxList) const = 0;<br class="">+};<br class="">+<br class="">+} // end namespace llvm<br class="">+<br class="">+#endif // LLVM_IR_IRBUILDERFOLDER_H<br class=""><br class="">diff --git a/llvm/include/llvm/IR/NoFolder.h b/llvm/include/llvm/IR/NoFolder.h<br class="">index c03cdee1eb83..1e35cfe096eb 100644<br class="">--- a/llvm/include/llvm/IR/NoFolder.h<br class="">+++ b/llvm/include/llvm/IR/NoFolder.h<br class="">@@ -26,11 +26,14 @@<br class=""> #include "llvm/IR/InstrTypes.h"<br class=""> #include "llvm/IR/Instruction.h"<br class=""> #include "llvm/IR/Instructions.h"<br class="">+#include "llvm/IR/IRBuilderFolder.h"<br class=""><br class=""> namespace llvm {<br class=""><br class=""> /// NoFolder - Create "constants" (actually, instructions) with no folding.<br class="">-class NoFolder {<br class="">+class NoFolder final : public IRBuilderFolder {<br class="">+ virtual void anchor();<br class="">+<br class=""> public:<br class=""> explicit NoFolder() = default;<br class=""><br class="">@@ -39,73 +42,76 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Instruction *CreateAdd(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false,<br class="">+ bool HasNSW = false) const override {<br class=""> BinaryOperator *BO = BinaryOperator::CreateAdd(LHS, RHS);<br class=""> if (HasNUW) BO->setHasNoUnsignedWrap();<br class=""> if (HasNSW) BO->setHasNoSignedWrap();<br class=""> return BO;<br class=""> }<br class=""><br class="">- Instruction *CreateFAdd(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateFAdd(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateFAdd(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateSub(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false,<br class="">+ bool HasNSW = false) const override {<br class=""> BinaryOperator *BO = BinaryOperator::CreateSub(LHS, RHS);<br class=""> if (HasNUW) BO->setHasNoUnsignedWrap();<br class=""> if (HasNSW) BO->setHasNoSignedWrap();<br class=""> return BO;<br class=""> }<br class=""><br class="">- Instruction *CreateFSub(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateFSub(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateFSub(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateMul(Constant *LHS, Constant *RHS,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false,<br class="">+ bool HasNSW = false) const override {<br class=""> BinaryOperator *BO = BinaryOperator::CreateMul(LHS, RHS);<br class=""> if (HasNUW) BO->setHasNoUnsignedWrap();<br class=""> if (HasNSW) BO->setHasNoSignedWrap();<br class=""> return BO;<br class=""> }<br class=""><br class="">- Instruction *CreateFMul(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateFMul(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateFMul(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateUDiv(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> if (!isExact)<br class=""> return BinaryOperator::CreateUDiv(LHS, RHS);<br class=""> return BinaryOperator::CreateExactUDiv(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateSDiv(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> if (!isExact)<br class=""> return BinaryOperator::CreateSDiv(LHS, RHS);<br class=""> return BinaryOperator::CreateExactSDiv(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateFDiv(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateFDiv(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateFDiv(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateURem(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateURem(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateURem(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateSRem(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateSRem(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateSRem(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateFRem(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateFRem(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateFRem(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateShl(Constant *LHS, Constant *RHS, bool HasNUW = false,<br class="">- bool HasNSW = false) const {<br class="">+ bool HasNSW = false) const override {<br class=""> BinaryOperator *BO = BinaryOperator::CreateShl(LHS, RHS);<br class=""> if (HasNUW) BO->setHasNoUnsignedWrap();<br class=""> if (HasNSW) BO->setHasNoSignedWrap();<br class="">@@ -113,33 +119,33 @@ class NoFolder {<br class=""> }<br class=""><br class=""> Instruction *CreateLShr(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> if (!isExact)<br class=""> return BinaryOperator::CreateLShr(LHS, RHS);<br class=""> return BinaryOperator::CreateExactLShr(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateAShr(Constant *LHS, Constant *RHS,<br class="">- bool isExact = false) const {<br class="">+ bool isExact = false) const override {<br class=""> if (!isExact)<br class=""> return BinaryOperator::CreateAShr(LHS, RHS);<br class=""> return BinaryOperator::CreateExactAShr(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateAnd(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateAnd(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateAnd(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateOr(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateOr(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateOr(LHS, RHS);<br class=""> }<br class=""><br class="">- Instruction *CreateXor(Constant *LHS, Constant *RHS) const {<br class="">+ Instruction *CreateXor(Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::CreateXor(LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateBinOp(Instruction::BinaryOps Opc,<br class="">- Constant *LHS, Constant *RHS) const {<br class="">+ Constant *LHS, Constant *RHS) const override {<br class=""> return BinaryOperator::Create(Opc, LHS, RHS);<br class=""> }<br class=""><br class="">@@ -148,22 +154,24 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Instruction *CreateNeg(Constant *C,<br class="">- bool HasNUW = false, bool HasNSW = false) const {<br class="">+ bool HasNUW = false,<br class="">+ bool HasNSW = false) const override {<br class=""> BinaryOperator *BO = BinaryOperator::CreateNeg(C);<br class=""> if (HasNUW) BO->setHasNoUnsignedWrap();<br class=""> if (HasNSW) BO->setHasNoSignedWrap();<br class=""> return BO;<br class=""> }<br class=""><br class="">- Instruction *CreateFNeg(Constant *C) const {<br class="">+ Instruction *CreateFNeg(Constant *C) const override {<br class=""> return UnaryOperator::CreateFNeg(C);<br class=""> }<br class=""><br class="">- Instruction *CreateNot(Constant *C) const {<br class="">+ Instruction *CreateNot(Constant *C) const override {<br class=""> return BinaryOperator::CreateNot(C);<br class=""> }<br class=""><br class="">- Instruction *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const {<br class="">+ Instruction *CreateUnOp(Instruction::UnaryOps Opc,<br class="">+ Constant *C) const override {<br class=""> return UnaryOperator::Create(Opc, C);<br class=""> }<br class=""><br class="">@@ -172,11 +180,12 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ ArrayRef<Constant *> IdxList) const override {<br class=""> return ConstantExpr::getGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class="">- Constant *CreateGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const {<br class="">+ Constant *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class="">@@ -184,25 +193,25 @@ class NoFolder {<br class=""> }<br class=""><br class=""> Instruction *CreateGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ ArrayRef<Value *> IdxList) const override {<br class=""> return GetElementPtrInst::Create(Ty, C, IdxList);<br class=""> }<br class=""><br class="">- Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Constant *> IdxList) const {<br class="">+ Constant *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Constant *> IdxList) const override {<br class=""> return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList);<br class=""> }<br class=""><br class=""> Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> // This form of the function only exists to avoid ambiguous overload<br class=""> // warnings about whether to convert Idx to ArrayRef<Constant *> or<br class=""> // ArrayRef<Value *>.<br class=""> return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx);<br class=""> }<br class=""><br class="">- Instruction *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,<br class="">- ArrayRef<Value *> IdxList) const {<br class="">+ Instruction *CreateInBoundsGetElementPtr(<br class="">+ Type *Ty, Constant *C, ArrayRef<Value *> IdxList) const override {<br class=""> return GetElementPtrInst::CreateInBounds(Ty, C, IdxList);<br class=""> }<br class=""><br class="">@@ -211,49 +220,49 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Instruction *CreateCast(Instruction::CastOps Op, Constant *C,<br class="">- Type *DestTy) const {<br class="">+ Type *DestTy) const override {<br class=""> return CastInst::Create(Op, C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreatePointerCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreatePointerCast(Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreatePointerCast(C, DestTy);<br class=""> }<br class=""><br class=""> Instruction *CreatePointerBitCastOrAddrSpaceCast(<br class="">- Constant *C, Type *DestTy) const {<br class="">+ Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreatePointerBitCastOrAddrSpaceCast(C, DestTy);<br class=""> }<br class=""><br class=""> Instruction *CreateIntCast(Constant *C, Type *DestTy,<br class="">- bool isSigned) const {<br class="">+ bool isSigned) const override {<br class=""> return CastInst::CreateIntegerCast(C, DestTy, isSigned);<br class=""> }<br class=""><br class="">- Instruction *CreateFPCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateFPCast(Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreateFPCast(C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreateBitCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::BitCast, C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::IntToPtr, C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const override {<br class=""> return CreateCast(Instruction::PtrToInt, C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreateZExtOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreateSExtOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">- Instruction *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {<br class="">+ Instruction *CreateTruncOrBitCast(Constant *C, Type *DestTy) const override {<br class=""> return CastInst::CreateTruncOrBitCast(C, DestTy);<br class=""> }<br class=""><br class="">@@ -262,12 +271,12 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Instruction *CreateICmp(CmpInst::Predicate P,<br class="">- Constant *LHS, Constant *RHS) const {<br class="">+ Constant *LHS, Constant *RHS) const override {<br class=""> return new ICmpInst(P, LHS, RHS);<br class=""> }<br class=""><br class=""> Instruction *CreateFCmp(CmpInst::Predicate P,<br class="">- Constant *LHS, Constant *RHS) const {<br class="">+ Constant *LHS, Constant *RHS) const override {<br class=""> return new FCmpInst(P, LHS, RHS);<br class=""> }<br class=""><br class="">@@ -276,31 +285,32 @@ class NoFolder {<br class=""> //===--------------------------------------------------------------------===//<br class=""><br class=""> Instruction *CreateSelect(Constant *C,<br class="">- Constant *True, Constant *False) const {<br class="">+ Constant *True, Constant *False) const override {<br class=""> return SelectInst::Create(C, True, False);<br class=""> }<br class=""><br class="">- Instruction *CreateExtractElement(Constant *Vec, Constant *Idx) const {<br class="">+ Instruction *CreateExtractElement(Constant *Vec,<br class="">+ Constant *Idx) const override {<br class=""> return ExtractElementInst::Create(Vec, Idx);<br class=""> }<br class=""><br class=""> Instruction *CreateInsertElement(Constant *Vec, Constant *NewElt,<br class="">- Constant *Idx) const {<br class="">+ Constant *Idx) const override {<br class=""> return InsertElementInst::Create(Vec, NewElt, Idx);<br class=""> }<br class=""><br class=""> Instruction *CreateShuffleVector(Constant *V1, Constant *V2,<br class="">- Constant *Mask) const {<br class="">+ Constant *Mask) const override {<br class=""> return new ShuffleVectorInst(V1, V2, Mask);<br class=""> }<br class=""><br class=""> Instruction *CreateExtractValue(Constant *Agg,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return ExtractValueInst::Create(Agg, IdxList);<br class=""> }<br class=""><br class=""> Instruction *CreateInsertValue(Constant *Agg, Constant *Val,<br class="">- ArrayRef<unsigned> IdxList) const {<br class="">+ ArrayRef<unsigned> IdxList) const override {<br class=""> return InsertValueInst::Create(Agg, Val, IdxList);<br class=""> }<br class=""> };<br class=""><br class="">diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp<br class="">index 0e4828d912dc..059bf9a53275 100644<br class="">--- a/llvm/lib/Analysis/ConstantFolding.cpp<br class="">+++ b/llvm/lib/Analysis/ConstantFolding.cpp<br class="">@@ -23,6 +23,7 @@<br class=""> #include "llvm/ADT/STLExtras.h"<br class=""> #include "llvm/ADT/SmallVector.h"<br class=""> #include "llvm/ADT/StringRef.h"<br class="">+#include "llvm/Analysis/TargetFolder.h"<br class=""> #include "llvm/Analysis/TargetLibraryInfo.h"<br class=""> #include "llvm/Analysis/ValueTracking.h"<br class=""> #include "llvm/Analysis/VectorUtils.h"<br class="">@@ -2660,3 +2661,5 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,<br class=""><br class=""> return false;<br class=""> }<br class="">+<br class="">+void TargetFolder::anchor() {}<br class=""><br class="">diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp<br class="">index 0dd78f2f2d4b..457255b157cc 100644<br class="">--- a/llvm/lib/IR/IRBuilder.cpp<br class="">+++ b/llvm/lib/IR/IRBuilder.cpp<br class="">@@ -24,6 +24,7 @@<br class=""> #include "llvm/IR/Intrinsics.h"<br class=""> #include "llvm/IR/LLVMContext.h"<br class=""> #include "llvm/IR/Operator.h"<br class="">+#include "llvm/IR/NoFolder.h"<br class=""> #include "llvm/IR/Statepoint.h"<br class=""> #include "llvm/IR/Type.h"<br class=""> #include "llvm/IR/Value.h"<br class="">@@ -784,3 +785,9 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,<br class=""> Function *Fn = Intrinsic::getDeclaration(M, ID, Types);<br class=""> return createCallHelper(Fn, Args, this, Name, FMFSource);<br class=""> }<br class="">+<br class="">+IRBuilderDefaultInserter::~IRBuilderDefaultInserter() {}<br class="">+IRBuilderCallbackInserter::~IRBuilderCallbackInserter() {}<br class="">+IRBuilderFolder::~IRBuilderFolder() {}<br class="">+void ConstantFolder::anchor() {}<br class="">+void NoFolder::anchor() {}<br class=""><br class="">diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp<br class="">index 0038ac5038ca..c65244c1045d 100644<br class="">--- a/llvm/lib/Transforms/Scalar/SROA.cpp<br class="">+++ b/llvm/lib/Transforms/Scalar/SROA.cpp<br class="">@@ -129,7 +129,7 @@ namespace {<br class=""><br class=""> /// A custom IRBuilder inserter which prefixes all names, but only in<br class=""> /// Assert builds.<br class="">-class IRBuilderPrefixedInserter : public IRBuilderDefaultInserter {<br class="">+class IRBuilderPrefixedInserter final : public IRBuilderDefaultInserter {<br class=""> std::string Prefix;<br class=""><br class=""> const Twine getNameWithPrefix(const Twine &Name) const {<br class="">@@ -139,9 +139,8 @@ class IRBuilderPrefixedInserter : public IRBuilderDefaultInserter {<br class=""> public:<br class=""> void SetNamePrefix(const Twine &P) { Prefix = P.str(); }<br class=""><br class="">-protected:<br class=""> void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB,<br class="">- BasicBlock::iterator InsertPt) const {<br class="">+ BasicBlock::iterator InsertPt) const override {<br class=""> IRBuilderDefaultInserter::InsertHelper(I, getNameWithPrefix(Name), BB,<br class=""> InsertPt);<br class=""> }<br class="">@@ -2368,7 +2367,8 @@ class llvm::sroa::AllocaSliceRewriter<br class=""> Instruction *OldUserI = cast<Instruction>(OldUse->getUser());<br class=""> IRB.SetInsertPoint(OldUserI);<br class=""> IRB.SetCurrentDebugLocation(OldUserI->getDebugLoc());<br class="">- IRB.SetNamePrefix(Twine(NewAI.getName()) + "." + Twine(BeginOffset) + ".");<br class="">+ IRB.getInserter().SetNamePrefix(<br class="">+ Twine(NewAI.getName()) + "." + Twine(BeginOffset) + ".");<br class=""><br class=""> CanSROA &= visit(cast<Instruction>(OldUse->getUser()));<br class=""> if (VecTy || IntTy)<br class=""><br class="">diff --git a/polly/include/polly/CodeGen/IRBuilder.h b/polly/include/polly/CodeGen/IRBuilder.h<br class="">index 8aeef3856a07..fb5d14a8b88b 100644<br class="">--- a/polly/include/polly/CodeGen/IRBuilder.h<br class="">+++ b/polly/include/polly/CodeGen/IRBuilder.h<br class="">@@ -131,15 +131,14 @@ class ScopAnnotator {<br class=""> ///<br class=""> /// This is used to add additional items such as e.g. the llvm.loop.parallel<br class=""> /// metadata.<br class="">-class IRInserter : protected llvm::IRBuilderDefaultInserter {<br class="">+class IRInserter final : public llvm::IRBuilderDefaultInserter {<br class=""> public:<br class=""> IRInserter() = default;<br class=""> IRInserter(class ScopAnnotator &A) : Annotator(&A) {}<br class=""><br class="">-protected:<br class=""> void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,<br class=""> llvm::BasicBlock *BB,<br class="">- llvm::BasicBlock::iterator InsertPt) const {<br class="">+ llvm::BasicBlock::iterator InsertPt) const override {<br class=""> llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);<br class=""> if (Annotator)<br class=""> Annotator->annotate(I);<br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class="">llvm-commits@lists.llvm.org<br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>