Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit c10ced9

Browse files
author
Aditya Nandakumar
committed
[GISel]: Add MachineIRBuilder support for passing in Flags while building
https://reviews.llvm.org/D55516 Add the ability to pass in flags to buildInstr calls. Currently no validation is performed but that can be easily performed based on the opcode (if necessary). Reviewed by: paquette. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348893 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a6e46e6 commit c10ced9

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

include/llvm/CodeGen/GlobalISel/ConstantFoldingMIRBuilder.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class ConstantFoldingMIRBuilder : public MachineIRBuilder {
7878
// Try to provide an overload for buildInstr for binary ops in order to
7979
// constant fold.
8080
MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps,
81-
ArrayRef<SrcOp> SrcOps) override {
81+
ArrayRef<SrcOp> SrcOps,
82+
Optional<unsigned> Flags = None) override {
8283
switch (Opc) {
8384
default:
8485
break;

include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,9 @@ class MachineIRBuilder {
10581058
/// \return a MachineInstrBuilder for the newly created instruction.
10591059

10601060
MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0,
1061-
const SrcOp &Src1) {
1062-
return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1});
1061+
const SrcOp &Src1,
1062+
Optional<unsigned> Flags = None) {
1063+
return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1}, Flags);
10631064
}
10641065

10651066
/// Build and insert \p Res = G_SUB \p Op0, \p Op1
@@ -1074,8 +1075,9 @@ class MachineIRBuilder {
10741075
/// \return a MachineInstrBuilder for the newly created instruction.
10751076

10761077
MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0,
1077-
const SrcOp &Src1) {
1078-
return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1});
1078+
const SrcOp &Src1,
1079+
Optional<unsigned> Flags = None) {
1080+
return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1}, Flags);
10791081
}
10801082

10811083
/// Build and insert \p Res = G_MUL \p Op0, \p Op1
@@ -1089,8 +1091,9 @@ class MachineIRBuilder {
10891091
///
10901092
/// \return a MachineInstrBuilder for the newly created instruction.
10911093
MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0,
1092-
const SrcOp &Src1) {
1093-
return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1});
1094+
const SrcOp &Src1,
1095+
Optional<unsigned> Flags = None) {
1096+
return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1}, Flags);
10941097
}
10951098

10961099
/// Build and insert \p Res = G_AND \p Op0, \p Op1
@@ -1125,7 +1128,8 @@ class MachineIRBuilder {
11251128
}
11261129

11271130
virtual MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps,
1128-
ArrayRef<SrcOp> SrcOps);
1131+
ArrayRef<SrcOp> SrcOps,
1132+
Optional<unsigned> Flags = None);
11291133
};
11301134

11311135
} // End namespace llvm.

lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ void MachineIRBuilder::validateSelectOp(const LLT &ResTy, const LLT &TstTy,
786786

787787
MachineInstrBuilder MachineIRBuilder::buildInstr(unsigned Opc,
788788
ArrayRef<DstOp> DstOps,
789-
ArrayRef<SrcOp> SrcOps) {
789+
ArrayRef<SrcOp> SrcOps,
790+
Optional<unsigned> Flags) {
790791
switch (Opc) {
791792
default:
792793
break;
@@ -995,5 +996,7 @@ MachineInstrBuilder MachineIRBuilder::buildInstr(unsigned Opc,
995996
Op.addDefToMIB(*getMRI(), MIB);
996997
for (const SrcOp &Op : SrcOps)
997998
Op.addSrcToMIB(MIB);
999+
if (Flags)
1000+
MIB->setFlags(*Flags);
9981001
return MIB;
9991002
}

0 commit comments

Comments
 (0)