forked from OSchip/llvm-project
[MIR] Teach the parser how to deal with register banks.
llvm-svn: 265802
This commit is contained in:
parent
fcc5811797
commit
876ddf8107
|
@ -15,17 +15,19 @@
|
||||||
#include "llvm/CodeGen/MIRParser/MIRParser.h"
|
#include "llvm/CodeGen/MIRParser/MIRParser.h"
|
||||||
#include "MIParser.h"
|
#include "MIParser.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
|
||||||
#include "llvm/ADT/StringMap.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/AsmParser/Parser.h"
|
#include "llvm/AsmParser/Parser.h"
|
||||||
#include "llvm/AsmParser/SlotMapping.h"
|
#include "llvm/AsmParser/SlotMapping.h"
|
||||||
|
#include "llvm/CodeGen/GlobalISel/RegisterBank.h"
|
||||||
|
#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
|
||||||
|
#include "llvm/CodeGen/MIRYamlMapping.h"
|
||||||
#include "llvm/CodeGen/MachineConstantPool.h"
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
|
||||||
#include "llvm/CodeGen/MachineFrameInfo.h"
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||||
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||||
#include "llvm/CodeGen/MIRYamlMapping.h"
|
|
||||||
#include "llvm/IR/BasicBlock.h"
|
#include "llvm/IR/BasicBlock.h"
|
||||||
#include "llvm/IR/DiagnosticInfo.h"
|
#include "llvm/IR/DiagnosticInfo.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
|
@ -33,9 +35,9 @@
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/ValueSymbolTable.h"
|
#include "llvm/IR/ValueSymbolTable.h"
|
||||||
#include "llvm/Support/LineIterator.h"
|
#include "llvm/Support/LineIterator.h"
|
||||||
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/SMLoc.h"
|
#include "llvm/Support/SMLoc.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
|
||||||
#include "llvm/Support/YAMLTraits.h"
|
#include "llvm/Support/YAMLTraits.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -53,6 +55,8 @@ class MIRParserImpl {
|
||||||
SlotMapping IRSlots;
|
SlotMapping IRSlots;
|
||||||
/// Maps from register class names to register classes.
|
/// Maps from register class names to register classes.
|
||||||
StringMap<const TargetRegisterClass *> Names2RegClasses;
|
StringMap<const TargetRegisterClass *> Names2RegClasses;
|
||||||
|
/// Maps from register bank names to register banks.
|
||||||
|
StringMap<const RegisterBank *> Names2RegBanks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
|
MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
|
||||||
|
@ -149,12 +153,18 @@ private:
|
||||||
void createDummyFunction(StringRef Name, Module &M);
|
void createDummyFunction(StringRef Name, Module &M);
|
||||||
|
|
||||||
void initNames2RegClasses(const MachineFunction &MF);
|
void initNames2RegClasses(const MachineFunction &MF);
|
||||||
|
void initNames2RegBanks(const MachineFunction &MF);
|
||||||
|
|
||||||
/// Check if the given identifier is a name of a register class.
|
/// Check if the given identifier is a name of a register class.
|
||||||
///
|
///
|
||||||
/// Return null if the name isn't a register class.
|
/// Return null if the name isn't a register class.
|
||||||
const TargetRegisterClass *getRegClass(const MachineFunction &MF,
|
const TargetRegisterClass *getRegClass(const MachineFunction &MF,
|
||||||
StringRef Name);
|
StringRef Name);
|
||||||
|
|
||||||
|
/// Check if the given identifier is a name of a register bank.
|
||||||
|
///
|
||||||
|
/// Return null if the name isn't a register bank.
|
||||||
|
const RegisterBank *getRegBank(const MachineFunction &MF, StringRef Name);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@ -356,11 +366,18 @@ bool MIRParserImpl::initializeRegisterInfo(MachineFunction &MF,
|
||||||
Reg = RegInfo.createGenericVirtualRegister(/*Size*/ 1);
|
Reg = RegInfo.createGenericVirtualRegister(/*Size*/ 1);
|
||||||
} else {
|
} else {
|
||||||
const auto *RC = getRegClass(MF, VReg.Class.Value);
|
const auto *RC = getRegClass(MF, VReg.Class.Value);
|
||||||
if (!RC)
|
if (RC) {
|
||||||
return error(VReg.Class.SourceRange.Start,
|
|
||||||
Twine("use of undefined register class '") +
|
|
||||||
VReg.Class.Value + "'");
|
|
||||||
Reg = RegInfo.createVirtualRegister(RC);
|
Reg = RegInfo.createVirtualRegister(RC);
|
||||||
|
} else {
|
||||||
|
const auto *RegBank = getRegBank(MF, VReg.Class.Value);
|
||||||
|
if (!RegBank)
|
||||||
|
return error(
|
||||||
|
VReg.Class.SourceRange.Start,
|
||||||
|
Twine("use of undefined register class or register bank '") +
|
||||||
|
VReg.Class.Value + "'");
|
||||||
|
Reg = RegInfo.createGenericVirtualRegister(/*Size*/ 1);
|
||||||
|
RegInfo.setRegBank(Reg, *RegBank);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!PFS.VirtualRegisterSlots.insert(std::make_pair(VReg.ID.Value, Reg))
|
if (!PFS.VirtualRegisterSlots.insert(std::make_pair(VReg.ID.Value, Reg))
|
||||||
.second)
|
.second)
|
||||||
|
@ -707,6 +724,21 @@ void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MIRParserImpl::initNames2RegBanks(const MachineFunction &MF) {
|
||||||
|
if (!Names2RegBanks.empty())
|
||||||
|
return;
|
||||||
|
const RegisterBankInfo *RBI = MF.getSubtarget().getRegBankInfo();
|
||||||
|
// If the target does not support GlobalISel, we may not have a
|
||||||
|
// register bank info.
|
||||||
|
if (!RBI)
|
||||||
|
return;
|
||||||
|
for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
|
||||||
|
const auto &RegBank = RBI->getRegBank(I);
|
||||||
|
Names2RegBanks.insert(
|
||||||
|
std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
|
const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
|
||||||
StringRef Name) {
|
StringRef Name) {
|
||||||
initNames2RegClasses(MF);
|
initNames2RegClasses(MF);
|
||||||
|
@ -716,6 +748,15 @@ const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
|
||||||
return RegClassInfo->getValue();
|
return RegClassInfo->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RegisterBank *MIRParserImpl::getRegBank(const MachineFunction &MF,
|
||||||
|
StringRef Name) {
|
||||||
|
initNames2RegBanks(MF);
|
||||||
|
auto RegBankInfo = Names2RegBanks.find(Name);
|
||||||
|
if (RegBankInfo == Names2RegBanks.end())
|
||||||
|
return nullptr;
|
||||||
|
return RegBankInfo->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
|
MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
|
||||||
: Impl(std::move(Impl)) {}
|
: Impl(std::move(Impl)) {}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ name: test
|
||||||
isSSA: true
|
isSSA: true
|
||||||
tracksRegLiveness: true
|
tracksRegLiveness: true
|
||||||
registers:
|
registers:
|
||||||
# CHECK: [[@LINE+1]]:20: use of undefined register class 'gr3200'
|
# CHECK: [[@LINE+1]]:20: use of undefined register class or register bank 'gr3200'
|
||||||
- {id: 0, class: 'gr3200'}
|
- {id: 0, class: 'gr3200'}
|
||||||
body: |
|
body: |
|
||||||
bb.0.entry:
|
bb.0.entry:
|
||||||
|
|
Loading…
Reference in New Issue