summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-09 21:28:04 +0000
committerTim Northover <tnorthover@apple.com>2016-08-09 21:28:04 +0000
commit5ed648e50987853e1590d42dc56a268fad58df19 (patch)
tree3607f84ac4bf48df8d1bdcc7c08ef017341fa98d /llvm/lib
parent0a328c5f30b8c4ada2019e7583b2af5869256588 (diff)
downloadbcm5719-llvm-5ed648e50987853e1590d42dc56a268fad58df19.tar.gz
bcm5719-llvm-5ed648e50987853e1590d42dc56a268fad58df19.zip
GlobalISel: first translation support for Constants.
For now put them all in the entry block. This should be correct but may give poor runtime performance. Hopefully MachineSinking combined with isReMaterializable can solve those issues, but if not the interface is sound enough to support alternatives. llvm-svn: 278168
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 618a3859e22..ef836304c14 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -49,7 +49,12 @@ unsigned IRTranslator::getOrCreateVReg(const Value &Val) {
unsigned Size = DL->getTypeSizeInBits(Val.getType());
unsigned VReg = MRI->createGenericVirtualRegister(Size);
ValReg = VReg;
- assert(!isa<Constant>(Val) && "Not yet implemented");
+
+ if (auto CV = dyn_cast<Constant>(&Val)) {
+ bool Success = translate(*CV, VReg);
+ if (!Success)
+ report_fatal_error("unable to translate constant");
+ }
}
return ValReg;
}
@@ -312,6 +317,15 @@ bool IRTranslator::translate(const Instruction &Inst) {
}
}
+bool IRTranslator::translate(const Constant &C, unsigned Reg) {
+ if (auto CI = dyn_cast<ConstantInt>(&C)) {
+ EntryBuilder.buildConstant(LLT{*CI->getType()}, Reg, CI->getZExtValue());
+ return true;
+ }
+
+ llvm_unreachable("unhandled constant kind");
+}
+
void IRTranslator::finalize() {
// Release the memory used by the different maps we
@@ -326,6 +340,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
return false;
CLI = MF.getSubtarget().getCallLowering();
MIRBuilder.setMF(MF);
+ EntryBuilder.setMF(MF);
MRI = &MF.getRegInfo();
DL = &F.getParent()->getDataLayout();
@@ -342,6 +357,13 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
if (!Succeeded)
report_fatal_error("Unable to lower arguments");
+ // Now that we've got the ABI handling code, it's safe to set a location for
+ // any Constants we find in the IR.
+ if (MBB.empty())
+ EntryBuilder.setMBB(MBB);
+ else
+ EntryBuilder.setInstr(MBB.back(), /* Before */ false);
+
for (const BasicBlock &BB: F) {
MachineBasicBlock &MBB = getOrCreateBB(BB);
// Set the insertion point of all the following translations to
OpenPOWER on IntegriCloud