Skip to content

Commit

Permalink
AMDGPU/SI: Add hsa code object directives
Browse files Browse the repository at this point in the history
Reviewers: arsenm

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10757

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240831 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tstellarAMD committed Jun 26, 2015
1 parent 4aad126 commit ac1a45e
Show file tree
Hide file tree
Showing 23 changed files with 561 additions and 10 deletions.
26 changes: 26 additions & 0 deletions docs/AMDGPUUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ strings:
v_mul_i32_i24 v1, v2, v3
v_mul_i32_i24_e32 v1, v2, v3
v_mul_i32_i24_e64 v1, v2, v3
Assembler Directives
--------------------

.hsa_code_object_version major, minor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*major* and *minor* are integers that specify the version of the HSA code
object that will be generated by the assembler. This value will be stored
in an entry of the .note section.

.hsa_code_object_isa [major, minor, stepping, vendor, arch]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*major*, *minor*, and *stepping* are all integers that describe the instruction
set architecture (ISA) version of the assembly program.

*vendor* and *arch* are quoted strings. *vendor* should always be equal to
"AMD" and *arch* should always be equal to "AMDGPU".

If no arguments are specified, then the assembler will derive the ISA version,
*vendor*, and *arch* from the value of the -mcpu option that is passed to the
assembler.

ISA version, *vendor*, and *arch* will all be stored in a single entry of the
.note section.
13 changes: 13 additions & 0 deletions lib/Target/AMDGPU/AMDGPU.td
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ class SubtargetFeatureLDSBankCount <int Value> : SubtargetFeature <
def FeatureLDSBankCount16 : SubtargetFeatureLDSBankCount<16>;
def FeatureLDSBankCount32 : SubtargetFeatureLDSBankCount<32>;

class SubtargetFeatureISAVersion <int Major, int Minor, int Stepping>
: SubtargetFeature <
"isaver"#Major#"."#Minor#"."#Stepping,
"IsaVersion",
"ISAVersion"#Major#"_"#Minor#"_"#Stepping,
"Instruction set version number"
>;

def FeatureISAVersion7_0_0 : SubtargetFeatureISAVersion <7,0,0>;
def FeatureISAVersion7_0_1 : SubtargetFeatureISAVersion <7,0,1>;
def FeatureISAVersion8_0_0 : SubtargetFeatureISAVersion <8,0,0>;
def FeatureISAVersion8_0_1 : SubtargetFeatureISAVersion <8,0,1>;

class SubtargetFeatureLocalMemorySize <int Value> : SubtargetFeature<
"localmemorysize"#Value,
"LocalMemorySize",
Expand Down
9 changes: 9 additions & 0 deletions lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
//

#include "AMDGPUAsmPrinter.h"
#include "MCTargetDesc/AMDGPUTargetStreamer.h"
#include "InstPrinter/AMDGPUInstPrinter.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "AMDGPU.h"
#include "AMDKernelCodeT.h"
#include "AMDGPUSubtarget.h"
Expand Down Expand Up @@ -127,6 +129,13 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
getSIProgramInfo(KernelInfo, MF);
EmitProgramInfoSI(MF, KernelInfo);
}
// Emit directives
AMDGPUTargetStreamer *TS =
static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer());
TS->EmitDirectiveHSACodeObjectVersion(1, 0);
AMDGPU::IsaVersion ISA = STM.getIsaVersion();
TS->EmitDirectiveHSACodeObjectISA(ISA.Major, ISA.Minor, ISA.Stepping,
"AMD", "AMDGPU");
} else {
EmitProgramInfoR600(MF);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Target/AMDGPU/AMDGPUSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
WavefrontSize(0), CFALUBug(false), LocalMemorySize(0),
EnableVGPRSpilling(false), SGPRInitBug(false), IsGCN(false),
GCN1Encoding(false), GCN3Encoding(false), CIInsts(false), LDSBankCount(0),
IsaVersion(ISAVersion0_0_0),
FrameLowering(TargetFrameLowering::StackGrowsUp,
64 * 16, // Maximum stack alignment (long16)
0),
Expand Down Expand Up @@ -109,6 +110,10 @@ unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
}
}

AMDGPU::IsaVersion AMDGPUSubtarget::getIsaVersion() const {
return AMDGPU::getIsaVersion(getFeatureBits());
}

