object-introspection/oi/FuncGen.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
3.7 KiB
C
Raw Permalink Normal View History

2022-12-19 14:37:51 +00:00
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <filesystem>
#include <map>
#include <set>
2023-08-16 20:40:36 +01:00
#include <span>
2022-12-19 14:37:51 +00:00
#include <string>
2023-04-26 16:20:53 +01:00
#include "oi/ContainerInfo.h"
2023-06-22 17:27:21 +01:00
#include "oi/Features.h"
2022-12-19 14:37:51 +00:00
namespace fs = std::filesystem;
namespace oi::detail {
2022-12-19 14:37:51 +00:00
class FuncGen {
public:
2023-08-16 20:40:36 +01:00
static void DeclareExterns(std::string& code);
2023-09-27 02:14:23 +01:00
static void DefineJitLog(std::string& code, FeatureSet features);
2023-08-16 20:40:36 +01:00
static void DeclareStoreData(std::string& testCode);
static void DefineStoreData(std::string& testCode);
2022-12-19 14:37:51 +00:00
static void DeclareEncodeData(std::string& testCode);
static void DefineEncodeData(std::string& testCode);
2022-12-19 14:37:51 +00:00
static void DeclareEncodeDataSize(std::string& testCode);
static void DefineEncodeDataSize(std::string& testCode);
2022-12-19 14:37:51 +00:00
bool DeclareGetSizeFuncs(std::string& testCode,
const ContainerInfoRefSet& containerInfo,
FeatureSet features);
2022-12-19 14:37:51 +00:00
bool DefineGetSizeFuncs(std::string& testCode,
const ContainerInfoRefSet& containerInfo,
FeatureSet features);
2022-12-19 14:37:51 +00:00
static void DeclareGetContainer(std::string& testCode);
2022-12-19 14:37:51 +00:00
static void DeclareGetSize(std::string& testCode, const std::string& type);
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
static void DefineTopLevelIntrospect(std::string& code,
codegenv2: improve multi argument generation (#395) Summary: Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types. This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con. This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change. Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files. Differential Revision: D50835153 Pulled By: JakeHillion
2023-10-31 17:22:56 +00:00
const std::string& type,
const std::string& idToHash);
static void DefineTopLevelIntrospectNamed(
std::string& code,
const std::string& type,
const std::string& linkageName,
size_t exclusiveSize,
std::span<const std::string_view> typeNames);
2022-12-19 14:37:51 +00:00
static void DefineTopLevelGetSizeRef(std::string& testCode,
codegenv2: improve multi argument generation (#395) Summary: Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types. This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con. This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change. Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files. Differential Revision: D50835153 Pulled By: JakeHillion
2023-10-31 17:22:56 +00:00
const std::string& type,
const std::string& idToHash,
FeatureSet features);
static void DefineTopLevelGetSizeRefTyped(std::string& testCode,
codegenv2: improve multi argument generation (#395) Summary: Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types. This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con. This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change. Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files. Differential Revision: D50835153 Pulled By: JakeHillion
2023-10-31 17:22:56 +00:00
const std::string& type,
const std::string& idToHash,
FeatureSet features);
static void DefineOutputType(std::string& testCode,
codegenv2: improve multi argument generation (#395) Summary: Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types. This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con. This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change. Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files. Differential Revision: D50835153 Pulled By: JakeHillion
2023-10-31 17:22:56 +00:00
const std::string& type,
const std::string& idToHash);
2023-08-16 20:40:36 +01:00
static void DefineTreeBuilderInstructions(
std::string& testCode,
codegenv2: improve multi argument generation (#395) Summary: Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types. This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con. This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change. Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files. Differential Revision: D50835153 Pulled By: JakeHillion
2023-10-31 17:22:56 +00:00
const std::string& type,
const std::string& idToHash,
2023-08-16 20:40:36 +01:00
size_t exclusiveSize,
std::span<const std::string_view> typeNames);
2022-12-19 14:37:51 +00:00
static void DefineTopLevelGetSizeSmartPtr(std::string& testCode,
const std::string& rawType,
FeatureSet features);
2022-12-19 14:37:51 +00:00
static void DefineGetSizeTypedValueFunc(std::string& testCode,
const std::string& ctype);
2023-04-20 18:30:59 +01:00
static void DefineDataSegmentDataBuffer(std::string& testCode);
2023-08-16 20:40:36 +01:00
static void DefineBackInserterDataBuffer(std::string& code);
static void DefineBasicTypeHandlers(std::string& code, FeatureSet features);
static ContainerInfo GetOiArrayContainerInfo();
2022-12-19 14:37:51 +00:00
};
} // namespace oi::detail