summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJF Bastien <jfb@google.com>2015-08-10 22:36:48 +0000
committerJF Bastien <jfb@google.com>2015-08-10 22:36:48 +0000
commit4a6422562d797fd2d860800992620a4a16021872 (patch)
tree533f3c34b3ac56a211f6bdb055220a18f6ff4c0c /llvm/lib
parent6dce129051d849509727fdb953416a5c0fdbdc7c (diff)
downloadbcm5719-llvm-4a6422562d797fd2d860800992620a4a16021872.tar.gz
bcm5719-llvm-4a6422562d797fd2d860800992620a4a16021872.zip
WebAssembly: print immediates
Summary: For now output using C99's hexadecimal floating-point representation. This patch also cleans up how machine operands are printed: instead of special-casing per type of machine instruction, the code now handles operands generically. Reviewers: sunfish Subscribers: llvm-commits, jfb Differential Revision: http://reviews.llvm.org/D11914 llvm-svn: 244520
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp46
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp6
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td10
3 files changed, 42 insertions, 20 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 99b23c7433b..35a4be3805d 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -99,28 +99,36 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
OS << "(setlocal @" << TargetRegisterInfo::virtReg2Index(Reg) << ' ';
}
- OS << '(';
-
- bool PrintOperands = true;
- switch (MI->getOpcode()) {
- case WebAssembly::ARGUMENT_Int32:
- case WebAssembly::ARGUMENT_Int64:
- case WebAssembly::ARGUMENT_Float32:
- case WebAssembly::ARGUMENT_Float64:
- OS << Name(TII, MI) << ' ' << MI->getOperand(1).getImm();
- PrintOperands = false;
- break;
- default:
- OS << Name(TII, MI);
- break;
- }
-
- if (PrintOperands)
- for (const MachineOperand &MO : MI->uses()) {
- if (MO.isReg() && MO.isImplicit())
+ OS << '(' << Name(TII, MI);
+ for (const MachineOperand &MO : MI->uses())
+ switch (MO.getType()) {
+ default:
+ llvm_unreachable("unexpected machine operand type");
+ case MachineOperand::MO_Register: {
+ if (MO.isImplicit())
continue;
unsigned Reg = MO.getReg();
OS << " @" << TargetRegisterInfo::virtReg2Index(Reg);
+ } break;
+ case MachineOperand::MO_Immediate: {
+ OS << ' ' << MO.getImm();
+ } break;
+ case MachineOperand::MO_FPImmediate: {
+ static const size_t BufBytes = 128;
+ char buf[BufBytes];
+ APFloat FP = MO.getFPImm()->getValueAPF();
+ const APFloat CanonicalNaN = APFloat::getQNaN(FP.getSemantics());
+ if (FP.isNaN() && !FP.bitwiseIsEqual(CanonicalNaN))
+ // WebAssembly only has NaNs that are positive, quiet, without payload.
+ FP = CanonicalNaN;
+ // Use C99's hexadecimal floating-point representation.
+ auto Written =
+ FP.convertToHexString(buf, /*hexDigits=*/0, /*upperCase=*/false,
+ APFloat::rmNearestTiesToEven);
+ assert(Written != 0);
+ assert(Written < BufBytes);
+ OS << ' ' << buf;
+ } break;
}
OS << ')';
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 4360116a7f1..ee155fdbb22 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -108,7 +108,11 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
// Compute derived properties from the register classes.
computeRegisterProperties(Subtarget->getRegisterInfo());
- // FIXME: setOperationAction...
+ // FIXME: many setOperationAction are missing...
+
+ // Don't expand the following types to constant pools.
+ setOperationAction(ISD::ConstantFP, MVT::f32, Legal);
+ setOperationAction(ISD::ConstantFP, MVT::f64, Legal);
}
MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
index e88a93a63ae..c6335723b4c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -64,6 +64,16 @@ defm : ARGUMENT<Int64>;
defm : ARGUMENT<Float32>;
defm : ARGUMENT<Float64>;
+
+def Immediate_I32 : I<(outs Int32:$res), (ins i32imm:$imm),
+ [(set Int32:$res, imm:$imm)]>;
+def Immediate_I64 : I<(outs Int64:$res), (ins i64imm:$imm),
+ [(set Int64:$res, imm:$imm)]>;
+def Immediate_F32 : I<(outs Float32:$res), (ins f32imm:$imm),
+ [(set Float32:$res, fpimm:$imm)]>;
+def Immediate_F64 : I<(outs Float64:$res), (ins f64imm:$imm),
+ [(set Float64:$res, fpimm:$imm)]>;
+
//===----------------------------------------------------------------------===//
// Additional sets of instructions.
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud