All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Di Federico via qemu development <qemu-devel@nongnu.org>
To: Anton Johansson <anjo@rev.ng>
Cc: qemu-devel@nongnu.org, brian.cain@oss.qualcomm.com,
	pierrick.bouvier@oss.qualcomm.com, philmd@mailo.com
Subject: Re: [PATCH v2 20/50] helper-to-tcg: Introduce pseudo instructions
Date: Wed, 9 Sep 2026 13:09:03 +0200	[thread overview]
Message-ID: <20260909130903.7cffa06d@spawn> (raw)
In-Reply-To: <20260730031025.12926-21-anjo@rev.ng>

On Thu, 30 Jul 2026 05:09:54 +0200
Anton Johansson <anjo@rev.ng> wrote:

> "pseudo" instructions makes it easy to add custom instructions to
> LLVM IR in the form of calls to undefined functions.  These will be used
> in future commits to express functionality present in TCG that is missing
> from LLVM IR (certain vector ops.), or to simplify the backend by
> collecting similar instruction mappings into a single opcode
> (idendity mapping).
> 
> Mapping from a call instructions in LLVM IR to an enum representing the
> pseudo instruction is also handled, this avoids string comparisons in
> the backend, and is easy to switch over.
> 
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
>  .../helper-to-tcg/include/PseudoInst.hpp      |  75 +++++++
>  .../helper-to-tcg/include/PseudoInst.inc      |  78 ++++++++
>  subprojects/helper-to-tcg/meson.build         |   1 +
>  subprojects/helper-to-tcg/src/PseudoInst.cpp  | 183 ++++++++++++++++++
>  4 files changed, 337 insertions(+)
>  create mode 100644 subprojects/helper-to-tcg/include/PseudoInst.hpp
>  create mode 100644 subprojects/helper-to-tcg/include/PseudoInst.inc
>  create mode 100644 subprojects/helper-to-tcg/src/PseudoInst.cpp
> 
> diff --git a/subprojects/helper-to-tcg/include/PseudoInst.hpp b/subprojects/helper-to-tcg/include/PseudoInst.hpp
> new file mode 100644
> index 0000000000..ef0b03cb5b
> --- /dev/null
> +++ b/subprojects/helper-to-tcg/include/PseudoInst.hpp
> @@ -0,0 +1,75 @@
> +//
> +//  Copyright(c) 2026 rev.ng Labs Srl. All Rights Reserved.
> +//
> +//  This program is free software; you can redistribute it and/or modify
> +//  it under the terms of the GNU General Public License as published by
> +//  the Free Software Foundation; either version 2 of the License, or
> +//  (at your option) any later version.
> +//
> +//  This program is distributed in the hope that it will be useful,
> +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +//  GNU General Public License for more details.
> +//
> +//  You should have received a copy of the GNU General Public License
> +//  along with this program; if not, see <http://www.gnu.org/licenses/>.
> +//
> +
> +#pragma once
> +
> +#include <stdint.h>
> +
> +#include <llvm/ADT/ArrayRef.h>
> +#include <llvm/IR/IRBuilder.h>
> +#include <llvm/IR/Module.h>
> +#include <llvm/IR/Value.h>
> +
> +// Pseudo instructions refers to extra LLVM instructions implemented as
> +// calls to undefined functions.  They are useful for amending LLVM IR to
> +// simplify mapping to TCG in the backend, e.g.
> +//
> +//   %2 = call i32 @IdentityMap.i32.i16(i16 %1)
> +//
> +// is a pseudo opcode used to communicate that %1 and %2 should be mapped
> +// to the same value in TCG.
> +
> +enum PseudoInstArg {
> +    ArgAny,
> +    ArgInt,
> +    ArgVec,
> +    ArgPtr,
> +    ArgLabel,
> +    ArgVoid,
> +};
> +
> +// Define an enum `PseudoInst` consisting of the names of pseudo instructions
> +// defined in "PseudoInst.inc".
> +#define PSEUDO_INST_DEF(name, ret, args) name
> +enum PseudoInst : uint8_t {
> +#include "PseudoInst.inc"
> +};
> +#undef PSEUDO_INST_DEF
> +
> +// Retrieve string representation and argument counts for a given
> +// pseudo instruction.
> +const char *pseudoInstName(PseudoInst Inst);
> +uint8_t pseudoInstArgCount(PseudoInst Inst);
> +llvm::ArrayRef<PseudoInstArg> pseudoInstArgTypes(PseudoInst Inst);
> +
> +// Maps `PseudoInst`, return type, and argument types, to a `FunctionCallee`
> +// that can be called.  Provided argument types are matched against
> +// "PseudoInst.inc" for verification and an assert triggers on failure.
> +llvm::FunctionCallee pseudoInstFunction(llvm::Module &M, PseudoInst Inst,
> +                                        llvm::Type *RetType,
> +                                        llvm::ArrayRef<llvm::Type *> ArgTypes);
> +
> +// Convenience function that gets a pseudo instruction via
> +// `pseudoInstFunction()` and creates a call to it via the provided `IRBuilder`.
> +llvm::CallInst *createPseudoInstCall(llvm::Module &M,
> +                                     llvm::IRBuilder<> &Builder,
> +                                     PseudoInst Inst, llvm::Type *RetType,
> +                                     llvm::ArrayRef<llvm::Value *> Values);

