From 7d40a132455f44a25dddb536d9fc02bac0235d64 Mon Sep 17 00:00:00 2001 From: Jatin Chaudhary Date: Wed, 21 Oct 2020 05:39:12 -0400 Subject: [PATCH] Adding -x hip/c/none after each input file, this should allow compilations like 'hipcc a.cc b.o c.c' Change-Id: If35571c0f8ff8bf51aebd793fc0c81c0e418ca5c --- bin/hipcc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/hipcc b/bin/hipcc index 3403b5ab92..31f7d391f7 100755 --- a/bin/hipcc +++ b/bin/hipcc @@ -370,6 +370,7 @@ my $compileOnly = 0; my $needCXXFLAGS = 0; # need to add CXX flags to compile step my $needCFLAGS = 0; # need to add C flags to compile step my $needLDFLAGS = 1; # need to add LDFLAGS to compile step. +my $fileTypeFlag = 0; # to see if -x flag is mentioned my $hasC = 0; # options contain a c-style file my $hasCXX = 0; # options contain a cpp-style file (NVCC must force recognition as GPU file) my $hasCU = 0; # options contain a cu-style file (HCC must force recognition as GPU file) @@ -655,6 +656,8 @@ foreach $arg (@ARGV) $toolArgs = substr $toolArgs, 0, -8; chomp $toolArgs; } + } elsif ($arg eq '-x') { + $fileTypeFlag = 1; } elsif ($arg eq 'c' and $prevArg eq '-x') { $hasC = 1; $hasCXX = 0; @@ -693,11 +696,17 @@ foreach $arg (@ARGV) } elsif ($prevArg ne '-o') { # input files and libraries # Skip guessing if `-x {c|c++|hip}` is already specified. - if (not ($hasC or $hasCXX or $hasHIP)) { + + # Add proper file extension before each file type + # File Extension -> Flag + # .c -> -x c + # .cpp/.cxx/.cc/.cu/.cuh/.hip -> -x hip + # rest of the files -> -x none + if ($fileTypeFlag eq 0) { if ($arg =~ /\.c$/) { $hasC = 1; $needCFLAGS = 1; - $toolArgs .= " -x c" + $toolArgs .= " -x c"; } elsif (($arg =~ /\.cpp$/) or ($arg =~ /\.cxx$/) or ($arg =~ /\.cc$/) ) { $needCXXFLAGS = 1; if ($HIP_COMPILE_CXX_AS_HIP eq '0' or $HIP_COMPILER ne "clang") { @@ -714,8 +723,13 @@ foreach $arg (@ARGV) } else { $hasCU = 1; } + } else { + if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") { + $toolArgs .= " -x none"; + } } - } elsif ($hasC) { + } + if ($hasC) { $needCFLAGS = 1; } elsif ($hasCXX) { $needCXXFLAGS = 1;