[llvm] r369833 - [GlobalISel] Introduce a G_DYN_STACKALLOC opcode to represent dynamic allocas.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 19:25:57 PDT 2019
Author: aemerson
Date: Fri Aug 23 19:25:56 2019
New Revision: 369833
URL: http://llvm.org/viewvc/llvm-project?rev=369833&view=rev
Log:
[GlobalISel] Introduce a G_DYN_STACKALLOC opcode to represent dynamic allocas.
This just adds the opcode and verifier, it will be used to replace existing
dynamic alloca handling in a subsequent patch.
Differential Revision: https://reviews.llvm.org/D66677
Added:
llvm/trunk/test/MachineVerifier/test_g_dyn_stackalloc.mir
Modified:
llvm/trunk/include/llvm/Support/TargetOpcodes.def
llvm/trunk/include/llvm/Target/GenericOpcodes.td
llvm/trunk/lib/CodeGen/MachineVerifier.cpp
Modified: llvm/trunk/include/llvm/Support/TargetOpcodes.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetOpcodes.def?rev=369833&r1=369832&r2=369833&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/TargetOpcodes.def (original)
+++ llvm/trunk/include/llvm/Support/TargetOpcodes.def Fri Aug 23 19:25:56 2019
@@ -590,12 +590,15 @@ HANDLE_TARGET_OPCODE(G_BLOCK_ADDR)
/// Generic jump table address
HANDLE_TARGET_OPCODE(G_JUMP_TABLE)
+/// Generic dynamic stack allocation.
+HANDLE_TARGET_OPCODE(G_DYN_STACKALLOC)
+
// TODO: Add more generic opcodes as we move along.
/// Marker for the end of the generic opcode.
/// This is used to check if an opcode is in the range of the
/// generic opcodes.
-HANDLE_TARGET_OPCODE_MARKER(PRE_ISEL_GENERIC_OPCODE_END, G_JUMP_TABLE)
+HANDLE_TARGET_OPCODE_MARKER(PRE_ISEL_GENERIC_OPCODE_END, G_DYN_STACKALLOC)
/// BUILTIN_OP_END - This must be the last enum value in this list.
/// The target-specific post-isel opcode values start here.
Modified: llvm/trunk/include/llvm/Target/GenericOpcodes.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/GenericOpcodes.td?rev=369833&r1=369832&r2=369833&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GenericOpcodes.td (original)
+++ llvm/trunk/include/llvm/Target/GenericOpcodes.td Fri Aug 23 19:25:56 2019
@@ -189,6 +189,12 @@ def G_JUMP_TABLE : GenericInstruction {
let hasSideEffects = 0;
}
+def G_DYN_STACKALLOC : GenericInstruction {
+ let OutOperandList = (outs ptype0:$dst);
+ let InOperandList = (ins type1:$size, i32imm:$align);
+ let hasSideEffects = 1;
+}
+
//------------------------------------------------------------------------------
// Binary ops.
//------------------------------------------------------------------------------
Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=369833&r1=369832&r2=369833&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Fri Aug 23 19:25:56 2019
@@ -1437,6 +1437,27 @@ void MachineVerifier::verifyPreISelGener
break;
}
+ case TargetOpcode::G_DYN_STACKALLOC: {
+ const MachineOperand &DstOp = MI->getOperand(0);
+ const MachineOperand &AllocOp = MI->getOperand(1);
+ const MachineOperand &AlignOp = MI->getOperand(2);
+
+ if (!DstOp.isReg() || !MRI->getType(DstOp.getReg()).isPointer()) {
+ report("dst operand 0 must be a pointer type", MI);
+ break;
+ }
+
+ if (!AllocOp.isReg() || !MRI->getType(AllocOp.getReg()).isScalar()) {
+ report("src operand 1 must be a scalar reg type", MI);
+ break;
+ }
+
+ if (!AlignOp.isImm()) {
+ report("src operand 2 must be an immediate type", MI);
+ break;
+ }
+ break;
+ }
default:
break;
}
Added: llvm/trunk/test/MachineVerifier/test_g_dyn_stackalloc.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MachineVerifier/test_g_dyn_stackalloc.mir?rev=369833&view=auto
==============================================================================
--- llvm/trunk/test/MachineVerifier/test_g_dyn_stackalloc.mir (added)
+++ llvm/trunk/test/MachineVerifier/test_g_dyn_stackalloc.mir Fri Aug 23 19:25:56 2019
@@ -0,0 +1,25 @@
+# RUN: not llc -march=aarch64 -o /dev/null -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
+# REQUIRES: global-isel, aarch64-registered-target
+
+---
+name: test_dyn_stackalloc
+legalized: true
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $x0
+ %0:_(s64) = COPY $x0
+ %1:_(p0) = COPY $x0
+ ; CHECK: Bad machine code: Too few operands
+ G_DYN_STACKALLOC
+
+ ; CHECK: dst operand 0 must be a pointer type
+ %3:_(s64) = G_DYN_STACKALLOC %0, 4
+
+ ; CHECK: src operand 1 must be a scalar reg type
+ %4:_(p0) = G_DYN_STACKALLOC 0, 4
+
+ ; CHECK: src operand 2 must be an immediate type
+ %5:_(p0) = G_DYN_STACKALLOC %0, %0
+
+...
More information about the llvm-commits
mailing list