Layout for stage 1 of pinpoint plugin

This commit is contained in:
York Jasper Niebuhr 2025-10-25 14:12:56 +02:00
parent 31f8c19b6f
commit 6c1183edc5
7 changed files with 88 additions and 4 deletions

View File

@ -9,3 +9,4 @@ message(STATUS "GCC plugin path: ${GCC_PLUGIN_PATH}")
target_include_directories(spslr_pinpoint PRIVATE ${GCC_PLUGIN_PATH}/include ${CMAKE_CURRENT_SOURCE_DIR}/safegcc ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(stage0)
add_subdirectory(stage1)

View File

@ -4,6 +4,7 @@
#include <safe-plugin-version.h>
#include <stage0.h>
#include <stage1.h>
int plugin_is_GPL_compatible;
@ -26,7 +27,14 @@ int plugin_init(struct plugin_name_args* plugin_info, struct plugin_gcc_version*
separate_offset_pass_info.pos_op = PASS_POS_INSERT_AFTER;
register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, nullptr, &separate_offset_pass_info);
// Stage 1 -> TODO
// Stage 1 -> stage 0 separators are replaced with inline assembly
struct register_pass_info asm_offset_pass_info;
asm_offset_pass_info.pass = new asm_offset_pass(nullptr);
asm_offset_pass_info.ref_pass_instance_number = 1;
asm_offset_pass_info.reference_pass_name = "separate_offset";
asm_offset_pass_info.pos_op = PASS_POS_INSERT_AFTER;
register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, nullptr, &asm_offset_pass_info);
return 0;
}

View File

@ -1,4 +1,5 @@
#include <safe-gcc-plugin.h>
#include <safe-tree.h>
#ifndef SAFEGCC_GIMPLE_H
#define SAFEGCC_GIMPLE_H

View File

@ -1,5 +1,6 @@
#include <stage0.h>
#include <pinpoint_config.h>
#include <pinpoint_error.h>
static tree separator_decl = NULL_TREE;
@ -62,8 +63,40 @@ gimple* make_stage0_gimple_separator(tree lhs, UID target, std::size_t offset) {
return call;
}
bool is_stage0_separator(gimple* stmt, UID& target, std::size_t& offset) {
// TODO
return false;
static bool decl_is_separator(tree fndecl) {
if (!fndecl)
return false;
tree name_tree = DECL_NAME(fndecl);
if (!name_tree)
return false;
const char* name = IDENTIFIER_POINTER(name_tree);
if (!name)
return false;
return strcmp(name, SPSLR_PINPOINT_STAGE0_SEPARATOR) == 0;
}
bool is_stage0_separator(gimple* stmt, UID& target, std::size_t& offset) {
if (!stmt || !is_gimple_call(stmt))
return false;
tree fndecl = gimple_call_fndecl(stmt);
if (!decl_is_separator(fndecl))
return false;
tree arg0 = gimple_call_arg (stmt, 0);
tree arg1 = gimple_call_arg (stmt, 1);
if (!arg0 || TREE_CODE(arg0) != INTEGER_CST)
pinpoint_fatal("is_state0_separator failed to get target UID from separator");
if (!arg1 || TREE_CODE(arg1) != INTEGER_CST)
pinpoint_fatal("is_state0_separator failed to get field offset from separator");
target = static_cast<UID>(tree_to_uhwi(arg0));
offset = static_cast<std::size_t>(tree_to_uhwi(arg1));
return true;
}

View File

@ -0,0 +1,2 @@
target_sources(spslr_pinpoint PRIVATE asm_offset_pass.cpp)
target_include_directories(spslr_pinpoint PRIVATE .)

View File

@ -0,0 +1,31 @@
#include <stage1.h>
#include <stage0.h>
static void separator_assemble_maybe(gimple_stmt_iterator* gsi) {
// TODO
}
static const pass_data asm_offset_pass_data = {
GIMPLE_PASS,
"asm_offset",
OPTGROUP_NONE,
TV_NONE,
0,0,0,0,
TODO_update_ssa
};
asm_offset_pass::asm_offset_pass(gcc::context* ctxt) : gimple_opt_pass(asm_offset_pass_data, ctxt) {}
unsigned int asm_offset_pass::execute(function* fn) {
if (!fn)
return 0;
basic_block bb;
FOR_EACH_BB_FN(bb, fn) {
for (gimple_stmt_iterator gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
separator_assemble_maybe(&gsi);
}
return 0;
}

8
pinpoint/stage1/stage1.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <safe-gimple.h>
struct asm_offset_pass : gimple_opt_pass {
asm_offset_pass(gcc::context* ctxt);
unsigned int execute(function* fn) override;
};