2010-04-23 04:06:42 +08:00
|
|
|
//===-- FastISel.cpp - Implementation of the FastISel class ---------------===//
|
2008-08-14 04:19:35 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the implementation of the FastISel class.
|
|
|
|
//
|
2008-10-01 04:48:29 +08:00
|
|
|
// "Fast" instruction selection is designed to emit very poor code quickly.
|
|
|
|
// Also, it is not designed to be able to do much lowering, so most illegal
|
2008-10-13 09:59:13 +08:00
|
|
|
// types (e.g. i64 on 32-bit targets) and operations are not supported. It is
|
|
|
|
// also not intended to be able to do much optimization, except in a few cases
|
|
|
|
// where doing optimizations reduces overall compile time. For example, folding
|
|
|
|
// constants into immediate fields is often done, because it's cheap and it
|
|
|
|
// reduces the number of instructions later phases have to examine.
|
2008-10-01 04:48:29 +08:00
|
|
|
//
|
|
|
|
// "Fast" instruction selection is able to fail gracefully and transfer
|
|
|
|
// control to the SelectionDAG selector for operations that it doesn't
|
2008-10-13 09:59:13 +08:00
|
|
|
// support. In many cases, this allows us to avoid duplicating a lot of
|
2008-10-01 04:48:29 +08:00
|
|
|
// the complicated lowering logic that SelectionDAG currently has.
|
|
|
|
//
|
|
|
|
// The intended use for "fast" instruction selection is "-O0" mode
|
|
|
|
// compilation, where the quality of the generated code is irrelevant when
|
2008-10-13 09:59:13 +08:00
|
|
|
// weighed against the speed at which the code can be generated. Also,
|
2008-10-01 04:48:29 +08:00
|
|
|
// at -O0, the LLVM optimizers are not running, and this makes the
|
|
|
|
// compile time of codegen a much higher portion of the overall compile
|
2008-10-13 09:59:13 +08:00
|
|
|
// time. Despite its limitations, "fast" instruction selection is able to
|
2008-10-01 04:48:29 +08:00
|
|
|
// handle enough code on its own to provide noticeable overall speedups
|
|
|
|
// in -O0 compiles.
|
|
|
|
//
|
|
|
|
// Basic operations are supported in a target-independent way, by reading
|
|
|
|
// the same instruction descriptions that the SelectionDAG selector reads,
|
|
|
|
// and identifying simple arithmetic operations that can be directly selected
|
2008-10-13 09:59:13 +08:00
|
|
|
// from simple operators. More complicated operations currently require
|
2008-10-01 04:48:29 +08:00
|
|
|
// target-specific code.
|
|
|
|
//
|
2008-08-14 04:19:35 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-06-17 04:34:15 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2014-06-13 08:45:11 +08:00
|
|
|
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Analysis/Loads.h"
|
2015-01-15 10:16:27 +08:00
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/CodeGen/FastISel.h"
|
2010-07-08 00:01:37 +08:00
|
|
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
2014-06-12 11:29:26 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2008-08-14 04:19:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2008-09-26 01:05:24 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2008-08-14 04:19:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2014-06-12 11:29:26 +08:00
|
|
|
#include "llvm/CodeGen/StackMaps.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2016-01-20 08:26:52 +08:00
|
|
|
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2015-06-23 20:21:54 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Operator.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-08-14 04:19:35 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2008-08-21 06:45:34 +08:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2008-08-21 05:05:57 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2008-08-14 04:19:35 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "isel"
|
|
|
|
|
2011-11-29 03:59:09 +08:00
|
|
|
STATISTIC(NumFastIselSuccessIndependent, "Number of insts selected by "
|
2014-09-04 02:46:45 +08:00
|
|
|
"target-independent selector");
|
2011-11-29 03:59:09 +08:00
|
|
|
STATISTIC(NumFastIselSuccessTarget, "Number of insts selected by "
|
2014-09-04 02:46:45 +08:00
|
|
|
"target-specific selector");
|
2011-11-30 03:40:47 +08:00
|
|
|
STATISTIC(NumFastIselDead, "Number of dead insts removed on failure");
|
2011-11-17 05:05:28 +08:00
|
|
|
|
2014-07-12 06:01:42 +08:00
|
|
|
void FastISel::ArgListEntry::setAttributes(ImmutableCallSite *CS,
|
|
|
|
unsigned AttrIdx) {
|
2014-09-04 02:46:45 +08:00
|
|
|
IsSExt = CS->paramHasAttr(AttrIdx, Attribute::SExt);
|
|
|
|
IsZExt = CS->paramHasAttr(AttrIdx, Attribute::ZExt);
|
|
|
|
IsInReg = CS->paramHasAttr(AttrIdx, Attribute::InReg);
|
|
|
|
IsSRet = CS->paramHasAttr(AttrIdx, Attribute::StructRet);
|
|
|
|
IsNest = CS->paramHasAttr(AttrIdx, Attribute::Nest);
|
|
|
|
IsByVal = CS->paramHasAttr(AttrIdx, Attribute::ByVal);
|
|
|
|
IsInAlloca = CS->paramHasAttr(AttrIdx, Attribute::InAlloca);
|
|
|
|
IsReturned = CS->paramHasAttr(AttrIdx, Attribute::Returned);
|
2016-03-30 01:37:21 +08:00
|
|
|
IsSwiftSelf = CS->paramHasAttr(AttrIdx, Attribute::SwiftSelf);
|
2016-04-02 05:41:15 +08:00
|
|
|
IsSwiftError = CS->paramHasAttr(AttrIdx, Attribute::SwiftError);
|
2014-09-04 02:46:45 +08:00
|
|
|
Alignment = CS->getParamAlignment(AttrIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the current block to which generated machine instructions will be
|
|
|
|
/// appended, and clear the local CSE map.
|
2010-07-10 17:00:22 +08:00
|
|
|
void FastISel::startNewBlock() {
|
|
|
|
LocalValueMap.clear();
|
|
|
|
|
2013-07-04 12:53:49 +08:00
|
|
|
// Instructions are appended to FuncInfo.MBB. If the basic block already
|
2013-07-04 12:32:39 +08:00
|
|
|
// contains labels or copies, use the last instruction as the last local
|
|
|
|
// value.
|
2014-04-14 08:51:57 +08:00
|
|
|
EmitStartPt = nullptr;
|
2013-07-04 12:32:39 +08:00
|
|
|
if (!FuncInfo.MBB->empty())
|
|
|
|
EmitStartPt = &FuncInfo.MBB->back();
|
2011-08-19 06:06:10 +08:00
|
|
|
LastLocalValue = EmitStartPt;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::lowerArguments() {
|
2013-02-11 09:27:15 +08:00
|
|
|
if (!FuncInfo.CanLowerReturn)
|
|
|
|
// Fallback to SDISel argument lowering code to deal with sret pointer
|
|
|
|
// parameter.
|
|
|
|
return false;
|
2013-07-08 08:37:03 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
if (!fastLowerArguments())
|
2013-02-11 09:27:15 +08:00
|
|
|
return false;
|
|
|
|
|
2013-06-22 06:56:30 +08:00
|
|
|
// Enter arguments into ValueMap for uses in non-entry BBs.
|
2013-02-11 09:27:15 +08:00
|
|
|
for (Function::const_arg_iterator I = FuncInfo.Fn->arg_begin(),
|
2014-09-04 02:46:45 +08:00
|
|
|
E = FuncInfo.Fn->arg_end();
|
|
|
|
I != E; ++I) {
|
2015-10-14 03:47:46 +08:00
|
|
|
DenseMap<const Value *, unsigned>::iterator VI = LocalValueMap.find(&*I);
|
2013-06-22 06:56:30 +08:00
|
|
|
assert(VI != LocalValueMap.end() && "Missed an argument?");
|
2015-10-14 03:47:46 +08:00
|
|
|
FuncInfo.ValueMap[&*I] = VI->second;
|
2013-02-11 09:27:15 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-19 06:06:10 +08:00
|
|
|
void FastISel::flushLocalValueMap() {
|
|
|
|
LocalValueMap.clear();
|
|
|
|
LastLocalValue = EmitStartPt;
|
|
|
|
recomputeInsertPt();
|
2014-09-09 04:24:10 +08:00
|
|
|
SavedInsertPt = FuncInfo.InsertPt;
|
2010-07-10 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
2014-08-28 08:09:46 +08:00
|
|
|
bool FastISel::hasTrivialKill(const Value *V) {
|
2010-05-15 06:53:18 +08:00
|
|
|
// Don't consider constants or arguments to have trivial kills.
|
2010-05-12 07:54:07 +08:00
|
|
|
const Instruction *I = dyn_cast<Instruction>(V);
|
2010-05-15 06:53:18 +08:00
|
|
|
if (!I)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// No-op casts are trivially coalesced by fast-isel.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *Cast = dyn_cast<CastInst>(I))
|
2014-02-19 06:05:46 +08:00
|
|
|
if (Cast->isNoopCast(DL.getIntPtrType(Cast->getContext())) &&
|
2012-11-01 16:07:29 +08:00
|
|
|
!hasTrivialKill(Cast->getOperand(0)))
|
2010-05-15 06:53:18 +08:00
|
|
|
return false;
|
|
|
|
|
2014-08-28 08:09:46 +08:00
|
|
|
// Even the value might have only one use in the LLVM IR, it is possible that
|
|
|
|
// FastISel might fold the use into another instruction and now there is more
|
|
|
|
// than one use at the Machine Instruction level.
|
|
|
|
unsigned Reg = lookUpRegForValue(V);
|
|
|
|
if (Reg && !MRI.use_empty(Reg))
|
|
|
|
return false;
|
|
|
|
|
2011-11-16 07:34:05 +08:00
|
|
|
// GEPs with all zero indices are trivially coalesced by fast-isel.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *GEP = dyn_cast<GetElementPtrInst>(I))
|
2011-11-16 07:34:05 +08:00
|
|
|
if (GEP->hasAllZeroIndices() && !hasTrivialKill(GEP->getOperand(0)))
|
|
|
|
return false;
|
|
|
|
|
2010-05-15 06:53:18 +08:00
|
|
|
// Only instructions with a single use in the same basic block are considered
|
|
|
|
// to have trivial kills.
|
|
|
|
return I->hasOneUse() &&
|
|
|
|
!(I->getOpcode() == Instruction::BitCast ||
|
|
|
|
I->getOpcode() == Instruction::PtrToInt ||
|
|
|
|
I->getOpcode() == Instruction::IntToPtr) &&
|
2014-03-09 11:16:01 +08:00
|
|
|
cast<Instruction>(*I->user_begin())->getParent() == I->getParent();
|
2010-05-12 07:54:07 +08:00
|
|
|
}
|
|
|
|
|
2010-04-15 09:51:59 +08:00
|
|
|
unsigned FastISel::getRegForValue(const Value *V) {
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT RealVT = TLI.getValueType(DL, V->getType(), /*AllowUnknown=*/true);
|
2009-04-08 04:40:11 +08:00
|
|
|
// Don't handle non-simple values in FastISel.
|
|
|
|
if (!RealVT.isSimple())
|
|
|
|
return 0;
|
2008-09-11 05:01:08 +08:00
|
|
|
|
2008-12-08 15:57:47 +08:00
|
|
|
// Ignore illegal types. We must do this before looking up the value
|
|
|
|
// in ValueMap because Arguments are given virtual registers regardless
|
|
|
|
// of whether FastISel can handle them.
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT VT = RealVT.getSimpleVT();
|
2008-09-11 05:01:08 +08:00
|
|
|
if (!TLI.isTypeLegal(VT)) {
|
2011-05-26 07:49:02 +08:00
|
|
|
// Handle integer promotions, though, because they're common and easy.
|
|
|
|
if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)
|
2009-08-12 08:36:31 +08:00
|
|
|
VT = TLI.getTypeToTransformTo(V->getContext(), VT).getSimpleVT();
|
2008-09-11 05:01:08 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-20 09:07:47 +08:00
|
|
|
// Look up the value to see if we already have a register for it.
|
|
|
|
unsigned Reg = lookUpRegForValue(V);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Reg)
|
2008-12-08 15:57:47 +08:00
|
|
|
return Reg;
|
|
|
|
|
2010-05-06 08:02:14 +08:00
|
|
|
// In bottom-up mode, just create the virtual register which will be used
|
|
|
|
// to hold the value. It will be materialized later.
|
2010-07-10 17:00:22 +08:00
|
|
|
if (isa<Instruction>(V) &&
|
|
|
|
(!isa<AllocaInst>(V) ||
|
|
|
|
!FuncInfo.StaticAllocaMap.count(cast<AllocaInst>(V))))
|
|
|
|
return FuncInfo.InitializeRegForValue(V);
|
|
|
|
|
2012-10-03 16:10:01 +08:00
|
|
|
SavePoint SaveInsertPt = enterLocalValueArea();
|
2010-07-10 17:00:22 +08:00
|
|
|
|
|
|
|
// Materialize the value in a register. Emit any instructions in the
|
|
|
|
// local value area.
|
|
|
|
Reg = materializeRegForValue(V, VT);
|
|
|
|
|
2012-10-03 16:10:01 +08:00
|
|
|
leaveLocalValueArea(SaveInsertPt);
|
2010-05-06 08:02:14 +08:00
|
|
|
|
2010-07-10 17:00:22 +08:00
|
|
|
return Reg;
|
2010-05-04 07:36:34 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
unsigned FastISel::materializeConstant(const Value *V, MVT VT) {
|
2010-05-04 07:36:34 +08:00
|
|
|
unsigned Reg = 0;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *CI = dyn_cast<ConstantInt>(V)) {
|
2008-09-20 06:16:54 +08:00
|
|
|
if (CI->getValue().getActiveBits() <= 64)
|
2014-09-04 04:56:59 +08:00
|
|
|
Reg = fastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
|
2014-08-20 03:05:24 +08:00
|
|
|
} else if (isa<AllocaInst>(V))
|
2014-09-04 04:56:52 +08:00
|
|
|
Reg = fastMaterializeAlloca(cast<AllocaInst>(V));
|
2014-08-20 03:05:24 +08:00
|
|
|
else if (isa<ConstantPointerNull>(V))
|
2008-10-08 06:03:27 +08:00
|
|
|
// Translate this as an integer zero so that it can be
|
|
|
|
// local-CSE'd with actual integer zeros.
|
2014-09-04 02:46:45 +08:00
|
|
|
Reg = getRegForValue(
|
|
|
|
Constant::getNullValue(DL.getIntPtrType(V->getContext())));
|
|
|
|
else if (const auto *CF = dyn_cast<ConstantFP>(V)) {
|
2014-08-20 03:05:24 +08:00
|
|
|
if (CF->isNullValue())
|
2014-09-04 04:56:52 +08:00
|
|
|
Reg = fastMaterializeFloatZero(CF);
|
2014-08-20 03:05:24 +08:00
|
|
|
else
|
2011-04-28 06:41:55 +08:00
|
|
|
// Try to emit the constant directly.
|
2014-09-04 04:56:59 +08:00
|
|
|
Reg = fastEmit_f(VT, VT, ISD::ConstantFP, CF);
|
2008-08-28 02:10:19 +08:00
|
|
|
|
|
|
|
if (!Reg) {
|
2010-04-14 01:07:06 +08:00
|
|
|
// Try to emit the constant by using an integer constant with a cast.
|
2008-08-28 02:10:19 +08:00
|
|
|
const APFloat &Flt = CF->getValueAPF();
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT IntVT = TLI.getPointerTy(DL);
|
2008-08-28 02:10:19 +08:00
|
|
|
|
|
|
|
uint64_t x[2];
|
|
|
|
uint32_t IntBitWidth = IntVT.getSizeInBits();
|
2008-10-10 07:00:39 +08:00
|
|
|
bool isExact;
|
2014-09-04 02:46:45 +08:00
|
|
|
(void)Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
|
|
|
|
APFloat::rmTowardZero, &isExact);
|
2008-10-10 07:00:39 +08:00
|
|
|
if (isExact) {
|
2011-07-19 05:45:40 +08:00
|
|
|
APInt IntVal(IntBitWidth, x);
|
2008-08-28 02:10:19 +08:00
|
|
|
|
2009-07-22 08:24:57 +08:00
|
|
|
unsigned IntegerReg =
|
2014-09-04 02:46:45 +08:00
|
|
|
getRegForValue(ConstantInt::get(V->getContext(), IntVal));
|
2008-09-20 06:16:54 +08:00
|
|
|
if (IntegerReg != 0)
|
2014-09-04 04:56:59 +08:00
|
|
|
Reg = fastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg,
|
2014-09-04 02:46:45 +08:00
|
|
|
/*Kill=*/false);
|
2008-09-20 06:16:54 +08:00
|
|
|
}
|
2008-08-28 02:10:19 +08:00
|
|
|
}
|
2014-09-04 02:46:45 +08:00
|
|
|
} else if (const auto *Op = dyn_cast<Operator>(V)) {
|
|
|
|
if (!selectOperator(Op, Op->getOpcode()))
|
2010-07-01 10:58:57 +08:00
|
|
|
if (!isa<Instruction>(Op) ||
|
2014-09-04 04:56:52 +08:00
|
|
|
!fastSelectInstruction(cast<Instruction>(Op)))
|
2010-07-01 10:58:57 +08:00
|
|
|
return 0;
|
2010-06-21 22:17:46 +08:00
|
|
|
Reg = lookUpRegForValue(Op);
|
2008-08-29 05:19:07 +08:00
|
|
|
} else if (isa<UndefValue>(V)) {
|
2008-09-04 07:32:19 +08:00
|
|
|
Reg = createResultReg(TLI.getRegClassFor(VT));
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
2010-07-10 17:00:22 +08:00
|
|
|
TII.get(TargetOpcode::IMPLICIT_DEF), Reg);
|
2008-08-28 02:10:19 +08:00
|
|
|
}
|
2014-08-20 03:05:24 +08:00
|
|
|
return Reg;
|
|
|
|
}
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
/// Helper for getRegForValue. This function is called when the value isn't
|
|
|
|
/// already available in a register and must be materialized with new
|
|
|
|
/// instructions.
|
2014-08-20 03:05:24 +08:00
|
|
|
unsigned FastISel::materializeRegForValue(const Value *V, MVT VT) {
|
|
|
|
unsigned Reg = 0;
|
|
|
|
// Give the target-specific code a try first.
|
|
|
|
if (isa<Constant>(V))
|
2014-09-04 04:56:52 +08:00
|
|
|
Reg = fastMaterializeConstant(cast<Constant>(V));
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2014-08-20 03:05:24 +08:00
|
|
|
// If target-specific code couldn't or didn't want to handle the value, then
|
|
|
|
// give target-independent code a try.
|
|
|
|
if (!Reg)
|
2014-09-04 02:46:45 +08:00
|
|
|
Reg = materializeConstant(V, VT);
|
2014-08-20 03:05:24 +08:00
|
|
|
|
2008-09-20 06:16:54 +08:00
|
|
|
// Don't cache constant materializations in the general ValueMap.
|
|
|
|
// To do so would require tracking what uses they dominate.
|
2014-08-20 03:05:24 +08:00
|
|
|
if (Reg) {
|
2008-09-25 09:28:51 +08:00
|
|
|
LocalValueMap[V] = Reg;
|
2010-07-10 17:00:22 +08:00
|
|
|
LastLocalValue = MRI.getVRegDef(Reg);
|
|
|
|
}
|
2008-09-04 07:32:19 +08:00
|
|
|
return Reg;
|
2008-08-28 02:10:19 +08:00
|
|
|
}
|
|
|
|
|
2010-04-15 09:51:59 +08:00
|
|
|
unsigned FastISel::lookUpRegForValue(const Value *V) {
|
2008-09-09 09:26:59 +08:00
|
|
|
// Look up the value to see if we already have a register for it. We
|
|
|
|
// cache values defined by Instructions across blocks, and other values
|
|
|
|
// only locally. This is because Instructions already have the SSA
|
2010-05-04 07:36:34 +08:00
|
|
|
// def-dominates-use requirement enforced.
|
2010-07-08 00:29:44 +08:00
|
|
|
DenseMap<const Value *, unsigned>::iterator I = FuncInfo.ValueMap.find(V);
|
|
|
|
if (I != FuncInfo.ValueMap.end())
|
2010-06-21 22:21:47 +08:00
|
|
|
return I->second;
|
2012-10-03 16:10:01 +08:00
|
|
|
return LocalValueMap[V];
|
2008-09-09 09:26:59 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
void FastISel::updateValueMap(const Value *I, unsigned Reg, unsigned NumRegs) {
|
2008-09-06 02:18:20 +08:00
|
|
|
if (!isa<Instruction>(I)) {
|
|
|
|
LocalValueMap[I] = Reg;
|
2011-05-17 05:06:17 +08:00
|
|
|
return;
|
2009-04-12 15:45:01 +08:00
|
|
|
}
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2010-07-08 00:29:44 +08:00
|
|
|
unsigned &AssignedReg = FuncInfo.ValueMap[I];
|
2009-04-12 15:45:01 +08:00
|
|
|
if (AssignedReg == 0)
|
2010-07-10 17:00:22 +08:00
|
|
|
// Use the new register.
|
2009-04-12 15:45:01 +08:00
|
|
|
AssignedReg = Reg;
|
2009-04-12 15:46:30 +08:00
|
|
|
else if (Reg != AssignedReg) {
|
2010-07-10 17:00:22 +08:00
|
|
|
// Arrange for uses of AssignedReg to be replaced by uses of Reg.
|
2011-05-17 05:06:17 +08:00
|
|
|
for (unsigned i = 0; i < NumRegs; i++)
|
2014-09-04 02:46:45 +08:00
|
|
|
FuncInfo.RegFixups[AssignedReg + i] = Reg + i;
|
2010-07-10 17:00:22 +08:00
|
|
|
|
|
|
|
AssignedReg = Reg;
|
2008-09-06 02:18:20 +08:00
|
|
|
}
|
2008-08-30 08:38:46 +08:00
|
|
|
}
|
|
|
|
|
2010-05-12 07:54:07 +08:00
|
|
|
std::pair<unsigned, bool> FastISel::getRegForGEPIndex(const Value *Idx) {
|
2008-12-08 15:57:47 +08:00
|
|
|
unsigned IdxN = getRegForValue(Idx);
|
|
|
|
if (IdxN == 0)
|
|
|
|
// Unhandled operand. Halt "fast" selection and bail.
|
2010-05-12 07:54:07 +08:00
|
|
|
return std::pair<unsigned, bool>(0, false);
|
|
|
|
|
|
|
|
bool IdxNIsKill = hasTrivialKill(Idx);
|
2008-12-08 15:57:47 +08:00
|
|
|
|
|
|
|
// If the index is smaller or larger than intptr_t, truncate or extend it.
|
2015-07-09 10:09:04 +08:00
|
|
|
MVT PtrVT = TLI.getPointerTy(DL);
|
2009-08-11 06:56:29 +08:00
|
|
|
EVT IdxVT = EVT::getEVT(Idx->getType(), /*HandleUnknown=*/false);
|
2010-05-12 07:54:07 +08:00
|
|
|
if (IdxVT.bitsLT(PtrVT)) {
|
2014-09-04 04:56:59 +08:00
|
|
|
IdxN = fastEmit_r(IdxVT.getSimpleVT(), PtrVT, ISD::SIGN_EXTEND, IdxN,
|
2014-09-04 02:46:45 +08:00
|
|
|
IdxNIsKill);
|
2010-05-12 07:54:07 +08:00
|
|
|
IdxNIsKill = true;
|
2014-09-04 02:46:45 +08:00
|
|
|
} else if (IdxVT.bitsGT(PtrVT)) {
|
|
|
|
IdxN =
|
2014-09-04 04:56:59 +08:00
|
|
|
fastEmit_r(IdxVT.getSimpleVT(), PtrVT, ISD::TRUNCATE, IdxN, IdxNIsKill);
|
2010-05-12 07:54:07 +08:00
|
|
|
IdxNIsKill = true;
|
|
|
|
}
|
|
|
|
return std::pair<unsigned, bool>(IdxN, IdxNIsKill);
|
2008-12-08 15:57:47 +08:00
|
|
|
}
|
|
|
|
|
2010-07-10 17:00:22 +08:00
|
|
|
void FastISel::recomputeInsertPt() {
|
|
|
|
if (getLastLocalValue()) {
|
|
|
|
FuncInfo.InsertPt = getLastLocalValue();
|
2010-07-20 06:48:56 +08:00
|
|
|
FuncInfo.MBB = FuncInfo.InsertPt->getParent();
|
2010-07-10 17:00:22 +08:00
|
|
|
++FuncInfo.InsertPt;
|
|
|
|
} else
|
|
|
|
FuncInfo.InsertPt = FuncInfo.MBB->getFirstNonPHI();
|
|
|
|
|
|
|
|
// Now skip past any EH_LABELs, which must remain at the beginning.
|
|
|
|
while (FuncInfo.InsertPt != FuncInfo.MBB->end() &&
|
|
|
|
FuncInfo.InsertPt->getOpcode() == TargetOpcode::EH_LABEL)
|
|
|
|
++FuncInfo.InsertPt;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:40:47 +08:00
|
|
|
void FastISel::removeDeadCode(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator E) {
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 13:05:36 +08:00
|
|
|
assert(I.isValid() && E.isValid() && std::distance(I, E) > 0 &&
|
|
|
|
"Invalid iterator!");
|
2011-11-30 03:40:47 +08:00
|
|
|
while (I != E) {
|
|
|
|
MachineInstr *Dead = &*I;
|
|
|
|
++I;
|
|
|
|
Dead->eraseFromParent();
|
2013-03-09 06:56:31 +08:00
|
|
|
++NumFastIselDead;
|
2011-11-30 03:40:47 +08:00
|
|
|
}
|
|
|
|
recomputeInsertPt();
|
|
|
|
}
|
|
|
|
|
2012-10-03 16:10:01 +08:00
|
|
|
FastISel::SavePoint FastISel::enterLocalValueArea() {
|
2010-07-10 17:00:22 +08:00
|
|
|
MachineBasicBlock::iterator OldInsertPt = FuncInfo.InsertPt;
|
2014-02-19 06:05:46 +08:00
|
|
|
DebugLoc OldDL = DbgLoc;
|
2010-07-10 17:00:22 +08:00
|
|
|
recomputeInsertPt();
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = DebugLoc();
|
2014-09-04 02:46:45 +08:00
|
|
|
SavePoint SP = {OldInsertPt, OldDL};
|
2012-10-03 16:10:01 +08:00
|
|
|
return SP;
|
2010-07-10 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
2012-10-03 16:10:01 +08:00
|
|
|
void FastISel::leaveLocalValueArea(SavePoint OldInsertPt) {
|
2010-07-10 17:00:22 +08:00
|
|
|
if (FuncInfo.InsertPt != FuncInfo.MBB->begin())
|
2016-07-09 02:36:41 +08:00
|
|
|
LastLocalValue = &*std::prev(FuncInfo.InsertPt);
|
2010-07-10 17:00:22 +08:00
|
|
|
|
|
|
|
// Restore the previous insert position.
|
2012-10-03 16:10:01 +08:00
|
|
|
FuncInfo.InsertPt = OldInsertPt.InsertPt;
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = OldInsertPt.DL;
|
2010-07-10 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectBinaryOp(const User *I, unsigned ISDOpcode) {
|
2009-08-11 06:56:29 +08:00
|
|
|
EVT VT = EVT::getEVT(I->getType(), /*HandleUnknown=*/true);
|
2009-08-12 04:47:22 +08:00
|
|
|
if (VT == MVT::Other || !VT.isSimple())
|
2008-08-21 09:41:07 +08:00
|
|
|
// Unhandled type. Halt "fast" selection and bail.
|
|
|
|
return false;
|
2008-09-06 02:44:22 +08:00
|
|
|
|
2008-08-27 04:52:40 +08:00
|
|
|
// We only handle legal types. For example, on x86-32 the instruction
|
|
|
|
// selector contains all of the 64-bit instructions from x86-64,
|
|
|
|
// under the assumption that i64 won't be used if the target doesn't
|
|
|
|
// support it.
|
2008-09-06 02:44:22 +08:00
|
|
|
if (!TLI.isTypeLegal(VT)) {
|
2009-08-12 04:47:22 +08:00
|
|
|
// MVT::i1 is special. Allow AND, OR, or XOR because they
|
2008-09-06 02:44:22 +08:00
|
|
|
// don't require additional zeroing, which makes them easy.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (VT == MVT::i1 && (ISDOpcode == ISD::AND || ISDOpcode == ISD::OR ||
|
|
|
|
ISDOpcode == ISD::XOR))
|
2009-08-12 08:36:31 +08:00
|
|
|
VT = TLI.getTypeToTransformTo(I->getContext(), VT);
|
2008-09-06 02:44:22 +08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2008-08-21 09:41:07 +08:00
|
|
|
|
2011-04-17 09:16:47 +08:00
|
|
|
// Check if the first operand is a constant, and handle it as "ri". At -O0,
|
|
|
|
// we don't have anything that canonicalizes operand order.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *CI = dyn_cast<ConstantInt>(I->getOperand(0)))
|
2011-04-17 09:16:47 +08:00
|
|
|
if (isa<Instruction>(I) && cast<Instruction>(I)->isCommutative()) {
|
|
|
|
unsigned Op1 = getRegForValue(I->getOperand(1));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Op1)
|
|
|
|
return false;
|
2011-04-17 09:16:47 +08:00
|
|
|
bool Op1IsKill = hasTrivialKill(I->getOperand(1));
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
unsigned ResultReg =
|
2014-09-04 04:56:59 +08:00
|
|
|
fastEmit_ri_(VT.getSimpleVT(), ISDOpcode, Op1, Op1IsKill,
|
2014-09-04 02:46:45 +08:00
|
|
|
CI->getZExtValue(), VT.getSimpleVT());
|
|
|
|
if (!ResultReg)
|
|
|
|
return false;
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2011-04-18 04:23:29 +08:00
|
|
|
// We successfully emitted code for the given LLVM Instruction.
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2011-04-18 04:23:29 +08:00
|
|
|
return true;
|
2011-04-17 09:16:47 +08:00
|
|
|
}
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned Op0 = getRegForValue(I->getOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Op0) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-20 08:35:17 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
bool Op0IsKill = hasTrivialKill(I->getOperand(0));
|
|
|
|
|
2008-08-21 09:41:07 +08:00
|
|
|
// Check if the second operand is a constant and handle it appropriately.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
|
2015-04-07 06:29:07 +08:00
|
|
|
uint64_t Imm = CI->getSExtValue();
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2011-04-18 15:00:40 +08:00
|
|
|
// Transform "sdiv exact X, 8" -> "sra X, 3".
|
|
|
|
if (ISDOpcode == ISD::SDIV && isa<BinaryOperator>(I) &&
|
2014-09-04 02:46:45 +08:00
|
|
|
cast<BinaryOperator>(I)->isExact() && isPowerOf2_64(Imm)) {
|
2011-04-18 15:00:40 +08:00
|
|
|
Imm = Log2_64(Imm);
|
|
|
|
ISDOpcode = ISD::SRA;
|
|
|
|
}
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2012-03-22 08:21:17 +08:00
|
|
|
// Transform "urem x, pow2" -> "and x, pow2-1".
|
|
|
|
if (ISDOpcode == ISD::UREM && isa<BinaryOperator>(I) &&
|
|
|
|
isPowerOf2_64(Imm)) {
|
|
|
|
--Imm;
|
|
|
|
ISDOpcode = ISD::AND;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned ResultReg = fastEmit_ri_(VT.getSimpleVT(), ISDOpcode, Op0,
|
2011-04-18 04:23:29 +08:00
|
|
|
Op0IsKill, Imm, VT.getSimpleVT());
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!ResultReg)
|
|
|
|
return false;
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2011-04-18 04:23:29 +08:00
|
|
|
// We successfully emitted code for the given LLVM Instruction.
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2011-04-18 04:23:29 +08:00
|
|
|
return true;
|
2008-08-21 09:41:07 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned Op1 = getRegForValue(I->getOperand(1));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Op1) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-20 08:11:48 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
bool Op1IsKill = hasTrivialKill(I->getOperand(1));
|
|
|
|
|
2008-08-28 02:10:19 +08:00
|
|
|
// Now we have both operands in registers. Emit the instruction.
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned ResultReg = fastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(),
|
2014-09-04 02:46:45 +08:00
|
|
|
ISDOpcode, Op0, Op0IsKill, Op1, Op1IsKill);
|
|
|
|
if (!ResultReg)
|
2008-08-20 08:11:48 +08:00
|
|
|
// Target-specific code wasn't able to find a machine opcode for
|
|
|
|
// the given ISD opcode and type. Halt "fast" selection and bail.
|
|
|
|
return false;
|
|
|
|
|
2008-08-20 08:23:20 +08:00
|
|
|
// We successfully emitted code for the given LLVM Instruction.
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2008-08-20 08:11:48 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectGetElementPtr(const User *I) {
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned N = getRegForValue(I->getOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-21 06:45:34 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
bool NIsKill = hasTrivialKill(I->getOperand(0));
|
|
|
|
|
2011-11-17 15:15:58 +08:00
|
|
|
// Keep a running tab of the total offset to coalesce multiple N = N + Offset
|
|
|
|
// into a single N = N + TotalOffset.
|
|
|
|
uint64_t TotalOffs = 0;
|
|
|
|
// FIXME: What's a good SWAG number for MaxOffs?
|
|
|
|
uint64_t MaxOffs = 2048;
|
2015-07-09 10:09:04 +08:00
|
|
|
MVT VT = TLI.getPointerTy(DL);
|
2016-01-20 08:26:52 +08:00
|
|
|
for (gep_type_iterator GTI = gep_type_begin(I), E = gep_type_end(I);
|
|
|
|
GTI != E; ++GTI) {
|
|
|
|
const Value *Idx = GTI.getOperand();
|
2016-12-02 10:24:42 +08:00
|
|
|
if (StructType *StTy = GTI.getStructTypeOrNull()) {
|
2015-03-12 07:36:10 +08:00
|
|
|
uint64_t Field = cast<ConstantInt>(Idx)->getZExtValue();
|
2008-08-21 06:45:34 +08:00
|
|
|
if (Field) {
|
|
|
|
// N = N + Offset
|
2014-02-19 06:05:46 +08:00
|
|
|
TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field);
|
2011-11-17 15:15:58 +08:00
|
|
|
if (TotalOffs >= MaxOffs) {
|
2014-09-04 04:56:59 +08:00
|
|
|
N = fastEmit_ri_(VT, ISD::ADD, N, NIsKill, TotalOffs, VT);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2011-11-17 15:15:58 +08:00
|
|
|
return false;
|
|
|
|
NIsKill = true;
|
|
|
|
TotalOffs = 0;
|
|
|
|
}
|
2008-08-21 06:45:34 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-01-20 08:26:52 +08:00
|
|
|
Type *Ty = GTI.getIndexedType();
|
2008-08-21 06:45:34 +08:00
|
|
|
|
|
|
|
// If this is a constant subscript, handle it quickly.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *CI = dyn_cast<ConstantInt>(Idx)) {
|
|
|
|
if (CI->isZero())
|
|
|
|
continue;
|
2011-11-17 15:15:58 +08:00
|
|
|
// N = N + Offset
|
2015-03-12 07:36:10 +08:00
|
|
|
uint64_t IdxN = CI->getValue().sextOrTrunc(64).getSExtValue();
|
|
|
|
TotalOffs += DL.getTypeAllocSize(Ty) * IdxN;
|
2011-11-17 15:15:58 +08:00
|
|
|
if (TotalOffs >= MaxOffs) {
|
2014-09-04 04:56:59 +08:00
|
|
|
N = fastEmit_ri_(VT, ISD::ADD, N, NIsKill, TotalOffs, VT);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2011-11-17 15:15:58 +08:00
|
|
|
return false;
|
|
|
|
NIsKill = true;
|
|
|
|
TotalOffs = 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (TotalOffs) {
|
2014-09-04 04:56:59 +08:00
|
|
|
N = fastEmit_ri_(VT, ISD::ADD, N, NIsKill, TotalOffs, VT);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-21 06:45:34 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
NIsKill = true;
|
2011-11-17 15:15:58 +08:00
|
|
|
TotalOffs = 0;
|
2008-08-21 06:45:34 +08:00
|
|
|
}
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-08-21 06:45:34 +08:00
|
|
|
// N = N + Idx * ElementSize;
|
2014-02-19 06:05:46 +08:00
|
|
|
uint64_t ElementSize = DL.getTypeAllocSize(Ty);
|
2010-05-12 07:54:07 +08:00
|
|
|
std::pair<unsigned, bool> Pair = getRegForGEPIndex(Idx);
|
|
|
|
unsigned IdxN = Pair.first;
|
|
|
|
bool IdxNIsKill = Pair.second;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!IdxN) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-21 06:45:34 +08:00
|
|
|
return false;
|
|
|
|
|
2008-08-27 04:57:08 +08:00
|
|
|
if (ElementSize != 1) {
|
2014-09-04 04:56:59 +08:00
|
|
|
IdxN = fastEmit_ri_(VT, ISD::MUL, IdxN, IdxNIsKill, ElementSize, VT);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!IdxN) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-27 04:57:08 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
IdxNIsKill = true;
|
2008-08-27 04:57:08 +08:00
|
|
|
}
|
2014-09-04 04:56:59 +08:00
|
|
|
N = fastEmit_rr(VT, VT, ISD::ADD, N, NIsKill, IdxN, IdxNIsKill);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-21 06:45:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-11-17 15:15:58 +08:00
|
|
|
if (TotalOffs) {
|
2014-09-04 04:56:59 +08:00
|
|
|
N = fastEmit_ri_(VT, ISD::ADD, N, NIsKill, TotalOffs, VT);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!N) // Unhandled operand. Halt "fast" selection and bail.
|
2011-11-17 15:15:58 +08:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-21 06:45:34 +08:00
|
|
|
|
|
|
|
// We successfully emitted code for the given LLVM Instruction.
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, N);
|
2008-08-21 06:45:34 +08:00
|
|
|
return true;
|
2008-08-20 08:11:48 +08:00
|
|
|
}
|
|
|
|
|
2014-06-12 11:29:26 +08:00
|
|
|
bool FastISel::addStackMapLiveVars(SmallVectorImpl<MachineOperand> &Ops,
|
|
|
|
const CallInst *CI, unsigned StartIdx) {
|
|
|
|
for (unsigned i = StartIdx, e = CI->getNumArgOperands(); i != e; ++i) {
|
|
|
|
Value *Val = CI->getArgOperand(i);
|
2014-07-02 06:25:49 +08:00
|
|
|
// Check for constants and encode them with a StackMaps::ConstantOp prefix.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *C = dyn_cast<ConstantInt>(Val)) {
|
2014-06-12 11:29:26 +08:00
|
|
|
Ops.push_back(MachineOperand::CreateImm(StackMaps::ConstantOp));
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(C->getSExtValue()));
|
|
|
|
} else if (isa<ConstantPointerNull>(Val)) {
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(StackMaps::ConstantOp));
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(0));
|
|
|
|
} else if (auto *AI = dyn_cast<AllocaInst>(Val)) {
|
2016-11-20 21:14:57 +08:00
|
|
|
// Values coming from a stack location also require a special encoding,
|
2014-07-02 06:25:49 +08:00
|
|
|
// but that is added later on by the target specific frame index
|
|
|
|
// elimination implementation.
|
2014-06-12 11:29:26 +08:00
|
|
|
auto SI = FuncInfo.StaticAllocaMap.find(AI);
|
|
|
|
if (SI != FuncInfo.StaticAllocaMap.end())
|
|
|
|
Ops.push_back(MachineOperand::CreateFI(SI->second));
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
unsigned Reg = getRegForValue(Val);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Reg)
|
2014-06-12 11:29:26 +08:00
|
|
|
return false;
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(Reg, /*IsDef=*/false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectStackmap(const CallInst *I) {
|
2014-07-02 06:25:49 +08:00
|
|
|
// void @llvm.experimental.stackmap(i64 <id>, i32 <numShadowBytes>,
|
|
|
|
// [live variables...])
|
|
|
|
assert(I->getCalledFunction()->getReturnType()->isVoidTy() &&
|
|
|
|
"Stackmap cannot return a value.");
|
|
|
|
|
|
|
|
// The stackmap intrinsic only records the live variables (the arguments
|
|
|
|
// passed to it) and emits NOPS (if requested). Unlike the patchpoint
|
|
|
|
// intrinsic, this won't be lowered to a function call. This means we don't
|
|
|
|
// have to worry about calling conventions and target-specific lowering code.
|
|
|
|
// Instead we perform the call lowering right here.
|
|
|
|
//
|
2015-08-11 05:27:03 +08:00
|
|
|
// CALLSEQ_START(0...)
|
2014-07-02 06:25:49 +08:00
|
|
|
// STACKMAP(id, nbytes, ...)
|
|
|
|
// CALLSEQ_END(0, 0)
|
|
|
|
//
|
|
|
|
SmallVector<MachineOperand, 32> Ops;
|
|
|
|
|
|
|
|
// Add the <id> and <numBytes> constants.
|
|
|
|
assert(isa<ConstantInt>(I->getOperand(PatchPointOpers::IDPos)) &&
|
|
|
|
"Expected a constant integer.");
|
|
|
|
const auto *ID = cast<ConstantInt>(I->getOperand(PatchPointOpers::IDPos));
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(ID->getZExtValue()));
|
|
|
|
|
|
|
|
assert(isa<ConstantInt>(I->getOperand(PatchPointOpers::NBytesPos)) &&
|
|
|
|
"Expected a constant integer.");
|
|
|
|
const auto *NumBytes =
|
2014-09-04 02:46:45 +08:00
|
|
|
cast<ConstantInt>(I->getOperand(PatchPointOpers::NBytesPos));
|
2014-07-02 06:25:49 +08:00
|
|
|
Ops.push_back(MachineOperand::CreateImm(NumBytes->getZExtValue()));
|
|
|
|
|
|
|
|
// Push live variables for the stack map (skipping the first two arguments
|
|
|
|
// <id> and <numBytes>).
|
|
|
|
if (!addStackMapLiveVars(Ops, I, 2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We are not adding any register mask info here, because the stackmap doesn't
|
|
|
|
// clobber anything.
|
|
|
|
|
|
|
|
// Add scratch registers as implicit def and early clobber.
|
|
|
|
CallingConv::ID CC = I->getCallingConv();
|
|
|
|
const MCPhysReg *ScratchRegs = TLI.getScratchRegisters(CC);
|
|
|
|
for (unsigned i = 0; ScratchRegs[i]; ++i)
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(
|
2014-09-04 02:46:45 +08:00
|
|
|
ScratchRegs[i], /*IsDef=*/true, /*IsImp=*/true, /*IsKill=*/false,
|
|
|
|
/*IsDead=*/false, /*IsUndef=*/false, /*IsEarlyClobber=*/true));
|
2014-07-02 06:25:49 +08:00
|
|
|
|
|
|
|
// Issue CALLSEQ_START
|
|
|
|
unsigned AdjStackDown = TII.getCallFrameSetupOpcode();
|
2015-08-11 05:27:03 +08:00
|
|
|
auto Builder =
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(AdjStackDown));
|
|
|
|
const MCInstrDesc &MCID = Builder.getInstr()->getDesc();
|
|
|
|
for (unsigned I = 0, E = MCID.getNumOperands(); I < E; ++I)
|
|
|
|
Builder.addImm(0);
|
2014-07-02 06:25:49 +08:00
|
|
|
|
|
|
|
// Issue STACKMAP.
|
|
|
|
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::STACKMAP));
|
|
|
|
for (auto const &MO : Ops)
|
2017-01-13 17:58:52 +08:00
|
|
|
MIB.add(MO);
|
2014-07-02 06:25:49 +08:00
|
|
|
|
|
|
|
// Issue CALLSEQ_END
|
|
|
|
unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(AdjStackUp))
|
2014-09-04 02:46:45 +08:00
|
|
|
.addImm(0)
|
|
|
|
.addImm(0);
|
2014-07-02 06:25:49 +08:00
|
|
|
|
|
|
|
// Inform the Frame Information that we have a stackmap in this function.
|
2016-07-29 02:40:00 +08:00
|
|
|
FuncInfo.MF->getFrameInfo().setHasStackMap();
|
2014-07-02 06:25:49 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-12 06:19:02 +08:00
|
|
|
/// \brief Lower an argument list according to the target calling convention.
|
|
|
|
///
|
|
|
|
/// This is a helper for lowering intrinsics that follow a target calling
|
|
|
|
/// convention or require stack pointer adjustment. Only a subset of the
|
|
|
|
/// intrinsic's operands need to participate in the calling convention.
|
|
|
|
bool FastISel::lowerCallOperands(const CallInst *CI, unsigned ArgIdx,
|
|
|
|
unsigned NumArgs, const Value *Callee,
|
|
|
|
bool ForceRetVoidTy, CallLoweringInfo &CLI) {
|
|
|
|
ArgListTy Args;
|
|
|
|
Args.reserve(NumArgs);
|
|
|
|
|
|
|
|
// Populate the argument list.
|
|
|
|
// Attributes for args start at offset 1, after the return attribute.
|
|
|
|
ImmutableCallSite CS(CI);
|
|
|
|
for (unsigned ArgI = ArgIdx, ArgE = ArgIdx + NumArgs, AttrI = ArgIdx + 1;
|
|
|
|
ArgI != ArgE; ++ArgI) {
|
|
|
|
Value *V = CI->getOperand(ArgI);
|
|
|
|
|
|
|
|
assert(!V->getType()->isEmptyTy() && "Empty type passed to intrinsic.");
|
|
|
|
|
|
|
|
ArgListEntry Entry;
|
|
|
|
Entry.Val = V;
|
|
|
|
Entry.Ty = V->getType();
|
|
|
|
Entry.setAttributes(&CS, AttrI);
|
|
|
|
Args.push_back(Entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
Type *RetTy = ForceRetVoidTy ? Type::getVoidTy(CI->getType()->getContext())
|
|
|
|
: CI->getType();
|
|
|
|
CLI.setCallee(CI->getCallingConv(), RetTy, Callee, std::move(Args), NumArgs);
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
return lowerCallTo(CLI);
|
2014-07-12 06:19:02 +08:00
|
|
|
}
|
|
|
|
|
2015-06-23 20:21:54 +08:00
|
|
|
FastISel::CallLoweringInfo &FastISel::CallLoweringInfo::setCallee(
|
|
|
|
const DataLayout &DL, MCContext &Ctx, CallingConv::ID CC, Type *ResultTy,
|
2016-10-05 09:37:29 +08:00
|
|
|
StringRef Target, ArgListTy &&ArgsList, unsigned FixedArgs) {
|
2015-06-23 20:21:54 +08:00
|
|
|
SmallString<32> MangledName;
|
|
|
|
Mangler::getNameWithPrefix(MangledName, Target, DL);
|
|
|
|
MCSymbol *Sym = Ctx.getOrCreateSymbol(MangledName);
|
|
|
|
return setCallee(CC, ResultTy, Sym, std::move(ArgsList), FixedArgs);
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectPatchpoint(const CallInst *I) {
|
2014-07-12 06:19:02 +08:00
|
|
|
// void|i64 @llvm.experimental.patchpoint.void|i64(i64 <id>,
|
|
|
|
// i32 <numBytes>,
|
|
|
|
// i8* <target>,
|
|
|
|
// i32 <numArgs>,
|
|
|
|
// [Args...],
|
|
|
|
// [live variables...])
|
|
|
|
CallingConv::ID CC = I->getCallingConv();
|
|
|
|
bool IsAnyRegCC = CC == CallingConv::AnyReg;
|
|
|
|
bool HasDef = !I->getType()->isVoidTy();
|
2015-04-22 14:02:31 +08:00
|
|
|
Value *Callee = I->getOperand(PatchPointOpers::TargetPos)->stripPointerCasts();
|
2014-07-12 06:19:02 +08:00
|
|
|
|
|
|
|
// Get the real number of arguments participating in the call <numArgs>
|
|
|
|
assert(isa<ConstantInt>(I->getOperand(PatchPointOpers::NArgPos)) &&
|
|
|
|
"Expected a constant integer.");
|
|
|
|
const auto *NumArgsVal =
|
2014-09-04 02:46:45 +08:00
|
|
|
cast<ConstantInt>(I->getOperand(PatchPointOpers::NArgPos));
|
2014-07-12 06:19:02 +08:00
|
|
|
unsigned NumArgs = NumArgsVal->getZExtValue();
|
|
|
|
|
|
|
|
// Skip the four meta args: <id>, <numNopBytes>, <target>, <numArgs>
|
|
|
|
// This includes all meta-operands up to but not including CC.
|
|
|
|
unsigned NumMetaOpers = PatchPointOpers::CCPos;
|
|
|
|
assert(I->getNumArgOperands() >= NumMetaOpers + NumArgs &&
|
|
|
|
"Not enough arguments provided to the patchpoint intrinsic");
|
|
|
|
|
|
|
|
// For AnyRegCC the arguments are lowered later on manually.
|
|
|
|
unsigned NumCallArgs = IsAnyRegCC ? 0 : NumArgs;
|
|
|
|
CallLoweringInfo CLI;
|
2015-01-14 01:48:04 +08:00
|
|
|
CLI.setIsPatchPoint();
|
2014-07-12 06:19:02 +08:00
|
|
|
if (!lowerCallOperands(I, NumMetaOpers, NumCallArgs, Callee, IsAnyRegCC, CLI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(CLI.Call && "No call instruction specified.");
|
|
|
|
|
|
|
|
SmallVector<MachineOperand, 32> Ops;
|
|
|
|
|
|
|
|
// Add an explicit result reg if we use the anyreg calling convention.
|
|
|
|
if (IsAnyRegCC && HasDef) {
|
2014-07-15 10:22:43 +08:00
|
|
|
assert(CLI.NumResultRegs == 0 && "Unexpected result register.");
|
|
|
|
CLI.ResultReg = createResultReg(TLI.getRegClassFor(MVT::i64));
|
|
|
|
CLI.NumResultRegs = 1;
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(CLI.ResultReg, /*IsDef=*/true));
|
2014-07-12 06:19:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the <id> and <numBytes> constants.
|
|
|
|
assert(isa<ConstantInt>(I->getOperand(PatchPointOpers::IDPos)) &&
|
|
|
|
"Expected a constant integer.");
|
|
|
|
const auto *ID = cast<ConstantInt>(I->getOperand(PatchPointOpers::IDPos));
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(ID->getZExtValue()));
|
|
|
|
|
|
|
|
assert(isa<ConstantInt>(I->getOperand(PatchPointOpers::NBytesPos)) &&
|
|
|
|
"Expected a constant integer.");
|
|
|
|
const auto *NumBytes =
|
2014-09-04 02:46:45 +08:00
|
|
|
cast<ConstantInt>(I->getOperand(PatchPointOpers::NBytesPos));
|
2014-07-12 06:19:02 +08:00
|
|
|
Ops.push_back(MachineOperand::CreateImm(NumBytes->getZExtValue()));
|
|
|
|
|
2015-04-22 14:02:31 +08:00
|
|
|
// Add the call target.
|
|
|
|
if (const auto *C = dyn_cast<IntToPtrInst>(Callee)) {
|
|
|
|
uint64_t CalleeConstAddr =
|
|
|
|
cast<ConstantInt>(C->getOperand(0))->getZExtValue();
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(CalleeConstAddr));
|
|
|
|
} else if (const auto *C = dyn_cast<ConstantExpr>(Callee)) {
|
|
|
|
if (C->getOpcode() == Instruction::IntToPtr) {
|
|
|
|
uint64_t CalleeConstAddr =
|
|
|
|
cast<ConstantInt>(C->getOperand(0))->getZExtValue();
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(CalleeConstAddr));
|
|
|
|
} else
|
2014-07-12 06:19:02 +08:00
|
|
|
llvm_unreachable("Unsupported ConstantExpr.");
|
2015-04-22 14:02:31 +08:00
|
|
|
} else if (const auto *GV = dyn_cast<GlobalValue>(Callee)) {
|
|
|
|
Ops.push_back(MachineOperand::CreateGA(GV, 0));
|
2014-07-12 06:19:02 +08:00
|
|
|
} else if (isa<ConstantPointerNull>(Callee))
|
2015-04-22 14:02:31 +08:00
|
|
|
Ops.push_back(MachineOperand::CreateImm(0));
|
2014-07-12 06:19:02 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unsupported callee address.");
|
|
|
|
|
|
|
|
// Adjust <numArgs> to account for any arguments that have been passed on
|
|
|
|
// the stack instead.
|
|
|
|
unsigned NumCallRegArgs = IsAnyRegCC ? NumArgs : CLI.OutRegs.size();
|
|
|
|
Ops.push_back(MachineOperand::CreateImm(NumCallRegArgs));
|
|
|
|
|
|
|
|
// Add the calling convention
|
|
|
|
Ops.push_back(MachineOperand::CreateImm((unsigned)CC));
|
|
|
|
|
|
|
|
// Add the arguments we omitted previously. The register allocator should
|
|
|
|
// place these in any free register.
|
|
|
|
if (IsAnyRegCC) {
|
|
|
|
for (unsigned i = NumMetaOpers, e = NumMetaOpers + NumArgs; i != e; ++i) {
|
|
|
|
unsigned Reg = getRegForValue(I->getArgOperand(i));
|
|
|
|
if (!Reg)
|
|
|
|
return false;
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(Reg, /*IsDef=*/false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the arguments from the call instruction.
|
|
|
|
for (auto Reg : CLI.OutRegs)
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(Reg, /*IsDef=*/false));
|
|
|
|
|
|
|
|
// Push live variables for the stack map.
|
|
|
|
if (!addStackMapLiveVars(Ops, I, NumMetaOpers + NumArgs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Push the register mask info.
|
2015-03-12 06:42:13 +08:00
|
|
|
Ops.push_back(MachineOperand::CreateRegMask(
|
|
|
|
TRI.getCallPreservedMask(*FuncInfo.MF, CC)));
|
2014-07-12 06:19:02 +08:00
|
|
|
|
|
|
|
// Add scratch registers as implicit def and early clobber.
|
|
|
|
const MCPhysReg *ScratchRegs = TLI.getScratchRegisters(CC);
|
|
|
|
for (unsigned i = 0; ScratchRegs[i]; ++i)
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(
|
2014-09-04 02:46:45 +08:00
|
|
|
ScratchRegs[i], /*IsDef=*/true, /*IsImp=*/true, /*IsKill=*/false,
|
|
|
|
/*IsDead=*/false, /*IsUndef=*/false, /*IsEarlyClobber=*/true));
|
2014-07-12 06:19:02 +08:00
|
|
|
|
|
|
|
// Add implicit defs (return values).
|
|
|
|
for (auto Reg : CLI.InRegs)
|
|
|
|
Ops.push_back(MachineOperand::CreateReg(Reg, /*IsDef=*/true,
|
|
|
|
/*IsImpl=*/true));
|
|
|
|
|
2014-07-15 10:22:46 +08:00
|
|
|
// Insert the patchpoint instruction before the call generated by the target.
|
|
|
|
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, CLI.Call, DbgLoc,
|
2014-07-12 06:19:02 +08:00
|
|
|
TII.get(TargetOpcode::PATCHPOINT));
|
|
|
|
|
|
|
|
for (auto &MO : Ops)
|
2017-01-13 17:58:52 +08:00
|
|
|
MIB.add(MO);
|
2014-07-12 06:19:02 +08:00
|
|
|
|
|
|
|
MIB->setPhysRegsDeadExcept(CLI.InRegs, TRI);
|
|
|
|
|
|
|
|
// Delete the original call instruction.
|
|
|
|
CLI.Call->eraseFromParent();
|
|
|
|
|
|
|
|
// Inform the Frame Information that we have a patchpoint in this function.
|
2016-07-29 02:40:00 +08:00
|
|
|
FuncInfo.MF->getFrameInfo().setHasPatchPoint();
|
2014-07-12 06:19:02 +08:00
|
|
|
|
2014-07-15 10:22:43 +08:00
|
|
|
if (CLI.NumResultRegs)
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, CLI.ResultReg, CLI.NumResultRegs);
|
2014-07-12 06:19:02 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-12 06:01:42 +08:00
|
|
|
/// Returns an AttributeSet representing the attributes applied to the return
|
|
|
|
/// value of the given call.
|
|
|
|
static AttributeSet getReturnAttrs(FastISel::CallLoweringInfo &CLI) {
|
|
|
|
SmallVector<Attribute::AttrKind, 2> Attrs;
|
|
|
|
if (CLI.RetSExt)
|
|
|
|
Attrs.push_back(Attribute::SExt);
|
|
|
|
if (CLI.RetZExt)
|
|
|
|
Attrs.push_back(Attribute::ZExt);
|
|
|
|
if (CLI.IsInReg)
|
|
|
|
Attrs.push_back(Attribute::InReg);
|
|
|
|
|
|
|
|
return AttributeSet::get(CLI.RetTy->getContext(), AttributeSet::ReturnIndex,
|
|
|
|
Attrs);
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::lowerCallTo(const CallInst *CI, const char *SymName,
|
2014-07-12 06:01:42 +08:00
|
|
|
unsigned NumArgs) {
|
2015-06-23 20:21:54 +08:00
|
|
|
MCContext &Ctx = MF->getContext();
|
|
|
|
SmallString<32> MangledName;
|
|
|
|
Mangler::getNameWithPrefix(MangledName, SymName, DL);
|
|
|
|
MCSymbol *Sym = Ctx.getOrCreateSymbol(MangledName);
|
|
|
|
return lowerCallTo(CI, Sym, NumArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FastISel::lowerCallTo(const CallInst *CI, MCSymbol *Symbol,
|
|
|
|
unsigned NumArgs) {
|
2014-07-12 06:01:42 +08:00
|
|
|
ImmutableCallSite CS(CI);
|
|
|
|
|
2016-01-18 06:37:39 +08:00
|
|
|
FunctionType *FTy = CS.getFunctionType();
|
|
|
|
Type *RetTy = CS.getType();
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
ArgListTy Args;
|
|
|
|
Args.reserve(NumArgs);
|
|
|
|
|
|
|
|
// Populate the argument list.
|
|
|
|
// Attributes for args start at offset 1, after the return attribute.
|
|
|
|
for (unsigned ArgI = 0; ArgI != NumArgs; ++ArgI) {
|
|
|
|
Value *V = CI->getOperand(ArgI);
|
|
|
|
|
|
|
|
assert(!V->getType()->isEmptyTy() && "Empty type passed to intrinsic.");
|
|
|
|
|
|
|
|
ArgListEntry Entry;
|
|
|
|
Entry.Val = V;
|
|
|
|
Entry.Ty = V->getType();
|
|
|
|
Entry.setAttributes(&CS, ArgI + 1);
|
|
|
|
Args.push_back(Entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
CallLoweringInfo CLI;
|
2015-06-23 20:21:54 +08:00
|
|
|
CLI.setCallee(RetTy, FTy, Symbol, std::move(Args), CS, NumArgs);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
return lowerCallTo(CLI);
|
2014-07-12 06:01:42 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::lowerCallTo(CallLoweringInfo &CLI) {
|
2014-07-12 06:01:42 +08:00
|
|
|
// Handle the incoming return values from the call.
|
|
|
|
CLI.clearIns();
|
|
|
|
SmallVector<EVT, 4> RetTys;
|
2015-07-09 09:57:34 +08:00
|
|
|
ComputeValueVTs(TLI, DL, CLI.RetTy, RetTys);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
SmallVector<ISD::OutputArg, 4> Outs;
|
2015-07-09 09:57:34 +08:00
|
|
|
GetReturnInfo(CLI.RetTy, getReturnAttrs(CLI), Outs, TLI, DL);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool CanLowerReturn = TLI.CanLowerReturn(
|
|
|
|
CLI.CallConv, *FuncInfo.MF, CLI.IsVarArg, Outs, CLI.RetTy->getContext());
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
// FIXME: sret demotion isn't supported yet - bail out.
|
|
|
|
if (!CanLowerReturn)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned I = 0, E = RetTys.size(); I != E; ++I) {
|
|
|
|
EVT VT = RetTys[I];
|
|
|
|
MVT RegisterVT = TLI.getRegisterType(CLI.RetTy->getContext(), VT);
|
|
|
|
unsigned NumRegs = TLI.getNumRegisters(CLI.RetTy->getContext(), VT);
|
|
|
|
for (unsigned i = 0; i != NumRegs; ++i) {
|
|
|
|
ISD::InputArg MyFlags;
|
|
|
|
MyFlags.VT = RegisterVT;
|
|
|
|
MyFlags.ArgVT = VT;
|
|
|
|
MyFlags.Used = CLI.IsReturnValueUsed;
|
|
|
|
if (CLI.RetSExt)
|
|
|
|
MyFlags.Flags.setSExt();
|
|
|
|
if (CLI.RetZExt)
|
|
|
|
MyFlags.Flags.setZExt();
|
|
|
|
if (CLI.IsInReg)
|
|
|
|
MyFlags.Flags.setInReg();
|
|
|
|
CLI.Ins.push_back(MyFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle all of the outgoing arguments.
|
|
|
|
CLI.clearOuts();
|
|
|
|
for (auto &Arg : CLI.getArgs()) {
|
|
|
|
Type *FinalType = Arg.Ty;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsByVal)
|
2014-07-12 06:01:42 +08:00
|
|
|
FinalType = cast<PointerType>(Arg.Ty)->getElementType();
|
|
|
|
bool NeedsRegBlock = TLI.functionArgumentNeedsConsecutiveRegisters(
|
2014-09-04 02:46:45 +08:00
|
|
|
FinalType, CLI.CallConv, CLI.IsVarArg);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
ISD::ArgFlagsTy Flags;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsZExt)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setZExt();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsSExt)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setSExt();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsInReg)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setInReg();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsSRet)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setSRet();
|
2016-03-30 01:37:21 +08:00
|
|
|
if (Arg.IsSwiftSelf)
|
|
|
|
Flags.setSwiftSelf();
|
2016-04-02 05:41:15 +08:00
|
|
|
if (Arg.IsSwiftError)
|
|
|
|
Flags.setSwiftError();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsByVal)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setByVal();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsInAlloca) {
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setInAlloca();
|
|
|
|
// Set the byval flag for CCAssignFn callbacks that don't know about
|
|
|
|
// inalloca. This way we can know how many bytes we should've allocated
|
|
|
|
// and how many bytes a callee cleanup function will pop. If we port
|
|
|
|
// inalloca to more targets, we'll have to add custom inalloca handling in
|
|
|
|
// the various CC lowering callbacks.
|
|
|
|
Flags.setByVal();
|
|
|
|
}
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsByVal || Arg.IsInAlloca) {
|
2014-07-12 06:01:42 +08:00
|
|
|
PointerType *Ty = cast<PointerType>(Arg.Ty);
|
|
|
|
Type *ElementTy = Ty->getElementType();
|
|
|
|
unsigned FrameSize = DL.getTypeAllocSize(ElementTy);
|
|
|
|
// For ByVal, alignment should come from FE. BE will guess if this info is
|
|
|
|
// not there, but there are cases it cannot get right.
|
|
|
|
unsigned FrameAlign = Arg.Alignment;
|
|
|
|
if (!FrameAlign)
|
2015-07-09 10:09:28 +08:00
|
|
|
FrameAlign = TLI.getByValTypeAlignment(ElementTy, DL);
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setByValSize(FrameSize);
|
|
|
|
Flags.setByValAlign(FrameAlign);
|
|
|
|
}
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Arg.IsNest)
|
2014-07-12 06:01:42 +08:00
|
|
|
Flags.setNest();
|
|
|
|
if (NeedsRegBlock)
|
|
|
|
Flags.setInConsecutiveRegs();
|
|
|
|
unsigned OriginalAlignment = DL.getABITypeAlignment(Arg.Ty);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
|
|
|
|
|
|
|
CLI.OutVals.push_back(Arg.Val);
|
|
|
|
CLI.OutFlags.push_back(Flags);
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
if (!fastLowerCall(CLI))
|
2014-07-12 06:01:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Set all unused physreg defs as dead.
|
|
|
|
assert(CLI.Call && "No call instruction specified.");
|
|
|
|
CLI.Call->setPhysRegsDeadExcept(CLI.InRegs, TRI);
|
|
|
|
|
|
|
|
if (CLI.NumResultRegs && CLI.CS)
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::lowerCall(const CallInst *CI) {
|
2014-07-12 06:01:42 +08:00
|
|
|
ImmutableCallSite CS(CI);
|
|
|
|
|
2016-01-18 06:37:39 +08:00
|
|
|
FunctionType *FuncTy = CS.getFunctionType();
|
|
|
|
Type *RetTy = CS.getType();
|
2014-07-12 06:01:42 +08:00
|
|
|
|
|
|
|
ArgListTy Args;
|
|
|
|
ArgListEntry Entry;
|
|
|
|
Args.reserve(CS.arg_size());
|
|
|
|
|
|
|
|
for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
|
|
|
|
i != e; ++i) {
|
|
|
|
Value *V = *i;
|
|
|
|
|
|
|
|
// Skip empty types
|
|
|
|
if (V->getType()->isEmptyTy())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Entry.Val = V;
|
|
|
|
Entry.Ty = V->getType();
|
|
|
|
|
|
|
|
// Skip the first return-type Attribute to get to params.
|
|
|
|
Entry.setAttributes(&CS, i - CS.arg_begin() + 1);
|
|
|
|
Args.push_back(Entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if target-independent constraints permit a tail call here.
|
2014-09-04 04:56:52 +08:00
|
|
|
// Target-dependent constraints are checked within fastLowerCall.
|
2014-07-12 06:01:42 +08:00
|
|
|
bool IsTailCall = CI->isTailCall();
|
2014-07-16 08:01:22 +08:00
|
|
|
if (IsTailCall && !isInTailCallPosition(CS, TM))
|
2014-07-12 06:01:42 +08:00
|
|
|
IsTailCall = false;
|
|
|
|
|
|
|
|
CallLoweringInfo CLI;
|
|
|
|
CLI.setCallee(RetTy, FuncTy, CI->getCalledValue(), std::move(Args), CS)
|
2014-09-04 02:46:45 +08:00
|
|
|
.setTailCall(IsTailCall);
|
2014-07-12 06:01:42 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
return lowerCallTo(CLI);
|
2014-07-12 06:01:42 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectCall(const User *I) {
|
2011-04-27 01:18:34 +08:00
|
|
|
const CallInst *Call = cast<CallInst>(I);
|
|
|
|
|
|
|
|
// Handle simple inline asms.
|
2011-10-12 23:56:56 +08:00
|
|
|
if (const InlineAsm *IA = dyn_cast<InlineAsm>(Call->getCalledValue())) {
|
2014-07-17 06:20:51 +08:00
|
|
|
// If the inline asm has side effects, then make sure that no local value
|
|
|
|
// lives across by flushing the local value map.
|
|
|
|
if (IA->hasSideEffects())
|
|
|
|
flushLocalValueMap();
|
|
|
|
|
2011-04-27 01:18:34 +08:00
|
|
|
// Don't attempt to handle constraints.
|
|
|
|
if (!IA->getConstraintString().empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned ExtraInfo = 0;
|
|
|
|
if (IA->hasSideEffects())
|
|
|
|
ExtraInfo |= InlineAsm::Extra_HasSideEffects;
|
|
|
|
if (IA->isAlignStack())
|
|
|
|
ExtraInfo |= InlineAsm::Extra_IsAlignStack;
|
|
|
|
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
2011-04-27 01:18:34 +08:00
|
|
|
TII.get(TargetOpcode::INLINEASM))
|
2014-09-04 02:46:45 +08:00
|
|
|
.addExternalSymbol(IA->getAsmString().c_str())
|
|
|
|
.addImm(ExtraInfo);
|
2011-04-27 01:18:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-23 03:06:13 +08:00
|
|
|
MachineModuleInfo &MMI = FuncInfo.MF->getMMI();
|
2016-11-17 06:25:03 +08:00
|
|
|
computeUsesVAFloatArgument(*Call, MMI);
|
2012-02-23 03:06:13 +08:00
|
|
|
|
2014-07-12 04:42:12 +08:00
|
|
|
// Handle intrinsic function calls.
|
|
|
|
if (const auto *II = dyn_cast<IntrinsicInst>(Call))
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectIntrinsicCall(II);
|
2008-09-26 01:05:24 +08:00
|
|
|
|
2014-07-12 04:42:12 +08:00
|
|
|
// Usually, it does not make sense to initialize a value,
|
|
|
|
// make an unrelated function call and use the value, because
|
|
|
|
// it tends to be spilled on the stack. So, we move the pointer
|
|
|
|
// to the last local value to the beginning of the block, so that
|
|
|
|
// all the values which have already been materialized,
|
|
|
|
// appear after the call. It also makes sense to skip intrinsics
|
|
|
|
// since they tend to be inlined.
|
|
|
|
flushLocalValueMap();
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
return lowerCall(Call);
|
2014-07-12 04:42:12 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
|
2014-07-12 04:42:12 +08:00
|
|
|
switch (II->getIntrinsicID()) {
|
2014-09-04 02:46:45 +08:00
|
|
|
default:
|
|
|
|
break;
|
2014-07-12 04:42:12 +08:00
|
|
|
// At -O0 we don't care about the lifetime intrinsics.
|
2012-02-18 07:03:39 +08:00
|
|
|
case Intrinsic::lifetime_start:
|
|
|
|
case Intrinsic::lifetime_end:
|
2014-07-12 04:42:12 +08:00
|
|
|
// The donothing intrinsic does, well, nothing.
|
2012-07-07 01:33:39 +08:00
|
|
|
case Intrinsic::donothing:
|
2016-07-22 20:54:53 +08:00
|
|
|
// Neither does the assume intrinsic; it's also OK not to codegen its operand.
|
|
|
|
case Intrinsic::assume:
|
2012-02-18 07:03:39 +08:00
|
|
|
return true;
|
2009-02-13 10:16:35 +08:00
|
|
|
case Intrinsic::dbg_declare: {
|
2014-07-12 04:42:12 +08:00
|
|
|
const DbgDeclareInst *DI = cast<DbgDeclareInst>(II);
|
2015-04-22 02:24:23 +08:00
|
|
|
assert(DI->getVariable() && "Missing variable");
|
|
|
|
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
|
2012-03-16 05:33:44 +08:00
|
|
|
DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
|
2009-07-03 06:43:26 +08:00
|
|
|
return true;
|
2012-03-16 05:33:44 +08:00
|
|
|
}
|
2009-02-13 10:16:35 +08:00
|
|
|
|
2010-04-15 09:51:59 +08:00
|
|
|
const Value *Address = DI->getAddress();
|
2012-03-16 05:33:47 +08:00
|
|
|
if (!Address || isa<UndefValue>(Address)) {
|
2012-03-16 05:33:44 +08:00
|
|
|
DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
|
2010-02-06 10:26:02 +08:00
|
|
|
return true;
|
2012-03-16 05:33:44 +08:00
|
|
|
}
|
2010-09-15 04:29:31 +08:00
|
|
|
|
2013-07-10 04:28:37 +08:00
|
|
|
unsigned Offset = 0;
|
2013-06-17 04:34:15 +08:00
|
|
|
Optional<MachineOperand> Op;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *Arg = dyn_cast<Argument>(Address))
|
2011-09-09 06:59:09 +08:00
|
|
|
// Some arguments' frame index is recorded during argument lowering.
|
2013-07-10 04:28:37 +08:00
|
|
|
Offset = FuncInfo.getArgumentFrameIndex(Arg);
|
|
|
|
if (Offset)
|
2014-07-12 04:42:12 +08:00
|
|
|
Op = MachineOperand::CreateFI(Offset);
|
2013-06-17 04:34:15 +08:00
|
|
|
if (!Op)
|
|
|
|
if (unsigned Reg = lookUpRegForValue(Address))
|
|
|
|
Op = MachineOperand::CreateReg(Reg, false);
|
2012-03-20 09:07:58 +08:00
|
|
|
|
2012-03-30 08:02:55 +08:00
|
|
|
// If we have a VLA that has a "use" in a metadata node that's then used
|
|
|
|
// here but it has no other uses, then we have a problem. E.g.,
|
|
|
|
//
|
|
|
|
// int foo (const int *x) {
|
|
|
|
// char a[*x];
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If we assign 'a' a vreg and fast isel later on has to use the selection
|
|
|
|
// DAG isel, it will want to copy the value to the vreg. However, there are
|
|
|
|
// no uses, which goes counter to what selection DAG isel expects.
|
2013-06-17 04:34:15 +08:00
|
|
|
if (!Op && !Address->use_empty() && isa<Instruction>(Address) &&
|
2012-03-20 09:07:58 +08:00
|
|
|
(!isa<AllocaInst>(Address) ||
|
|
|
|
!FuncInfo.StaticAllocaMap.count(cast<AllocaInst>(Address))))
|
2013-06-17 04:34:15 +08:00
|
|
|
Op = MachineOperand::CreateReg(FuncInfo.InitializeRegForValue(Address),
|
2013-09-19 06:08:59 +08:00
|
|
|
false);
|
2013-06-17 04:34:15 +08:00
|
|
|
|
2013-09-19 06:08:59 +08:00
|
|
|
if (Op) {
|
2015-04-04 03:20:26 +08:00
|
|
|
assert(DI->getVariable()->isValidLocationForIntrinsic(DbgLoc) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
2013-07-10 04:28:37 +08:00
|
|
|
if (Op->isReg()) {
|
|
|
|
Op->setIsDebug(true);
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
2013-10-15 04:15:04 +08:00
|
|
|
TII.get(TargetOpcode::DBG_VALUE), false, Op->getReg(), 0,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
DI->getVariable(), DI->getExpression());
|
2013-10-15 04:15:04 +08:00
|
|
|
} else
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
2013-10-15 04:15:04 +08:00
|
|
|
TII.get(TargetOpcode::DBG_VALUE))
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(*Op)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addImm(0)
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
.addMetadata(DI->getVariable())
|
|
|
|
.addMetadata(DI->getExpression());
|
2013-09-19 06:08:59 +08:00
|
|
|
} else {
|
2012-03-20 09:07:53 +08:00
|
|
|
// We can't yet handle anything else here because it would require
|
|
|
|
// generating code, thus altering codegen because of debug info.
|
2013-05-23 02:02:19 +08:00
|
|
|
DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
|
2013-09-19 06:08:59 +08:00
|
|
|
}
|
2008-09-26 01:05:24 +08:00
|
|
|
return true;
|
2009-02-13 10:16:35 +08:00
|
|
|
}
|
2010-02-27 04:01:55 +08:00
|
|
|
case Intrinsic::dbg_value: {
|
2010-04-07 09:15:14 +08:00
|
|
|
// This form of DBG_VALUE is target-independent.
|
2014-07-12 04:42:12 +08:00
|
|
|
const DbgValueInst *DI = cast<DbgValueInst>(II);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(TargetOpcode::DBG_VALUE);
|
2010-04-15 09:51:59 +08:00
|
|
|
const Value *V = DI->getValue();
|
2015-04-04 03:20:26 +08:00
|
|
|
assert(DI->getVariable()->isValidLocationForIntrinsic(DbgLoc) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
2010-02-27 04:01:55 +08:00
|
|
|
if (!V) {
|
|
|
|
// Currently the optimizer can produce this; insert an undef to
|
|
|
|
// help debugging. Probably the optimizer should not do this.
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(0U)
|
|
|
|
.addImm(DI->getOffset())
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
.addMetadata(DI->getVariable())
|
|
|
|
.addMetadata(DI->getExpression());
|
2014-09-04 02:46:45 +08:00
|
|
|
} else if (const auto *CI = dyn_cast<ConstantInt>(V)) {
|
2011-06-25 04:46:11 +08:00
|
|
|
if (CI->getBitWidth() > 64)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addCImm(CI)
|
|
|
|
.addImm(DI->getOffset())
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
.addMetadata(DI->getVariable())
|
|
|
|
.addMetadata(DI->getExpression());
|
2012-07-07 01:44:22 +08:00
|
|
|
else
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addImm(CI->getZExtValue())
|
|
|
|
.addImm(DI->getOffset())
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
.addMetadata(DI->getVariable())
|
|
|
|
.addMetadata(DI->getExpression());
|
2014-09-04 02:46:45 +08:00
|
|
|
} else if (const auto *CF = dyn_cast<ConstantFP>(V)) {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addFPImm(CF)
|
|
|
|
.addImm(DI->getOffset())
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
.addMetadata(DI->getVariable())
|
|
|
|
.addMetadata(DI->getExpression());
|
2010-02-27 04:01:55 +08:00
|
|
|
} else if (unsigned Reg = lookUpRegForValue(V)) {
|
2013-09-17 07:29:03 +08:00
|
|
|
// FIXME: This does not handle register-indirect values at offset 0.
|
2013-07-10 04:28:37 +08:00
|
|
|
bool IsIndirect = DI->getOffset() != 0;
|
2014-09-04 02:46:45 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, IsIndirect, Reg,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
DI->getOffset(), DI->getVariable(), DI->getExpression());
|
2010-02-27 04:01:55 +08:00
|
|
|
} else {
|
|
|
|
// We can't yet handle anything else here because it would require
|
|
|
|
// generating code, thus altering codegen because of debug info.
|
2013-05-23 02:02:19 +08:00
|
|
|
DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
|
2010-11-23 11:31:01 +08:00
|
|
|
}
|
2010-02-27 04:01:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-05-14 08:47:51 +08:00
|
|
|
case Intrinsic::objectsize: {
|
2014-07-12 04:42:12 +08:00
|
|
|
ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1));
|
2011-05-14 08:47:51 +08:00
|
|
|
unsigned long long Res = CI->isZero() ? -1ULL : 0;
|
2014-07-12 04:42:12 +08:00
|
|
|
Constant *ResCI = ConstantInt::get(II->getType(), Res);
|
2011-05-14 08:47:51 +08:00
|
|
|
unsigned ResultReg = getRegForValue(ResCI);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!ResultReg)
|
2011-05-14 08:47:51 +08:00
|
|
|
return false;
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(II, ResultReg);
|
2011-05-14 08:47:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-08 00:47:20 +08:00
|
|
|
case Intrinsic::invariant_group_barrier:
|
2013-03-08 04:42:17 +08:00
|
|
|
case Intrinsic::expect: {
|
2014-07-12 04:42:12 +08:00
|
|
|
unsigned ResultReg = getRegForValue(II->getArgOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!ResultReg)
|
2013-03-12 05:44:37 +08:00
|
|
|
return false;
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(II, ResultReg);
|
2013-03-08 05:38:33 +08:00
|
|
|
return true;
|
2013-03-08 04:42:17 +08:00
|
|
|
}
|
2014-07-02 06:25:49 +08:00
|
|
|
case Intrinsic::experimental_stackmap:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectStackmap(II);
|
2014-07-12 06:19:02 +08:00
|
|
|
case Intrinsic::experimental_patchpoint_void:
|
|
|
|
case Intrinsic::experimental_patchpoint_i64:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectPatchpoint(II);
|
2008-09-26 01:05:24 +08:00
|
|
|
}
|
2010-04-14 01:07:06 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
return fastLowerIntrinsicCall(II);
|
2008-09-26 01:05:24 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectCast(const User *I, unsigned Opcode) {
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT SrcVT = TLI.getValueType(DL, I->getOperand(0)->getType());
|
|
|
|
EVT DstVT = TLI.getValueType(DL, I->getType());
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
if (SrcVT == MVT::Other || !SrcVT.isSimple() || DstVT == MVT::Other ||
|
|
|
|
!DstVT.isSimple())
|
2008-08-27 07:46:32 +08:00
|
|
|
// Unhandled type. Halt "fast" selection and bail.
|
|
|
|
return false;
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2011-05-26 07:49:02 +08:00
|
|
|
// Check if the destination type is legal.
|
2009-03-14 07:53:06 +08:00
|
|
|
if (!TLI.isTypeLegal(DstVT))
|
2011-05-26 07:49:02 +08:00
|
|
|
return false;
|
2009-03-14 07:53:06 +08:00
|
|
|
|
2011-05-26 07:49:02 +08:00
|
|
|
// Check if the source operand is legal.
|
2009-03-14 07:53:06 +08:00
|
|
|
if (!TLI.isTypeLegal(SrcVT))
|
2011-05-26 07:49:02 +08:00
|
|
|
return false;
|
2009-03-14 07:53:06 +08:00
|
|
|
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned InputReg = getRegForValue(I->getOperand(0));
|
2008-08-27 07:46:32 +08:00
|
|
|
if (!InputReg)
|
|
|
|
// Unhandled operand. Halt "fast" selection and bail.
|
|
|
|
return false;
|
2009-03-14 04:42:20 +08:00
|
|
|
|
2010-05-12 07:54:07 +08:00
|
|
|
bool InputRegIsKill = hasTrivialKill(I->getOperand(0));
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned ResultReg = fastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(),
|
2014-09-04 02:46:45 +08:00
|
|
|
Opcode, InputReg, InputRegIsKill);
|
2008-08-27 07:46:32 +08:00
|
|
|
if (!ResultReg)
|
|
|
|
return false;
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2008-08-27 07:46:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectBitCast(const User *I) {
|
2008-08-28 02:10:19 +08:00
|
|
|
// If the bitcast doesn't change the type, just use the operand value.
|
|
|
|
if (I->getType() == I->getOperand(0)->getType()) {
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned Reg = getRegForValue(I->getOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Reg)
|
2008-08-28 04:41:38 +08:00
|
|
|
return false;
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, Reg);
|
2008-08-28 02:10:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-23 11:31:01 +08:00
|
|
|
// Bitcasts of other values become reg-reg copies or BITCAST operators.
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT SrcEVT = TLI.getValueType(DL, I->getOperand(0)->getType());
|
|
|
|
EVT DstEVT = TLI.getValueType(DL, I->getType());
|
2012-12-17 22:30:06 +08:00
|
|
|
if (SrcEVT == MVT::Other || DstEVT == MVT::Other ||
|
|
|
|
!TLI.isTypeLegal(SrcEVT) || !TLI.isTypeLegal(DstEVT))
|
2008-08-27 07:46:32 +08:00
|
|
|
// Unhandled type. Halt "fast" selection and bail.
|
|
|
|
return false;
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2012-12-17 22:30:06 +08:00
|
|
|
MVT SrcVT = SrcEVT.getSimpleVT();
|
|
|
|
MVT DstVT = DstEVT.getSimpleVT();
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned Op0 = getRegForValue(I->getOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Op0) // Unhandled operand. Halt "fast" selection and bail.
|
2008-08-27 07:46:32 +08:00
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
bool Op0IsKill = hasTrivialKill(I->getOperand(0));
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-08-28 02:10:19 +08:00
|
|
|
// First, try to perform the bitcast by inserting a reg-reg copy.
|
|
|
|
unsigned ResultReg = 0;
|
2012-12-13 14:34:11 +08:00
|
|
|
if (SrcVT == DstVT) {
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *SrcClass = TLI.getRegClassFor(SrcVT);
|
|
|
|
const TargetRegisterClass *DstClass = TLI.getRegClassFor(DstVT);
|
2010-07-11 13:16:54 +08:00
|
|
|
// Don't attempt a cross-class copy. It will likely fail.
|
|
|
|
if (SrcClass == DstClass) {
|
|
|
|
ResultReg = createResultReg(DstClass);
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(Op0);
|
2010-07-11 13:16:54 +08:00
|
|
|
}
|
2008-08-28 02:10:19 +08:00
|
|
|
}
|
2010-11-23 11:31:01 +08:00
|
|
|
|
|
|
|
// If the reg-reg copy failed, select a BITCAST opcode.
|
2008-08-28 02:10:19 +08:00
|
|
|
if (!ResultReg)
|
2014-09-04 04:56:59 +08:00
|
|
|
ResultReg = fastEmit_r(SrcVT, DstVT, ISD::BITCAST, Op0, Op0IsKill);
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-08-28 02:10:19 +08:00
|
|
|
if (!ResultReg)
|
2008-08-27 07:46:32 +08:00
|
|
|
return false;
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2008-08-27 07:46:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-15 02:33:18 +08:00
|
|
|
// Remove local value instructions starting from the instruction after
|
|
|
|
// SavedLastLocalValue to the current function insert point.
|
|
|
|
void FastISel::removeDeadLocalValueCode(MachineInstr *SavedLastLocalValue)
|
|
|
|
{
|
|
|
|
MachineInstr *CurLastLocalValue = getLastLocalValue();
|
|
|
|
if (CurLastLocalValue != SavedLastLocalValue) {
|
|
|
|
// Find the first local value instruction to be deleted.
|
|
|
|
// This is the instruction after SavedLastLocalValue if it is non-NULL.
|
|
|
|
// Otherwise it's the first instruction in the block.
|
|
|
|
MachineBasicBlock::iterator FirstDeadInst(SavedLastLocalValue);
|
|
|
|
if (SavedLastLocalValue)
|
|
|
|
++FirstDeadInst;
|
|
|
|
else
|
|
|
|
FirstDeadInst = FuncInfo.MBB->getFirstNonPHI();
|
|
|
|
setLastLocalValue(SavedLastLocalValue);
|
|
|
|
removeDeadCode(FirstDeadInst, FuncInfo.InsertPt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::selectInstruction(const Instruction *I) {
|
2015-12-15 02:33:18 +08:00
|
|
|
MachineInstr *SavedLastLocalValue = getLastLocalValue();
|
2010-04-23 23:29:50 +08:00
|
|
|
// Just before the terminator instruction, insert instructions to
|
|
|
|
// feed PHI nodes in successor blocks.
|
2016-04-06 02:13:16 +08:00
|
|
|
if (isa<TerminatorInst>(I)) {
|
2015-12-15 02:33:18 +08:00
|
|
|
if (!handlePHINodesInSuccessorBlocks(I->getParent())) {
|
|
|
|
// PHI node handling may have generated local value instructions,
|
|
|
|
// even though it failed to handle all PHI nodes.
|
|
|
|
// We remove these instructions because SelectionDAGISel will generate
|
|
|
|
// them again.
|
|
|
|
removeDeadLocalValueCode(SavedLastLocalValue);
|
2010-04-23 23:29:50 +08:00
|
|
|
return false;
|
2015-12-15 02:33:18 +08:00
|
|
|
}
|
2016-04-06 02:13:16 +08:00
|
|
|
}
|
2010-04-23 23:29:50 +08:00
|
|
|
|
2016-03-22 08:59:13 +08:00
|
|
|
// FastISel does not handle any operand bundles except OB_funclet.
|
|
|
|
if (ImmutableCallSite CS = ImmutableCallSite(I))
|
|
|
|
for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i)
|
|
|
|
if (CS.getOperandBundleAt(i).getTagID() != LLVMContext::OB_funclet)
|
|
|
|
return false;
|
|
|
|
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = I->getDebugLoc();
|
2010-04-20 08:48:35 +08:00
|
|
|
|
2014-09-09 04:24:10 +08:00
|
|
|
SavedInsertPt = FuncInfo.InsertPt;
|
2011-11-30 03:40:47 +08:00
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *Call = dyn_cast<CallInst>(I)) {
|
2012-08-03 12:06:28 +08:00
|
|
|
const Function *F = Call->getCalledFunction();
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
LibFunc Func;
|
2014-04-16 05:30:06 +08:00
|
|
|
|
|
|
|
// As a special case, don't handle calls to builtin library functions that
|
|
|
|
// may be translated directly to target instructions.
|
2012-08-03 12:06:28 +08:00
|
|
|
if (F && !F->hasLocalLinkage() && F->hasName() &&
|
|
|
|
LibInfo->getLibFunc(F->getName(), Func) &&
|
2012-08-04 05:26:24 +08:00
|
|
|
LibInfo->hasOptimizedCodeGen(Func))
|
2012-08-03 12:06:28 +08:00
|
|
|
return false;
|
2014-04-16 05:30:06 +08:00
|
|
|
|
2015-12-16 08:08:18 +08:00
|
|
|
// Don't handle Intrinsic::trap if a trap function is specified.
|
2014-04-16 05:30:06 +08:00
|
|
|
if (F && F->getIntrinsicID() == Intrinsic::trap &&
|
2015-07-03 06:13:27 +08:00
|
|
|
Call->hasFnAttr("trap-func-name"))
|
2014-04-16 05:30:06 +08:00
|
|
|
return false;
|
2012-08-03 12:06:28 +08:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:27:58 +08:00
|
|
|
// First, try doing target-independent selection.
|
2014-09-03 05:07:44 +08:00
|
|
|
if (!SkipTargetIndependentISel) {
|
2014-09-04 02:46:45 +08:00
|
|
|
if (selectOperator(I, I->getOpcode())) {
|
2014-09-03 05:07:44 +08:00
|
|
|
++NumFastIselSuccessIndependent;
|
|
|
|
DbgLoc = DebugLoc();
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-09 04:24:10 +08:00
|
|
|
// Remove dead code.
|
|
|
|
recomputeInsertPt();
|
|
|
|
if (SavedInsertPt != FuncInfo.InsertPt)
|
|
|
|
removeDeadCode(FuncInfo.InsertPt, SavedInsertPt);
|
2014-09-03 05:07:44 +08:00
|
|
|
SavedInsertPt = FuncInfo.InsertPt;
|
|
|
|
}
|
|
|
|
// Next, try calling the target to attempt to handle the instruction.
|
2014-09-04 04:56:52 +08:00
|
|
|
if (fastSelectInstruction(I)) {
|
2014-09-03 05:07:44 +08:00
|
|
|
++NumFastIselSuccessTarget;
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = DebugLoc();
|
2009-12-05 09:27:58 +08:00
|
|
|
return true;
|
2010-04-20 08:48:35 +08:00
|
|
|
}
|
2014-09-09 04:24:10 +08:00
|
|
|
// Remove dead code.
|
|
|
|
recomputeInsertPt();
|
|
|
|
if (SavedInsertPt != FuncInfo.InsertPt)
|
|
|
|
removeDeadCode(FuncInfo.InsertPt, SavedInsertPt);
|
2009-12-05 09:27:58 +08:00
|
|
|
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = DebugLoc();
|
2014-08-28 10:06:55 +08:00
|
|
|
// Undo phi node updates, because they will be added again by SelectionDAG.
|
2015-12-15 02:33:18 +08:00
|
|
|
if (isa<TerminatorInst>(I)) {
|
|
|
|
// PHI node handling may have generated local value instructions.
|
|
|
|
// We remove them because SelectionDAGISel will generate them again.
|
|
|
|
removeDeadLocalValueCode(SavedLastLocalValue);
|
2014-08-28 10:06:55 +08:00
|
|
|
FuncInfo.PHINodesToUpdate.resize(FuncInfo.OrigNumPHINodesToUpdate);
|
2015-12-15 02:33:18 +08:00
|
|
|
}
|
2009-12-05 09:27:58 +08:00
|
|
|
return false;
|
2008-09-06 02:18:20 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
/// Emit an unconditional branch to the given block, unless it is the immediate
|
|
|
|
/// (fall-through) successor, and update the CFG.
|
2016-06-12 23:39:02 +08:00
|
|
|
void FastISel::fastEmitBranch(MachineBasicBlock *MSucc,
|
|
|
|
const DebugLoc &DbgLoc) {
|
2013-02-11 09:27:15 +08:00
|
|
|
if (FuncInfo.MBB->getBasicBlock()->size() > 1 &&
|
|
|
|
FuncInfo.MBB->isLayoutSuccessor(MSucc)) {
|
2012-04-11 02:18:10 +08:00
|
|
|
// For more accurate line information if this is the only instruction
|
|
|
|
// in the block then emit it, otherwise we have the unconditional
|
|
|
|
// fall-through case, which needs no instructions.
|
2008-10-03 06:15:21 +08:00
|
|
|
} else {
|
|
|
|
// The unconditional branch case.
|
2016-09-15 01:24:15 +08:00
|
|
|
TII.insertBranch(*FuncInfo.MBB, MSucc, nullptr,
|
2014-02-19 06:05:46 +08:00
|
|
|
SmallVector<MachineOperand, 0>(), DbgLoc);
|
2008-10-03 06:15:21 +08:00
|
|
|
}
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
if (FuncInfo.BPI) {
|
2015-11-24 16:51:23 +08:00
|
|
|
auto BranchProbability = FuncInfo.BPI->getEdgeProbability(
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
FuncInfo.MBB->getBasicBlock(), MSucc->getBasicBlock());
|
2015-11-24 16:51:23 +08:00
|
|
|
FuncInfo.MBB->addSuccessor(MSucc, BranchProbability);
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
} else
|
2015-11-24 16:51:23 +08:00
|
|
|
FuncInfo.MBB->addSuccessorWithoutProb(MSucc);
|
2008-10-03 06:15:21 +08:00
|
|
|
}
|
|
|
|
|
2015-08-26 09:38:00 +08:00
|
|
|
void FastISel::finishCondBranch(const BasicBlock *BranchBB,
|
|
|
|
MachineBasicBlock *TrueMBB,
|
|
|
|
MachineBasicBlock *FalseMBB) {
|
2015-08-27 04:46:49 +08:00
|
|
|
// Add TrueMBB as successor unless it is equal to the FalseMBB: This can
|
|
|
|
// happen in degenerate IR and MachineIR forbids to have a block twice in the
|
|
|
|
// successor/predecessor lists.
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
if (TrueMBB != FalseMBB) {
|
|
|
|
if (FuncInfo.BPI) {
|
2015-11-24 16:51:23 +08:00
|
|
|
auto BranchProbability =
|
|
|
|
FuncInfo.BPI->getEdgeProbability(BranchBB, TrueMBB->getBasicBlock());
|
|
|
|
FuncInfo.MBB->addSuccessor(TrueMBB, BranchProbability);
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
} else
|
2015-11-24 16:51:23 +08:00
|
|
|
FuncInfo.MBB->addSuccessorWithoutProb(TrueMBB);
|
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights.
We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled.
In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list.
Differential revision: http://reviews.llvm.org/D13963
llvm-svn: 251429
2015-10-28 01:59:36 +08:00
|
|
|
}
|
2015-08-26 09:38:00 +08:00
|
|
|
|
|
|
|
fastEmitBranch(FalseMBB, DbgLoc);
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
/// Emit an FNeg operation.
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectFNeg(const User *I) {
|
2009-09-04 06:53:57 +08:00
|
|
|
unsigned OpReg = getRegForValue(BinaryOperator::getFNegArgument(I));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!OpReg)
|
|
|
|
return false;
|
2010-05-12 07:54:07 +08:00
|
|
|
bool OpRegIsKill = hasTrivialKill(I);
|
|
|
|
|
2009-09-11 08:36:43 +08:00
|
|
|
// If the target has ISD::FNEG, use it.
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT VT = TLI.getValueType(DL, I->getType());
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned ResultReg = fastEmit_r(VT.getSimpleVT(), VT.getSimpleVT(), ISD::FNEG,
|
2014-09-04 02:46:45 +08:00
|
|
|
OpReg, OpRegIsKill);
|
|
|
|
if (ResultReg) {
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2009-09-11 08:36:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-11 08:34:46 +08:00
|
|
|
// Bitcast the value to integer, twiddle the sign bit with xor,
|
|
|
|
// and then bitcast it back to floating-point.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (VT.getSizeInBits() > 64)
|
|
|
|
return false;
|
2009-09-11 08:34:46 +08:00
|
|
|
EVT IntVT = EVT::getIntegerVT(I->getContext(), VT.getSizeInBits());
|
|
|
|
if (!TLI.isTypeLegal(IntVT))
|
|
|
|
return false;
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned IntReg = fastEmit_r(VT.getSimpleVT(), IntVT.getSimpleVT(),
|
2010-11-23 11:31:01 +08:00
|
|
|
ISD::BITCAST, OpReg, OpRegIsKill);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!IntReg)
|
2009-09-11 08:34:46 +08:00
|
|
|
return false;
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned IntResultReg = fastEmit_ri_(
|
2014-09-04 02:46:45 +08:00
|
|
|
IntVT.getSimpleVT(), ISD::XOR, IntReg, /*IsKill=*/true,
|
|
|
|
UINT64_C(1) << (VT.getSizeInBits() - 1), IntVT.getSimpleVT());
|
|
|
|
if (!IntResultReg)
|
2009-09-11 08:34:46 +08:00
|
|
|
return false;
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
ResultReg = fastEmit_r(IntVT.getSimpleVT(), VT.getSimpleVT(), ISD::BITCAST,
|
2014-09-04 02:46:45 +08:00
|
|
|
IntResultReg, /*IsKill=*/true);
|
|
|
|
if (!ResultReg)
|
2009-09-04 06:53:57 +08:00
|
|
|
return false;
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, ResultReg);
|
2009-09-04 06:53:57 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectExtractValue(const User *U) {
|
2011-05-17 04:27:46 +08:00
|
|
|
const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(U);
|
2011-05-17 04:34:53 +08:00
|
|
|
if (!EVI)
|
2011-05-17 04:27:46 +08:00
|
|
|
return false;
|
|
|
|
|
2011-05-17 05:06:17 +08:00
|
|
|
// Make sure we only try to handle extracts with a legal result. But also
|
|
|
|
// allow i1 because it's easy.
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT RealVT = TLI.getValueType(DL, EVI->getType(), /*AllowUnknown=*/true);
|
2011-05-17 04:27:46 +08:00
|
|
|
if (!RealVT.isSimple())
|
|
|
|
return false;
|
|
|
|
MVT VT = RealVT.getSimpleVT();
|
2011-05-17 05:06:17 +08:00
|
|
|
if (!TLI.isTypeLegal(VT) && VT != MVT::i1)
|
2011-05-17 04:27:46 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const Value *Op0 = EVI->getOperand(0);
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *AggTy = Op0->getType();
|
2011-05-17 04:27:46 +08:00
|
|
|
|
|
|
|
// Get the base result register.
|
|
|
|
unsigned ResultReg;
|
|
|
|
DenseMap<const Value *, unsigned>::iterator I = FuncInfo.ValueMap.find(Op0);
|
|
|
|
if (I != FuncInfo.ValueMap.end())
|
|
|
|
ResultReg = I->second;
|
2011-06-06 13:46:34 +08:00
|
|
|
else if (isa<Instruction>(Op0))
|
2011-05-17 04:27:46 +08:00
|
|
|
ResultReg = FuncInfo.InitializeRegForValue(Op0);
|
2011-06-06 13:46:34 +08:00
|
|
|
else
|
|
|
|
return false; // fast-isel can't handle aggregate constants at the moment
|
2011-05-17 04:27:46 +08:00
|
|
|
|
|
|
|
// Get the actual result register, which is an offset from the base register.
|
2011-07-13 18:26:04 +08:00
|
|
|
unsigned VTIndex = ComputeLinearIndex(AggTy, EVI->getIndices());
|
2011-05-17 04:27:46 +08:00
|
|
|
|
|
|
|
SmallVector<EVT, 4> AggValueVTs;
|
2015-07-09 09:57:34 +08:00
|
|
|
ComputeValueVTs(TLI, DL, AggTy, AggValueVTs);
|
2011-05-17 04:27:46 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < VTIndex; i++)
|
|
|
|
ResultReg += TLI.getNumRegisters(FuncInfo.Fn->getContext(), AggValueVTs[i]);
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(EVI, ResultReg);
|
2011-05-17 04:27:46 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::selectOperator(const User *I, unsigned Opcode) {
|
2008-09-06 02:18:20 +08:00
|
|
|
switch (Opcode) {
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::Add:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::ADD);
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::FAdd:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::FADD);
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::Sub:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SUB);
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::FSub:
|
2009-09-04 06:53:57 +08:00
|
|
|
// FNeg is currently represented in LLVM IR as a special case of FSub.
|
|
|
|
if (BinaryOperator::isFNeg(I))
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectFNeg(I);
|
|
|
|
return selectBinaryOp(I, ISD::FSUB);
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::Mul:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::MUL);
|
2009-06-05 06:49:04 +08:00
|
|
|
case Instruction::FMul:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::FMUL);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::SDiv:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SDIV);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::UDiv:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::UDIV);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::FDiv:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::FDIV);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::SRem:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SREM);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::URem:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::UREM);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::FRem:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::FREM);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::Shl:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SHL);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::LShr:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SRL);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::AShr:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::SRA);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::And:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::AND);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::Or:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::OR);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::Xor:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBinaryOp(I, ISD::XOR);
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
case Instruction::GetElementPtr:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectGetElementPtr(I);
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
case Instruction::Br: {
|
2010-04-15 09:51:59 +08:00
|
|
|
const BranchInst *BI = cast<BranchInst>(I);
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
if (BI->isUnconditional()) {
|
2010-04-15 09:51:59 +08:00
|
|
|
const BasicBlock *LLVMSucc = BI->getSuccessor(0);
|
2010-07-08 00:29:44 +08:00
|
|
|
MachineBasicBlock *MSucc = FuncInfo.MBBMap[LLVMSucc];
|
2014-09-04 04:56:52 +08:00
|
|
|
fastEmitBranch(MSucc, BI->getDebugLoc());
|
2008-09-04 07:12:08 +08:00
|
|
|
return true;
|
2008-08-27 08:31:01 +08:00
|
|
|
}
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
// Conditional branches are not handed yet.
|
|
|
|
// Halt "fast" selection and bail.
|
|
|
|
return false;
|
2008-08-14 04:19:35 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 09:08:41 +08:00
|
|
|
case Instruction::Unreachable:
|
2015-10-09 09:13:17 +08:00
|
|
|
if (TM.Options.TrapUnreachable)
|
|
|
|
return fastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0;
|
|
|
|
else
|
|
|
|
return true;
|
2008-09-05 09:08:41 +08:00
|
|
|
|
2008-09-11 04:11:02 +08:00
|
|
|
case Instruction::Alloca:
|
|
|
|
// FunctionLowering has the static-sized case covered.
|
2010-07-08 00:29:44 +08:00
|
|
|
if (FuncInfo.StaticAllocaMap.count(cast<AllocaInst>(I)))
|
2008-09-11 04:11:02 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Dynamic-sized alloca is not handled yet.
|
|
|
|
return false;
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-09-26 01:05:24 +08:00
|
|
|
case Instruction::Call:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCall(I);
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::BitCast:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectBitCast(I);
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
case Instruction::FPToSI:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::FP_TO_SINT);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::ZExt:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::ZERO_EXTEND);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::SExt:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::SIGN_EXTEND);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::Trunc:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::TRUNCATE);
|
2008-09-04 07:12:08 +08:00
|
|
|
case Instruction::SIToFP:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::SINT_TO_FP);
|
2008-09-04 07:12:08 +08:00
|
|
|
|
|
|
|
case Instruction::IntToPtr: // Deliberate fall-through.
|
|
|
|
case Instruction::PtrToInt: {
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT SrcVT = TLI.getValueType(DL, I->getOperand(0)->getType());
|
|
|
|
EVT DstVT = TLI.getValueType(DL, I->getType());
|
2008-09-04 07:12:08 +08:00
|
|
|
if (DstVT.bitsGT(SrcVT))
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::ZERO_EXTEND);
|
2008-09-04 07:12:08 +08:00
|
|
|
if (DstVT.bitsLT(SrcVT))
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectCast(I, ISD::TRUNCATE);
|
2008-09-04 07:12:08 +08:00
|
|
|
unsigned Reg = getRegForValue(I->getOperand(0));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!Reg)
|
|
|
|
return false;
|
2014-09-04 04:56:52 +08:00
|
|
|
updateValueMap(I, Reg);
|
2008-09-04 07:12:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
2008-09-24 05:53:34 +08:00
|
|
|
|
2011-05-17 04:27:46 +08:00
|
|
|
case Instruction::ExtractValue:
|
2014-09-04 02:46:45 +08:00
|
|
|
return selectExtractValue(I);
|
2011-05-17 04:27:46 +08:00
|
|
|
|
2010-04-20 23:00:41 +08:00
|
|
|
case Instruction::PHI:
|
|
|
|
llvm_unreachable("FastISel shouldn't visit PHI nodes!");
|
|
|
|
|
2008-09-04 07:12:08 +08:00
|
|
|
default:
|
|
|
|
// Unhandled instruction. Halt "fast" selection and bail.
|
|
|
|
return false;
|
|
|
|
}
|
2008-08-14 04:19:35 +08:00
|
|
|
}
|
|
|
|
|
2014-09-03 05:07:44 +08:00
|
|
|
FastISel::FastISel(FunctionLoweringInfo &FuncInfo,
|
|
|
|
const TargetLibraryInfo *LibInfo,
|
|
|
|
bool SkipTargetIndependentISel)
|
|
|
|
: FuncInfo(FuncInfo), MF(FuncInfo.MF), MRI(FuncInfo.MF->getRegInfo()),
|
2016-07-29 02:40:00 +08:00
|
|
|
MFI(FuncInfo.MF->getFrameInfo()), MCP(*FuncInfo.MF->getConstantPool()),
|
2015-07-08 02:39:02 +08:00
|
|
|
TM(FuncInfo.MF->getTarget()), DL(MF->getDataLayout()),
|
2014-10-09 07:38:33 +08:00
|
|
|
TII(*MF->getSubtarget().getInstrInfo()),
|
|
|
|
TLI(*MF->getSubtarget().getTargetLowering()),
|
|
|
|
TRI(*MF->getSubtarget().getRegisterInfo()), LibInfo(LibInfo),
|
2014-09-03 05:07:44 +08:00
|
|
|
SkipTargetIndependentISel(SkipTargetIndependentISel) {}
|
2008-08-21 05:05:57 +08:00
|
|
|
|
2008-08-15 05:51:29 +08:00
|
|
|
FastISel::~FastISel() {}
|
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::fastLowerArguments() { return false; }
|
2013-02-11 09:27:15 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::fastLowerCall(CallLoweringInfo & /*CLI*/) { return false; }
|
2014-07-12 06:01:42 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
bool FastISel::fastLowerIntrinsicCall(const IntrinsicInst * /*II*/) {
|
2014-07-12 04:42:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_(MVT, MVT, unsigned) { return 0; }
|
2008-08-14 04:19:35 +08:00
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_r(MVT, MVT, unsigned, unsigned /*Op0*/,
|
2014-09-04 02:46:45 +08:00
|
|
|
bool /*Op0IsKill*/) {
|
2008-08-14 04:19:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_rr(MVT, MVT, unsigned, unsigned /*Op0*/,
|
2014-09-04 02:46:45 +08:00
|
|
|
bool /*Op0IsKill*/, unsigned /*Op1*/,
|
|
|
|
bool /*Op1IsKill*/) {
|
2008-08-14 04:19:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_i(MVT, MVT, unsigned, uint64_t /*Imm*/) {
|
2008-08-21 06:45:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_f(MVT, MVT, unsigned,
|
2014-09-04 02:46:45 +08:00
|
|
|
const ConstantFP * /*FPImm*/) {
|
2008-08-27 09:09:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmit_ri(MVT, MVT, unsigned, unsigned /*Op0*/,
|
2014-09-04 02:46:45 +08:00
|
|
|
bool /*Op0IsKill*/, uint64_t /*Imm*/) {
|
2008-08-21 09:41:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
/// This method is a wrapper of fastEmit_ri. It first tries to emit an
|
|
|
|
/// instruction with an immediate operand using fastEmit_ri.
|
2008-08-21 06:45:34 +08:00
|
|
|
/// If that fails, it materializes the immediate into a register and try
|
2014-09-04 04:56:59 +08:00
|
|
|
/// fastEmit_rr instead.
|
|
|
|
unsigned FastISel::fastEmit_ri_(MVT VT, unsigned Opcode, unsigned Op0,
|
2014-09-04 02:46:45 +08:00
|
|
|
bool Op0IsKill, uint64_t Imm, MVT ImmType) {
|
2011-04-18 04:23:29 +08:00
|
|
|
// If this is a multiply by a power of two, emit this as a shift left.
|
|
|
|
if (Opcode == ISD::MUL && isPowerOf2_64(Imm)) {
|
|
|
|
Opcode = ISD::SHL;
|
|
|
|
Imm = Log2_64(Imm);
|
2011-04-18 14:55:51 +08:00
|
|
|
} else if (Opcode == ISD::UDIV && isPowerOf2_64(Imm)) {
|
|
|
|
// div x, 8 -> srl x, 3
|
|
|
|
Opcode = ISD::SRL;
|
|
|
|
Imm = Log2_64(Imm);
|
2011-04-18 04:23:29 +08:00
|
|
|
}
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2011-04-18 04:23:29 +08:00
|
|
|
// Horrible hack (to be removed), check to make sure shift amounts are
|
|
|
|
// in-range.
|
|
|
|
if ((Opcode == ISD::SHL || Opcode == ISD::SRA || Opcode == ISD::SRL) &&
|
|
|
|
Imm >= VT.getSizeInBits())
|
|
|
|
return 0;
|
2011-04-23 07:38:06 +08:00
|
|
|
|
2008-08-21 06:45:34 +08:00
|
|
|
// First check if immediate type is legal. If not, we can't use the ri form.
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned ResultReg = fastEmit_ri(VT, VT, Opcode, Op0, Op0IsKill, Imm);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (ResultReg)
|
2008-08-21 06:45:34 +08:00
|
|
|
return ResultReg;
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned MaterialReg = fastEmit_i(ImmType, ImmType, ISD::Constant, Imm);
|
2015-05-07 06:09:29 +08:00
|
|
|
bool IsImmKill = true;
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!MaterialReg) {
|
2011-04-30 07:34:52 +08:00
|
|
|
// This is a bit ugly/slow, but failing here means falling out of
|
|
|
|
// fast-isel, which would be very slow.
|
2014-09-04 02:46:45 +08:00
|
|
|
IntegerType *ITy =
|
|
|
|
IntegerType::get(FuncInfo.Fn->getContext(), VT.getSizeInBits());
|
2011-04-30 07:34:52 +08:00
|
|
|
MaterialReg = getRegForValue(ConstantInt::get(ITy, Imm));
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!MaterialReg)
|
|
|
|
return 0;
|
[Fast-ISel] Don't mark the first use of a remat constant as killed.
When emitting something like 'add x, 1000' if we remat the 1000 then we should be able to
mark the vreg containing 1000 as killed. Given that we go bottom up in fast-isel, a later
use of 1000 will be higher up in the BB and won't kill it, or be impacted by the lower kill.
However, rematerialised constant expressions aren't generated bottom up. The local value save area
grows downwards. This means that if you remat 2 constant expressions which both use 1000 then the
first will kill it, then the second, which is *lower* in the BB will read a killed register.
This is the case in the attached test where the 2 GEPs both need to generate 'add x, 6680' for the constant offset.
Note that this commit only makes kill flag generation conservative. There's nothing else obviously wrong with
the local value save area growing downwards, and in fact it needs to for handling arbitrarily complex constant expressions.
However, it would be nice if there was a solution which would let us generate more accurate kill flags, or just kill flags completely.
llvm-svn: 236922
2015-05-09 08:51:03 +08:00
|
|
|
// FIXME: If the materialized register here has no uses yet then this
|
|
|
|
// will be the first use and we should be able to mark it as killed.
|
|
|
|
// However, the local value area for materialising constant expressions
|
|
|
|
// grows down, not up, which means that any constant expressions we generate
|
|
|
|
// later which also use 'Imm' could be after this instruction and therefore
|
|
|
|
// after this kill.
|
|
|
|
IsImmKill = false;
|
2011-04-30 07:34:52 +08:00
|
|
|
}
|
2015-05-07 06:09:29 +08:00
|
|
|
return fastEmit_rr(VT, VT, Opcode, Op0, Op0IsKill, MaterialReg, IsImmKill);
|
2008-08-21 09:41:07 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
unsigned FastISel::createResultReg(const TargetRegisterClass *RC) {
|
2008-08-21 09:41:07 +08:00
|
|
|
return MRI.createVirtualRegister(RC);
|
2008-08-21 06:45:34 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
unsigned FastISel::constrainOperandRegClass(const MCInstrDesc &II, unsigned Op,
|
|
|
|
unsigned OpNum) {
|
2014-04-15 21:59:49 +08:00
|
|
|
if (TargetRegisterInfo::isVirtualRegister(Op)) {
|
|
|
|
const TargetRegisterClass *RegClass =
|
|
|
|
TII.getRegClass(II, OpNum, &TRI, *FuncInfo.MF);
|
|
|
|
if (!MRI.constrainRegClass(Op, RegClass)) {
|
|
|
|
// If it's not legal to COPY between the register classes, something
|
|
|
|
// has gone very wrong before we got here.
|
|
|
|
unsigned NewOp = createResultReg(RegClass);
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), NewOp).addReg(Op);
|
|
|
|
return NewOp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC) {
|
2008-08-21 09:41:07 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2008-08-14 04:19:35 +08:00
|
|
|
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg);
|
2008-08-14 04:19:35 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_r(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2008-08-14 04:19:35 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
|
|
|
|
2008-09-08 16:38:20 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill));
|
2008-09-08 16:38:20 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill));
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2008-09-08 16:38:20 +08:00
|
|
|
}
|
|
|
|
|
2008-08-14 04:19:35 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_rr(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill, unsigned Op1,
|
|
|
|
bool Op1IsKill) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2008-08-14 04:19:35 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
|
|
|
Op1 = constrainOperandRegClass(II, Op1, II.getNumDefs() + 1);
|
|
|
|
|
2008-09-08 16:38:20 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill));
|
2008-09-08 16:38:20 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill));
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2008-09-08 16:38:20 +08:00
|
|
|
}
|
2008-08-14 04:19:35 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
2008-08-21 09:41:07 +08:00
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_rrr(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill, unsigned Op1,
|
|
|
|
bool Op1IsKill, unsigned Op2,
|
|
|
|
bool Op2IsKill) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2011-05-06 01:59:04 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
|
|
|
Op1 = constrainOperandRegClass(II, Op1, II.getNumDefs() + 1);
|
|
|
|
Op2 = constrainOperandRegClass(II, Op2, II.getNumDefs() + 2);
|
|
|
|
|
2011-05-06 01:59:04 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill))
|
|
|
|
.addReg(Op2, getKillRegState(Op2IsKill));
|
2011-05-06 01:59:04 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill))
|
|
|
|
.addReg(Op2, getKillRegState(Op2IsKill));
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2011-05-06 01:59:04 +08:00
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_ri(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill, uint64_t Imm) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2008-08-21 09:41:07 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2014-08-28 04:47:33 +08:00
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
2014-04-15 21:59:49 +08:00
|
|
|
|
2008-09-08 16:38:20 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addImm(Imm);
|
2008-09-08 16:38:20 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addImm(Imm);
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2008-09-08 16:38:20 +08:00
|
|
|
}
|
2008-08-21 09:41:07 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_rii(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill, uint64_t Imm1,
|
|
|
|
uint64_t Imm2) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2011-03-12 05:33:55 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
|
|
|
|
2011-03-12 05:33:55 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addImm(Imm1)
|
|
|
|
.addImm(Imm2);
|
2011-03-12 05:33:55 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addImm(Imm1)
|
|
|
|
.addImm(Imm2);
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2011-03-12 05:33:55 +08:00
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2015-08-25 02:44:37 +08:00
|
|
|
unsigned FastISel::fastEmitInst_f(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const ConstantFP *FPImm) {
|
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
|
|
|
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
|
|
|
.addFPImm(FPImm);
|
|
|
|
else {
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
|
|
|
.addFPImm(FPImm);
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_rri(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, unsigned Op0,
|
|
|
|
bool Op0IsKill, unsigned Op1,
|
|
|
|
bool Op1IsKill, uint64_t Imm) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2008-08-21 09:41:07 +08:00
|
|
|
|
2014-04-15 21:59:49 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
|
|
|
|
Op1 = constrainOperandRegClass(II, Op1, II.getNumDefs() + 1);
|
|
|
|
|
2008-09-08 16:38:20 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill))
|
|
|
|
.addImm(Imm);
|
2008-09-08 16:38:20 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
|
2014-09-04 02:46:45 +08:00
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill))
|
|
|
|
.addReg(Op1, getKillRegState(Op1IsKill))
|
|
|
|
.addImm(Imm);
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2008-09-08 16:38:20 +08:00
|
|
|
}
|
2008-08-21 09:41:07 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
2008-08-26 04:20:32 +08:00
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_i(unsigned MachineInstOpcode,
|
2014-09-04 02:46:45 +08:00
|
|
|
const TargetRegisterClass *RC, uint64_t Imm) {
|
2008-08-26 04:20:32 +08:00
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-11-23 11:31:01 +08:00
|
|
|
|
2008-09-08 16:38:20 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2014-09-04 02:46:45 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
|
|
|
|
.addImm(Imm);
|
2008-09-08 16:38:20 +08:00
|
|
|
else {
|
2014-02-19 06:05:46 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).addImm(Imm);
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
|
2008-09-08 16:38:20 +08:00
|
|
|
}
|
2008-08-26 04:20:32 +08:00
|
|
|
return ResultReg;
|
2008-08-26 06:20:39 +08:00
|
|
|
}
|
2008-08-28 06:30:02 +08:00
|
|
|
|
2014-09-04 04:56:59 +08:00
|
|
|
unsigned FastISel::fastEmitInst_extractsubreg(MVT RetVT, unsigned Op0,
|
2014-09-04 02:46:45 +08:00
|
|
|
bool Op0IsKill, uint32_t Idx) {
|
2009-01-22 17:10:11 +08:00
|
|
|
unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT));
|
2010-07-09 00:40:22 +08:00
|
|
|
assert(TargetRegisterInfo::isVirtualRegister(Op0) &&
|
|
|
|
"Cannot yet extract from physregs");
|
2012-05-20 14:38:37 +08:00
|
|
|
const TargetRegisterClass *RC = MRI.getRegClass(Op0);
|
|
|
|
MRI.constrainRegClass(Op0, TRI.getSubClassWithSubReg(RC, Idx));
|
2014-09-04 02:46:45 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TargetOpcode::COPY),
|
|
|
|
ResultReg).addReg(Op0, getKillRegState(Op0IsKill), Idx);
|
2008-08-28 06:30:02 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
2009-03-14 04:42:20 +08:00
|
|
|
|
2014-09-04 04:56:52 +08:00
|
|
|
/// Emit MachineInstrs to compute the value of Op with all but the least
|
|
|
|
/// significant bit set to zero.
|
|
|
|
unsigned FastISel::fastEmitZExtFromI1(MVT VT, unsigned Op0, bool Op0IsKill) {
|
2014-09-04 04:56:59 +08:00
|
|
|
return fastEmit_ri(VT, VT, ISD::AND, Op0, Op0IsKill, 1);
|
2009-03-14 04:42:20 +08:00
|
|
|
}
|
2010-04-23 04:46:50 +08:00
|
|
|
|
|
|
|
/// HandlePHINodesInSuccessorBlocks - Handle PHI nodes in successor blocks.
|
|
|
|
/// Emit code to ensure constants are copied into registers when needed.
|
|
|
|
/// Remember the virtual registers that need to be added to the Machine PHI
|
|
|
|
/// nodes as input. We cannot just directly add them, because expansion
|
|
|
|
/// might result in multiple MBB's for one BB. As such, the start of the
|
|
|
|
/// BB might correspond to a different MBB than the end.
|
2014-09-04 02:46:45 +08:00
|
|
|
bool FastISel::handlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB) {
|
2010-04-23 04:46:50 +08:00
|
|
|
const TerminatorInst *TI = LLVMBB->getTerminator();
|
|
|
|
|
|
|
|
SmallPtrSet<MachineBasicBlock *, 4> SuccsHandled;
|
2014-08-28 10:06:55 +08:00
|
|
|
FuncInfo.OrigNumPHINodesToUpdate = FuncInfo.PHINodesToUpdate.size();
|
2010-04-23 04:46:50 +08:00
|
|
|
|
|
|
|
// Check successor nodes' PHI nodes that expect a constant to be available
|
|
|
|
// from this block.
|
|
|
|
for (unsigned succ = 0, e = TI->getNumSuccessors(); succ != e; ++succ) {
|
|
|
|
const BasicBlock *SuccBB = TI->getSuccessor(succ);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!isa<PHINode>(SuccBB->begin()))
|
|
|
|
continue;
|
2010-07-08 00:29:44 +08:00
|
|
|
MachineBasicBlock *SuccMBB = FuncInfo.MBBMap[SuccBB];
|
2010-04-23 04:46:50 +08:00
|
|
|
|
|
|
|
// If this terminator has multiple identical successors (common for
|
|
|
|
// switches), only handle each succ once.
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!SuccsHandled.insert(SuccMBB).second)
|
2014-09-04 02:46:45 +08:00
|
|
|
continue;
|
2010-04-23 04:46:50 +08:00
|
|
|
|
|
|
|
MachineBasicBlock::iterator MBBI = SuccMBB->begin();
|
|
|
|
|
|
|
|
// At this point we know that there is a 1-1 correspondence between LLVM PHI
|
|
|
|
// nodes and Machine PHI nodes, but the incoming operands have not been
|
|
|
|
// emitted yet.
|
|
|
|
for (BasicBlock::const_iterator I = SuccBB->begin();
|
2014-09-04 02:46:45 +08:00
|
|
|
const auto *PN = dyn_cast<PHINode>(I); ++I) {
|
2010-05-07 09:10:20 +08:00
|
|
|
|
2010-04-23 04:46:50 +08:00
|
|
|
// Ignore dead phi's.
|
2014-09-04 02:46:45 +08:00
|
|
|
if (PN->use_empty())
|
|
|
|
continue;
|
2010-04-23 04:46:50 +08:00
|
|
|
|
|
|
|
// Only handle legal types. Two interesting things to note here. First,
|
|
|
|
// by bailing out early, we may leave behind some dead instructions,
|
|
|
|
// since SelectionDAG's HandlePHINodesInSuccessorBlocks will insert its
|
2011-04-15 13:18:47 +08:00
|
|
|
// own moves. Second, this check is necessary because FastISel doesn't
|
2010-07-02 08:10:16 +08:00
|
|
|
// use CreateRegs to create registers, so it always creates
|
2010-04-23 04:46:50 +08:00
|
|
|
// exactly one register for each non-void instruction.
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT VT = TLI.getValueType(DL, PN->getType(), /*AllowUnknown=*/true);
|
2010-04-23 04:46:50 +08:00
|
|
|
if (VT == MVT::Other || !TLI.isTypeLegal(VT)) {
|
2012-02-04 08:39:19 +08:00
|
|
|
// Handle integer promotions, though, because they're common and easy.
|
2014-10-09 06:25:45 +08:00
|
|
|
if (!(VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)) {
|
2014-08-28 10:06:55 +08:00
|
|
|
FuncInfo.PHINodesToUpdate.resize(FuncInfo.OrigNumPHINodesToUpdate);
|
2010-04-23 04:46:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value *PHIOp = PN->getIncomingValueForBlock(LLVMBB);
|
|
|
|
|
2010-05-07 09:10:20 +08:00
|
|
|
// Set the DebugLoc for the copy. Prefer the location of the operand
|
|
|
|
// if there is one; use the location of the PHI otherwise.
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = PN->getDebugLoc();
|
2014-09-04 02:46:45 +08:00
|
|
|
if (const auto *Inst = dyn_cast<Instruction>(PHIOp))
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = Inst->getDebugLoc();
|
2010-05-07 09:10:20 +08:00
|
|
|
|
2010-04-23 04:46:50 +08:00
|
|
|
unsigned Reg = getRegForValue(PHIOp);
|
2014-08-28 10:06:55 +08:00
|
|
|
if (!Reg) {
|
|
|
|
FuncInfo.PHINodesToUpdate.resize(FuncInfo.OrigNumPHINodesToUpdate);
|
2010-04-23 04:46:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-09 02:36:41 +08:00
|
|
|
FuncInfo.PHINodesToUpdate.push_back(std::make_pair(&*MBBI++, Reg));
|
2014-02-19 06:05:46 +08:00
|
|
|
DbgLoc = DebugLoc();
|
2010-04-23 04:46:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-20 06:29:18 +08:00
|
|
|
|
|
|
|
bool FastISel::tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst) {
|
2013-04-20 07:26:18 +08:00
|
|
|
assert(LI->hasOneUse() &&
|
2014-09-04 02:46:45 +08:00
|
|
|
"tryToFoldLoad expected a LoadInst with a single use");
|
2013-04-20 06:29:18 +08:00
|
|
|
// We know that the load has a single use, but don't know what it is. If it
|
|
|
|
// isn't one of the folded instructions, then we can't succeed here. Handle
|
|
|
|
// this by scanning the single-use users of the load until we get to FoldInst.
|
2014-09-04 02:46:45 +08:00
|
|
|
unsigned MaxUsers = 6; // Don't scan down huge single-use chains of instrs.
|
2013-04-20 06:29:18 +08:00
|
|
|
|
2014-03-09 11:16:01 +08:00
|
|
|
const Instruction *TheUser = LI->user_back();
|
2014-09-04 02:46:45 +08:00
|
|
|
while (TheUser != FoldInst && // Scan up until we find FoldInst.
|
2013-04-20 06:29:18 +08:00
|
|
|
// Stay in the right block.
|
|
|
|
TheUser->getParent() == FoldInst->getParent() &&
|
2014-09-04 02:46:45 +08:00
|
|
|
--MaxUsers) { // Don't scan too far.
|
2013-04-20 06:29:18 +08:00
|
|
|
// If there are multiple or no uses of this instruction, then bail out.
|
|
|
|
if (!TheUser->hasOneUse())
|
|
|
|
return false;
|
|
|
|
|
2014-03-09 11:16:01 +08:00
|
|
|
TheUser = TheUser->user_back();
|
2013-04-20 06:29:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we didn't find the fold instruction, then we failed to collapse the
|
|
|
|
// sequence.
|
|
|
|
if (TheUser != FoldInst)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Don't try to fold volatile loads. Target has to deal with alignment
|
|
|
|
// constraints.
|
2013-04-20 07:26:18 +08:00
|
|
|
if (LI->isVolatile())
|
|
|
|
return false;
|
2013-04-20 06:29:18 +08:00
|
|
|
|
|
|
|
// Figure out which vreg this is going into. If there is no assigned vreg yet
|
|
|
|
// then there actually was no reference to it. Perhaps the load is referenced
|
|
|
|
// by a dead instruction.
|
|
|
|
unsigned LoadReg = getRegForValue(LI);
|
2014-09-04 02:46:45 +08:00
|
|
|
if (!LoadReg)
|
2013-04-20 06:29:18 +08:00
|
|
|
return false;
|
|
|
|
|
2013-04-20 07:26:18 +08:00
|
|
|
// We can't fold if this vreg has no uses or more than one use. Multiple uses
|
|
|
|
// may mean that the instruction got lowered to multiple MIs, or the use of
|
|
|
|
// the loaded value ended up being multiple operands of the result.
|
|
|
|
if (!MRI.hasOneUse(LoadReg))
|
2013-04-20 06:29:18 +08:00
|
|
|
return false;
|
|
|
|
|
2013-04-20 07:26:18 +08:00
|
|
|
MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(LoadReg);
|
2014-03-14 07:12:04 +08:00
|
|
|
MachineInstr *User = RI->getParent();
|
2013-04-20 06:29:18 +08:00
|
|
|
|
|
|
|
// Set the insertion point properly. Folding the load can cause generation of
|
2013-04-20 07:26:18 +08:00
|
|
|
// other random instructions (like sign extends) for addressing modes; make
|
2013-04-20 06:29:18 +08:00
|
|
|
// sure they get inserted in a logical place before the new instruction.
|
|
|
|
FuncInfo.InsertPt = User;
|
|
|
|
FuncInfo.MBB = User->getParent();
|
|
|
|
|
|
|
|
// Ask the target to try folding the load.
|
|
|
|
return tryToFoldLoadIntoMI(User, RI.getOperandNo(), LI);
|
|
|
|
}
|
|
|
|
|
2013-11-16 03:09:27 +08:00
|
|
|
bool FastISel::canFoldAddIntoGEP(const User *GEP, const Value *Add) {
|
|
|
|
// Must be an add.
|
|
|
|
if (!isa<AddOperator>(Add))
|
|
|
|
return false;
|
|
|
|
// Type size needs to match.
|
2014-02-19 06:05:46 +08:00
|
|
|
if (DL.getTypeSizeInBits(GEP->getType()) !=
|
|
|
|
DL.getTypeSizeInBits(Add->getType()))
|
2013-11-16 03:09:27 +08:00
|
|
|
return false;
|
|
|
|
// Must be in the same basic block.
|
|
|
|
if (isa<Instruction>(Add) &&
|
|
|
|
FuncInfo.MBBMap[cast<Instruction>(Add)->getParent()] != FuncInfo.MBB)
|
|
|
|
return false;
|
|
|
|
// Must have a constant operand.
|
|
|
|
return isa<ConstantInt>(cast<AddOperator>(Add)->getOperand(1));
|
|
|
|
}
|
2013-04-20 06:29:18 +08:00
|
|
|
|
2014-06-13 07:27:57 +08:00
|
|
|
MachineMemOperand *
|
|
|
|
FastISel::createMachineMemOperandFor(const Instruction *I) const {
|
|
|
|
const Value *Ptr;
|
|
|
|
Type *ValTy;
|
|
|
|
unsigned Alignment;
|
2016-07-16 02:26:59 +08:00
|
|
|
MachineMemOperand::Flags Flags;
|
2014-06-13 07:27:57 +08:00
|
|
|
bool IsVolatile;
|
|
|
|
|
|
|
|
if (const auto *LI = dyn_cast<LoadInst>(I)) {
|
|
|
|
Alignment = LI->getAlignment();
|
|
|
|
IsVolatile = LI->isVolatile();
|
|
|
|
Flags = MachineMemOperand::MOLoad;
|
|
|
|
Ptr = LI->getPointerOperand();
|
|
|
|
ValTy = LI->getType();
|
|
|
|
} else if (const auto *SI = dyn_cast<StoreInst>(I)) {
|
|
|
|
Alignment = SI->getAlignment();
|
|
|
|
IsVolatile = SI->isVolatile();
|
|
|
|
Flags = MachineMemOperand::MOStore;
|
|
|
|
Ptr = SI->getPointerOperand();
|
|
|
|
ValTy = SI->getValueOperand()->getType();
|
2014-09-04 02:46:45 +08:00
|
|
|
} else
|
2014-06-13 07:27:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2014-11-12 05:30:22 +08:00
|
|
|
bool IsNonTemporal = I->getMetadata(LLVMContext::MD_nontemporal) != nullptr;
|
|
|
|
bool IsInvariant = I->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 09:38:58 +08:00
|
|
|
bool IsDereferenceable =
|
|
|
|
I->getMetadata(LLVMContext::MD_dereferenceable) != nullptr;
|
2014-11-12 05:30:22 +08:00
|
|
|
const MDNode *Ranges = I->getMetadata(LLVMContext::MD_range);
|
2014-06-13 07:27:57 +08:00
|
|
|
|
2014-07-24 20:16:19 +08:00
|
|
|
AAMDNodes AAInfo;
|
|
|
|
I->getAAMetadata(AAInfo);
|
|
|
|
|
2014-09-04 02:46:45 +08:00
|
|
|
if (Alignment == 0) // Ensure that codegen never sees alignment 0.
|
2014-06-13 07:27:57 +08:00
|
|
|
Alignment = DL.getABITypeAlignment(ValTy);
|
|
|
|
|
2014-10-09 07:38:33 +08:00
|
|
|
unsigned Size = DL.getTypeStoreSize(ValTy);
|
2014-06-13 07:27:57 +08:00
|
|
|
|
|
|
|
if (IsVolatile)
|
|
|
|
Flags |= MachineMemOperand::MOVolatile;
|
|
|
|
if (IsNonTemporal)
|
|
|
|
Flags |= MachineMemOperand::MONonTemporal;
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 09:38:58 +08:00
|
|
|
if (IsDereferenceable)
|
|
|
|
Flags |= MachineMemOperand::MODereferenceable;
|
2014-06-13 07:27:57 +08:00
|
|
|
if (IsInvariant)
|
|
|
|
Flags |= MachineMemOperand::MOInvariant;
|
|
|
|
|
|
|
|
return FuncInfo.MF->getMachineMemOperand(MachinePointerInfo(Ptr), Flags, Size,
|
2014-07-24 20:16:19 +08:00
|
|
|
Alignment, AAInfo, Ranges);
|
2014-06-13 07:27:57 +08:00
|
|
|
}
|
2014-09-16 04:47:13 +08:00
|
|
|
|
|
|
|
CmpInst::Predicate FastISel::optimizeCmpPredicate(const CmpInst *CI) const {
|
|
|
|
// If both operands are the same, then try to optimize or fold the cmp.
|
|
|
|
CmpInst::Predicate Predicate = CI->getPredicate();
|
|
|
|
if (CI->getOperand(0) != CI->getOperand(1))
|
|
|
|
return Predicate;
|
|
|
|
|
|
|
|
switch (Predicate) {
|
|
|
|
default: llvm_unreachable("Invalid predicate!");
|
|
|
|
case CmpInst::FCMP_FALSE: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::FCMP_OEQ: Predicate = CmpInst::FCMP_ORD; break;
|
|
|
|
case CmpInst::FCMP_OGT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::FCMP_OGE: Predicate = CmpInst::FCMP_ORD; break;
|
|
|
|
case CmpInst::FCMP_OLT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::FCMP_OLE: Predicate = CmpInst::FCMP_ORD; break;
|
|
|
|
case CmpInst::FCMP_ONE: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::FCMP_ORD: Predicate = CmpInst::FCMP_ORD; break;
|
|
|
|
case CmpInst::FCMP_UNO: Predicate = CmpInst::FCMP_UNO; break;
|
|
|
|
case CmpInst::FCMP_UEQ: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::FCMP_UGT: Predicate = CmpInst::FCMP_UNO; break;
|
|
|
|
case CmpInst::FCMP_UGE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::FCMP_ULT: Predicate = CmpInst::FCMP_UNO; break;
|
|
|
|
case CmpInst::FCMP_ULE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::FCMP_UNE: Predicate = CmpInst::FCMP_UNO; break;
|
|
|
|
case CmpInst::FCMP_TRUE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
|
|
|
|
case CmpInst::ICMP_EQ: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::ICMP_NE: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::ICMP_UGT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::ICMP_UGE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::ICMP_ULT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::ICMP_ULE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::ICMP_SGT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::ICMP_SGE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
case CmpInst::ICMP_SLT: Predicate = CmpInst::FCMP_FALSE; break;
|
|
|
|
case CmpInst::ICMP_SLE: Predicate = CmpInst::FCMP_TRUE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Predicate;
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
}
|