object-introspection/oi/FuncGen.h
Jake Hillion a49f0e7410 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 10:22:56 -07:00

98 lines
3.7 KiB
C++

/*
* 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>
#include <span>
#include <string>
#include "oi/ContainerInfo.h"
#include "oi/Features.h"
namespace fs = std::filesystem;
namespace oi::detail {
class FuncGen {
public:
static void DeclareExterns(std::string& code);
static void DefineJitLog(std::string& code, FeatureSet features);
static void DeclareStoreData(std::string& testCode);
static void DefineStoreData(std::string& testCode);
static void DeclareEncodeData(std::string& testCode);
static void DefineEncodeData(std::string& testCode);
static void DeclareEncodeDataSize(std::string& testCode);
static void DefineEncodeDataSize(std::string& testCode);
bool DeclareGetSizeFuncs(std::string& testCode,
const ContainerInfoRefSet& containerInfo,
FeatureSet features);
bool DefineGetSizeFuncs(std::string& testCode,
const ContainerInfoRefSet& containerInfo,
FeatureSet features);
static void DeclareGetContainer(std::string& testCode);
static void DeclareGetSize(std::string& testCode, const std::string& type);
static void DefineTopLevelIntrospect(std::string& code,
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);
static void DefineTopLevelGetSizeRef(std::string& testCode,
const std::string& type,
const std::string& idToHash,
FeatureSet features);
static void DefineTopLevelGetSizeRefTyped(std::string& testCode,
const std::string& type,
const std::string& idToHash,
FeatureSet features);
static void DefineOutputType(std::string& testCode,
const std::string& type,
const std::string& idToHash);
static void DefineTreeBuilderInstructions(
std::string& testCode,
const std::string& type,
const std::string& idToHash,
size_t exclusiveSize,
std::span<const std::string_view> typeNames);
static void DefineTopLevelGetSizeSmartPtr(std::string& testCode,
const std::string& rawType,
FeatureSet features);
static void DefineGetSizeTypedValueFunc(std::string& testCode,
const std::string& ctype);
static void DefineDataSegmentDataBuffer(std::string& testCode);
static void DefineBackInserterDataBuffer(std::string& code);
static void DefineBasicTypeHandlers(std::string& code, FeatureSet features);
static ContainerInfo GetOiArrayContainerInfo();
};
} // namespace oi::detail