This looks like a class in disguise:

```
class PseudoInst {
public:
  enum Operation {
    // ...
  };

private:
  Operation TheOperation;

public:
  const char *name() const;
  // ...

public:
  FunctionCallee makeFunction(Module &M,
                              Type *RetType,
                              ArrayRef<llvm::Type *> ArgTypes);

  FunctionCallee makeCall(...);

public:
  static PseudoInst fromCall(const llvm::CallInst *Call);
};
```
> +
> +// Reverse mapping of above, takes a call instruction and attempts to map the
> +// callee to a `PseudoInst`.
> +PseudoInst getPseudoInstFromCall(const llvm::CallInst *Call);
> diff --git a/subprojects/helper-to-tcg/include/PseudoInst.inc b/subprojects/helper-to-tcg/include/PseudoInst.inc
> new file mode 100644
> index 0000000000..003d3fb186
> --- /dev/null
> +++ b/subprojects/helper-to-tcg/include/PseudoInst.inc
> @@ -0,0 +1,78 @@
> +PSEUDO_INST_DEF(InvalidPseudoInst,  ArgVoid, PSEUDO_INST_ARGVEC()),
> +// Identity mapping
> +PSEUDO_INST_DEF(IdentityMap,        ArgAny, PSEUDO_INST_ARGVEC(ArgAny)),
> +// Pointer arithmetic
> +PSEUDO_INST_DEF(PtrAdd,             ArgPtr, PSEUDO_INST_ARGVEC(ArgPtr, ArgInt)),
> +// Global accesses
> +PSEUDO_INST_DEF(AccessGlobalArray,  ArgInt, PSEUDO_INST_ARGVEC(ArgInt, ArgInt, ArgInt)),
> +PSEUDO_INST_DEF(AccessGlobalValue,  ArgInt, PSEUDO_INST_ARGVEC(ArgInt, ArgInt)),
> +// Conditional branch
> +PSEUDO_INST_DEF(Brcond,             ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgInt, ArgInt, ArgInt, ArgLabel, ArgLabel)),
> +// Conditional move
> +PSEUDO_INST_DEF(Movcond,            ArgInt, PSEUDO_INST_ARGVEC(ArgInt, ArgInt, ArgInt, ArgInt, ArgInt)),

Add more documentation.

* AFAIU `Brcond` represents a `icmp + br` in LLVM.
* AFAIU `Movcond` represents `icmp + select` in LLVM.
* `IdentityMap` is not obvious
* `PtrAdd` is not obvious

