Commit Graph

44 Commits

Author SHA1 Message Date
Lauri Vasama ca22055120 Emit clift.require in the Clifter 2026-05-13 15:32:34 +02:00
Pietro Fezzardi 8de85c25a0 Remove array field of opaque struct types 2026-05-13 08:51:25 +02:00
Andrea Gussoni 418263f804 Clifter: relax non packed struct check 2026-05-12 16:28:11 +02:00
Pietro Fezzardi da3ee051b9 Turn revng.stack_type into revng.stack_frame
The new named metadata doesn't embed the type of the stack anymore.
It's just a marker of the alloca that represents the stack frame.
2026-05-08 17:30:04 +02:00
Pietro Fezzardi f862e661af Clifter: make opaque types for arrays
When importing an alloca whose array size is not a constant 1,
import the alloca's element type as an opaque-array struct
instead of a real C array, matching the treatment that other
array-typed values already get. This keeps the rest of the
emitted code free of array rvalues that would otherwise decay to
pointers.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 141870ad9b Clifter: use LLVM DataLayout for struct sizes
Drop the previous workaround that always reported a struct byte
size of 0 (with a TODO referencing the missing DataLayout) and use
DataLayout::getStructLayout to get the real struct size. The
DataLayout is now available via the field added in a previous
commit.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 0ebea67eef Clifter: support model-sized pointers
Use model-sized pointers on function and call boundaries. These
are necessary for type checking, because llvm::DataLayout at the
moment is not guaranteed to have the same pointer size as the
model, due to quirks of how the DataLayout is initialised. The
function/call boundary is exactly where the model pointer size
becomes observable, so that's where the explicit cast is emitted.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 6c5ee3bd76 Clifter: s/emitImplicitCast/emitImplicitBitcast
Rename the helper to emitImplicitBitcast to make it clear that it
only ever emits a BitCastOp, never a more general cast. No
behavioural change.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi b8f10c2738 Clifter: drop type caches
Now that we need the llvm::DataLayout for e.g. computing pointer
sizes, caching pointer types becomes risky: different DataLayouts
coming from different LLVM Modules could disagree on the pointer
size, and securing against this would require clearing the caches
at every call to import.

Given that the caches in practice were not caching operations that
are supposed to be slow, just drop all the type caches to simplify
the codebase.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 6ecbbbbb37 Clifter: use llvm::DataLayout for pointer size
Replace the standalone PointerSize field with a pointer to the
function's llvm::DataLayout, and read the pointer size off the
DataLayout when needed. This keeps the importer aligned with what
LLVM thinks the pointer size is, instead of relying on an external
source of truth that may go stale.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 00db5561e3 Clifter: use llvm::DataLayout for helper structs
Use llvm::DataLayout to compute helper struct layouts in the
Clifter, mirroring what HelpersToHeader does. The layout query
replaces a couple of hand-rolled offset/size computations and
keeps the importer in sync with what LLVM and the helpers header
believe about each helper struct.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi bcc9935023 Clifter: generate opaque types for arrays
When importing an llvm::ArrayType, emit a Clift StructType with the
OpaqueType rank in its handle and a single i8 array field of the
right byte size, instead of a real array type. This avoids
exposing C array types as rvalues in the generated code, which is
a foot-gun because array rvalues immediately decay to pointers,
and provides a single name (via the existing OpaqueType infra) for
arrays of equal byte size.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi c96765412b Clifter: support byte-based GEPs
Rework the GEP-importing logic to handle the i8-typed,
byte-strided GEPs produced by ArithmeticToGEP (and natively used
elsewhere) in addition to the structured ones it already supported.
Indices are now interpreted as byte offsets and the importer walks
the model type tree at byte granularity to materialise the right
sequence of field/element accesses.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 4f04d3c58d Drop !revng.variable_type metadata
Drop the !revng.variable_type metadata and the matching helpers,
along with the only place in the Clifter that still consumed them.
After the previous LVB cleanup nothing emits this metadata, and the
model variable type can be reconstructed from the alloca's array
type alone.
2026-05-08 11:37:10 +02:00
Lauri Vasama 90e5dfd4c9 Pass MLIRContext by address
Passing by address is more conventional. This is what MLIR does most of
the time, and it avoids dereferences and addressofs everywhere.
2026-04-30 15:09:16 +03:00
Lauri Vasama 579cec1c59 Remove C-style comments in the Clifter 2026-04-30 15:09:16 +03:00
Lauri Vasama a338194eb7 Move namespace mlir::clift out of namespace mlir 2026-04-27 12:48:24 +03:00
Lauri Vasama d35e54627c Add Clift ValueType interface
Value types is the set of non-array object types. These types are
assignable, can be used as function parameters, and as return types
(along with void), and in other scenarios where the type must have usual
value-like behaviour with no weirdness (such as array decay).
2026-04-08 12:28:45 +03:00
Lauri Vasama 29c935ac90 Replace Clift type category helpers with casts 2026-04-08 12:25:04 +03:00
Lauri Vasama 9ba90e9b81 Replace ValueType with mlir::Type where applicable
`mlir::Type` is now used as the default C++ type for representing all
MLIR types, even when `ValueType` would be a valid constraint, unless
doing so provides a clear benefit in that specific context.
2026-04-08 12:20:00 +03:00
Lauri Vasama f9a4cb6384 Split up clift::dealias
* `unwrapTypedefs` matches `dealias(T, /*IgnoreQualifiers=*/true)`.
* `collapseTypedefs` matches `dealias(T)`.
2026-04-08 12:18:42 +03:00
Lauri Vasama be8351a17d Split up Clift PrimitiveType
* PrimitiveType is now an interface.
* VoidKind is now VoidType.
* FloatKind is now FloatType.
* The integer kinds are now IntegerType with IntegerKind.
2026-04-08 12:18:10 +03:00
Lauri Vasama a2be1b476a Split up Clift CastOp
* DecayOp - array or function to pointer decay. Not shown in C.
* BitCastOp - bit-preserving conversion. Emitted as bit_cast if
  necessary.
