diff options
| author | Tim Northover <tnorthover@apple.com> | 2016-12-05 21:47:07 +0000 |
|---|---|---|
| committer | Tim Northover <tnorthover@apple.com> | 2016-12-05 21:47:07 +0000 |
| commit | 9267ac5d4735ef910a3c7e26bc961cac4a0dc115 (patch) | |
| tree | c87c5393f5b7ba041049953efdfb5d0fd5a651ab /llvm/lib/CodeGen | |
| parent | 0d98da7c1f7a41f4d84e1232c1f53989a09f229e (diff) | |
| download | bcm5719-llvm-9267ac5d4735ef910a3c7e26bc961cac4a0dc115.tar.gz bcm5719-llvm-9267ac5d4735ef910a3c7e26bc961cac4a0dc115.zip | |
GlobalISel: make G_CONSTANT take a ConstantInt rather than int64_t.
This makes it more similar to the floating-point constant, and also allows for
larger constants to be translated later. There's no real functional change in
this patch though, just syntax updates.
llvm-svn: 288712
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 22 |
3 files changed, 21 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index a580e745171..b84bd646c78 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -703,9 +703,7 @@ bool IRTranslator::translate(const Constant &C, unsigned Reg) { else if (isa<UndefValue>(C)) EntryBuilder.buildInstr(TargetOpcode::IMPLICIT_DEF).addDef(Reg); else if (isa<ConstantPointerNull>(C)) - EntryBuilder.buildInstr(TargetOpcode::G_CONSTANT) - .addDef(Reg) - .addImm(0); + EntryBuilder.buildConstant(Reg, 0); else if (auto GV = dyn_cast<GlobalValue>(&C)) EntryBuilder.buildGlobalValue(Reg, GV); else if (auto CE = dyn_cast<ConstantExpr>(&C)) { diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp index ffb22b22e7c..eb25b6ca268 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -244,7 +244,7 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) { } case TargetOpcode::G_CONSTANT: { unsigned DstExt = MRI.createGenericVirtualRegister(WideTy); - MIRBuilder.buildConstant(DstExt, MI.getOperand(1).getImm()); + MIRBuilder.buildConstant(DstExt, *MI.getOperand(1).getCImm()); MIRBuilder.buildTrunc(MI.getOperand(0).getReg(), DstExt); MI.eraseFromParent(); return Legalized; diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 22f8d981a55..5c8a3547562 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -165,10 +165,26 @@ MachineInstrBuilder MachineIRBuilder::buildCopy(unsigned Res, unsigned Op) { return buildInstr(TargetOpcode::COPY).addDef(Res).addUse(Op); } -MachineInstrBuilder MachineIRBuilder::buildConstant(unsigned Res, int64_t Val) { - assert(MRI->getType(Res).isScalar() && "invalid operand type"); +MachineInstrBuilder MachineIRBuilder::buildConstant(unsigned Res, + const ConstantInt &Val) { + LLT Ty = MRI->getType(Res); + + assert(Ty.isScalar() || Ty.isPointer() && "invalid operand type"); + + const ConstantInt *NewVal = &Val; + if (Ty.getSizeInBits() != Val.getBitWidth()) + NewVal = ConstantInt::get(MF->getFunction()->getContext(), + Val.getValue().sextOrTrunc(Ty.getSizeInBits())); + + return buildInstr(TargetOpcode::G_CONSTANT).addDef(Res).addCImm(NewVal); +} - return buildInstr(TargetOpcode::G_CONSTANT).addDef(Res).addImm(Val); +MachineInstrBuilder MachineIRBuilder::buildConstant(unsigned Res, + int64_t Val) { + auto IntN = IntegerType::get(MF->getFunction()->getContext(), + MRI->getType(Res).getSizeInBits()); + ConstantInt *CI = ConstantInt::get(IntN, Val, true); + return buildConstant(Res, *CI); } MachineInstrBuilder MachineIRBuilder::buildFConstant(unsigned Res, |