Same for others, be more verbose about what they represent, why base
LLVM is not able to capture them and what they map to in TCG.
No need to go in depth for all vector operations, but for these docs
would be beneficial.

> +// Vector creation ops
> +PSEUDO_INST_DEF(VecSplat,           ArgVec, PSEUDO_INST_ARGVEC(ArgInt)),
> +PSEUDO_INST_DEF(VecConstant,        ArgVec, PSEUDO_INST_ARGVEC(ArgVec)),
> +// Vector unary ops
> +PSEUDO_INST_DEF(VecNot,             ArgVec, PSEUDO_INST_ARGVEC(ArgVec)),
> +// Vector scalar binary ops
> +PSEUDO_INST_DEF(VecAddScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecSubScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecMulScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecXorScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecOrScalar,        ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecAndScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecShlScalar,       ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecLShrScalar,      ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecAShrScalar,      ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgInt)),
> +// Vector unary ops that stores to pointer
> +PSEUDO_INST_DEF(VecNotStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec)),
> +// Vector binary ops that stores to pointer
> +PSEUDO_INST_DEF(VecAddStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecSubStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecMulStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecXorStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecOrStore,         ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecAndStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecShlStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecLShrStore,       ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecAShrStore,       ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecAddScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecSubScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecMulScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecXorScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecOrScalarStore,   ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecAndScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecShlScalarStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecLShrScalarStore, ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +PSEUDO_INST_DEF(VecAShrScalarStore, ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgInt)),
> +// Host memory operations
> +//                                                      vaddr,  value   sign    size    endian
> +PSEUDO_INST_DEF(GuestLoad,  ArgInt,  PSEUDO_INST_ARGVEC(ArgInt,         ArgInt, ArgInt, ArgInt)),
> +PSEUDO_INST_DEF(GuestStore, ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgInt,         ArgInt, ArgInt)),
> +// ...
> +PSEUDO_INST_DEF(VecTruncStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecZExtStore,         ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecSExtStore,         ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecSignedSatAddStore, ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecSignedSatSubStore, ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecSelectStore,       ArgVoid, PSEUDO_INST_ARGVEC(ArgInt, ArgPtr, ArgVec, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecFunnelShrStore,    ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecAbsStore,          ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecSignedMaxStore,    ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecUnsignedMaxStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecSignedMinStore,    ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecUnsignedMinStore,  ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecCtlzStore,         ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecCttzStore,         ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecCtpopStore,        ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec)),
> +PSEUDO_INST_DEF(VecWideCondBitsel,    ArgVec, PSEUDO_INST_ARGVEC(ArgVec, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecWideCondBitselStore,    ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgVec, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecCompare,           ArgVec, PSEUDO_INST_ARGVEC(ArgInt, ArgVec, ArgVec)),
> +PSEUDO_INST_DEF(VecSelect,            ArgVec, PSEUDO_INST_ARGVEC(ArgInt, ArgVec, ArgVec)),
> +

These would also benefit from more docs:

> +PSEUDO_INST_DEF(SignExtract,          ArgInt, PSEUDO_INST_ARGVEC(ArgInt, ArgInt, ArgInt)),
> +PSEUDO_INST_DEF(Extract,              ArgInt, PSEUDO_INST_ARGVEC(ArgInt, ArgInt, ArgInt)),
> +
> +PSEUDO_INST_DEF(Exception,            ArgVoid, PSEUDO_INST_ARGVEC(ArgPtr, ArgInt)),
> +PSEUDO_INST_DEF(GetPC,                ArgInt,  PSEUDO_INST_ARGVEC()),
> diff --git a/subprojects/helper-to-tcg/meson.build b/subprojects/helper-to-tcg/meson.build
> index 4fd0ddb778..b3a3de6297 100644
> --- a/subprojects/helper-to-tcg/meson.build
> +++ b/subprojects/helper-to-tcg/meson.build
> @@ -43,6 +43,7 @@ sources = [
>      'src/LlvmCompat.cpp',
>      'src/Pipeline.cpp',
>      'src/PrepareForOptPass/PrepareForOptPass.cpp',
> +    'src/PseudoInst.cpp',
>  ]
>  
>  clang = bindir / 'clang'
> diff --git a/subprojects/helper-to-tcg/src/PseudoInst.cpp b/subprojects/helper-to-tcg/src/PseudoInst.cpp
> new file mode 100644
> index 0000000000..91e0f25e3d
> --- /dev/null
> +++ b/subprojects/helper-to-tcg/src/PseudoInst.cpp
> @@ -0,0 +1,183 @@
> +//
> +//  Copyright(c) 2026 rev.ng Labs Srl. All Rights Reserved.
> +//
> +//  This program is free software; you can redistribute it and/or modify
> +//  it under the terms of the GNU General Public License as published by
> +//  the Free Software Foundation; either version 2 of the License, or
> +//  (at your option) any later version.
> +//
> +//  This program is distributed in the hope that it will be useful,
> +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +//  GNU General Public License for more details.
> +//
> +//  You should have received a copy of the GNU General Public License
> +//  along with this program; if not, see <http://www.gnu.org/licenses/>.
> +//
> +
> +#include "PseudoInst.hpp"
> +#include "LlvmCompat.hpp"
> +
> +#include <llvm/ADT/DenseMap.h>
> +#include <llvm/ADT/Twine.h>
> +#include <llvm/IR/Function.h>
> +#include <llvm/IR/Instructions.h>
> +#include <llvm/Support/Casting.h>
> +
> +using namespace llvm;
> +
> +// Define an array `PseudoInstName[]`, indexed by `PseudoInst` and mapping
> +// to a string representation of the enum.
> +#define PSEUDO_INST_DEF(name, ret, args) #name
> +static const char *PseudoInstName[] = {
> +#include "PseudoInst.inc"
> +};
> +#undef PSEUDO_INST_DEF
> +
> +// Define an array `PseudoInstArgTypes[]` indexed by `PseudoInst` and
> +// mapping to an array of `PseudoInstArg` representing allowed argument types.
> +#define PSEUDO_INST_ARGVEC(...) {__VA_ARGS__}
> +
> +#define PSEUDO_INST_DEF(name, ret, args) args
> +static const SmallVector<PseudoInstArg, 6> PseudoInstArgTypes[] = {
> +#include "PseudoInst.inc"
> +};
> +#undef PSEUDO_INST_DEF
> +#undef PSEUDO_INST_ARGVEC
> +
> +// In order to map from a `Function *` to a `PseudoInst`, we keep a map
> +// of all functions created, this simplifies mapping of callees to
> +// a `PseudoInst` that can be switched over.
> +static DenseMap<Function *, PseudoInst> MapFuncToInst;

Having a `llvm::Function` reference in a global variable is not nice.
All of this should be part of a class associated to a specific module.

> +
> +// Converts llvm `Type`s to a string representation
> +// that can be embedded in function names for basic overloading.
> +//
> +// Ex.
> +//
> +//      [8 x i8] -> "a8xi8"
> +//      <128 x i8> -> "v128xi8"
> +//
> +// LLVM has an implementation of a similar function used by intrinsics,
> +// called `getMangledTypeStr`, but it's not exposed.

Is this function for debugging purposes?
Please clearly identify functions that are not critical (i.e., they are
for debugging purposes).

> +inline std::string getMangledTypeStr(Type *Ty) {

Use `static` instead of `inline` in `.cpp` files.

> +    std::string TypeStr = "";
> +    llvm::raw_string_ostream TypeStream(TypeStr);
> +    switch (Ty->getTypeID()) {
> +    case Type::ArrayTyID: {
> +        auto *ArrayTy = cast<ArrayType>(Ty);
> +        std::string ElementStr = getMangledTypeStr(ArrayTy->getElementType());
> +        TypeStream << "a" << ArrayTy->getNumElements() << "x" << ElementStr;
> +    } break;
> +    case Type::FixedVectorTyID: {
> +        auto *VecTy = cast<VectorType>(Ty);
> +        uint32_t ElementCount = compat::getVectorElementCount(VecTy);
> +        std::string ElementStr = getMangledTypeStr(VecTy->getElementType());
> +        TypeStream << "v" << ElementCount << "x" << ElementStr;
> +    } break;
> +    case Type::StructTyID: {
> +        auto *StructTy = cast<StructType>(Ty);
> +        TypeStream << StructTy->getName();
> +    } break;
> +    case Type::IntegerTyID: {
> +        auto *IntTy = cast<IntegerType>(Ty);
> +        TypeStream << "i" << IntTy->getBitWidth();
> +    } break;
> +    case Type::PointerTyID: {
> +        TypeStream << "p";
> +    } break;
> +    default:
> +        abort();
> +    }
> +    return TypeStream.str();
> +}
> +
> +// Access functions into the static defined above.
> +
> +const char *pseudoInstName(PseudoInst Inst) { return PseudoInstName[Inst]; }
> +
> +uint8_t pseudoInstArgCount(PseudoInst Inst) {
> +    return PseudoInstArgTypes[Inst].size();
> +}
> +
> +llvm::ArrayRef<PseudoInstArg> pseudoInstArgTypes(PseudoInst Inst) {
> +    return PseudoInstArgTypes[Inst];
> +}
> +
> +// Match LLVM type against `PseudoIntsArg`.
> +static void assertMatchingType(PseudoInstArg Expected, Type *Ty) {
> +    const Type::TypeID Id = Ty->getTypeID();
> +    switch (Expected) {
> +    case ArgAny:
> +        return;
> +    case ArgInt:
> +        assert(Id == Type::IntegerTyID);
> +        return;
> +    case ArgVec:
> +        assert(Id == Type::FixedVectorTyID);
> +        return;
> +    case ArgPtr:
> +        assert(Id == Type::PointerTyID);
> +        return;
> +    case ArgLabel:
> +        assert(Id == Type::LabelTyID);
> +        return;
> +    case ArgVoid:
> +        assert(Id == Type::VoidTyID);
> +        return;
> +    default:
> +        abort();
> +    };
> +}
> +
> +llvm::FunctionCallee pseudoInstFunction(llvm::Module &M, PseudoInst Inst,
> +                                        llvm::Type *RetType,
> +                                        llvm::ArrayRef<llvm::Type *> ArgTypes) {
> +    ArrayRef<PseudoInstArg> PArgTypes = pseudoInstArgTypes(Inst);
> +    assert(PArgTypes.size() == ArgTypes.size());
> +    for (size_t I = 0; I < ArgTypes.size(); ++I) {
> +        assertMatchingType(PArgTypes[I], ArgTypes[I]);
> +    }
> +
> +    auto *FT = llvm::FunctionType::get(RetType, ArgTypes, false);
> +
> +    std::string FnName{PseudoInstName[Inst]};
> +    if (!RetType->isVoidTy()) {
> +        FnName += ".";
> +        FnName += getMangledTypeStr(RetType);
> +    }
> +    for (llvm::Type *Ty : ArgTypes) {
> +        if (Ty->isLabelTy()) {
> +            continue;
> +        }
> +        FnName += ".";
> +        FnName += getMangledTypeStr(Ty);
> +    }
> +
> +    llvm::FunctionCallee Fn = M.getOrInsertFunction(FnName, FT);
> +    auto *F = cast<Function>(Fn.getCallee());
> +    MapFuncToInst.insert({F, Inst});
> +
> +    return Fn;
> +}
> +
> +llvm::CallInst *createPseudoInstCall(llvm::Module &M, IRBuilder<> &Builder,

You could get `M` from `Builder.GetInsertPoint`.

> +                                     PseudoInst Inst, llvm::Type *RetType,
> +                                     llvm::ArrayRef<llvm::Value *> Values) {
> +    SmallVector<Type *, 8> ArgTypes;
> +    for (Value *V : Values) {
> +        ArgTypes.push_back(V->getType());
> +    }
> +
> +    FunctionCallee Fn = pseudoInstFunction(M, Inst, RetType, ArgTypes);
> +    return Builder.CreateCall(Fn, Values);
> +}
> +
> +PseudoInst getPseudoInstFromCall(const CallInst *Call) {
> +    Function *F = Call->getCalledFunction();
> +    auto It = MapFuncToInst.find(F);
> +    if (It == MapFuncToInst.end()) {
> +        return InvalidPseudoInst;
> +    }
> +    return It->second;
> +}
> -- 
> 2.52.0

Reviewed-by: Alessandro Di Federico <ale@rev.ng>

-- 
Alessandro Di Federico
rev.ng Labs


  reply	other threads:[~2026-09-09 11:12 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  3:09 [PATCH v2 00/50] Introduce helper-to-tcg Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 01/50] accel/tcg: Add bitreverse and funnel-shift runtime helper functions Anton Johansson via qemu development
2026-07-30  8:04   ` Philippe Mathieu-Daudé
2026-07-30 14:43   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 02/50] accel/tcg: Add getpc helper Anton Johansson via qemu development
2026-07-30 14:48   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 03/50] tcg: Introduce tcg-global-mappings Anton Johansson via qemu development
2026-07-30 16:11   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 04/50] tcg: Increase maximum TB size Anton Johansson via qemu development
2026-07-30 16:13   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 05/50] tcg: Expose tcg_gen_ussub_sat() Anton Johansson via qemu development
2026-07-30  7:52   ` Philippe Mathieu-Daudé
2026-07-30 16:17   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 06/50] Add helper-to-tcg subproject Anton Johansson via qemu development
2026-07-30 15:56   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 07/50] helper-to-tcg: Introduce get-llvm-ir.py Anton Johansson via qemu development
2026-08-04 12:08   ` Alessandro Di Federico via qemu development
2026-08-11 11:35     ` Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 08/50] helper-to-tcg: Handle LLVM version compatibility Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 09/50] helper-to-tcg: Introduce custom LLVM pipeline Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 10/50] helper-to-tcg: Add pipeline --debug and --debug-only Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 11/50] helper-to-tcg: Add simple error creation helper Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 12/50] helper-to-tcg: Introduce PrepareForOptPass Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 13/50] helper-to-tcg: PrepareForOptPass, demangle function names Anton Johansson via qemu development
2026-08-07 16:03   ` Alessandro Di Federico via qemu development
2026-08-11 10:09     ` Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 14/50] helper-to-tcg: PrepareForOptPass, map annotations Anton Johansson via qemu development
2026-08-07 10:26   ` Alessandro Di Federico via qemu development
2026-08-11  9:52     ` Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 15/50] helper-to-tcg: PrepareForOptPass, cull unused functions Anton Johansson via qemu development
2026-08-11 10:13   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 16/50] helper-to-tcg: PrepareForOptPass, undef llvm.returnaddress Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 17/50] helper-to-tcg: PrepareForOptPass, fixup inline attributes Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 18/50] helper-to-tcg: PrepareForOptPass, collect debuginfo Anton Johansson via qemu development
2026-09-09 11:11   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 19/50] helper-to-tcg: Pipeline, run optimization pass Anton Johansson via qemu development
2026-09-09 11:09   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 20/50] helper-to-tcg: Introduce pseudo instructions Anton Johansson via qemu development
2026-09-09 11:09   ` Alessandro Di Federico via qemu development [this message]
2026-07-30  3:09 ` [PATCH v2 21/50] helper-to-tcg: Add guest vector layout description Anton Johansson via qemu development
2026-09-16 12:28   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 22/50] helper-to-tcg: Introduce PrepareForTcgPass Anton Johansson via qemu development
2026-09-16 12:42   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 23/50] helper-to-tcg: PrepareForTcgPass, remove functions with cycles Anton Johansson via qemu development
2026-09-16 13:16   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 24/50] helper-to-tcg: PrepareForTcgPass, demote PHI nodes Anton Johansson via qemu development
2026-09-16 13:32   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 25/50] helper-to-tcg: PrepareForTcgPass, map TCG globals Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 26/50] helper-to-tcg: PrepareForTcgPass, transform GEPs Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 27/50] helper-to-tcg: PrepareForTcgPass, canonicalize IR Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 28/50] helper-to-tcg: PrepareForTcgPass, identity map trivial expressions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 29/50] helper-to-tcg: Introduce TcgV structure Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 30/50] helper-to-tcg: Introduce TcgGenPass Anton Johansson via qemu development
2026-08-07 10:27   ` Alessandro Di Federico via qemu development
2026-08-11 10:16     ` Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 31/50] helper-to-tcg: TcgGenPass, linearize basic blocks Anton Johansson via qemu development
2026-09-16 13:26   ` Alessandro Di Federico via qemu development
2026-07-30  3:10 ` [PATCH v2 32/50] helper-to-tcg: TcgGenPass, introduce Value <-> TcgV map Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 33/50] helper-to-tcg: TcgGenPass, add structs for string emission Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 34/50] helper-to-tcg: TcgGenPass, map arguments to TCG Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 35/50] helper-to-tcg: TcgGenPass, propagate constant expresssions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 36/50] helper-to-tcg: TcgGenPass, allocate TCG registers Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 37/50] helper-to-tcg: TcgGenPass, emit TCG strings Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 38/50] helper-to-tcg: Add README Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 39/50] helper-to-tcg: Add end-to-end tests Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 40/50] test: helper-to-tcg docker tests Anton Johansson via qemu development
2026-07-31 11:46   ` Alessandro Di Federico via qemu development
2026-07-31 11:48   ` Alessandro Di Federico via qemu development
2026-07-31 16:47   ` Pierrick Bouvier
2026-07-30  3:10 ` [PATCH v2 41/50] target/hexagon: Add get_tb_mmu_index() Anton Johansson via qemu development
2026-07-30  7:49   ` Philippe Mathieu-Daudé
2026-07-30  3:10 ` [PATCH v2 42/50] target/hexagon: Increase VECTOR_TEMPS_MAX Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 43/50] target/hexagon: Provide env to tcg global mapping Anton Johansson via qemu development
2026-07-30 16:28   ` Richard Henderson
2026-07-30  3:10 ` [PATCH v2 44/50] target/hexagon: Keep gen_slotval/check_noshuf for helper-to-tcg Anton Johansson via qemu development
2026-07-31 11:46   ` Alessandro Di Federico via qemu development
2026-07-30  3:10 ` [PATCH v2 45/50] target/hexagon: Emit annotations for helpers Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 46/50] target/hexagon: Split probe_and_commit helper Anton Johansson via qemu development
2026-07-30  7:50   ` Philippe Mathieu-Daudé
2026-07-30  3:10 ` [PATCH v2 47/50] target/hexagon: Use helper-to-tcg helper calls Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 48/50] target/hexagon: Manually call generated HVX instructions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 49/50] target/hexagon: Use idef-parser as a fallback Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 50/50] target/hexagon: Use helper-to-tcg Anton Johansson via qemu development
2026-08-04 12:08   ` Alessandro Di Federico via qemu development

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909130903.7cffa06d@spawn \
    --to=qemu-devel@nongnu.org \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=brian.cain@oss.qualcomm.com \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.