From: Gabe Black Date: Mon, 23 Dec 2019 06:00:46 +0000 (-0800) Subject: sim: Rename allocate in GuestABI to prepare. X-Git-Tag: v20.0.0.0~358 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4e894d867398eb8c3732343b159bedf248bf96b1;p=gem5.git sim: Rename allocate in GuestABI to prepare. This method can be used for allocating resources for registers and/or arguments, but it can also be used for generic preparation for them as well. For instance, it can be used to detect some sort of property of the function signature as a whole (if it's variadic for instance) which can be stored in position and used to change ABI behavior. Change-Id: I8a090be65dc4987e35cd115562114cd1b748155f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24106 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/sim/guest_abi.hh b/src/sim/guest_abi.hh index 97d3e21e3..310fc00d0 100644 --- a/src/sim/guest_abi.hh +++ b/src/sim/guest_abi.hh @@ -50,7 +50,7 @@ invokeSimcall(ThreadContext *tc, // Default construct a Position to track consumed resources. Built in // types will be zero initialized. auto position = GuestABI::initializePosition(tc); - GuestABI::allocateSignature(tc, position); + GuestABI::prepareForFunction(tc, position); return GuestABI::callFrom(tc, position, target); } @@ -70,7 +70,7 @@ invokeSimcall(ThreadContext *tc, // Default construct a Position to track consumed resources. Built in // types will be zero initialized. auto position = GuestABI::initializePosition(tc); - GuestABI::allocateArguments(tc, position); + GuestABI::prepareForArguments(tc, position); GuestABI::callFrom(tc, position, target); } @@ -96,7 +96,7 @@ dumpSimcall(std::string name, ThreadContext *tc, auto position = GuestABI::initializePosition(tc); std::ostringstream ss; - GuestABI::allocateSignature(tc, position); + GuestABI::prepareForFunction(tc, position); ss << name; GuestABI::dumpArgsFrom(0, ss, tc, position); return ss.str(); diff --git a/src/sim/guest_abi.test.cc b/src/sim/guest_abi.test.cc index 9b1fe6121..9ac7defc2 100644 --- a/src/sim/guest_abi.test.cc +++ b/src/sim/guest_abi.test.cc @@ -66,8 +66,8 @@ struct TestABI_1D using Position = int; }; -// ABI anchor for an ABI which uses the allocate() hook. -struct TestABI_Allocate +// ABI anchor for an ABI which uses the prepare() hook. +struct TestABI_Prepare { using Position = int; }; @@ -136,31 +136,31 @@ struct Result -struct Argument +struct Argument { static int - get(ThreadContext *tc, TestABI_Allocate::Position &position) + get(ThreadContext *tc, TestABI_Prepare::Position &position) { return tc->ints[--position]; } static void - allocate(ThreadContext *tc, TestABI_Allocate::Position &position) + prepare(ThreadContext *tc, TestABI_Prepare::Position &position) { position++; } }; template -struct Result +struct Result { static void store(ThreadContext *tc, const Ret &ret) {} static void - allocate(ThreadContext *tc, TestABI_Allocate::Position &position) + prepare(ThreadContext *tc, TestABI_Prepare::Position &position) { position++; } @@ -243,14 +243,14 @@ testIntVoid(ThreadContext *tc, int a, float b, int c, double d, // Test functions which verify that the return allocating ABI allocates space // for its return value successfully. void -testAllocateVoid(ThreadContext *tc, int a, int b) +testPrepareVoid(ThreadContext *tc, int a, int b) { EXPECT_EQ(a, tc->ints[1]); EXPECT_EQ(b, tc->ints[0]); } int -testAllocateInt(ThreadContext *tc, int a, int b) +testPrepareInt(ThreadContext *tc, int a, int b) { EXPECT_EQ(a, tc->ints[2]); EXPECT_EQ(b, tc->ints[1]); @@ -299,11 +299,11 @@ TEST(GuestABI, ABI_1D_args) EXPECT_EQ(tc.floatResult, tc.DefaultFloatResult); } -TEST(GuestABI, ABI_Allocate) +TEST(GuestABI, ABI_Prepare) { ThreadContext tc; - invokeSimcall(&tc, testAllocateVoid); - invokeSimcall(&tc, testAllocateInt); + invokeSimcall(&tc, testPrepareVoid); + invokeSimcall(&tc, testPrepareInt); } TEST(GuestABI, ABI_2D_args) diff --git a/src/sim/guest_abi/definition.hh b/src/sim/guest_abi/definition.hh index c61d1aef9..b43a482d0 100644 --- a/src/sim/guest_abi/definition.hh +++ b/src/sim/guest_abi/definition.hh @@ -72,11 +72,12 @@ struct Result typename ABI::Position &position); /* - * Adjust the position of arguments based on the return type, if necessary. + * Prepare for a result of type Ret. This might mean, for instance, + * allocating an argument register for a result pointer. * - * This method can be excluded if no adjustment is necessary. + * This method can be excluded if no preparation is necessary. */ - static void allocate(ThreadContext *tc, typename ABI::Position &position); + static void prepare(ThreadContext *tc, typename ABI::Position &position); }; /* @@ -101,10 +102,10 @@ struct Argument static Arg get(ThreadContext *tc, typename ABI::Position &position); /* - * Adjust the position of arguments based on the argument type, if - * necessary. + * Prepare for an argument of type Arg. This might mean, for instance, + * allocating an argument register for a result pointer. * - * This method can be excluded if no adjustment is necessary. + * This method can be excluded if no preparation is necessary. */ static void allocate(ThreadContext *tc, typename ABI::Position &position); }; diff --git a/src/sim/guest_abi/layout.hh b/src/sim/guest_abi/layout.hh index 562f3ee33..ecc3a0826 100644 --- a/src/sim/guest_abi/layout.hh +++ b/src/sim/guest_abi/layout.hh @@ -71,63 +71,63 @@ initializePosition(const ThreadContext *tc) } /* - * This struct template provides a default allocate() method in case the + * This struct template provides a default prepare() method in case the * Result or Argument template doesn't provide one. This is the default in * cases where the return or argument type doesn't affect where things are * stored. */ template class Role, typename Type, typename Enabled=void> -struct Allocator +struct Preparer { static void - allocate(ThreadContext *tc, typename ABI::Position &position) + prepare(ThreadContext *tc, typename ABI::Position &position) {} }; /* * If the return or argument type isn't void and does affect where things - * are stored, the ABI can implement an allocate() method for the various + * are stored, the ABI can implement a prepare() method for the various * argument and/or return types, and this specialization will call into it. */ template class Role, typename Type> -struct Allocator::allocate)> +struct Preparer::prepare)> { static void - allocate(ThreadContext *tc, typename ABI::Position &position) + prepare(ThreadContext *tc, typename ABI::Position &position) { - Role::allocate(tc, position); + Role::prepare(tc, position); } }; template static void -allocateResult(ThreadContext *tc, typename ABI::Position &position) +prepareForResult(ThreadContext *tc, typename ABI::Position &position) { - Allocator::allocate(tc, position); + Preparer::prepare(tc, position); } template static void -allocateArguments(ThreadContext *tc, typename ABI::Position &position) +prepareForArguments(ThreadContext *tc, typename ABI::Position &position) { return; } template static void -allocateArguments(ThreadContext *tc, typename ABI::Position &position) +prepareForArguments(ThreadContext *tc, typename ABI::Position &position) { - Allocator::allocate(tc, position); - allocateArguments(tc, position); + Preparer::prepare(tc, position); + prepareForArguments(tc, position); } template static void -allocateSignature(ThreadContext *tc, typename ABI::Position &position) +prepareForFunction(ThreadContext *tc, typename ABI::Position &position) { - allocateResult(tc, position); - allocateArguments(tc, position); + prepareForResult(tc, position); + prepareForArguments(tc, position); } /*