Changeset View
Changeset View
Standalone View
Standalone View
lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Show All 17 Lines | |||||
#include "llvm/ADT/APInt.h" | #include "llvm/ADT/APInt.h" | ||||
#include "llvm/ADT/SmallBitVector.h" | #include "llvm/ADT/SmallBitVector.h" | ||||
#include "llvm/ADT/SmallString.h" | #include "llvm/ADT/SmallString.h" | ||||
#include "llvm/ADT/STLExtras.h" | #include "llvm/ADT/STLExtras.h" | ||||
#include "llvm/ADT/StringRef.h" | #include "llvm/ADT/StringRef.h" | ||||
#include "llvm/ADT/StringSwitch.h" | #include "llvm/ADT/StringSwitch.h" | ||||
#include "llvm/ADT/Twine.h" | #include "llvm/ADT/Twine.h" | ||||
#include "llvm/CodeGen/MachineValueType.h" | #include "llvm/CodeGen/MachineValueType.h" | ||||
#include "llvm/MC/MCAsmInfo.h" | |||||
#include "llvm/MC/MCContext.h" | #include "llvm/MC/MCContext.h" | ||||
#include "llvm/MC/MCExpr.h" | #include "llvm/MC/MCExpr.h" | ||||
#include "llvm/MC/MCInst.h" | #include "llvm/MC/MCInst.h" | ||||
#include "llvm/MC/MCInstrDesc.h" | #include "llvm/MC/MCInstrDesc.h" | ||||
#include "llvm/MC/MCInstrInfo.h" | #include "llvm/MC/MCInstrInfo.h" | ||||
#include "llvm/MC/MCParser/MCAsmLexer.h" | #include "llvm/MC/MCParser/MCAsmLexer.h" | ||||
#include "llvm/MC/MCParser/MCAsmParser.h" | #include "llvm/MC/MCParser/MCAsmParser.h" | ||||
#include "llvm/MC/MCParser/MCAsmParserExtension.h" | #include "llvm/MC/MCParser/MCAsmParserExtension.h" | ||||
#include "llvm/MC/MCParser/MCParsedAsmOperand.h" | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" | ||||
#include "llvm/MC/MCParser/MCTargetAsmParser.h" | #include "llvm/MC/MCParser/MCTargetAsmParser.h" | ||||
#include "llvm/MC/MCRegisterInfo.h" | #include "llvm/MC/MCRegisterInfo.h" | ||||
#include "llvm/MC/MCStreamer.h" | #include "llvm/MC/MCStreamer.h" | ||||
#include "llvm/MC/MCSubtargetInfo.h" | #include "llvm/MC/MCSubtargetInfo.h" | ||||
#include "llvm/MC/MCSymbol.h" | #include "llvm/MC/MCSymbol.h" | ||||
#include "llvm/Support/Casting.h" | #include "llvm/Support/Casting.h" | ||||
#include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||
#include "llvm/Support/ELF.h" | #include "llvm/Support/ELF.h" | ||||
#include "llvm/Support/ErrorHandling.h" | #include "llvm/Support/ErrorHandling.h" | ||||
#include "llvm/Support/MathExtras.h" | #include "llvm/Support/MathExtras.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include "llvm/Support/SMLoc.h" | #include "llvm/Support/SMLoc.h" | ||||
#include "llvm/Support/TargetRegistry.h" | #include "llvm/Support/TargetRegistry.h" | ||||
#include "llvm/Support/raw_ostream.h" | |||||
#include "llvm/Support/MathExtras.h" | |||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstring> | #include <cstring> | ||||
#include <iterator> | #include <iterator> | ||||
#include <map> | #include <map> | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
▲ Show 20 Lines • Show All 608 Lines • ▼ Show 20 Lines | |||||
#include "AMDGPUGenAsmMatcher.inc" | #include "AMDGPUGenAsmMatcher.inc" | ||||
/// } | /// } | ||||
private: | private: | ||||
bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor); | bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor); | ||||
bool ParseDirectiveHSACodeObjectVersion(); | bool ParseDirectiveHSACodeObjectVersion(); | ||||
bool ParseDirectiveHSACodeObjectISA(); | bool ParseDirectiveHSACodeObjectISA(); | ||||
bool ParseDirectiveHSACodeObjectMetadata(); | |||||
bool ParseAMDKernelCodeTValue(StringRef ID, amd_kernel_code_t &Header); | bool ParseAMDKernelCodeTValue(StringRef ID, amd_kernel_code_t &Header); | ||||
bool ParseDirectiveAMDKernelCodeT(); | bool ParseDirectiveAMDKernelCodeT(); | ||||
bool ParseSectionDirectiveHSAText(); | bool ParseSectionDirectiveHSAText(); | ||||
bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const; | bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const; | ||||
bool ParseDirectiveAMDGPUHsaKernel(); | bool ParseDirectiveAMDGPUHsaKernel(); | ||||
bool ParseDirectiveAMDGPUHsaModuleGlobal(); | bool ParseDirectiveAMDGPUHsaModuleGlobal(); | ||||
bool ParseDirectiveAMDGPUHsaProgramGlobal(); | bool ParseDirectiveAMDGPUHsaProgramGlobal(); | ||||
bool ParseSectionDirectiveHSADataGlobalAgent(); | bool ParseSectionDirectiveHSADataGlobalAgent(); | ||||
▲ Show 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectISA() { | ||||
ArchName = getLexer().getTok().getStringContents(); | ArchName = getLexer().getTok().getStringContents(); | ||||
Lex(); | Lex(); | ||||
getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping, | getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping, | ||||
VendorName, ArchName); | VendorName, ArchName); | ||||
return false; | return false; | ||||
} | } | ||||
bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectMetadata() { | |||||
nhaustov: Maybe rename to ParseDirectiveRuntimeMetadata to match EmitRuntimeMetadata? | |||||
std::string Metadata; | |||||
raw_string_ostream MS(Metadata); | |||||
getLexer().setSkipSpace(false); | |||||
bool FoundEnd = false; | |||||
while (!getLexer().is(AsmToken::Eof)) { | |||||
while (getLexer().is(AsmToken::Space)) { | |||||
MS << ' '; | |||||
Lex(); | |||||
} | |||||
if (getLexer().is(AsmToken::Identifier)) { | |||||
StringRef ID = getLexer().getTok().getIdentifier(); | |||||
if (ID == ".end_amdgpu_runtime_metadata") { | |||||
Lex(); | |||||
FoundEnd = true; | |||||
break; | |||||
} | |||||
} | |||||
MS << Parser.parseStringToEndOfStatement() | |||||
<< getContext().getAsmInfo()->getSeparatorString(); | |||||
Parser.eatToEndOfStatement(); | |||||
} | |||||
getLexer().setSkipSpace(true); | |||||
if (getLexer().is(AsmToken::Eof) && !FoundEnd) | |||||
return TokError("expected directive .end_amdgpu_runtime_metadata not found"); | |||||
MS.flush(); | |||||
getTargetStreamer().EmitRuntimeMetadata(Metadata); | |||||
return false; | |||||
} | |||||
bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(StringRef ID, | bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(StringRef ID, | ||||
amd_kernel_code_t &Header) { | amd_kernel_code_t &Header) { | ||||
SmallString<40> ErrStr; | SmallString<40> ErrStr; | ||||
raw_svector_ostream Err(ErrStr); | raw_svector_ostream Err(ErrStr); | ||||
if (!parseAmdKernelCodeField(ID, getParser(), Header, Err)) { | if (!parseAmdKernelCodeField(ID, getParser(), Header, Err)) { | ||||
return TokError(Err.str()); | return TokError(Err.str()); | ||||
} | } | ||||
Lex(); | Lex(); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) { | ||||
StringRef IDVal = DirectiveID.getString(); | StringRef IDVal = DirectiveID.getString(); | ||||
if (IDVal == ".hsa_code_object_version") | if (IDVal == ".hsa_code_object_version") | ||||
return ParseDirectiveHSACodeObjectVersion(); | return ParseDirectiveHSACodeObjectVersion(); | ||||
if (IDVal == ".hsa_code_object_isa") | if (IDVal == ".hsa_code_object_isa") | ||||
return ParseDirectiveHSACodeObjectISA(); | return ParseDirectiveHSACodeObjectISA(); | ||||
if (IDVal == ".amdgpu_runtime_metadata") | |||||
return ParseDirectiveHSACodeObjectMetadata(); | |||||
if (IDVal == ".amd_kernel_code_t") | if (IDVal == ".amd_kernel_code_t") | ||||
return ParseDirectiveAMDKernelCodeT(); | return ParseDirectiveAMDKernelCodeT(); | ||||
if (IDVal == ".hsatext") | if (IDVal == ".hsatext") | ||||
return ParseSectionDirectiveHSAText(); | return ParseSectionDirectiveHSAText(); | ||||
if (IDVal == ".amdgpu_hsa_kernel") | if (IDVal == ".amdgpu_hsa_kernel") | ||||
return ParseDirectiveAMDGPUHsaKernel(); | return ParseDirectiveAMDGPUHsaKernel(); | ||||
▲ Show 20 Lines • Show All 1,577 Lines • Show Last 20 Lines |
Maybe rename to ParseDirectiveRuntimeMetadata to match EmitRuntimeMetadata?