Skip to content

Commit

Permalink
Removes some deprecated functions, and removes the basic block functi… (
Browse files Browse the repository at this point in the history
#569)

* Removes some deprecated functions, and removes the basic block function cloning apis, in favor of apis on Arch

* More tweaks for removing unnecessary APIs

* Goodbye dse

* Fix issue

* Tweaks

* Remove some annoying logs
  • Loading branch information
pgoodman authored Dec 17, 2021
1 parent 93aba7c commit 28e48fe
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 2,377 deletions.
2 changes: 0 additions & 2 deletions bin/lift/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ int main(int argc, char *argv[]) {
// Optimize the module, but with a particular focus on only the functions
// that we actually lifted.
remill::OptimizationGuide guide = {};
guide.eliminate_dead_stores = true;
remill::OptimizeModule(arch, module, manager.traces, guide);

// Create a new module in which we will move all the lifted functions. Prepare
Expand Down Expand Up @@ -422,7 +421,6 @@ int main(int argc, char *argv[]) {

guide.slp_vectorize = true;
guide.loop_vectorize = true;
guide.eliminate_dead_stores = false;
remill::OptimizeBareModule(&dest_module, guide);
}

Expand Down
29 changes: 24 additions & 5 deletions include/remill/Arch/Arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,27 @@ class Arch {
// Returns the name of the program counter register.
virtual std::string_view ProgramCounterRegisterName(void) const = 0;

// Create a lifted function declaration with name `name` inside of `module`.
//
// NOTE(pag): This should be called after `PrepareModule` and after the
// semantics have been loaded.
llvm::Function *DeclareLiftedFunction(std::string_view name,
llvm::Module *module) const;

// Create a lifted function with name `name` inside of `module`.
//
// NOTE(pag): This should be called after `PrepareModule` and after the
// semantics have been loaded.
llvm::Function *DefineLiftedFunction(std::string_view name,
llvm::Module *module) const;

// Initialize an empty lifted function with the default variables that it
// should contain.
void InitializeEmptyLiftedFunction(llvm::Function *func) const;

// Converts an LLVM module object to have the right triple / data layout
// information for the target architecture and ensures remill required functions
// have the appropriate prototype and internal variables
// information for the target architecture and ensures remill required
// functions have the appropriate prototype and internal variables
void PrepareModule(llvm::Module *mod) const;

// Get the state pointer and various other types from the `llvm::LLVMContext`
Expand Down Expand Up @@ -293,9 +311,10 @@ class Arch {
// Populate the table of register information.
virtual void PopulateRegisterTable(void) const = 0;

// Populate the `__remill_basic_block` function with variables.
virtual void PopulateBasicBlockFunction(llvm::Module *module,
llvm::Function *bb_func) const = 0;
// Populate a just-initialized lifted function function with architecture-
// specific variables.
virtual void FinishLiftedFunctionInitialization(
llvm::Module *module, llvm::Function *bb_func) const = 0;

llvm::Triple BasicTriple(void) const;

Expand Down
4 changes: 0 additions & 4 deletions include/remill/Arch/Runtime/Intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

extern "C" {

// The basic block "template".
[[gnu::used]] Memory *__remill_basic_block(State &state, addr_t pc,
Memory *memory);

// Memory read intrinsics.
[[gnu::used, gnu::const]] extern uint8_t __remill_read_memory_8(Memory *,
addr_t);
Expand Down
4 changes: 1 addition & 3 deletions include/remill/Arch/X86/Runtime/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,7 @@ static_assert(96 == sizeof(AddressSpace),

// Named the same way as the 64-bit version to keep names the same
// across architectures. All registers are here, even the 64-bit ones. The
// 64-bit ones are inaccessible in lifted 32-bit code because they will
// not be referenced by named variables in the `__remill_basic_block`
// function.
// 64-bit ones are not used in lifted 32-bit code.
struct alignas(8) GPR final {

// Prevents LLVM from casting a `GPR` into an `i64` to access `rax`.
Expand Down
3 changes: 0 additions & 3 deletions include/remill/BC/Annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ static bool Remove(llvm::Function *func) {
template <typename OriginType>
static void Annotate(llvm::Function *func) {
auto &C = func->getContext();
DLOG(INFO) << "Annotating: " << func->getName().str() << ": "
<< OriginType::metadata_kind << " -> "
<< OriginType::metadata_value;
auto node =
llvm::MDNode::get(C, llvm::MDString::get(C, OriginType::metadata_value));
func->setMetadata(OriginType::metadata_kind, node);
Expand Down
64 changes: 0 additions & 64 deletions include/remill/BC/DeadStoreEliminator.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/remill/BC/InstructionLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class InstructionLifter {
void ClearCache(void) const;

protected:
friend class TraceLifter;

// Lift an operand to an instruction.
virtual llvm::Value *LiftOperand(Instruction &inst, llvm::BasicBlock *block,
llvm::Value *state_ptr, llvm::Argument *arg,
Expand Down Expand Up @@ -136,6 +134,8 @@ class InstructionLifter {
std::string_view reg_name, llvm::ConstantInt *zero);

private:
friend class TraceLifter;

InstructionLifter(const InstructionLifter &) = delete;
InstructionLifter(InstructionLifter &&) noexcept = delete;
InstructionLifter(void) = delete;
Expand Down
2 changes: 1 addition & 1 deletion include/remill/BC/Lifter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 202 Trail of Bits, Inc.
* Copyright (c) 2020 Trail of Bits, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
8 changes: 2 additions & 6 deletions include/remill/BC/Optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct OptimizationGuide {
bool loop_vectorize;
bool verify_input;
bool verify_output;
bool eliminate_dead_stores;
};

template <typename T>
Expand Down Expand Up @@ -165,11 +164,8 @@ inline static void OptimizeModule(const remill::Arch *arch,
return OptimizeModule(arch, module, trace_func_gen, guide);
}

// Optimize a normal module. This might not contain special functions
// like `__remill_basic_block`.
//
// NOTE(pag): It is an error to specify `guide.eliminate_dead_stores` as
// `true`.
// Optimize a normal module. This might not contain special Remill-specific
// intrinsics functions like `__remill_jump`, etc.
void OptimizeBareModule(llvm::Module *module, OptimizationGuide guide = {});

inline static void
Expand Down
34 changes: 0 additions & 34 deletions include/remill/BC/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,6 @@ std::string FindSemanticsBitcodeFile(std::string_view arch);
// Return a pointer to the Nth argument (N=0 is the first argument).
llvm::Argument *NthArgument(llvm::Function *func, size_t index);

// Returns a pointer to the `__remill_basic_block` function.
llvm::Function *BasicBlockFunction(llvm::Module *module);

// Return the type of a lifted function.
//
// NOTE(pag): Deprecated. Use `remill::Arch::LiftedFunctionType()` instead.
llvm::FunctionType *LiftedFunctionType(llvm::Module *module)
__attribute__((deprecated));

// Return a vector of arguments to pass to a lifted function, where the
// arguments are derived from `block`.
std::array<llvm::Value *, kNumBlockArgs>
Expand All @@ -200,28 +191,6 @@ using ISelCallback =
std::function<void(llvm::GlobalVariable *, llvm::Function *)>;
void ForEachISel(llvm::Module *module, ISelCallback callback);

// Declare a lifted function of the correct type.
llvm::Function *DeclareLiftedFunction(llvm::Module *module,
std::string_view name);

// Returns the type of a state pointer.
//
// NOTE(pag): Deprecated. Use `remill::Arch::StatePointerType()` instead.
llvm::PointerType *StatePointerType(llvm::Module *module)
__attribute__((deprecated));

// Returns the type of a state pointer.
//
// NOTE(pag): Deprecated. Use `remill::Arch::MemoryPointerType()` instead.
llvm::PointerType *MemoryPointerType(llvm::Module *module)
__attribute__((deprecated));

// Returns the type of an address (addr_t in the State.h).
//
// NOTE(pag): Deprecated. Use `remill::Arch::AddressType()` instead.
llvm::IntegerType *AddressType(llvm::Module *module)
__attribute__((deprecated));

using ValueMap = std::unordered_map<llvm::Value *, llvm::Value *>;
using TypeMap = std::unordered_map<llvm::Type *, llvm::Type *>;
using MDMap = std::unordered_map<llvm::Metadata *, llvm::Metadata *>;
Expand All @@ -242,9 +211,6 @@ void CloneFunctionInto(llvm::Function *source_func, llvm::Function *dest_func,
// `source_func` into the module of `dest_func`.
void CloneFunctionInto(llvm::Function *source_func, llvm::Function *dest_func);

// Make `func` a clone of the `__remill_basic_block` function.
void CloneBlockFunctionInto(llvm::Function *func);

// Returns a list of callers of a specific function.
std::vector<llvm::CallInst *> CallersOf(llvm::Function *func);

Expand Down
7 changes: 4 additions & 3 deletions lib/Arch/AArch32/Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ void AArch32Arch::PopulateRegisterTable(void) const {
}


// Populate the `__remill_basic_block` function with variables.
void AArch32Arch::PopulateBasicBlockFunction(llvm::Module *module,
llvm::Function *bb_func) const {
// Populate a just-initialized lifted function function with architecture-
// specific variables.
void AArch32Arch::FinishLiftedFunctionInitialization(
llvm::Module *module, llvm::Function *bb_func) const {
const auto &dl = module->getDataLayout();
CHECK_EQ(sizeof(State), dl.getTypeAllocSize(StateStructType()))
<< "Mismatch between size of State type for x86/amd64 and what is in "
Expand Down
7 changes: 4 additions & 3 deletions lib/Arch/AArch32/Arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class AArch32Arch final : public Arch {
// Populate the table of register information.
void PopulateRegisterTable(void) const final;

// Populate the `__remill_basic_block` function with variables.
void PopulateBasicBlockFunction(llvm::Module *module,
llvm::Function *bb_func) const final;
// Populate a just-initialized lifted function function with architecture-
// specific variables.
void FinishLiftedFunctionInitialization(
llvm::Module *module, llvm::Function *bb_func) const final;

private:
AArch32Arch(void) = delete;
Expand Down
12 changes: 0 additions & 12 deletions lib/Arch/AArch32/Runtime/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,3 @@

#include "remill/Arch/AArch32/Runtime/State.h"
#include "remill/Arch/Runtime/Float.h"

extern "C" {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"

// Instructions will be lifted into clones of this function.
[[gnu::used]] Memory *__remill_basic_block(State &, addr_t, Memory *);

#pragma clang diagnostic pop

} // extern C
14 changes: 8 additions & 6 deletions lib/Arch/AArch64/Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ class AArch64Arch final : public Arch {
// Populate the table of register information.
void PopulateRegisterTable(void) const final;

// Populate the `__remill_basic_block` function with variables.
void PopulateBasicBlockFunction(llvm::Module *module,
llvm::Function *bb_func) const final;
// Populate a just-initialized lifted function function with architecture-
// specific variables.
void FinishLiftedFunctionInitialization(
llvm::Module *module, llvm::Function *bb_func) const final;

private:
AArch64Arch(void) = delete;
Expand Down Expand Up @@ -458,9 +459,10 @@ void AArch64Arch::PopulateRegisterTable(void) const {
REG(TPIDRRO_EL0, sr.tpidrro_el0.qword, u64);
}

// Populate the `__remill_basic_block` function with variables.
void AArch64Arch::PopulateBasicBlockFunction(llvm::Module *module,
llvm::Function *bb_func) const {
// Populate a just-initialized lifted function function with architecture-
// specific variables.
void AArch64Arch::FinishLiftedFunctionInitialization(
llvm::Module *module, llvm::Function *bb_func) const {

auto &context = module->getContext();
auto u32 = llvm::Type::getInt32Ty(context);
Expand Down
7 changes: 0 additions & 7 deletions lib/Arch/AArch64/Runtime/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@

#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/Arch/Runtime/Float.h"

extern "C" {

// Instructions will be lifted into clones of this function.
[[gnu::used]] Memory *__remill_basic_block(State &, addr_t, Memory *);

} // extern C
Loading

0 comments on commit 28e48fe

Please sign in to comment.