summaryrefslogtreecommitdiff
path: root/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-23 21:01:33 +0000
committerTim Northover <tnorthover@apple.com>2016-08-23 21:01:33 +0000
commit2a105605e344121de62a3efd023b1b6aa7d550f6 (patch)
tree189472eda438b1ad9f2fa2e3b31b3365fd2dff61 /lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
parent4f24b7db0e2b0b21ab8de0fbbd0353fd467eacf0 (diff)
downloadllvm-2a105605e344121de62a3efd023b1b6aa7d550f6.tar.gz
GlobalISel: make truncate/extend casts uniform
They really should have both types represented, but early variants were created before MachineInstrs could have multiple types so they're rather ambiguous. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279567 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/GlobalISel/MachineIRBuilder.cpp')
-rw-r--r--lib/CodeGen/GlobalISel/MachineIRBuilder.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index 923238955627..c9499ca7e6fb 100644
--- a/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -141,18 +141,21 @@ MachineInstrBuilder MachineIRBuilder::buildUAdde(LLT Ty, unsigned Res,
.addUse(CarryIn);
}
-MachineInstrBuilder MachineIRBuilder::buildAnyExtend(LLT Ty, unsigned Res,
- unsigned Op) {
- return buildInstr(TargetOpcode::G_ANYEXTEND, Ty).addDef(Res).addUse(Op);
+MachineInstrBuilder MachineIRBuilder::buildAnyExt(ArrayRef<LLT> Tys,
+ unsigned Res, unsigned Op) {
+ validateTruncExt(Tys, true);
+ return buildInstr(TargetOpcode::G_ANYEXT, Tys).addDef(Res).addUse(Op);
}
MachineInstrBuilder MachineIRBuilder::buildSExt(ArrayRef<LLT> Tys, unsigned Res,
unsigned Op) {
+ validateTruncExt(Tys, true);
return buildInstr(TargetOpcode::G_SEXT, Tys).addDef(Res).addUse(Op);
}
MachineInstrBuilder MachineIRBuilder::buildZExt(ArrayRef<LLT> Tys, unsigned Res,
unsigned Op) {
+ validateTruncExt(Tys, true);
return buildInstr(TargetOpcode::G_ZEXT, Tys).addDef(Res).addUse(Op);
}
@@ -216,14 +219,16 @@ MachineInstrBuilder MachineIRBuilder::buildIntrinsic(ArrayRef<LLT> Tys,
return MIB;
}
-MachineInstrBuilder MachineIRBuilder::buildTrunc(LLT Ty, unsigned Res,
- unsigned Op) {
- return buildInstr(TargetOpcode::G_TRUNC, Ty).addDef(Res).addUse(Op);
+MachineInstrBuilder MachineIRBuilder::buildTrunc(ArrayRef<LLT> Tys,
+ unsigned Res, unsigned Op) {
+ validateTruncExt(Tys, false);
+ return buildInstr(TargetOpcode::G_TRUNC, Tys).addDef(Res).addUse(Op);
}
-MachineInstrBuilder MachineIRBuilder::buildFPTrunc(LLT Ty, unsigned Res,
- unsigned Op) {
- return buildInstr(TargetOpcode::G_FPTRUNC, Ty).addDef(Res).addUse(Op);
+MachineInstrBuilder MachineIRBuilder::buildFPTrunc(ArrayRef<LLT> Tys,
+ unsigned Res, unsigned Op) {
+ validateTruncExt(Tys, false);
+ return buildInstr(TargetOpcode::G_FPTRUNC, Tys).addDef(Res).addUse(Op);
}
MachineInstrBuilder MachineIRBuilder::buildICmp(ArrayRef<LLT> Tys,
@@ -257,3 +262,22 @@ MachineInstrBuilder MachineIRBuilder::buildSelect(LLT Ty, unsigned Res,
.addUse(Op0)
.addUse(Op1);
}
+
+void MachineIRBuilder::validateTruncExt(ArrayRef<LLT> Tys, bool IsExtend) {
+ assert(Tys.size() == 2 && "cast should have a source and a dest type");
+ LLT DstTy{Tys[0]}, SrcTy{Tys[1]};
+
+ if (DstTy.isVector()) {
+ assert(SrcTy.isVector() && "mismatched cast between vecot and non-vector");
+ assert(SrcTy.getNumElements() == DstTy.getNumElements() &&
+ "different number of elements in a trunc/ext");
+ } else
+ assert(DstTy.isScalar() && SrcTy.isScalar() && "invalid extend/trunc");
+
+ if (IsExtend)
+ assert(DstTy.getSizeInBits() > SrcTy.getSizeInBits() &&
+ "invalid narrowing extend");
+ else
+ assert(DstTy.getSizeInBits() < SrcTy.getSizeInBits() &&
+ "invalid widening trunc");
+}