[llvm] [SandboxIR][NFC] SingleLLVMInstructionImpl class (PR #102687)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 15:47:17 PDT 2024
https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/102687
>From efeb8413396289cb312b1296d3fd29950743e6f6 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Wed, 7 Aug 2024 10:09:15 -0700
Subject: [PATCH 1/2] [SandboxIR][NFC] SingleLLVMInstructionImpl class
This patch introduces the SingleLLVMInstructionImpl class which implements
a couple of functions shared across all Instructions that map to a single
LLVM Instructions. This avoids code replication.
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 214 ++++++------------------
1 file changed, 50 insertions(+), 164 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 4c452ce0b4a61..f744aa045b3ca 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -713,27 +713,43 @@ class Instruction : public sandboxir::User {
#endif
};
-class SelectInst : public Instruction {
- /// Use Context::createSelectInst(). Don't call the
- /// constructor directly.
- SelectInst(llvm::SelectInst *CI, Context &Ctx)
- : Instruction(ClassID::Select, Opcode::Select, CI, Ctx) {}
- friend Context; // for SelectInst()
+/// Instructions that contain a single LLVM Instruction can inherit from this.
+class SingleLLVMInstructionImpl : public Instruction {
+ SingleLLVMInstructionImpl(ClassID ID, Opcode Opc, llvm::Instruction *I,
+ sandboxir::Context &SBCtx)
+ : Instruction(ID, Opc, I, SBCtx) {}
+
+ // All instructions are friends with this so they can call the constructor.
+#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
+#include "llvm/SandboxIR/SandboxIRValues.def"
+ friend class UnaryInstruction;
+ friend class CallBase;
+
Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
return getOperandUseDefault(OpIdx, Verify);
}
SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
return {cast<llvm::Instruction>(Val)};
}
- static Value *createCommon(Value *Cond, Value *True, Value *False,
- const Twine &Name, IRBuilder<> &Builder,
- Context &Ctx);
public:
unsigned getUseOperandNo(const Use &Use) const final {
return getUseOperandNoDefault(Use);
}
unsigned getNumOfIRInstrs() const final { return 1u; }
+};
+
+class SelectInst : public SingleLLVMInstructionImpl {
+ /// Use Context::createSelectInst(). Don't call the
+ /// constructor directly.
+ SelectInst(llvm::SelectInst *CI, Context &Ctx)
+ : SingleLLVMInstructionImpl(ClassID::Select, Opcode::Select, CI, Ctx) {}
+ friend Context; // for SelectInst()
+ static Value *createCommon(Value *Cond, Value *True, Value *False,
+ const Twine &Name, IRBuilder<> &Builder,
+ Context &Ctx);
+
+public:
static Value *create(Value *Cond, Value *True, Value *False,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name = "");
@@ -759,18 +775,12 @@ class SelectInst : public Instruction {
#endif
};
-class InsertElementInst final : public Instruction {
+class InsertElementInst final : public SingleLLVMInstructionImpl {
/// Use Context::createInsertElementInst() instead.
InsertElementInst(llvm::Instruction *I, Context &Ctx)
- : Instruction(ClassID::InsertElement, Opcode::InsertElement, I, Ctx) {}
- friend class Context; // For accessing the constructor in
- // create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
+ : SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
+ I, Ctx) {}
+ friend class Context; // For accessing the constructor in create*()
public:
static Value *create(Value *Vec, Value *NewElt, Value *Idx,
@@ -787,10 +797,6 @@ class InsertElementInst final : public Instruction {
return llvm::InsertElementInst::isValidOperands(Vec->Val, NewElt->Val,
Idx->Val);
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
#ifndef NDEBUG
void verify() const final {
assert(isa<llvm::InsertElementInst>(Val) && "Expected InsertElementInst");
@@ -805,23 +811,13 @@ class InsertElementInst final : public Instruction {
#endif
};
-class BranchInst : public Instruction {
+class BranchInst : public SingleLLVMInstructionImpl {
/// Use Context::createBranchInst(). Don't call the constructor directly.
BranchInst(llvm::BranchInst *BI, Context &Ctx)
- : Instruction(ClassID::Br, Opcode::Br, BI, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::Br, Opcode::Br, BI, Ctx) {}
friend Context; // for BranchInst()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
static BranchInst *create(BasicBlock *IfTrue, Instruction *InsertBefore,
Context &Ctx);
static BranchInst *create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd,
@@ -900,11 +896,11 @@ class BranchInst : public Instruction {
};
/// An abstract class, parent of unary instructions.
-class UnaryInstruction : public Instruction {
+class UnaryInstruction : public SingleLLVMInstructionImpl {
protected:
UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI,
Context &Ctx)
- : Instruction(ID, Opc, LLVMI, Ctx) {}
+ : SingleLLVMInstructionImpl(ID, Opc, LLVMI, Ctx) {}
public:
static bool classof(const Instruction *I) {
@@ -920,23 +916,13 @@ class LoadInst final : public UnaryInstruction {
LoadInst(llvm::LoadInst *LI, Context &Ctx)
: UnaryInstruction(ClassID::Load, Opcode::Load, LI, Ctx) {}
friend Context; // for LoadInst()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
/// Return true if this is a load from a volatile memory location.
bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
/// Specify whether this is a volatile load or not.
void setVolatile(bool V);
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name = "");
@@ -965,27 +951,18 @@ class LoadInst final : public UnaryInstruction {
#endif
};
-class StoreInst final : public Instruction {
+class StoreInst final : public SingleLLVMInstructionImpl {
/// Use StoreInst::create().
StoreInst(llvm::StoreInst *SI, Context &Ctx)
- : Instruction(ClassID::Store, Opcode::Store, SI, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
friend Context; // for StoreInst()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
/// Return true if this is a store from a volatile memory location.
bool isVolatile() const { return cast<llvm::StoreInst>(Val)->isVolatile(); }
/// Specify whether this is a volatile store or not.
void setVolatile(bool V);
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
+
static StoreInst *create(Value *V, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx);
static StoreInst *create(Value *V, Value *Ptr, MaybeAlign Align,
@@ -1042,19 +1019,13 @@ class UnreachableInst final : public Instruction {
#endif
};
-class ReturnInst final : public Instruction {
+class ReturnInst final : public SingleLLVMInstructionImpl {
/// Use ReturnInst::create() instead of calling the constructor.
ReturnInst(llvm::Instruction *I, Context &Ctx)
- : Instruction(ClassID::Ret, Opcode::Ret, I, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
ReturnInst(ClassID SubclassID, llvm::Instruction *I, Context &Ctx)
- : Instruction(SubclassID, Opcode::Ret, I, Ctx) {}
+ : SingleLLVMInstructionImpl(SubclassID, Opcode::Ret, I, Ctx) {}
friend class Context; // For accessing the constructor in create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
static ReturnInst *createCommon(Value *RetVal, IRBuilder<> &Builder,
Context &Ctx);
@@ -1066,10 +1037,6 @@ class ReturnInst final : public Instruction {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::Ret;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
/// \Returns null if there is no return value.
Value *getReturnValue() const;
#ifndef NDEBUG
@@ -1079,9 +1046,9 @@ class ReturnInst final : public Instruction {
#endif
};
-class CallBase : public Instruction {
+class CallBase : public SingleLLVMInstructionImpl {
CallBase(ClassID ID, Opcode Opc, llvm::Instruction *I, Context &Ctx)
- : Instruction(ID, Opc, I, Ctx) {}
+ : SingleLLVMInstructionImpl(ID, Opc, I, Ctx) {}
friend class CallInst; // For constructor.
friend class InvokeInst; // For constructor.
friend class CallBrInst; // For constructor.
@@ -1219,12 +1186,6 @@ class CallInst final : public CallBase {
: CallBase(ClassID::Call, Opcode::Call, I, Ctx) {}
friend class Context; // For accessing the constructor in
// create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
static CallInst *create(FunctionType *FTy, Value *Func,
@@ -1241,10 +1202,6 @@ class CallInst final : public CallBase {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::Call;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
#ifndef NDEBUG
void verify() const final {}
void dump(raw_ostream &OS) const override;
@@ -1259,12 +1216,6 @@ class InvokeInst final : public CallBase {
: CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
friend class Context; // For accessing the constructor in
// create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
static InvokeInst *create(FunctionType *FTy, Value *Func,
@@ -1284,10 +1235,6 @@ class InvokeInst final : public CallBase {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::Invoke;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
BasicBlock *getNormalDest() const;
BasicBlock *getUnwindDest() const;
void setNormalDest(BasicBlock *BB);
@@ -1323,12 +1270,6 @@ class CallBrInst final : public CallBase {
: CallBase(ClassID::CallBr, Opcode::CallBr, I, Ctx) {}
friend class Context; // For accessing the constructor in
// create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
static CallBrInst *create(FunctionType *FTy, Value *Func,
@@ -1350,10 +1291,6 @@ class CallBrInst final : public CallBase {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::CallBr;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
unsigned getNumIndirectDests() const {
return cast<llvm::CallBrInst>(Val)->getNumIndirectDests();
}
@@ -1379,21 +1316,16 @@ class CallBrInst final : public CallBase {
#endif
};
-class GetElementPtrInst final : public Instruction {
+class GetElementPtrInst final : public SingleLLVMInstructionImpl {
/// Use Context::createGetElementPtrInst(). Don't call
/// the constructor directly.
GetElementPtrInst(llvm::Instruction *I, Context &Ctx)
- : Instruction(ClassID::GetElementPtr, Opcode::GetElementPtr, I, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::GetElementPtr, Opcode::GetElementPtr,
+ I, Ctx) {}
GetElementPtrInst(ClassID SubclassID, llvm::Instruction *I, Context &Ctx)
- : Instruction(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
+ : SingleLLVMInstructionImpl(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
friend class Context; // For accessing the constructor in
// create*()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -1409,10 +1341,6 @@ class GetElementPtrInst final : public Instruction {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::GetElementPtr;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
Type *getSourceElementType() const {
return cast<llvm::GetElementPtrInst>(Val)->getSourceElementType();
@@ -1484,13 +1412,6 @@ class GetElementPtrInst final : public Instruction {
};
class AllocaInst final : public UnaryInstruction {
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
-
AllocaInst(llvm::AllocaInst *AI, Context &Ctx)
: UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
Ctx) {}
@@ -1507,11 +1428,6 @@ class AllocaInst final : public UnaryInstruction {
BasicBlock *InsertAtEnd, Context &Ctx,
Value *ArraySize = nullptr, const Twine &Name = "");
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
-
/// Return true if there is an allocation size parameter to the allocation
/// instruction that is not 1.
bool isArrayAllocation() const {
@@ -1620,18 +1536,8 @@ class CastInst : public UnaryInstruction {
: UnaryInstruction(ClassID::Cast, getCastOpcode(CI->getOpcode()), CI,
Ctx) {}
friend Context; // for SBCastInstruction()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
static Value *create(Type *DestTy, Opcode Op, Value *Operand,
BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
const Twine &Name = "");
@@ -1714,17 +1620,11 @@ class AddrSpaceCastInst final
}
};
-class PHINode final : public Instruction {
+class PHINode final : public SingleLLVMInstructionImpl {
/// Use Context::createPHINode(). Don't call the constructor directly.
PHINode(llvm::PHINode *PHI, Context &Ctx)
- : Instruction(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
friend Context; // for PHINode()
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
/// Helper for mapped_iterator.
struct LLVMBBToBB {
Context &Ctx;
@@ -1733,10 +1633,6 @@ class PHINode final : public Instruction {
};
public:
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
static PHINode *create(Type *Ty, unsigned NumReservedValues,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name = "");
@@ -1810,27 +1706,17 @@ class PHINode final : public Instruction {
/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
/// an OpaqueInstr.
-class OpaqueInst : public sandboxir::Instruction {
+class OpaqueInst : public SingleLLVMInstructionImpl {
OpaqueInst(llvm::Instruction *I, sandboxir::Context &Ctx)
- : sandboxir::Instruction(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
+ : SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
OpaqueInst(ClassID SubclassID, llvm::Instruction *I, sandboxir::Context &Ctx)
- : sandboxir::Instruction(SubclassID, Opcode::Opaque, I, Ctx) {}
+ : SingleLLVMInstructionImpl(SubclassID, Opcode::Opaque, I, Ctx) {}
friend class Context; // For constructor.
- Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
- return getOperandUseDefault(OpIdx, Verify);
- }
- SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
- return {cast<llvm::Instruction>(Val)};
- }
public:
static bool classof(const sandboxir::Value *From) {
return From->getSubclassID() == ClassID::Opaque;
}
- unsigned getUseOperandNo(const Use &Use) const final {
- return getUseOperandNoDefault(Use);
- }
- unsigned getNumOfIRInstrs() const final { return 1u; }
#ifndef NDEBUG
void verify() const final {
// Nothing to do
>From 791f9ede0f3bd16a1d5f23e07c06f5f55ff54d53 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Fri, 9 Aug 2024 15:40:51 -0700
Subject: [PATCH 2/2] fixup! [SandboxIR][NFC] SingleLLVMInstructionImpl class
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 202 +++----------------
llvm/include/llvm/SandboxIR/Use.h | 2 +-
llvm/lib/SandboxIR/SandboxIR.cpp | 214 ++-------------------
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 20 +-
4 files changed, 54 insertions(+), 384 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index f744aa045b3ca..cf1246951ecc1 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -356,11 +356,11 @@ class Value {
void dumpCommonSuffix(raw_ostream &OS) const;
void printAsOperandCommon(raw_ostream &OS) const;
friend raw_ostream &operator<<(raw_ostream &OS, const sandboxir::Value &V) {
- V.dump(OS);
+ V.dumpOS(OS);
return OS;
}
- virtual void dump(raw_ostream &OS) const = 0;
- LLVM_DUMP_METHOD virtual void dump() const = 0;
+ virtual void dumpOS(raw_ostream &OS) const = 0;
+ LLVM_DUMP_METHOD void dump() const;
#endif
};
@@ -378,14 +378,8 @@ class Argument : public sandboxir::Value {
void verify() const final {
assert(isa<llvm::Argument>(Val) && "Expected Argument!");
}
- friend raw_ostream &operator<<(raw_ostream &OS,
- const sandboxir::Argument &TArg) {
- TArg.dump(OS);
- return OS;
- }
void printAsOperand(raw_ostream &OS) const;
- void dump(raw_ostream &OS) const final;
- LLVM_DUMP_METHOD void dump() const final;
+ void dumpOS(raw_ostream &OS) const final;
#endif
};
@@ -474,10 +468,7 @@ class User : public Value {
assert(isa<llvm::User>(Val) && "Expected User!");
}
void dumpCommonHeader(raw_ostream &OS) const final;
- void dump(raw_ostream &OS) const override {
- // TODO: Remove this tmp implementation once we get the Instruction classes.
- }
- LLVM_DUMP_METHOD void dump() const override {
+ void dumpOS(raw_ostream &OS) const override {
// TODO: Remove this tmp implementation once we get the Instruction classes.
}
#endif
@@ -510,13 +501,7 @@ class Constant : public sandboxir::User {
void verify() const override {
assert(isa<llvm::Constant>(Val) && "Expected Constant!");
}
- friend raw_ostream &operator<<(raw_ostream &OS,
- const sandboxir::Constant &SBC) {
- SBC.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
+ void dumpOS(raw_ostream &OS) const override;
#endif
};
@@ -605,12 +590,7 @@ class BasicBlock : public Value {
void verify() const final {
assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
}
- friend raw_ostream &operator<<(raw_ostream &OS, const BasicBlock &SBBB) {
- SBBB.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const final;
- LLVM_DUMP_METHOD void dump() const final;
+ void dumpOS(raw_ostream &OS) const final;
#endif
};
@@ -657,12 +637,6 @@ class Instruction : public sandboxir::User {
public:
static const char *getOpcodeName(Opcode Opc);
-#ifndef NDEBUG
- friend raw_ostream &operator<<(raw_ostream &OS, Opcode Opc) {
- OS << getOpcodeName(Opc);
- return OS;
- }
-#endif
/// This is used by BasicBlock::iterator.
virtual unsigned getNumOfIRInstrs() const = 0;
/// \Returns a BasicBlock::iterator for this Instruction.
@@ -703,18 +677,12 @@ class Instruction : public sandboxir::User {
static bool classof(const sandboxir::Value *From);
#ifndef NDEBUG
- friend raw_ostream &operator<<(raw_ostream &OS,
- const sandboxir::Instruction &SBI) {
- SBI.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
+ void dumpOS(raw_ostream &OS) const override;
#endif
};
/// Instructions that contain a single LLVM Instruction can inherit from this.
-class SingleLLVMInstructionImpl : public Instruction {
+template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
SingleLLVMInstructionImpl(ClassID ID, Opcode Opc, llvm::Instruction *I,
sandboxir::Context &SBCtx)
: Instruction(ID, Opc, I, SBCtx) {}
@@ -737,9 +705,16 @@ class SingleLLVMInstructionImpl : public Instruction {
return getUseOperandNoDefault(Use);
}
unsigned getNumOfIRInstrs() const final { return 1u; }
+#ifndef NDEBUG
+ void verify() const final { assert(isa<LLVMT>(Val) && "Expected LLVMT!"); }
+ void dumpOS(raw_ostream &OS) const override {
+ dumpCommonPrefix(OS);
+ dumpCommonSuffix(OS);
+ }
+#endif
};
-class SelectInst : public SingleLLVMInstructionImpl {
+class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
/// Use Context::createSelectInst(). Don't call the
/// constructor directly.
SelectInst(llvm::SelectInst *CI, Context &Ctx)
@@ -766,16 +741,10 @@ class SelectInst : public SingleLLVMInstructionImpl {
void swapValues() { cast<llvm::SelectInst>(Val)->swapValues(); }
/// For isa/dyn_cast.
static bool classof(const Value *From);
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::SelectInst>(Val) && "Expected SelectInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class InsertElementInst final : public SingleLLVMInstructionImpl {
+class InsertElementInst final
+ : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {
/// Use Context::createInsertElementInst() instead.
InsertElementInst(llvm::Instruction *I, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
@@ -797,21 +766,9 @@ class InsertElementInst final : public SingleLLVMInstructionImpl {
return llvm::InsertElementInst::isValidOperands(Vec->Val, NewElt->Val,
Idx->Val);
}
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::InsertElementInst>(Val) && "Expected InsertElementInst");
- }
- friend raw_ostream &operator<<(raw_ostream &OS,
- const InsertElementInst &IEI) {
- IEI.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class BranchInst : public SingleLLVMInstructionImpl {
+class BranchInst : public SingleLLVMInstructionImpl<llvm::BranchInst> {
/// Use Context::createBranchInst(). Don't call the constructor directly.
BranchInst(llvm::BranchInst *BI, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::Br, Opcode::Br, BI, Ctx) {}
@@ -881,22 +838,11 @@ class BranchInst : public SingleLLVMInstructionImpl {
map_iterator(ConstLLVMRange.end(), ConstBBMap);
return make_range(ConstMappedBegin, ConstMappedEnd);
}
-
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::BranchInst>(Val) && "Expected BranchInst!");
- }
- friend raw_ostream &operator<<(raw_ostream &OS, const BranchInst &BI) {
- BI.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
/// An abstract class, parent of unary instructions.
-class UnaryInstruction : public SingleLLVMInstructionImpl {
+class UnaryInstruction
+ : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {
protected:
UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI,
Context &Ctx)
@@ -942,16 +888,9 @@ class LoadInst final : public UnaryInstruction {
Align getAlign() const { return cast<llvm::LoadInst>(Val)->getAlign(); }
bool isUnordered() const { return cast<llvm::LoadInst>(Val)->isUnordered(); }
bool isSimple() const { return cast<llvm::LoadInst>(Val)->isSimple(); }
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::LoadInst>(Val) && "Expected LoadInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class StoreInst final : public SingleLLVMInstructionImpl {
+class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {
/// Use StoreInst::create().
StoreInst(llvm::StoreInst *SI, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
@@ -980,13 +919,6 @@ class StoreInst final : public SingleLLVMInstructionImpl {
Align getAlign() const { return cast<llvm::StoreInst>(Val)->getAlign(); }
bool isSimple() const { return cast<llvm::StoreInst>(Val)->isSimple(); }
bool isUnordered() const { return cast<llvm::StoreInst>(Val)->isUnordered(); }
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::StoreInst>(Val) && "Expected StoreInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class UnreachableInst final : public Instruction {
@@ -1010,16 +942,9 @@ class UnreachableInst final : public Instruction {
llvm_unreachable("UnreachableInst has no operands!");
}
unsigned getNumOfIRInstrs() const final { return 1u; }
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::UnreachableInst>(Val) && "Expected UnreachableInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class ReturnInst final : public SingleLLVMInstructionImpl {
+class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {
/// Use ReturnInst::create() instead of calling the constructor.
ReturnInst(llvm::Instruction *I, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
@@ -1039,14 +964,9 @@ class ReturnInst final : public SingleLLVMInstructionImpl {
}
/// \Returns null if there is no return value.
Value *getReturnValue() const;
-#ifndef NDEBUG
- void verify() const final {}
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class CallBase : public SingleLLVMInstructionImpl {
+class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {
CallBase(ClassID ID, Opcode Opc, llvm::Instruction *I, Context &Ctx)
: SingleLLVMInstructionImpl(ID, Opc, I, Ctx) {}
friend class CallInst; // For constructor.
@@ -1202,11 +1122,6 @@ class CallInst final : public CallBase {
static bool classof(const Value *From) {
return From->getSubclassID() == ClassID::Call;
}
-#ifndef NDEBUG
- void verify() const final {}
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class InvokeInst final : public CallBase {
@@ -1252,15 +1167,6 @@ class InvokeInst final : public CallBase {
unsigned getNumSuccessors() const {
return cast<llvm::InvokeInst>(Val)->getNumSuccessors();
}
-#ifndef NDEBUG
- void verify() const final {}
- friend raw_ostream &operator<<(raw_ostream &OS, const InvokeInst &I) {
- I.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class CallBrInst final : public CallBase {
@@ -1305,18 +1211,10 @@ class CallBrInst final : public CallBase {
unsigned getNumSuccessors() const {
return cast<llvm::CallBrInst>(Val)->getNumSuccessors();
}
-#ifndef NDEBUG
- void verify() const final {}
- friend raw_ostream &operator<<(raw_ostream &OS, const CallBrInst &I) {
- I.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
-class GetElementPtrInst final : public SingleLLVMInstructionImpl {
+class GetElementPtrInst final
+ : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {
/// Use Context::createGetElementPtrInst(). Don't call
/// the constructor directly.
GetElementPtrInst(llvm::Instruction *I, Context &Ctx)
@@ -1403,12 +1301,6 @@ class GetElementPtrInst final : public SingleLLVMInstructionImpl {
Offset);
}
// TODO: Add missing member functions.
-
-#ifndef NDEBUG
- void verify() const final {}
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class AllocaInst final : public UnaryInstruction {
@@ -1487,13 +1379,6 @@ class AllocaInst final : public UnaryInstruction {
return I->getSubclassID() == Instruction::ClassID::Alloca;
return false;
}
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::AllocaInst>(Val) && "Expected AllocaInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class CastInst : public UnaryInstruction {
@@ -1551,13 +1436,6 @@ class CastInst : public UnaryInstruction {
static bool classof(const Value *From);
Type *getSrcTy() const { return cast<llvm::CastInst>(Val)->getSrcTy(); }
Type *getDestTy() const { return cast<llvm::CastInst>(Val)->getDestTy(); }
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::CastInst>(Val) && "Expected CastInst!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
// Helper class to simplify stamping out CastInst subclasses.
@@ -1620,7 +1498,7 @@ class AddrSpaceCastInst final
}
};
-class PHINode final : public SingleLLVMInstructionImpl {
+class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
/// Use Context::createPHINode(). Don't call the constructor directly.
PHINode(llvm::PHINode *PHI, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
@@ -1695,18 +1573,11 @@ class PHINode final : public SingleLLVMInstructionImpl {
// TODO: Implement
// void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
// uint32_t ToIdx = 0)
-#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::PHINode>(Val) && "Expected PHINode!");
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
/// an OpaqueInstr.
-class OpaqueInst : public SingleLLVMInstructionImpl {
+class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {
OpaqueInst(llvm::Instruction *I, sandboxir::Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
OpaqueInst(ClassID SubclassID, llvm::Instruction *I, sandboxir::Context &Ctx)
@@ -1717,18 +1588,6 @@ class OpaqueInst : public SingleLLVMInstructionImpl {
static bool classof(const sandboxir::Value *From) {
return From->getSubclassID() == ClassID::Opaque;
}
-#ifndef NDEBUG
- void verify() const final {
- // Nothing to do
- }
- friend raw_ostream &operator<<(raw_ostream &OS,
- const sandboxir::OpaqueInst &OI) {
- OI.dump(OS);
- return OS;
- }
- void dump(raw_ostream &OS) const override;
- LLVM_DUMP_METHOD void dump() const override;
-#endif
};
class Context {
@@ -1882,8 +1741,7 @@ class Function : public Constant {
assert(isa<llvm::Function>(Val) && "Expected Function!");
}
void dumpNameAndArgs(raw_ostream &OS) const;
- void dump(raw_ostream &OS) const final;
- LLVM_DUMP_METHOD void dump() const final;
+ void dumpOS(raw_ostream &OS) const final;
#endif
};
diff --git a/llvm/include/llvm/SandboxIR/Use.h b/llvm/include/llvm/SandboxIR/Use.h
index 5b55337b12bc2..c4a774aa3a89e 100644
--- a/llvm/include/llvm/SandboxIR/Use.h
+++ b/llvm/include/llvm/SandboxIR/Use.h
@@ -61,7 +61,7 @@ class Use {
}
bool operator!=(const Use &Other) const { return !(*this == Other); }
#ifndef NDEBUG
- void dump(raw_ostream &OS) const;
+ void dumpOS(raw_ostream &OS) const;
void dump() const;
#endif // NDEBUG
};
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index f810a93461477..2b61a3723d483 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -30,7 +30,7 @@ void Use::swap(Use &OtherUse) {
}
#ifndef NDEBUG
-void Use::dump(raw_ostream &OS) const {
+void Use::dumpOS(raw_ostream &OS) const {
Value *Def = nullptr;
if (LLVMUse == nullptr)
OS << "<null> LLVM Use! ";
@@ -58,7 +58,7 @@ void Use::dump(raw_ostream &OS) const {
OS << "\n";
}
-void Use::dump() const { dump(dbgs()); }
+void Use::dump() const { dumpOS(dbgs()); }
#endif // NDEBUG
Use OperandUseIterator::operator*() const { return Use; }
@@ -203,17 +203,18 @@ void Value::printAsOperandCommon(raw_ostream &OS) const {
OS << "NULL ";
}
+void Value::dump() const {
+ dumpOS(dbgs());
+ dbgs() << "\n";
+}
+
void Argument::printAsOperand(raw_ostream &OS) const {
printAsOperandCommon(OS);
}
-void Argument::dump(raw_ostream &OS) const {
+void Argument::dumpOS(raw_ostream &OS) const {
dumpCommonPrefix(OS);
dumpCommonSuffix(OS);
}
-void Argument::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
#endif // NDEBUG
Use User::getOperandUseDefault(unsigned OpIdx, bool Verify) const {
@@ -472,13 +473,9 @@ bool Instruction::classof(const sandboxir::Value *From) {
}
#ifndef NDEBUG
-void Instruction::dump(raw_ostream &OS) const {
+void Instruction::dumpOS(raw_ostream &OS) const {
OS << "Unimplemented! Please override dump().";
}
-void Instruction::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
#endif // NDEBUG
Value *SelectInst::createCommon(Value *Cond, Value *True, Value *False,
@@ -514,18 +511,6 @@ bool SelectInst::classof(const Value *From) {
return From->getSubclassID() == ClassID::Select;
}
-#ifndef NDEBUG
-void SelectInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void SelectInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
BranchInst *BranchInst::create(BasicBlock *IfTrue, Instruction *InsertBefore,
Context &Ctx) {
auto &Builder = Ctx.getLLVMIRBuilder();
@@ -596,16 +581,6 @@ const BasicBlock *
BranchInst::ConstLLVMBBToSBBB::operator()(const llvm::BasicBlock *BB) const {
return cast<BasicBlock>(Ctx.getValue(BB));
}
-#ifndef NDEBUG
-void BranchInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-void BranchInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
void LoadInst::setVolatile(bool V) {
Ctx.getTracker()
@@ -657,18 +632,6 @@ Value *LoadInst::getPointerOperand() const {
return Ctx.getValue(cast<llvm::LoadInst>(Val)->getPointerOperand());
}
-#ifndef NDEBUG
-void LoadInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void LoadInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
void StoreInst::setVolatile(bool V) {
Ctx.getTracker()
.emplaceIfTracking<
@@ -720,18 +683,6 @@ Value *StoreInst::getPointerOperand() const {
return Ctx.getValue(cast<llvm::StoreInst>(Val)->getPointerOperand());
}
-#ifndef NDEBUG
-void StoreInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void StoreInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
UnreachableInst *UnreachableInst::create(Instruction *InsertBefore,
Context &Ctx) {
auto &Builder = Ctx.getLLVMIRBuilder();
@@ -753,18 +704,6 @@ bool UnreachableInst::classof(const Value *From) {
return From->getSubclassID() == ClassID::Unreachable;
}
-#ifndef NDEBUG
-void UnreachableInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void UnreachableInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
ReturnInst *ReturnInst::createCommon(Value *RetVal, IRBuilder<> &Builder,
Context &Ctx) {
llvm::ReturnInst *NewRI;
@@ -795,18 +734,6 @@ Value *ReturnInst::getReturnValue() const {
return LLVMRetVal != nullptr ? Ctx.getValue(LLVMRetVal) : nullptr;
}
-#ifndef NDEBUG
-void ReturnInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void ReturnInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
Value *CallBase::getCalledOperand() const {
return Ctx.getValue(cast<llvm::CallBase>(Val)->getCalledOperand());
}
@@ -867,18 +794,6 @@ CallInst *CallInst::create(FunctionType *FTy, Value *Func,
NameStr);
}
-#ifndef NDEBUG
-void CallInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void CallInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
InvokeInst *InvokeInst::create(FunctionType *FTy, Value *Func,
BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, BBIterator WhereIt,
@@ -943,17 +858,6 @@ BasicBlock *InvokeInst::getSuccessor(unsigned SuccIdx) const {
Ctx.getValue(cast<llvm::InvokeInst>(Val)->getSuccessor(SuccIdx)));
}
-#ifndef NDEBUG
-void InvokeInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-void InvokeInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
CallBrInst *CallBrInst::create(FunctionType *FTy, Value *Func,
BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
@@ -1039,17 +943,6 @@ BasicBlock *CallBrInst::getSuccessor(unsigned Idx) const {
Ctx.getValue(cast<llvm::CallBrInst>(Val)->getSuccessor(Idx)));
}
-#ifndef NDEBUG
-void CallBrInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-void CallBrInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
Value *GetElementPtrInst::create(Type *Ty, Value *Ptr,
ArrayRef<Value *> IdxList,
BasicBlock::iterator WhereIt,
@@ -1092,18 +985,6 @@ Value *GetElementPtrInst::getPointerOperand() const {
return Ctx.getValue(cast<llvm::GetElementPtrInst>(Val)->getPointerOperand());
}
-#ifndef NDEBUG
-void GetElementPtrInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void GetElementPtrInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
BasicBlock *PHINode::LLVMBBToBB::operator()(llvm::BasicBlock *LLVMBB) const {
return cast<BasicBlock>(Ctx.getValue(LLVMBB));
}
@@ -1299,18 +1180,6 @@ Value *AllocaInst::getArraySize() {
return Ctx.getValue(cast<llvm::AllocaInst>(Val)->getArraySize());
}
-#ifndef NDEBUG
-void AllocaInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void AllocaInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
Value *CastInst::create(Type *DestTy, Opcode Op, Value *Operand,
BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
const Twine &Name) {
@@ -1346,38 +1215,6 @@ bool CastInst::classof(const Value *From) {
return From->getSubclassID() == ClassID::Cast;
}
-#ifndef NDEBUG
-void CastInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void CastInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-
-void PHINode::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void PHINode::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-
-void OpaqueInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void OpaqueInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
Value *InsertElementInst::create(Value *Vec, Value *NewElt, Value *Idx,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name) {
@@ -1404,18 +1241,6 @@ Value *InsertElementInst::create(Value *Vec, Value *NewElt, Value *Idx,
return Ctx.getOrCreateConstant(cast<llvm::Constant>(NewV));
}
-#ifndef NDEBUG
-void InsertElementInst::dump(raw_ostream &OS) const {
- dumpCommonPrefix(OS);
- dumpCommonSuffix(OS);
-}
-
-void InsertElementInst::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-#endif // NDEBUG
-
Constant *Constant::createInt(Type *Ty, uint64_t V, Context &Ctx,
bool IsSigned) {
llvm::Constant *LLVMC = llvm::ConstantInt::get(Ty, V, IsSigned);
@@ -1423,16 +1248,11 @@ Constant *Constant::createInt(Type *Ty, uint64_t V, Context &Ctx,
}
#ifndef NDEBUG
-void Constant::dump(raw_ostream &OS) const {
+void Constant::dumpOS(raw_ostream &OS) const {
dumpCommonPrefix(OS);
dumpCommonSuffix(OS);
}
-void Constant::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
-
void Function::dumpNameAndArgs(raw_ostream &OS) const {
auto *F = cast<llvm::Function>(Val);
OS << *F->getReturnType() << " @" << F->getName() << "(";
@@ -1448,7 +1268,7 @@ void Function::dumpNameAndArgs(raw_ostream &OS) const {
[&] { OS << ", "; });
OS << ")";
}
-void Function::dump(raw_ostream &OS) const {
+void Function::dumpOS(raw_ostream &OS) const {
dumpNameAndArgs(OS);
OS << " {\n";
auto *LLVMF = cast<llvm::Function>(Val);
@@ -1464,10 +1284,6 @@ void Function::dump(raw_ostream &OS) const {
[&OS] { OS << "\n"; });
OS << "}\n";
}
-void Function::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
#endif // NDEBUG
BasicBlock::iterator::pointer
@@ -1804,7 +1620,7 @@ Instruction &BasicBlock::back() const {
}
#ifndef NDEBUG
-void BasicBlock::dump(raw_ostream &OS) const {
+void BasicBlock::dumpOS(raw_ostream &OS) const {
llvm::BasicBlock *BB = cast<llvm::BasicBlock>(Val);
const auto &Name = BB->getName();
OS << Name;
@@ -1833,13 +1649,9 @@ void BasicBlock::dump(raw_ostream &OS) const {
}
} else {
for (auto &SBI : *this) {
- SBI.dump(OS);
+ SBI.dumpOS(OS);
OS << "\n";
}
}
}
-void BasicBlock::dump() const {
- dump(dbgs());
- dbgs() << "\n";
-}
#endif // NDEBUG
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 3e52b05ad2e94..f98a60b49ecab 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -102,12 +102,12 @@ define void @foo(i32 %v1) {
#ifndef NDEBUG
std::string Buff;
raw_string_ostream BS(Buff);
- F->dump(BS);
- Arg0->dump(BS);
- BB->dump(BS);
- AddI->dump(BS);
- Const0->dump(BS);
- OpaqueI->dump(BS);
+ F->dumpOS(BS);
+ Arg0->dumpOS(BS);
+ BB->dumpOS(BS);
+ AddI->dumpOS(BS);
+ Const0->dumpOS(BS);
+ OpaqueI->dumpOS(BS);
#endif
}
@@ -176,11 +176,11 @@ define i32 @foo(i32 %v0, i32 %v1) {
EXPECT_EQ(Ret->getOperand(0), I0);
#ifndef NDEBUG
- // Check Use.dump()
+ // Check Use.dump(()
std::string Buff;
raw_string_ostream BS(Buff);
BS << "\n";
- I0->getOperandUse(0).dump(BS);
+ I0->getOperandUse(0).dumpOS(BS);
EXPECT_EQ(Buff, R"IR(
Def: i32 %v0 ; SB2. (Argument)
User: %add0 = add i32 %v0, %v1 ; SB5. (Opaque)
@@ -396,7 +396,7 @@ define void @foo(i32 %arg0, i32 %arg1) {
std::string Buff;
raw_string_ostream BS(Buff);
BS << "\n";
- F->dump(BS);
+ F->dumpOS(BS);
EXPECT_EQ(Buff, R"IR(
void @foo(i32 %arg0, i32 %arg1) {
bb0:
@@ -465,7 +465,7 @@ define void @foo(i32 %v1) {
std::string Buff;
raw_string_ostream BS(Buff);
BS << "\n";
- BB0.dump(BS);
+ BB0.dumpOS(BS);
EXPECT_EQ(Buff, R"IR(
bb0:
br label %bb1 ; SB3. (Br)
More information about the llvm-commits
mailing list