Skip to content

Commit 7084b56

Browse files
committed
[HIP] Handle compile -m options and propagate into LLC
Allow the compile options for -m such as -mxnack/-mno-xnack, -msram-ecc/-mno-sram-ecc, -mcode-object-v3/-mno-code-object-v3 to propagate into LLC args. Fix an issue where -mattr was pushed even when it was empty. Also add lit tests to verify features are properly passed. Differential Revision: https://reviews.llvm.org/D57977 Reviewers: yaxunl, kzhuravl llvm-svn: 353952
1 parent 6a03b93 commit 7084b56

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,26 @@ const char *AMDGCN::Linker::constructLlcCommand(
159159
llvm::StringRef OutputFilePrefix, const char *InputFileName) const {
160160
// Construct llc command.
161161
ArgStringList LlcArgs{InputFileName, "-mtriple=amdgcn-amd-amdhsa",
162-
"-filetype=obj", "-mattr=-code-object-v3",
163-
Args.MakeArgString("-mcpu=" + SubArchName), "-o"};
162+
"-filetype=obj",
163+
Args.MakeArgString("-mcpu=" + SubArchName)};
164+
165+
// Extract all the -m options
166+
std::vector<llvm::StringRef> Features;
167+
handleTargetFeaturesGroup(
168+
Args, Features, options::OPT_m_amdgpu_Features_Group);
169+
170+
// Add features to mattr such as code-object-v3 and xnack
171+
std::string MAttrString = "-mattr=";
172+
for(auto OneFeature : Features) {
173+
MAttrString.append(Args.MakeArgString(OneFeature));
174+
if (OneFeature != Features.back())
175+
MAttrString.append(",");
176+
}
177+
if(!Features.empty())
178+
LlcArgs.push_back(Args.MakeArgString(MAttrString));
179+
180+
// Add output filename
181+
LlcArgs.push_back("-o");
164182
std::string LlcOutputFileName =
165183
C.getDriver().GetTemporaryPath(OutputFilePrefix, "o");
166184
const char *LlcOutputFile =
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// REQUIRES: clang-driver
2+
// REQUIRES: x86-registered-target
3+
// REQUIRES: amdgpu-registered-target
4+
5+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
6+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
7+
// RUN: -mcode-object-v3 2>&1 | FileCheck %s -check-prefix=COV3
8+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
9+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
10+
// RUN: -mno-code-object-v3 2>&1 | FileCheck %s -check-prefix=NOCOV3
11+
12+
// COV3: {{.*}}clang{{.*}}"-target-feature" "+code-object-v3"
13+
// NOCOV3: {{.*}}clang{{.*}}"-target-feature" "-code-object-v3"
14+
15+
16+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
17+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
18+
// RUN: -mxnack 2>&1 | FileCheck %s -check-prefix=XNACK
19+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
20+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
21+
// RUN: -mno-xnack 2>&1 | FileCheck %s -check-prefix=NOXNACK
22+
23+
// XNACK: {{.*}}clang{{.*}}"-target-feature" "+xnack"
24+
// NOXNACK: {{.*}}clang{{.*}}"-target-feature" "-xnack"
25+
26+
27+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
28+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
29+
// RUN: -msram-ecc 2>&1 | FileCheck %s -check-prefix=SRAM
30+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
31+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
32+
// RUN: -mno-sram-ecc 2>&1 | FileCheck %s -check-prefix=NOSRAM
33+
34+
// SRAM: {{.*}}clang{{.*}}"-target-feature" "+sram-ecc"
35+
// NOSRAM: {{.*}}clang{{.*}}"-target-feature" "-sram-ecc"
36+
37+
38+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
39+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
40+
// RUN: -mcode-object-v3 -mxnack -msram-ecc \
41+
// RUN: 2>&1 | FileCheck %s -check-prefix=ALL3
42+
// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
43+
// RUN: -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
44+
// RUN: -mno-code-object-v3 -mno-xnack -mno-sram-ecc \
45+
// RUN: 2>&1 | FileCheck %s -check-prefix=NOALL3
46+
47+
// ALL3: {{.*}}clang{{.*}}"-target-feature" "+code-object-v3" "-target-feature" "+xnack" "-target-feature" "+sram-ecc"
48+
// NOALL3: {{.*}}clang{{.*}}"-target-feature" "-code-object-v3" "-target-feature" "-xnack" "-target-feature" "-sram-ecc"

0 commit comments

Comments
 (0)