LLVM 23.0.0git
SandboxVectorizerIR.cpp
Go to the documentation of this file.
1//===- SandboxVectorizerIR.cpp - Sandbox IR Specialization ----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/SandboxIR/Type.h"
12
13namespace llvm::sandboxir {
14
17 auto &Builder = Instruction::setInsertPos(InsertBefore);
18 // TODO: Replace with actual instruction sequence!
20 auto *LLVMC = cast<llvm::Constant>(C->Val);
21 auto *LLVMVecTy = llvm::FixedVectorType::get(PackOps[0]->Val->getType(), 2);
22 auto *LLVMPoison = llvm::PoisonValue::get(LLVMVecTy);
23 llvm::Value *NewV =
24 Builder.CreateInsertElement(LLVMPoison, PackOps[0]->Val, LLVMC, "TEST");
25
26 if (auto *NewInsert = dyn_cast<llvm::InsertElementInst>(NewV))
27 return Ctx.createPackInst({NewInsert});
28 assert(isa<llvm::Constant>(NewV) && "Expected constant");
29 return Ctx.getOrCreateConstant(cast<llvm::Constant>(NewV));
30}
31
32bool PackInst::classof(const Value *From) {
33 return From->getSubclassID() == ClassID::Pack;
34}
35
37SBVecContext::createPackInst(ArrayRef<llvm::Instruction *> PackInstrs) {
38 assert(all_of(PackInstrs,
39 [](llvm::Value *V) {
42 }) &&
43 "Expected inserts or extracts!");
44 auto NewPtr = std::unique_ptr<PackInst>(new PackInst(PackInstrs, *this));
45 return cast<PackInst>(registerValue(std::move(NewPtr)));
46}
47
48} // namespace llvm::sandboxir
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:39
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:873
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
LLVM Value Representation.
Definition Value.h:75
static LLVM_ABI Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition Constant.cpp:48
LLVM_ABI Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
Definition Context.cpp:35
static IRBuilder & setInsertPos(InsertPosition Pos)
Helper function for create().
static bool classof(const Value *From)
For isa/dyn_cast.
static Value * create(ArrayRef< Value * > PackOps, InsertPosition InsertBefore, SBVecContext &Ctx)
static LLVM_ABI IntegerType * getInt32Ty(Context &Ctx)
Definition Type.cpp:21
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition Value.h:122
ClassID getSubclassID() const
Definition Value.h:213
Context & Ctx
All values point to the context.
Definition Value.h:201
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1738
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559