bool AMDGPUSubtarget::isVGPRSpillingEnabled(
const SIMachineFunctionInfo *MFI) const {
return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling;
Expand All @@ -131,3 +136,4 @@ void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Policy.OnlyBottomUp = false;
}
}

13 changes: 13 additions & 0 deletions lib/Target/AMDGPU/AMDGPUSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "AMDGPUIntrinsicInfo.h"
#include "AMDGPUSubtarget.h"
#include "R600ISelLowering.h"
#include "AMDKernelCodeT.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Target/TargetSubtargetInfo.h"
Expand Down Expand Up @@ -48,6 +50,14 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
};

enum {
ISAVersion0_0_0,
ISAVersion7_0_0,
ISAVersion7_0_1,
ISAVersion8_0_0,
ISAVersion8_0_1
};

private:
std::string DevName;
bool Is64bit;
Expand Down Expand Up @@ -77,6 +87,7 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
bool CIInsts;
bool FeatureDisable;
int LDSBankCount;
unsigned IsaVersion;

AMDGPUFrameLowering FrameLowering;
std::unique_ptr<AMDGPUTargetLowering> TLInfo;
Expand Down Expand Up @@ -236,6 +247,8 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {

unsigned getAmdKernelCodeChipID() const;

AMDGPU::IsaVersion getIsaVersion() const;

bool enableMachineScheduler() const override {
return true;
}
Expand Down
111 changes: 111 additions & 0 deletions lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//===----------------------------------------------------------------------===//

#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "MCTargetDesc/AMDGPUTargetStreamer.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "SIDefines.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -314,6 +316,11 @@ class AMDGPUAsmParser : public MCTargetAsmParser {

/// }

private:
bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor);
bool ParseDirectiveHSACodeObjectVersion();
bool ParseDirectiveHSACodeObjectISA();

public:
AMDGPUAsmParser(MCSubtargetInfo &STI, MCAsmParser &_Parser,
const MCInstrInfo &MII,
Expand All @@ -329,6 +336,11 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
}

AMDGPUTargetStreamer &getTargetStreamer() {
MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
return static_cast<AMDGPUTargetStreamer &>(TS);
}

unsigned getForcedEncodingSize() const {
return ForcedEncodingSize;
}
Expand Down Expand Up @@ -581,7 +593,106 @@ bool AMDGPUAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
llvm_unreachable("Implement any new match types added!");
}

bool AMDGPUAsmParser::ParseDirectiveMajorMinor(uint32_t &Major,
uint32_t &Minor) {
if (getLexer().isNot(AsmToken::Integer))
return TokError("invalid major version");

Major = getLexer().getTok().getIntVal();
Lex();

if (getLexer().isNot(AsmToken::Comma))
return TokError("minor version number required, comma expected");
Lex();

if (getLexer().isNot(AsmToken::Integer))
return TokError("invalid minor version");

Minor = getLexer().getTok().getIntVal();
Lex();

return false;
}

bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectVersion() {

uint32_t Major;
uint32_t Minor;

if (ParseDirectiveMajorMinor(Major, Minor))
return true;

getTargetStreamer().EmitDirectiveHSACodeObjectVersion(Major, Minor);
return false;
}

bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectISA() {

uint32_t Major;
uint32_t Minor;
uint32_t Stepping;
StringRef VendorName;
StringRef ArchName;

// If this directive has no arguments, then use the ISA version for the
// targeted GPU.
if (getLexer().is(AsmToken::EndOfStatement)) {
AMDGPU::IsaVersion Isa = AMDGPU::getIsaVersion(STI.getFeatureBits());
getTargetStreamer().EmitDirectiveHSACodeObjectISA(Isa.Major, Isa.Minor,
Isa.Stepping,
"AMD", "AMDGPU");
return false;
}


if (ParseDirectiveMajorMinor(Major, Minor))
return true;

if (getLexer().isNot(AsmToken::Comma))
return TokError("stepping version number required, comma expected");
Lex();

if (getLexer().isNot(AsmToken::Integer))
return TokError("invalid stepping version");

Stepping = getLexer().getTok().getIntVal();
Lex();

if (getLexer().isNot(AsmToken::Comma))
return TokError("vendor name required, comma expected");
Lex();

if (getLexer().isNot(AsmToken::String))
return TokError("invalid vendor name");

VendorName = getLexer().getTok().getStringContents();
Lex();

if (getLexer().isNot(AsmToken::Comma))
return TokError("arch name required, comma expected");
Lex();

if (getLexer().isNot(AsmToken::String))
return TokError("invalid arch name");

ArchName = getLexer().getTok().getStringContents();
Lex();

getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping,
VendorName, ArchName);
return false;
}

bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
MCAsmParser &Parser = getParser();
StringRef IDVal = DirectiveID.getString();

if (IDVal == ".hsa_code_object_version")
return ParseDirectiveHSACodeObjectVersion();

if (IDVal == ".hsa_code_object_isa")
return ParseDirectiveHSACodeObjectISA();

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Target/AMDGPU/AsmParser/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
type = Library
name = AMDGPUAsmParser
parent = AMDGPU
required_libraries = MC MCParser AMDGPUDesc AMDGPUInfo Support
required_libraries = MC MCParser AMDGPUDesc AMDGPUInfo AMDGPUUtils Support
add_to_library_groups = AMDGPU
1 change: 1 addition & 0 deletions lib/Target/AMDGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ add_subdirectory(AsmParser)
add_subdirectory(InstPrinter)
add_subdirectory(TargetInfo)
add_subdirectory(MCTargetDesc)
add_subdirectory(Utils)
4 changes: 2 additions & 2 deletions lib/Target/AMDGPU/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
;===------------------------------------------------------------------------===;

[common]
subdirectories = AsmParser InstPrinter MCTargetDesc TargetInfo
subdirectories = AsmParser InstPrinter MCTargetDesc TargetInfo Utils

[component_0]
type = TargetGroup
Expand All @@ -29,5 +29,5 @@ has_asmprinter = 1
type = Library
name = AMDGPUCodeGen
parent = AMDGPU
required_libraries = Analysis AsmPrinter CodeGen Core IPO MC AMDGPUAsmParser AMDGPUAsmPrinter AMDGPUDesc AMDGPUInfo Scalar SelectionDAG Support Target TransformUtils
required_libraries = Analysis AsmPrinter CodeGen Core IPO MC AMDGPUAsmParser AMDGPUAsmPrinter AMDGPUDesc AMDGPUInfo AMDGPUUtils Scalar SelectionDAG Support Target TransformUtils
add_to_library_groups = AMDGPU
22 changes: 22 additions & 0 deletions lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "AMDGPUMCTargetDesc.h"
#include "AMDGPUMCAsmInfo.h"
#include "AMDGPUTargetStreamer.h"
#include "InstPrinter/AMDGPUInstPrinter.h"
#include "SIDefines.h"
#include "llvm/MC/MCCodeGenInfo.h"
Expand Down Expand Up @@ -72,6 +73,19 @@ static MCInstPrinter *createAMDGPUMCInstPrinter(const Triple &T,
return new AMDGPUInstPrinter(MAI, MII, MRI);
}

static MCTargetStreamer *createAMDGPUAsmTargetStreamer(MCStreamer &S,
formatted_raw_ostream &OS,
MCInstPrinter *InstPrint,
bool isVerboseAsm) {
return new AMDGPUTargetAsmStreamer(S, OS);
}

static MCTargetStreamer * createAMDGPUObjectTargetStreamer(
MCStreamer &S,
const MCSubtargetInfo &STI) {
return new AMDGPUTargetELFStreamer(S);
}

extern "C" void LLVMInitializeAMDGPUTargetMC() {
for (Target *T : {&TheAMDGPUTarget, &TheGCNTarget}) {
RegisterMCAsmInfo<AMDGPUMCAsmInfo> X(*T);
Expand All @@ -84,7 +98,15 @@ extern "C" void LLVMInitializeAMDGPUTargetMC() {
TargetRegistry::RegisterMCAsmBackend(*T, createAMDGPUAsmBackend);
}

// R600 specific registration
TargetRegistry::RegisterMCCodeEmitter(TheAMDGPUTarget,
createR600MCCodeEmitter);

// GCN specific registration
TargetRegistry::RegisterMCCodeEmitter(TheGCNTarget, createSIMCCodeEmitter);

TargetRegistry::RegisterAsmTargetStreamer(TheGCNTarget,
createAMDGPUAsmTargetStreamer);
TargetRegistry::RegisterObjectTargetStreamer(TheGCNTarget,
createAMDGPUObjectTargetStreamer);
}
Loading

0 comments on commit ac1a45e

Please sign in to comment.