[llvm] r260590 - [Target] Add a helper function to check if an opcode is invalid after isel.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 13:16:56 PST 2016
Author: qcolombet
Date: Thu Feb 11 15:16:56 2016
New Revision: 260590
URL: http://llvm.org/viewvc/llvm-project?rev=260590&view=rev
Log:
[Target] Add a helper function to check if an opcode is invalid after isel.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/trunk/include/llvm/CodeGen/MachineInstr.h
llvm/trunk/include/llvm/Target/TargetOpcodes.h
llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=260590&r1=260589&r2=260590&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h Thu Feb 11 15:16:56 2016
@@ -92,6 +92,7 @@ public:
/// setBasicBlock or setMI.
///
/// \pre setBasicBlock or setMI must have been called.
+ /// \pre Ty == nullptr or isPreISelGenericOpcode(Opcode)
///
/// \return The newly created instruction.
MachineInstr *buildInstr(unsigned Opcode, Type *Ty, unsigned Res,
@@ -109,6 +110,7 @@ public:
/// Build and insert \p Res<def> = \p Opcode \p Op0.
///
/// \pre setBasicBlock or setMI must have been called.
+ /// \pre not isPreISelGenericOpcode(\p Opcode)
///
/// \return The newly created instruction.
MachineInstr *buildInstr(unsigned Opcode, unsigned Res, unsigned Op0);
@@ -116,6 +118,7 @@ public:
/// Build and insert = \p Opcode.
///
/// \pre setBasicBlock or setMI must have been called.
+ /// \pre not isPreISelGenericOpcode(\p Opcode)
///
/// \return The newly created instruction.
MachineInstr *buildInstr(unsigned Opcode);
Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=260590&r1=260589&r2=260590&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Thu Feb 11 15:16:56 2016
@@ -190,10 +190,8 @@ public:
/// Set the type of the instruction.
/// \pre getOpcode() is in the range of the generic opcodes.
void setType(Type *Ty) {
- assert(
- (!Ty || (getOpcode() >= TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START &&
- getOpcode() <= TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END)) &&
- "Non generic instructions are not supposed to be typed");
+ assert((!Ty || isPreISelGenericOpcode(getOpcode())) &&
+ "Non generic instructions are not supposed to be typed");
this->Ty = Ty;
}
Type *getType() const { return Ty; }
Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.h?rev=260590&r1=260589&r2=260590&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOpcodes.h (original)
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.h Thu Feb 11 15:16:56 2016
@@ -25,6 +25,13 @@ enum {
#include "llvm/Target/TargetOpcodes.def"
};
} // end namespace TargetOpcode
+
+/// Check whether the given Opcode is a generic opcode that is not supposed
+/// to appear after ISel.
+static inline bool isPreISelGenericOpcode(unsigned Opcode) {
+ return Opcode >= TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START &&
+ Opcode <= TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
+}
} // end namespace llvm
#endif
Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp?rev=260590&r1=260589&r2=260590&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp Thu Feb 11 15:16:56 2016
@@ -15,6 +15,7 @@
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetOpcodes.h"
#include "llvm/Target/TargetSubtargetInfo.h"
using namespace llvm;
@@ -62,14 +63,22 @@ MachineInstr *MachineIRBuilder::buildIns
unsigned Op1) {
MachineInstr *NewMI =
BuildMI(getMF(), DL, getTII().get(Opcode), Res).addReg(Op0).addReg(Op1);
- if (Ty)
+ if (Ty) {
+ assert(isPreISelGenericOpcode(Opcode) &&
+ "Only generic instruction can have a type");
NewMI->setType(Ty);
+ } else
+ assert(!isPreISelGenericOpcode(Opcode) &&
+ "Generic instruction must have a type");
getMBB().insert(getInsertPt(), NewMI);
return NewMI;
}
MachineInstr *MachineIRBuilder::buildInstr(unsigned Opcode, unsigned Res,
unsigned Op0) {
+ assert(!isPreISelGenericOpcode(Opcode) &&
+ "Generic instruction must have a type");
+
MachineInstr *NewMI =
BuildMI(getMF(), DL, getTII().get(Opcode), Res).addReg(Op0);
getMBB().insert(getInsertPt(), NewMI);
@@ -77,6 +86,9 @@ MachineInstr *MachineIRBuilder::buildIns
}
MachineInstr *MachineIRBuilder::buildInstr(unsigned Opcode) {
+ assert(!isPreISelGenericOpcode(Opcode) &&
+ "Generic instruction must have a type");
+
MachineInstr *NewMI = BuildMI(getMF(), DL, getTII().get(Opcode));
getMBB().insert(getInsertPt(), NewMI);
return NewMI;
More information about the llvm-commits
mailing list