]> granicus.if.org Git - llvm/commitdiff
[AMDGPU][llvm-mc] Predefined symbols to access -mcpu from the assembly source (.optio...
authorArtem Tamazov <artem.tamazov@amd.com>
Tue, 14 Jun 2016 15:03:59 +0000 (15:03 +0000)
committerArtem Tamazov <artem.tamazov@amd.com>
Tue, 14 Jun 2016 15:03:59 +0000 (15:03 +0000)
The feature allows for conditional assembly etc.
TODO: make those symbols read-only.
Test added.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272673 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
test/MC/AMDGPU/symbol_special.s [new file with mode: 0644]

index 0120c04a4eb12e3a36b5498cd175eec5798acd0c..12303a67c27d2e67300268dc32e834bd7b98600e 100644 (file)
@@ -60,8 +60,6 @@ class AMDGPUOperand : public MCParsedAsmOperand {
 public:
   AMDGPUOperand(enum KindTy K) : MCParsedAsmOperand(), Kind(K) {}
 
-  MCContext *Ctx;
-
   typedef std::unique_ptr<AMDGPUOperand> Ptr;
 
   struct Modifiers {
@@ -586,6 +584,21 @@ public:
     }
 
     setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
+
+    {
+      // TODO: make those pre-defined variables read-only.
+      // Currently there is none suitable machinery in the core llvm-mc for this.
+      // MCSymbol::isRedefinable is intended for another purpose, and
+      // AsmParser::parseDirectiveSet() cannot be specialized for specific target.
+      AMDGPU::IsaVersion Isa = AMDGPU::getIsaVersion(getSTI().getFeatureBits());
+      MCContext &Ctx = getContext();
+      MCSymbol *Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_major"));
+      Sym->setVariableValue(MCConstantExpr::create(Isa.Major, Ctx));
+      Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_minor"));
+      Sym->setVariableValue(MCConstantExpr::create(Isa.Minor, Ctx));
+      Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_stepping"));
+      Sym->setVariableValue(MCConstantExpr::create(Isa.Stepping, Ctx));
+    }
   }
 
   AMDGPUTargetStreamer &getTargetStreamer() {
diff --git a/test/MC/AMDGPU/symbol_special.s b/test/MC/AMDGPU/symbol_special.s
new file mode 100644 (file)
index 0000000..75d36b8
--- /dev/null
@@ -0,0 +1,48 @@
+// RUN: llvm-mc -arch=amdgcn -mcpu=bonaire %s | FileCheck %s --check-prefix=BONAIRE
+// RUN: llvm-mc -arch=amdgcn -mcpu=hawaii %s | FileCheck %s --check-prefix=HAWAII
+// RUN: llvm-mc -arch=amdgcn -mcpu=tonga %s | FileCheck %s --check-prefix=TONGA
+// RUN: llvm-mc -arch=amdgcn -mcpu=fiji %s | FileCheck %s --check-prefix=FIJI
+
+.if .option.machine_version_major == 0
+.byte 0
+.elseif .option.machine_version_major == 7
+.byte 7
+.elseif .option.machine_version_major == 8
+.byte 8
+.else
+.error "major unknown"
+.endif
+// BONAIRE: .byte 7
+// HAWAII: .byte 7
+// TONGA: .byte 8
+// FIJI: .byte 8
+
+.if .option.machine_version_minor == 0
+.byte 0
+.else
+.error "minor unknown"
+.endif
+// BONAIRE: .byte 0
+// HAWAII: .byte 0
+// TONGA: .byte 0
+// FIJI: .byte 0
+
+.if .option.machine_version_stepping == 0
+.byte 0
+.elseif .option.machine_version_stepping == 1
+.byte 1
+.elseif .option.machine_version_stepping == 3
+.byte 3
+.else
+.error "stepping unknown"
+.endif
+// BONAIRE: .byte 0
+// HAWAII: .byte 1
+// TONGA: .byte 0
+// FIJI: .byte 3
+
+v_add_f32 v0, v0, v[.option.machine_version_major]
+// BONAIRE: v_add_f32_e32 v0, v0, v7
+// HAWAII: v_add_f32_e32 v0, v0, v7
+// TONGA: v_add_f32_e32 v0, v0, v8
+// FIJI: v_add_f32_e32 v0, v0, v8