Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td @@ -303,222 +303,143 @@ let Defs = [ARGUMENTS] in { +// Defines atomic and non-atomic stores, regular and truncating +class WebAssemblyStore : + I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, rc:$val), [], + !strconcat(Name, "\t${off}(${addr})${p2align}, $val"), Opcode>; // Basic store. // Note: WebAssembly inverts SelectionDAG's usual operand order. -def STORE_I32 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I32:$val), [], - "i32.store\t${off}(${addr})${p2align}, $val", 0x36>; -def STORE_I64 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I64:$val), [], - "i64.store\t${off}(${addr})${p2align}, $val", 0x37>; -def STORE_F32 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - F32:$val), [], - "f32.store\t${off}(${addr})${p2align}, $val", 0x38>; -def STORE_F64 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - F64:$val), [], - "f64.store\t${off}(${addr})${p2align}, $val", 0x39>; +def STORE_I32 : WebAssemblyStore; +def STORE_I64 : WebAssemblyStore; +def STORE_F32 : WebAssemblyStore; +def STORE_F64 : WebAssemblyStore; } // Defs = [ARGUMENTS] // Select stores with no constant offset. -def : Pat<(store I32:$val, I32:$addr), (STORE_I32 0, 0, I32:$addr, I32:$val)>; -def : Pat<(store I64:$val, I32:$addr), (STORE_I64 0, 0, I32:$addr, I64:$val)>; -def : Pat<(store F32:$val, I32:$addr), (STORE_F32 0, 0, I32:$addr, F32:$val)>; -def : Pat<(store F64:$val, I32:$addr), (STORE_F64 0, 0, I32:$addr, F64:$val)>; +class StorePatNoOffset : + Pat<(node ty:$val, I32:$addr), (inst 0, 0, $addr, $val)>; + +def : StorePatNoOffset; +def : StorePatNoOffset; +def : StorePatNoOffset; +def : StorePatNoOffset; // Select stores with a constant offset. -def : Pat<(store I32:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(store I64:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(store F32:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE_F32 0, imm:$off, I32:$addr, F32:$val)>; -def : Pat<(store F64:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE_F64 0, imm:$off, I32:$addr, F64:$val)>; -def : Pat<(store I32:$val, (or_is_add I32:$addr, imm:$off)), - (STORE_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(store I64:$val, (or_is_add I32:$addr, imm:$off)), - (STORE_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(store F32:$val, (or_is_add I32:$addr, imm:$off)), - (STORE_F32 0, imm:$off, I32:$addr, F32:$val)>; -def : Pat<(store F64:$val, (or_is_add I32:$addr, imm:$off)), - (STORE_F64 0, imm:$off, I32:$addr, F64:$val)>; -def : Pat<(store I32:$val, (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE_I32 0, tglobaladdr:$off, I32:$addr, I32:$val)>; -def : Pat<(store I64:$val, (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE_I64 0, tglobaladdr:$off, I32:$addr, I64:$val)>; -def : Pat<(store F32:$val, (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE_F32 0, tglobaladdr:$off, I32:$addr, F32:$val)>; -def : Pat<(store F64:$val, (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE_F64 0, tglobaladdr:$off, I32:$addr, F64:$val)>; -def : Pat<(store I32:$val, (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE_I32 0, texternalsym:$off, I32:$addr, I32:$val)>; -def : Pat<(store I64:$val, (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE_I64 0, texternalsym:$off, I32:$addr, I64:$val)>; -def : Pat<(store F32:$val, (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE_F32 0, texternalsym:$off, I32:$addr, F32:$val)>; -def : Pat<(store F64:$val, (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE_F64 0, texternalsym:$off, I32:$addr, F64:$val)>; +class StorePatImmOff : + Pat<(storekind ty:$val, (operand I32:$addr, imm:$off)), + (inst 0, imm:$off, $addr, ty:$val)>; + +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; + +class StorePatGlobalAddr : + Pat<(storekind ty:$val, (regPlusGA I32:$addr, + (WebAssemblywrapper tglobaladdr:$off))), + (inst 0, tglobaladdr:$off, I32:$addr, ty:$val)>; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; + +class StorePatExternalSym : + Pat<(storekind ty:$val, (add I32:$addr, + (WebAssemblywrapper texternalsym:$off))), + (inst 0, texternalsym:$off, I32:$addr, ty:$val)>; +def : StorePatExternalSym; +def : StorePatExternalSym; +def : StorePatExternalSym; +def : StorePatExternalSym; // Select stores with just a constant offset. -def : Pat<(store I32:$val, imm:$off), - (STORE_I32 0, imm:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(store I64:$val, imm:$off), - (STORE_I64 0, imm:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(store F32:$val, imm:$off), - (STORE_F32 0, imm:$off, (CONST_I32 0), F32:$val)>; -def : Pat<(store F64:$val, imm:$off), - (STORE_F64 0, imm:$off, (CONST_I32 0), F64:$val)>; -def : Pat<(store I32:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE_I32 0, tglobaladdr:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(store I64:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE_I64 0, tglobaladdr:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(store F32:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE_F32 0, tglobaladdr:$off, (CONST_I32 0), F32:$val)>; -def : Pat<(store F64:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE_F64 0, tglobaladdr:$off, (CONST_I32 0), F64:$val)>; -def : Pat<(store I32:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE_I32 0, texternalsym:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(store I64:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE_I64 0, texternalsym:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(store F32:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE_F32 0, texternalsym:$off, (CONST_I32 0), F32:$val)>; -def : Pat<(store F64:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE_F64 0, texternalsym:$off, (CONST_I32 0), F64:$val)>; +class StorePatOffsetOnly : + Pat<(storekind ty:$val, imm:$off), + (inst 0, imm:$off, (CONST_I32 0), ty:$val)>; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; + +class StorePatGlobalAddrOffOnly : + Pat<(storekind ty:$val, (WebAssemblywrapper tglobaladdr:$off)), + (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$val)>; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; + +class StorePatExternSymOffOnly : + Pat<(storekind ty:$val, (WebAssemblywrapper texternalsym:$off)), + (inst 0, texternalsym:$off, (CONST_I32 0), ty:$val)>; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; + let Defs = [ARGUMENTS] in { // Truncating store. -def STORE8_I32 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I32:$val), [], - "i32.store8\t${off}(${addr})${p2align}, $val", 0x3a>; -def STORE16_I32 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I32:$val), [], - "i32.store16\t${off}(${addr})${p2align}, $val", 0x3b>; -def STORE8_I64 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I64:$val), [], - "i64.store8\t${off}(${addr})${p2align}, $val", 0x3c>; -def STORE16_I64 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I64:$val), [], - "i64.store16\t${off}(${addr})${p2align}, $val", 0x3d>; -def STORE32_I64 : I<(outs), (ins P2Align:$p2align, offset32_op:$off, I32:$addr, - I64:$val), [], - "i64.store32\t${off}(${addr})${p2align}, $val", 0x3e>; +def STORE8_I32 : WebAssemblyStore; +def STORE16_I32 : WebAssemblyStore; +def STORE8_I64 : WebAssemblyStore; +def STORE16_I64 : WebAssemblyStore; +def STORE32_I64 : WebAssemblyStore; } // Defs = [ARGUMENTS] // Select truncating stores with no constant offset. -def : Pat<(truncstorei8 I32:$val, I32:$addr), - (STORE8_I32 0, 0, I32:$addr, I32:$val)>; -def : Pat<(truncstorei16 I32:$val, I32:$addr), - (STORE16_I32 0, 0, I32:$addr, I32:$val)>; -def : Pat<(truncstorei8 I64:$val, I32:$addr), - (STORE8_I64 0, 0, I32:$addr, I64:$val)>; -def : Pat<(truncstorei16 I64:$val, I32:$addr), - (STORE16_I64 0, 0, I32:$addr, I64:$val)>; -def : Pat<(truncstorei32 I64:$val, I32:$addr), - (STORE32_I64 0, 0, I32:$addr, I64:$val)>; +def : StorePatNoOffset; +def : StorePatNoOffset; +def : StorePatNoOffset; +def : StorePatNoOffset; +def : StorePatNoOffset; // Select truncating stores with a constant offset. -def : Pat<(truncstorei8 I32:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE8_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei16 I32:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE16_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei8 I64:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE8_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei16 I64:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE16_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei32 I64:$val, (regPlusImm I32:$addr, imm:$off)), - (STORE32_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei8 I32:$val, (or_is_add I32:$addr, imm:$off)), - (STORE8_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei16 I32:$val, (or_is_add I32:$addr, imm:$off)), - (STORE16_I32 0, imm:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei8 I64:$val, (or_is_add I32:$addr, imm:$off)), - (STORE8_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei16 I64:$val, (or_is_add I32:$addr, imm:$off)), - (STORE16_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei32 I64:$val, (or_is_add I32:$addr, imm:$off)), - (STORE32_I64 0, imm:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei8 I32:$val, - (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE8_I32 0, tglobaladdr:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei16 I32:$val, - (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE16_I32 0, tglobaladdr:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei8 I64:$val, - (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE8_I64 0, tglobaladdr:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei16 I64:$val, - (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE16_I64 0, tglobaladdr:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei32 I64:$val, - (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off))), - (STORE32_I64 0, tglobaladdr:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei8 I32:$val, (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE8_I32 0, texternalsym:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei16 I32:$val, - (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE16_I32 0, texternalsym:$off, I32:$addr, I32:$val)>; -def : Pat<(truncstorei8 I64:$val, - (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE8_I64 0, texternalsym:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei16 I64:$val, - (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE16_I64 0, texternalsym:$off, I32:$addr, I64:$val)>; -def : Pat<(truncstorei32 I64:$val, - (add I32:$addr, - (WebAssemblywrapper texternalsym:$off))), - (STORE32_I64 0, texternalsym:$off, I32:$addr, I64:$val)>; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; +def : StorePatImmOff; + +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatGlobalAddr; +def : StorePatExternalSym; +def : StorePatExternalSym; +def : StorePatExternalSym; +def : StorePatExternalSym; +def : StorePatExternalSym; // Select truncating stores with just a constant offset. -def : Pat<(truncstorei8 I32:$val, imm:$off), - (STORE8_I32 0, imm:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei16 I32:$val, imm:$off), - (STORE16_I32 0, imm:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei8 I64:$val, imm:$off), - (STORE8_I64 0, imm:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei16 I64:$val, imm:$off), - (STORE16_I64 0, imm:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei32 I64:$val, imm:$off), - (STORE32_I64 0, imm:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei8 I32:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE8_I32 0, tglobaladdr:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei16 I32:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE16_I32 0, tglobaladdr:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei8 I64:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE8_I64 0, tglobaladdr:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei16 I64:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE16_I64 0, tglobaladdr:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper tglobaladdr:$off)), - (STORE32_I64 0, tglobaladdr:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei8 I32:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE8_I32 0, texternalsym:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei16 I32:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE16_I32 0, texternalsym:$off, (CONST_I32 0), I32:$val)>; -def : Pat<(truncstorei8 I64:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE8_I64 0, texternalsym:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei16 I64:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE16_I64 0, texternalsym:$off, (CONST_I32 0), I64:$val)>; -def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper texternalsym:$off)), - (STORE32_I64 0, texternalsym:$off, (CONST_I32 0), I64:$val)>; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatOffsetOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatGlobalAddrOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; +def : StorePatExternSymOffOnly; let Defs = [ARGUMENTS] in {