diff options
author | Tim Northover <tnorthover@apple.com> | 2016-07-29 22:32:36 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2016-07-29 22:32:36 +0000 |
commit | 5fb414d87051004410a42096b23cb7a58e2ed881 (patch) | |
tree | 6808f68a2cb07e36ed307b2d08d9e498a449ff3c /llvm/lib/CodeGen | |
parent | 31b07f14451454847a79f84f220976e753a38ed8 (diff) | |
download | bcm5719-llvm-5fb414d87051004410a42096b23cb7a58e2ed881.tar.gz bcm5719-llvm-5fb414d87051004410a42096b23cb7a58e2ed881.zip |
GlobalISel: support translation of intrinsic calls.
These come in two variants for now: G_INTRINSIC and G_INTRINSIC_W_SIDE_EFFECTS.
We may decide to split the latter up with finer-grained restrictions later, if
necessary.
llvm-svn: 277224
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 34 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 14 |
2 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index b0751c0bb5e..80ec1b529d3 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -19,8 +19,10 @@ #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Function.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" +#include "llvm/Target/TargetIntrinsicInfo.h" #include "llvm/Target/TargetLowering.h" #define DEBUG_TYPE "irtranslator" @@ -175,6 +177,34 @@ bool IRTranslator::translateCast(unsigned Opcode, const CastInst &CI) { return true; } +bool IRTranslator::translateCall(const CallInst &CI) { + auto TII = MIRBuilder.getMF().getTarget().getIntrinsicInfo(); + const Function &F = *CI.getCalledFunction(); + Intrinsic::ID ID = F.getIntrinsicID(); + if (TII && ID == Intrinsic::not_intrinsic) + ID = static_cast<Intrinsic::ID>(TII->getIntrinsicID(&F)); + + assert(ID != Intrinsic::not_intrinsic && "FIXME: support real calls"); + + // Need types (starting with return) & args. + SmallVector<LLT, 4> Tys; + Tys.emplace_back(*CI.getType()); + for (auto &Arg : CI.arg_operands()) + Tys.emplace_back(*Arg->getType()); + + unsigned Res = CI.getType()->isVoidTy() ? 0 : getOrCreateVReg(CI); + MachineInstrBuilder MIB = + MIRBuilder.buildIntrinsic(Tys, ID, Res, !CI.doesNotAccessMemory()); + + for (auto &Arg : CI.arg_operands()) { + if (ConstantInt *CI = dyn_cast<ConstantInt>(Arg)) + MIB.addImm(CI->getSExtValue()); + else + MIB.addUse(getOrCreateVReg(*Arg)); + } + return true; +} + bool IRTranslator::translateStaticAlloca(const AllocaInst &AI) { assert(AI.isStaticAlloca() && "only handle static allocas now"); MachineFunction &MF = MIRBuilder.getMF(); @@ -218,6 +248,10 @@ bool IRTranslator::translate(const Instruction &Inst) { case Instruction::Ret: return translateReturn(cast<ReturnInst>(Inst)); + // Calls + case Instruction::Call: + return translateCall(cast<CallInst>(Inst)); + // Casts case Instruction::BitCast: return translateBitCast(cast<CastInst>(Inst)); diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 426de444d88..5e737d5e2bb 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -143,3 +143,17 @@ MachineInstrBuilder MachineIRBuilder::buildSequence(LLT Ty, unsigned Res, MIB.addUse(Op); return MIB; } + +MachineInstrBuilder MachineIRBuilder::buildIntrinsic(ArrayRef<LLT> Tys, + Intrinsic::ID ID, + unsigned Res, + bool HasSideEffects) { + auto MIB = + buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS + : TargetOpcode::G_INTRINSIC, + Tys); + if (Res) + MIB.addDef(Res); + MIB.addIntrinsicID(ID); + return MIB; +} |