mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-05 10:39:21 +00:00
[fast-isel] Add X86FastIsel::FastLowerArguments to handle functions with 6 or
fewer scalar integer (i32 or i64) arguments. It completely eliminates the need for SDISel for trivial functions. Also, add the new llc -fast-isel-abort-args option, which is similar to -fast-isel-abort option, but for formal argument lowering. llvm-svn: 176052
This commit is contained in:
parent
9dd0c20307
commit
37142b6930
@ -145,6 +145,10 @@ EnableFastISelVerbose("fast-isel-verbose", cl::Hidden,
|
||||
static cl::opt<bool>
|
||||
EnableFastISelAbort("fast-isel-abort", cl::Hidden,
|
||||
cl::desc("Enable abort calls when \"fast\" instruction fails"));
|
||||
static cl::opt<bool>
|
||||
EnableFastISelAbortArgs("fast-isel-abort-args", cl::Hidden,
|
||||
cl::desc("Enable abort calls when \"fast\" instruction fails to "
|
||||
"lower formal arguments"));
|
||||
|
||||
static cl::opt<bool>
|
||||
UseMBPI("use-mbpi",
|
||||
@ -1048,6 +1052,12 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
|
||||
if (LLVMBB == &Fn.getEntryBlock()) {
|
||||
// Lower any arguments needed in this block if this is the entry block.
|
||||
if (!FastIS->LowerArguments()) {
|
||||
|
||||
if (EnableFastISelAbortArgs)
|
||||
// The "fast" selector couldn't lower these arguments. For the
|
||||
// purpose of debugging, just abort.
|
||||
llvm_unreachable("FastISel didn't lower all arguments");
|
||||
|
||||
// Call target indepedent SDISel argument lowering code if the target
|
||||
// specific routine is not successful.
|
||||
LowerArguments(LLVMBB);
|
||||
|
@ -75,6 +75,8 @@ public:
|
||||
virtual bool TryToFoldLoad(MachineInstr *MI, unsigned OpNo,
|
||||
const LoadInst *LI);
|
||||
|
||||
virtual bool FastLowerArguments();
|
||||
|
||||
#include "X86GenFastISel.inc"
|
||||
|
||||
private:
|
||||
@ -1520,6 +1522,77 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
|
||||
}
|
||||
}
|
||||
|
||||
bool X86FastISel::FastLowerArguments() {
|
||||
if (!FuncInfo.CanLowerReturn)
|
||||
return false;
|
||||
|
||||
const Function *F = FuncInfo.Fn;
|
||||
if (F->isVarArg())
|
||||
return false;
|
||||
|
||||
CallingConv::ID CC = F->getCallingConv();
|
||||
if (CC != CallingConv::C)
|
||||
return false;
|
||||
|
||||
if (!Subtarget->is64Bit())
|
||||
return false;
|
||||
|
||||
// Only handle simple cases. i.e. Up to 6 i32/i64 scalar arguments.
|
||||
unsigned Idx = 1;
|
||||
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
|
||||
I != E; ++I, ++Idx) {
|
||||
if (Idx > 6)
|
||||
return false;
|
||||
|
||||
if (F->getAttributes().hasAttribute(Idx, Attribute::ByVal) ||
|
||||
F->getAttributes().hasAttribute(Idx, Attribute::InReg) ||
|
||||
F->getAttributes().hasAttribute(Idx, Attribute::StructRet) ||
|
||||
F->getAttributes().hasAttribute(Idx, Attribute::Nest))
|
||||
return false;
|
||||
|
||||
Type *ArgTy = I->getType();
|
||||
if (ArgTy->isStructTy() || ArgTy->isArrayTy() || ArgTy->isVectorTy())
|
||||
return false;
|
||||
|
||||
EVT ArgVT = TLI.getValueType(ArgTy);
|
||||
switch (ArgVT.getSimpleVT().SimpleTy) {
|
||||
case MVT::i32:
|
||||
case MVT::i64:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static const uint16_t GPR32ArgRegs[] = {
|
||||
X86::EDI, X86::ESI, X86::EDX, X86::ECX, X86::R8D, X86::R9D
|
||||
};
|
||||
static const uint16_t GPR64ArgRegs[] = {
|
||||
X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8 , X86::R9
|
||||
};
|
||||
|
||||
Idx = 0;
|
||||
const TargetRegisterClass *RC32 = TLI.getRegClassFor(MVT::i32);
|
||||
const TargetRegisterClass *RC64 = TLI.getRegClassFor(MVT::i64);
|
||||
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
|
||||
I != E; ++I, ++Idx) {
|
||||
if (I->use_empty())
|
||||
continue;
|
||||
bool is32Bit = TLI.getValueType(I->getType()) == MVT::i32;
|
||||
const TargetRegisterClass *RC = is32Bit ? RC32 : RC64;
|
||||
unsigned SrcReg = is32Bit ? GPR32ArgRegs[Idx] : GPR64ArgRegs[Idx];
|
||||
unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
|
||||
// FIXME: Unfortunately it's necessary to emit a copy from the livein copy.
|
||||
// Without this, EmitLiveInCopies may eliminate the livein if its only
|
||||
// use is a bitcast (which isn't turned into an instruction).
|
||||
unsigned ResultReg = createResultReg(RC);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
|
||||
ResultReg).addReg(DstReg, getKillRegState(true));
|
||||
UpdateValueMap(I, ResultReg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool X86FastISel::X86SelectCall(const Instruction *I) {
|
||||
const CallInst *CI = cast<CallInst>(I);
|
||||
const Value *Callee = CI->getCalledValue();
|
||||
|
25
test/CodeGen/X86/fast-isel-args.ll
Normal file
25
test/CodeGen/X86/fast-isel-args.ll
Normal file
@ -0,0 +1,25 @@
|
||||
; RUN: llc < %s -fast-isel -fast-isel-abort -fast-isel-abort-args -verify-machineinstrs -mtriple=x86_64-apple-darwin10
|
||||
|
||||
; Just make sure these don't abort when lowering the arguments.
|
||||
define i32 @t1(i32 %a, i32 %b, i32 %c) {
|
||||
entry:
|
||||
%add = add nsw i32 %b, %a
|
||||
%add1 = add nsw i32 %add, %c
|
||||
ret i32 %add1
|
||||
}
|
||||
|
||||
define i64 @t2(i64 %a, i64 %b, i64 %c) {
|
||||
entry:
|
||||
%add = add nsw i64 %b, %a
|
||||
%add1 = add nsw i64 %add, %c
|
||||
ret i64 %add1
|
||||
}
|
||||
|
||||
define i64 @t3(i32 %a, i64 %b, i32 %c) #2 {
|
||||
entry:
|
||||
%conv = sext i32 %a to i64
|
||||
%add = add nsw i64 %conv, %b
|
||||
%conv1 = sext i32 %c to i64
|
||||
%add2 = add nsw i64 %add, %conv1
|
||||
ret i64 %add2
|
||||
}
|
Loading…
Reference in New Issue
Block a user