Commit Graph

3168 Commits

Author SHA1 Message Date
Giacomo Vercesi 8d89c6a318 PipelineC: rp_initialize: only use argc and argv
Switch from specifying `libraries` and `pipelines` in `rp_initialize`
and `rp_manager_create` to the use of command-line options that are to
be passed via `argc` and `argv` in `rp_initialize`.
2023-04-20 14:43:12 +02:00
Giacomo Vercesi 9a972009d1 PipelineC: size and const-correctness
Fix the return type (often mismatched from uint64_t to int) and the
const-correctness of many functions in PipelineC
2023-04-20 14:43:12 +02:00
Andrea Gussoni 659aff1bbf Fix loop promotion criterion
A bug introduced no loop promotion by mistake, we now correctly exit the
loop promotion routine if the loop has been already promoted to `while`
or `do-while` loop.
2023-04-19 16:07:46 +02:00
Pietro Fezzardi 8413e6e872 InitModelType: fix type of cstringLiterals 2023-04-14 14:54:14 +02:00
Pietro Fezzardi 56db9e6660 Make getExpectedModelType more strict on integers
This commit teaches getExpectedModelType about the fact that various
bitwise operations are only allowed to have integer operands.

It also updates VMA, which uses getExpectedModelType, to take this
into account.
2023-04-14 14:54:14 +02:00
Pietro Fezzardi 118929b8fd InitModelTypes: don't run VMA if PointerOnly 2023-04-14 14:54:14 +02:00
Alessandro Di Federico f7a3fa8f07 SegregateStackAccesses: fix returning structs
In SegregateStackAccesses sometimes we have to replace a call whose call
type does not match the callee type. Specifically when the return type
is a `StructType`, sometimes the call returns an identical `StructType`,
but with a different identity.

This commit adapts the return type of new calls on the fly.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 35d2323fa0 SegregateStackAccesses: assert(findAssociatedCall) 2023-04-14 14:54:14 +02:00
Alessandro Di Federico be79842827 Enable DCE of revng_init_local_sp 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 2bacc7ab68 DecompileFunction: fix handling of {and,or} i1
We used to emit bitwise `&` and `|` but, given that we emit `i1` as
`bool`, it's more appropriate to use `&&` and `||`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b09526a5b4 DecompileFunction: drop redundant handling of IntToPtr
They were already handle above since `isa<IntToPtr>` implies
`isa<CastInst>`. Same for `PtrToInt`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico a9eae1c96b Purge remaining traces of InsertValueInst
InsertValue has long been superseded by `struct_initialier`, so we don't
expect it in the IR we work on.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 79c2ca38f6 Introduce SplitOverflowIntrinsicsPass
This pass splits calls `*.with.overflow*` intrinsics into the a pair of
instructions: the underlying operation and a call to an `Helper`-tagged
function that computes whether such operation overflowed.

For instance, we go from:

    %2 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %0, i32 %1)
    %3 = extractvalue { i32, i1 } %2, 1
    br i1 %3, label %..., label %...

To:

    %2 = mul i32 %0, %1
    %3 = call i1 @mul_overflow_u32(i32 %0, i32 %1)
    br i1 %3, label %..., label %...

This saves from handling `struct` in the backend.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 82fcf858ba getStrongModelInfo: handle call_stack_arguments 2023-04-14 14:54:14 +02:00
Alessandro Di Federico c8a955813d getStrongModelInfo: fix prototype lookup in model
Limit lookup of function prototypes in the model to isolated functions
only.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b206957e5f DetectStackSizeAnalysis: fail if no Architecture 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 8860ea16e2 Introduce HoistStructPhis
This pass turns phis of invocations of pure functions into an invocation
of the pure functions with one phis per argument of the original
invocations.

