[llvm] r260579 - [GlobalISel] Add the necessary plumbing to lower formal arguments.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 11:59:41 PST 2016
Author: qcolombet
Date: Thu Feb 11 13:59:41 2016
New Revision: 260579
URL: http://llvm.org/viewvc/llvm-project?rev=260579&view=rev
Log:
[GlobalISel] Add the necessary plumbing to lower formal arguments.
Modified:
llvm/trunk/include/llvm/Target/TargetLowering.h
llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=260579&r1=260578&r2=260579&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLowering.h Thu Feb 11 13:59:41 2016
@@ -33,6 +33,9 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
+#ifdef LLVM_BUILD_GLOBAL_ISEL
+# include "llvm/IR/Function.h"
+#endif
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
@@ -2517,6 +2520,22 @@ public:
unsigned VReg) const {
return false;
}
+
+ /// This hook must be implemented to lower the incoming (formal)
+ /// arguments, described by \p Args, for GlobalISel. Each argument
+ /// must end up in the related virtual register described by VRegs.
+ /// In other words, the first argument should end up in VRegs[0],
+ /// the second in VRegs[1], and so on.
+ /// \p MIRBuilder is set to the proper insertion for the argument
+ /// lowering.
+ ///
+ /// \return True if the lowering succeeded, false otherwise.
+ virtual bool
+ LowerFormalArguments(MachineIRBuilder &MIRBuilder,
+ const Function::ArgumentListType &Args,
+ const SmallVectorImpl<unsigned> &VRegs) const {
+ return false;
+ }
#endif
/// Return true if result of the specified node is used by a return node
Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=260579&r1=260578&r2=260579&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Thu Feb 11 13:59:41 2016
@@ -12,6 +12,7 @@
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/IR/Constant.h"
@@ -103,9 +104,22 @@ void IRTranslator::finalize() {
bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
const Function &F = *MF.getFunction();
+ if (F.empty())
+ return false;
TLI = MF.getSubtarget().getTargetLowering();
MIRBuilder.setFunction(MF);
MRI = &MF.getRegInfo();
+ // Setup the arguments.
+ MachineBasicBlock &MBB = getOrCreateBB(&F.front());
+ MIRBuilder.setBasicBlock(MBB);
+ SmallVector<unsigned, 8> VRegArgs;
+ for (const Argument &Arg: F.args())
+ VRegArgs.push_back(*getOrCreateVRegs(&Arg).begin());
+ bool Succeeded = TLI->LowerFormalArguments(MIRBuilder, F.getArgumentList(),
+ VRegArgs);
+ if (!Succeeded)
+ report_fatal_error("Unable to lower arguments");
+
for (const BasicBlock &BB: F) {
MachineBasicBlock &MBB = getOrCreateBB(&BB);
MIRBuilder.setBasicBlock(MBB);
More information about the llvm-commits
mailing list