* ExtendOp - zero- or sign-extending conversion from any integer type to
  any wider integer type.
* TruncateOp - truncating conversion from any integer type to any
  narrower integer type.
* PtrResizeOp - resizes a pointer without changing its pointee type.
2026-04-08 12:11:54 +03:00
Ivan Krysak 1b689079d1 Clifter: enforce lambda captures 2026-03-27 14:11:04 +01:00
Lauri Vasama 9d58a4ab9d Clifter: make a warning louder and expand it 2026-03-27 14:10:17 +01:00
Ivan Krysak c354642902 Clifter: fix a newly introduced bug
This fixes the invalidation problem introduced by reading attributes
in the scope whose execution order depends on the function processing
order.
2026-03-27 12:27:26 +00:00
Ivan Krysak b632772cbb ImportModel: import function attributes 2026-03-27 08:12:51 +00:00
Ivan Krysak 02ae9bfac3 Clifter: adopt importFunctionDeclaration 2026-03-27 08:11:45 +00:00
Ivan Krysak c30f309f5e Clift: introduce getMutableComment 2026-03-27 08:09:09 +00:00
Ivan Krysak 7f66f25253 mlir::clift::ClassAttr: add attribute support 2026-03-27 07:19:27 +00:00
Ivan Krysak 928bcdb118 mlir::clift::FunctionType: add attribute support 2026-03-27 07:19:27 +00:00
Ivan Krysak 278b898793 llvm-to-clift -> clifter 2026-03-27 07:05:44 +00:00
Ivan Krysak 6dc6ad2cf3 importModelTypes -> importTypes 2026-03-26 16:28:48 +00:00
Lauri Vasama b8348f17b2 Overhaul Clifter structure
Split function specific state into a separate FunctionClifter class with
limited lifetime.
2026-02-13 08:41:39 +02:00
Lauri Vasama 8b709ea532 Assign local variable and label handles in Clifter
Handles were previously assigned in the model name import pipe, but as
they are not expected to change often, they can be improted in the
Clifter. Additionally, in some cases it may be desirable to emit C
using generated names instead of those imported from the model, in which
case no handles would be available.
2026-02-13 08:41:39 +02:00
Alessandro Di Federico 557baea6db Clifter: fix handling of Scalar returnMethod 2025-12-22 11:34:46 +01:00
Alessandro Di Federico a1f9bd2d16 Minor changes 2025-12-22 11:34:46 +01:00
Lauri Vasama cee099c2df Rename Clift GoToOp to GotoOp 2025-11-12 15:28:54 +02:00
Lauri Vasama 220439dfce Remove FunctionType::getCliftFunctionType
Change FunctionType::getFunctionType to return clift::FunctionType
instead of clift::ValueType.
2025-11-12 15:28:54 +02:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Lauri Vasama 9305d3e472 Add Clifter support for pointer comparisons 2025-10-24 15:34:12 +02:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak ecb9d76c64 Model: drop obsolete default value handling 2025-10-13 18:33:10 +03:00
Lauri Vasama 22d6f70ee2 Clift directory structure overhaul 2025-10-13 15:08:20 +02:00