This makes handling phis easier in the backend and is necessary after
the introduction of simplify-cfg with sinking enabled.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b73bb90d0c Handle the freeze instruction 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 2deb057364 DecompileFunction: introduce buildInvalid
Factor code to emit poison and undef values.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ccb660646e Introduce SimplifyCFGWithHoistAndSinkPass
This is a simple pass that enables running simplify-cfg with the legacy
pass manager enabling instruction hoisting and sinking.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 859a9ec2cf SegregateStackAccesses: do not iterate and modify
SegregateStackAccesses creates new functions. Iterating over existing
functions while creating new ones is problematic, so we now first
collect all the functions we want to inspect and then process them.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 886e1696a2 llvmIntToModelType: adapt to opaque pointers
This commit introduces modelType, which supersedes `llvmIntToModelType`
in order to better handle translation of LLVM types into model types
after introduction of opaque pointer types.  The main differences is
that `modelType` accepts the `Value` (instead of just the `Type`), so it
can better handle `AllocaInst` and `GlobalVariable`, which provide
information about the pointee.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 5cfeb0fc36 InjectStackSizeProbesAtCallSitesPass: use nomerge
The `nomerge` attribute prevents this type of problematic deduplication
(specifically by simplify-cfg with sinking enabled) of calls to markers.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico f87a86677d MakeModelGEP: handle multiple identical incoming
Since MakeModelGEP works Use-wise, if a `Value` was used multiple times
in a phi, we used to replace them with distinct model GEPs. This led to
generate illegal IR.

This commit fixes this situation by detecting the situation and reusing
the same model GEP.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico c32f7cd8f3 LoopRewriteWithCanonicalIV: NewVal == Op 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ba05ddfaaf DLA: handle ConstantPointerNull 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6610213da4 DLA: drop support for InsertValue
They shouldn't appear in the IR at this stage of the pipeline.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 03bbf22a48 DLA: improve handling of phis
DLA used to support phis in return values, but didn't handle phis
referring to other phis.
This commit fixes that.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 237aefcc9a DLA: drop LoopInfoWrapperPass
It was not being used.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 82512ef81f CreateIntToPtr: adopt opaque pointer type 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ef6ec4ed0f Minor changes 2023-04-14 14:54:14 +02:00
Alessandro Di Federico d33f339ec9 Adapt to revng.callerblock.start dismission
We no longer attach non-dbg metadata to instructions, it's not robust.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 3d5e0d3106 DecompileFunction: update handling of strings
Simplify the emission of string literas after the introduction of opaque
pointers, which basically take out of the equation GEP ConstantExpr.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6b7a62fff8 AddAssignmentMarkersPass::run*: fix return value 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 7291314505 Stop using getPointer
After introduction of opaque pointers, it's not very effective.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 017aa6a47f Drop CallToLifted
We no longer have such tag, we now inspect the callee using
`isCallToIsolatedFunction`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 4c469e5180 Adopt getCallToTagged
`isCallToTagged` used to return a pointer in case of success.
We now have `getCallToTagged` for that.

Also, these functions have been moved to revng.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ead746ba68 Adopt MemoryEffects
Switch from function attributes to MemoryEffects.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 50838957f4 Adopt new isSafeToExpandAt usage 2023-04-14 14:54:14 +02:00
Alessandro Di Federico f86ca062b4 DLA: handle scSequentialUMinExpr 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 4a3b75757d s/zextOrSelf/zext/g 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 887009a14b InaccessibleMemOnly: adopt MemoryEffects 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 340f64e150 Drop usages of PointerType::getElementType 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 21bbd8b414 Drop usages of Type::getPointerElementType 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 95615cf400 Adopt new APInt::toString signature 2023-04-14 14:54:14 +02:00
Alessandro Di Federico cad027abb2 Add missing includes 2023-04-14 14:54:14 +02:00
Alessandro Di Federico e2ee3f5495 Switch from llvm::Optional to std::optional 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 0e5863e2e4 Make CreateLoad usages opaque pointers-compatible 2023-04-14 14:54:14 +02:00
Alessandro Di Federico b9dcb977bd Adopt CallBase::arg_size 2023-04-14 14:54:14 +02:00
Alessandro Di Federico dd383076ab Drop arg_operands in favor of args 2023-04-14 14:54:14 +02:00