mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
330d2b6cc7
This commit: * Introduces `_` as a prefix for all non-user entities we emit in decompiled code. Also, some names have been changed to be more concise. Specifically, the following entities have changed: `_ENUM_UNDERLYING`, `_ABI`, `_REG`, `_padding_at_`, `_artificial_struct_`, `_artificial_wrapper_`, `_stack`, `_break_from_loop_`, `_var_`, `_stack_arguments`, `_artificial_struct_returned_`, `_enum_max_value_`. * Introduce _PACKED for `__attribute__((packed))`. * `EnumEntry` name: drop the `EnumType` name prefix.
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
//
|
|
// Copyright (c) rev.ng Labs Srl. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Support/Casting.h"
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "revng/Support/Debug.h"
|
|
#include "revng/Support/FunctionTags.h"
|
|
#include "revng/Support/IRHelpers.h"
|
|
|
|
#include "revng-c/PromoteStackPointer/RemoveStackAlignmentPass.h"
|
|
|
|
using namespace llvm;
|
|
|
|
static bool isMask(Value *V, unsigned MaxMaskedBits) {
|
|
if (auto *CI = dyn_cast<ConstantInt>(V)) {
|
|
APInt Value = CI->getValue();
|
|
Value.flipAllBits();
|
|
return (Value.isMask() and Value.countTrailingOnes() <= MaxMaskedBits);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool RemoveStackAlignmentPass::runOnModule(Module &Module) {
|
|
if (FunctionTags::Isolated.functions(&Module).empty())
|
|
return false;
|
|
|
|
auto *InitFunction = Module.getFunction("_init_local_sp");
|
|
revng_assert(InitFunction != nullptr);
|
|
|
|
bool Result = false;
|
|
for (CallBase *Call : callers(InitFunction)) {
|
|
for (User *U : Call->users()) {
|
|
if (auto *I = dyn_cast<BinaryOperator>(U)) {
|
|
if (I->getOpcode() == Instruction::And
|
|
and isMask(I->getOperand(1), 12)) {
|
|
U->replaceAllUsesWith(I->getOperand(0));
|
|
Result = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return Result;
|
|
}
|
|
|
|
void RemoveStackAlignmentPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.setPreservesCFG();
|
|
}
|
|
|
|
char RemoveStackAlignmentPass::ID = 0;
|
|
|
|
using Register = RegisterPass<RemoveStackAlignmentPass>;
|
|
static Register R("remove-stack-alignment", "Remove Stack Alignment Pass");
|