llvm/llvm/include/llvm/SandboxIR/Instruction.h

//===- Instruction.h --------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_SANDBOXIR_INSTRUCTION_H
#define LLVM_SANDBOXIR_INSTRUCTION_H

#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/SandboxIR/BasicBlock.h"
#include "llvm/SandboxIR/Constant.h"
#include "llvm/SandboxIR/User.h"

namespace llvm::sandboxir {

/// A sandboxir::User with operands, opcode and linked with previous/next
/// instructions in an instruction list.
class Instruction : public User {};

/// Instructions that contain a single LLVM Instruction can inherit from this.
template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {};

class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {};

class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {};

class InsertElementInst final
    : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {};

class ExtractElementInst final
    : public SingleLLVMInstructionImpl<llvm::ExtractElementInst> {};

class ShuffleVectorInst final
    : public SingleLLVMInstructionImpl<llvm::ShuffleVectorInst> {};

class InsertValueInst
    : public SingleLLVMInstructionImpl<llvm::InsertValueInst> {};

class BranchInst : public SingleLLVMInstructionImpl<llvm::BranchInst> {};

/// An abstract class, parent of unary instructions.
class UnaryInstruction
    : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {};

class ExtractValueInst : public UnaryInstruction {};

class VAArgInst : public UnaryInstruction {};

class FreezeInst : public UnaryInstruction {};

class LoadInst final : public UnaryInstruction {};

class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {};

class UnreachableInst final : public Instruction {};

class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {};

class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {};

class CallInst final : public CallBase {};

class InvokeInst final : public CallBase {};

class CallBrInst final : public CallBase {};

class LandingPadInst : public SingleLLVMInstructionImpl<llvm::LandingPadInst> {};

class FuncletPadInst : public SingleLLVMInstructionImpl<llvm::FuncletPadInst> {};

class CatchPadInst : public FuncletPadInst {};

class CleanupPadInst : public FuncletPadInst {};

class CatchReturnInst
    : public SingleLLVMInstructionImpl<llvm::CatchReturnInst> {};

class CleanupReturnInst
    : public SingleLLVMInstructionImpl<llvm::CleanupReturnInst> {};

class GetElementPtrInst final
    : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {};

class CatchSwitchInst
    : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {};

class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {};

class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {};

class UnaryOperator : public UnaryInstruction {};

class BinaryOperator : public SingleLLVMInstructionImpl<llvm::BinaryOperator> {};

/// An or instruction, which can be marked as "disjoint", indicating that the
/// inputs don't have a 1 in the same bit position. Meaning this instruction
/// can also be treated as an add.
class PossiblyDisjointInst : public BinaryOperator {};

class AtomicRMWInst : public SingleLLVMInstructionImpl<llvm::AtomicRMWInst> {};

class AtomicCmpXchgInst
    : public SingleLLVMInstructionImpl<llvm::AtomicCmpXchgInst> {};

class AllocaInst final : public UnaryInstruction {};

class CastInst : public UnaryInstruction {};

/// Instruction that can have a nneg flag (zext/uitofp).
class PossiblyNonNegInst : public CastInst {};

// Helper class to simplify stamping out CastInst subclasses.
template <Instruction::Opcode Op> class CastInstImpl : public CastInst {};

class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {};
class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {};
class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
class AddrSpaceCastInst final
    : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {};

class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {};

// Wraps a static function that takes a single Predicate parameter
// LLVMValType should be the type of the wrapped class
#define WRAP_STATIC_PREDICATE
// Wraps a member function that takes no parameters
// LLVMValType should be the type of the wrapped class
#define WRAP_MEMBER
// Wraps both--a common idiom in the CmpInst classes
#define WRAP_BOTH

class CmpInst : public SingleLLVMInstructionImpl<llvm::CmpInst> {};

class ICmpInst : public CmpInst {};

class FCmpInst : public CmpInst {};

#undef WRAP_STATIC_PREDICATE
#undef WRAP_MEMBER
#undef WRAP_BOTH

/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
/// an OpaqueInstr.
class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {};

} // namespace llvm::sandboxir

#endif // LLVM_SANDBOXIR_INSTRUCTION_H